Skip to content

Commit f866781

Browse files
committed
Check leaves size maximum in MerkleComputation
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.
1 parent 4d57288 commit f866781

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/consensus/merkle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <consensus/merkle.h>
66
#include <hash.h>
7+
#include <util/check.h>
78

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

0 commit comments

Comments
 (0)