Skip to content

Commit

Permalink
fuzz: add coverage for `bitcoinconsensus_verify_script_with_spent_out…
Browse files Browse the repository at this point in the history
…puts`

Co-authored-by: Antonie Poinsot <[email protected]>
  • Loading branch information
brunoerg and darosior committed Oct 13, 2023
1 parent c5f2a75 commit ff8e2fc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/test/fuzz/script_bitcoin_consensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,23 @@ FUZZ_TARGET(script_bitcoin_consensus)
}
(void)bitcoinconsensus_verify_script(random_bytes_1.data(), random_bytes_1.size(), random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p);
(void)bitcoinconsensus_verify_script_with_amount(random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(), n_in, flags, err_p);

std::vector<UTXO> spent_outputs;
std::vector<std::vector<unsigned char>> spent_spks;
if (n_in <= 24386) {
spent_outputs.reserve(n_in);
spent_spks.reserve(n_in);
for (size_t i = 0; i < n_in; ++i) {
spent_spks.push_back(ConsumeRandomLengthByteVector(fuzzed_data_provider));
const CAmount value{ConsumeMoney(fuzzed_data_provider)};
const auto spk_size{static_cast<unsigned>(spent_spks.back().size())};
spent_outputs.push_back({.scriptPubKey = spent_spks.back().data(), .scriptPubKeySize = spk_size, .value = value});
}
}

const auto spent_outs_size{static_cast<unsigned>(spent_outputs.size())};

(void)bitcoinconsensus_verify_script_with_spent_outputs(
random_bytes_1.data(), random_bytes_1.size(), money, random_bytes_2.data(), random_bytes_2.size(),
spent_outputs.data(), spent_outs_size, n_in, flags, err_p);
}

0 comments on commit ff8e2fc

Please sign in to comment.