Skip to content

Commit

Permalink
Check leaves size maximum in MerkleComputation
Browse files Browse the repository at this point in the history
Belt and suspenders for future code changes.

Currently this function is only called from TransactionMerklePath() which sets leaves to the block transactions, so the Assume always holds.
  • Loading branch information
Sjors committed Dec 17, 2024
1 parent 4d57288 commit f866781
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/consensus/merkle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <consensus/merkle.h>
#include <hash.h>
#include <util/check.h>

/* WARNING! If you're reading this because you're learning about crypto
and/or designing a new system that will use merkle trees, keep in mind
Expand Down Expand Up @@ -87,6 +88,7 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated)
static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot, bool* pmutated, uint32_t leaf_pos, std::vector<uint256>* path)
{
if (path) path->clear();
Assume(leaves.size() <= UINT32_MAX);
if (leaves.size() == 0) {
if (pmutated) *pmutated = false;
if (proot) *proot = uint256();
Expand Down

0 comments on commit f866781

Please sign in to comment.