Branch data Line data Source code
1 : : // Copyright (c) 2020-2021 The Bitcoin Core developers
2 : : // Distributed under the MIT software license, see the accompanying
3 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 : :
5 : : #include <merkleblock.h>
6 : : #include <test/fuzz/FuzzedDataProvider.h>
7 : : #include <test/fuzz/fuzz.h>
8 : : #include <test/fuzz/util.h>
9 : : #include <uint256.h>
10 : :
11 : : #include <cstdint>
12 : : #include <optional>
13 : : #include <string>
14 : : #include <vector>
15 : :
16 [ + - ]: 966 : FUZZ_TARGET(merkleblock)
17 : : {
18 : 534 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19 : 534 : CPartialMerkleTree partial_merkle_tree;
20 [ + - ]: 534 : CallOneOf(
21 : : fuzzed_data_provider,
22 : 92 : [&] {
23 : 92 : const std::optional<CPartialMerkleTree> opt_partial_merkle_tree = ConsumeDeserializable<CPartialMerkleTree>(fuzzed_data_provider);
24 [ + + ]: 92 : if (opt_partial_merkle_tree) {
25 [ + - ]: 59 : partial_merkle_tree = *opt_partial_merkle_tree;
26 : : }
27 : 92 : },
28 : 442 : [&] {
29 : 442 : CMerkleBlock merkle_block;
30 : 442 : const std::optional<CBlock> opt_block = ConsumeDeserializable<CBlock>(fuzzed_data_provider, TX_WITH_WITNESS);
31 [ + + ]: 442 : CBloomFilter bloom_filter;
32 [ + + ]: 442 : std::set<Txid> txids;
33 [ + + + + ]: 442 : if (opt_block && !opt_block->vtx.empty()) {
34 [ + + ]: 238 : if (fuzzed_data_provider.ConsumeBool()) {
35 [ + - ]: 76 : merkle_block = CMerkleBlock{*opt_block, bloom_filter};
36 [ + + ]: 162 : } else if (fuzzed_data_provider.ConsumeBool()) {
37 [ + + + + ]: 23441 : LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
38 [ + - ]: 23316 : txids.insert(Txid::FromUint256(ConsumeUInt256(fuzzed_data_provider)));
39 : : }
40 [ + - ]: 125 : merkle_block = CMerkleBlock{*opt_block, txids};
41 : : }
42 : : }
43 [ + - ]: 442 : partial_merkle_tree = merkle_block.txn;
44 : 1326 : });
45 : 534 : (void)partial_merkle_tree.GetNumTransactions();
46 : 534 : std::vector<uint256> matches;
47 : 534 : std::vector<unsigned int> indices;
48 [ + - ]: 534 : (void)partial_merkle_tree.ExtractMatches(matches, indices);
49 : 1068 : }
|