Bitcoin Core 22.99.0
P2P Digital Currency
merkleblock.cpp
Go to the documentation of this file.
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>
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
16FUZZ_TARGET(merkleblock)
17{
18 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
19 CPartialMerkleTree partial_merkle_tree;
21 fuzzed_data_provider,
22 [&] {
23 const std::optional<CPartialMerkleTree> opt_partial_merkle_tree = ConsumeDeserializable<CPartialMerkleTree>(fuzzed_data_provider);
24 if (opt_partial_merkle_tree) {
25 partial_merkle_tree = *opt_partial_merkle_tree;
26 }
27 },
28 [&] {
29 CMerkleBlock merkle_block;
30 const std::optional<CBlock> opt_block = ConsumeDeserializable<CBlock>(fuzzed_data_provider);
31 CBloomFilter bloom_filter;
32 std::set<uint256> txids;
33 if (opt_block && !opt_block->vtx.empty()) {
34 if (fuzzed_data_provider.ConsumeBool()) {
35 merkle_block = CMerkleBlock{*opt_block, bloom_filter};
36 } else if (fuzzed_data_provider.ConsumeBool()) {
37 while (fuzzed_data_provider.ConsumeBool()) {
38 txids.insert(ConsumeUInt256(fuzzed_data_provider));
39 }
40 merkle_block = CMerkleBlock{*opt_block, txids};
41 }
42 }
43 partial_merkle_tree = merkle_block.txn;
44 });
45 (void)partial_merkle_tree.GetNumTransactions();
46 std::vector<uint256> matches;
47 std::vector<unsigned int> indices;
48 (void)partial_merkle_tree.ExtractMatches(matches, indices);
49}
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
Definition: bloom.h:45
void insert(Span< const unsigned char > vKey)
Definition: bloom.cpp:48
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
Definition: merkleblock.h:125
CPartialMerkleTree txn
Definition: merkleblock.h:129
Data structure that represents a partial merkle tree.
Definition: merkleblock.h:55
uint256 ExtractMatches(std::vector< uint256 > &vMatch, std::vector< unsigned int > &vnIndex)
extract the matching txid's represented by this partial merkle tree and their respective indices with...
unsigned int GetNumTransactions() const
Get number of transactions the merkle proof is indicating for cross-reference with local blockchain k...
Definition: merkleblock.h:113
FUZZ_TARGET(merkleblock)
Definition: merkleblock.cpp:16
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:153
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition: util.h:40