Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
merkleblock.cpp
Go to the documentation of this file.
1
// Copyright (c) 2020-present 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
FUZZ_TARGET
(merkleblock)
17
{
18
FuzzedDataProvider
fuzzed_data_provider(buffer.data(), buffer.size());
19
CPartialMerkleTree
partial_merkle_tree;
20
CallOneOf
(
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,
TX_WITH_WITNESS
);
31
CBloomFilter
bloom_filter;
32
std::set<Txid> 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
LIMITED_WHILE
(fuzzed_data_provider.
ConsumeBool
(), 10000) {
38
txids.insert(
Txid::FromUint256
(
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<Txid> matches;
47
std::vector<unsigned int> indices;
48
(void)partial_merkle_tree.
ExtractMatches
(matches, indices);
49
}
FuzzedDataProvider.h
CBloomFilter
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
Definition
bloom.h:45
CMerkleBlock
Used to relay blocks as header + vector<merkle branch> to filtered nodes.
Definition
merkleblock.h:127
CMerkleBlock::txn
CPartialMerkleTree txn
Definition
merkleblock.h:131
CPartialMerkleTree
Data structure that represents a partial merkle tree.
Definition
merkleblock.h:57
CPartialMerkleTree::GetNumTransactions
unsigned int GetNumTransactions() const
Get number of transactions the merkle proof is indicating for cross-reference with local blockchain k...
Definition
merkleblock.h:115
CPartialMerkleTree::ExtractMatches
uint256 ExtractMatches(std::vector< Txid > &vMatch, std::vector< unsigned int > &vnIndex)
extract the matching txid's represented by this partial merkle tree and their respective indices with...
Definition
merkleblock.cpp:152
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
transaction_identifier< false >::FromUint256
static transaction_identifier FromUint256(const uint256 &id)
Definition
transaction_identifier.h:49
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
LIMITED_WHILE
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition
fuzz.h:22
merkleblock.h
TX_WITH_WITNESS
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition
transaction.h:180
util.h
ConsumeUInt256
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition
util.h:167
CallOneOf
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition
util.h:35
ConsumeDeserializable
std::optional< T > ConsumeDeserializable(FuzzedDataProvider &fuzzed_data_provider, const P ¶ms, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition
util.h:100
uint256.h
Generated on
for Bitcoin Core by
1.17.0