18 if (position >= block.
vtx.size()) {
19 throw std::out_of_range(
"Position out of range");
22 uint256 current_hash = block.
vtx[position]->GetHash().ToUint256();
24 for (
const uint256& sibling : merkle_path) {
25 if (position % 2 == 0) {
26 current_hash =
Hash(current_hash, sibling);
28 current_hash =
Hash(sibling, current_hash);
30 position = position / 2;
40 const bool with_witness = fuzzed_data_provider.
ConsumeBool();
45 const size_t num_txs = block->vtx.size();
46 std::vector<uint256> tx_hashes;
47 tx_hashes.reserve(num_txs);
49 for (
size_t i = 0; i < num_txs; ++i) {
50 tx_hashes.push_back(block->vtx[i]->GetHash().ToUint256());
58 if (tx_hashes.size() == 1) {
59 assert(merkle_root == tx_hashes[0]);
64 if (tx_hashes.size() == 1) {
65 assert(block_merkle_root == tx_hashes[0]);
68 if (!block->vtx.empty()){
70 if (tx_hashes.size() == 1) {
76 const uint32_t position = fuzzed_data_provider.
ConsumeIntegralInRange<uint32_t>(0, num_txs > 0 ? num_txs - 1 : 0);
80 if (tx_hashes.size() > 1) {
82 assert(merkle_root_from_merkle_path == merkle_root);
83 assert(merkle_root_from_merkle_path == block_merkle_root);
87 assert(merkle_path.size() <= 32);
88 if (num_txs == 1 || num_txs == 0) {
89 assert(merkle_path.empty());
std::vector< CTransactionRef > vtx
T ConsumeIntegralInRange(T min, T max)
uint256 ComputeMerkleRoot(std::vector< uint256 > hashes, bool *mutated)
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
std::vector< uint256 > TransactionMerklePath(const CBlock &block, uint32_t position)
Compute merkle path to the specified transaction.
uint256 BlockWitnessMerkleRoot(const CBlock &block, bool *mutated)
uint256 Hash(const T &in1)
Compute the 256-bit hash of an object.
static constexpr TransactionSerParams TX_NO_WITNESS
static constexpr TransactionSerParams TX_WITH_WITNESS
uint256 ComputeMerkleRootFromPath(const CBlock &block, uint32_t position, const std::vector< uint256 > &merkle_path)