| 25 | } |
| 26 | |
| 27 | FUZZ_TARGET(script_flags) |
| 28 | { |
| 29 | if (buffer.size() > 100'000) return; |
| 30 | SpanReader ds{buffer}; |
| 31 | try { |
| 32 | const CTransaction tx(deserialize, TX_WITH_WITNESS, ds); |
| 33 | |
| 34 | script_verify_flags verify_flags; |
| 35 | ds >> verify_flags; |
| 36 | |
| 37 | assert(verify_flags == script_verify_flags::from_int(verify_flags.as_int())); |
| 38 | |
| 39 | if (!IsValidFlagCombination(verify_flags)) return; |
| 40 | |
| 41 | script_verify_flags fuzzed_flags; |
| 42 | ds >> fuzzed_flags; |
| 43 | |
| 44 | std::vector<CTxOut> spent_outputs; |
| 45 | for (unsigned i = 0; i < tx.vin.size(); ++i) { |
| 46 | CTxOut prevout; |
| 47 | ds >> prevout; |
| 48 | if (!MoneyRange(prevout.nValue)) { |
| 49 | // prevouts should be consensus-valid |
| 50 | prevout.nValue = 1; |
| 51 | } |
| 52 | spent_outputs.push_back(prevout); |
| 53 | } |
| 54 | PrecomputedTransactionData txdata; |
| 55 | txdata.Init(tx, std::move(spent_outputs)); |
| 56 | |
| 57 | for (unsigned i = 0; i < tx.vin.size(); ++i) { |
| 58 | const CTxOut& prevout = txdata.m_spent_outputs.at(i); |
| 59 | const TransactionSignatureChecker checker{&tx, i, prevout.nValue, txdata, MissingDataBehavior::ASSERT_FAIL}; |
| 60 | |
| 61 | ScriptError serror; |
| 62 | const bool ret = VerifyScript(tx.vin.at(i).scriptSig, prevout.scriptPubKey, &tx.vin.at(i).scriptWitness, verify_flags, checker, &serror); |
| 63 | assert(ret == (serror == SCRIPT_ERR_OK)); |
| 64 | |
| 65 | // Verify that removing flags from a passing test or adding flags to a failing test does not change the result |
| 66 | if (ret) { |
| 67 | verify_flags &= ~fuzzed_flags; |
| 68 | } else { |
| 69 | verify_flags |= fuzzed_flags; |
| 70 | } |
| 71 | if (!IsValidFlagCombination(verify_flags)) return; |
| 72 | |
| 73 | ScriptError serror_fuzzed; |
| 74 | const bool ret_fuzzed = VerifyScript(tx.vin.at(i).scriptSig, prevout.scriptPubKey, &tx.vin.at(i).scriptWitness, verify_flags, checker, &serror_fuzzed); |
| 75 | assert(ret_fuzzed == (serror_fuzzed == SCRIPT_ERR_OK)); |
| 76 | |
| 77 | assert(ret_fuzzed == ret); |
| 78 | } |
| 79 | } catch (const std::ios_base::failure&) { |
| 80 | return; |
| 81 | } |
| 82 | } |
nothing calls this directly
no test coverage detected