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.
This commit is contained in:
Sjors Provoost 2024-12-17 10:11:54 +07:00
parent 4d57288246
commit f86678156a
No known key found for this signature in database
GPG key ID: 57FF9BDBCC301009

View file

@ -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
@ -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();