MCPcopy Create free account
hub / github.com/ElementsProject/elements / FUZZ_TARGET_INIT

Function FUZZ_TARGET_INIT

src/test/fuzz/script_flags.cpp:19–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19FUZZ_TARGET_INIT(script_flags, initialize_script_flags)
20{
21 CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
22 try {
23 int nVersion;
24 ds >> nVersion;
25 ds.SetVersion(nVersion);
26 } catch (const std::ios_base::failure&) {
27 return;
28 }
29
30 try {
31 const CTransaction tx(deserialize, ds);
32
33 unsigned int verify_flags;
34 ds >> verify_flags;
35
36 if (!IsValidFlagCombination(verify_flags)) return;
37
38 unsigned int fuzzed_flags;
39 ds >> fuzzed_flags;
40
41 std::vector<CTxOut> spent_outputs;
42 for (unsigned i = 0; i < tx.vin.size(); ++i) {
43 CTxOut prevout;
44 ds >> prevout;
45 if (!MoneyRange(prevout.nValue.GetAmount())) {
46 // prevouts should be consensus-valid
47 prevout.nValue.SetToAmount(1);
48 }
49 spent_outputs.push_back(prevout);
50 }
51 PrecomputedTransactionData txdata;
52 txdata.Init(tx, std::move(spent_outputs));
53
54 for (unsigned i = 0; i < tx.vin.size(); ++i) {
55 const CTxOut& prevout = txdata.m_spent_outputs.at(i);
56 const TransactionSignatureChecker checker{&tx, i, prevout.nValue, txdata, MissingDataBehavior::ASSERT_FAIL};
57
58 ScriptError serror;
59 const CScriptWitness *script_witness = tx.witness.vtxinwit.size() > i ? &tx.witness.vtxinwit[i].scriptWitness : nullptr;
60 const bool ret = VerifyScript(tx.vin.at(i).scriptSig, prevout.scriptPubKey, script_witness, verify_flags, checker, &serror);
61 assert(ret == (serror == SCRIPT_ERR_OK));
62
63 // Verify that removing flags from a passing test or adding flags to a failing test does not change the result
64 if (ret) {
65 verify_flags &= ~fuzzed_flags;
66 } else {
67 verify_flags |= fuzzed_flags;
68 }
69 if (!IsValidFlagCombination(verify_flags)) return;
70
71 ScriptError serror_fuzzed;
72 const bool ret_fuzzed = VerifyScript(tx.vin.at(i).scriptSig, prevout.scriptPubKey, script_witness, verify_flags, checker, &serror_fuzzed);
73 assert(ret_fuzzed == (serror_fuzzed == SCRIPT_ERR_OK));
74
75 assert(ret_fuzzed == ret);
76 }

Callers

nothing calls this directly

Calls 9

IsValidFlagCombinationFunction · 0.85
VerifyScriptFunction · 0.85
GetAmountMethod · 0.80
SetToAmountMethod · 0.80
MoneyRangeFunction · 0.50
SetVersionMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected