From f86678156a3d3ce6488b383a2d6d91d28fcd2b73 Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Tue, 17 Dec 2024 10:11:54 +0700 Subject: [PATCH] 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. --- src/consensus/merkle.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/consensus/merkle.cpp b/src/consensus/merkle.cpp index 4b321d6c88b..7dd24e1868f 100644 --- a/src/consensus/merkle.cpp +++ b/src/consensus/merkle.cpp @@ -4,6 +4,7 @@ #include #include +#include /* 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 @@ -87,6 +88,7 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated) static void MerkleComputation(const std::vector& leaves, uint256* proot, bool* pmutated, uint32_t leaf_pos, std::vector* path) { if (path) path->clear(); + Assume(leaves.size() <= UINT32_MAX); if (leaves.size() == 0) { if (pmutated) *pmutated = false; if (proot) *proot = uint256();