merkle: remove unused `proot` and `pmutated` args from `MerkleComputation`
What changed, and why it matters
This is a small code cleanup in Bitcoin Core's merkle tree calculation. It removes two unused parameters (`proot` and `pmutated`) from an internal helper function because the only place that called it always passed `nullptr` for both. There is no security issue here—just simplification of the code.
No action needed. This is a benign refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors MerkleComputation() in src/consensus/merkle.cpp to remove the proot and pmutated output pointer arguments, since ComputeMerklePath() was the sole caller and always passed nullptr. The function now only computes a Merkle path. The unused mutated flag and root computation logic are removed. This is a pure cleanup with no functional or security change.
Changed components
src/consensus/merkle.cppInspect captured patch +3 / −10
diff --git a/src/consensus/merkle.cpp b/src/consensus/merkle.cpp
index 94e8effe..d7f1435f 100644
--- a/src/consensus/merkle.cpp
+++ b/src/consensus/merkle.cpp
@@ -84,17 +84,14 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated)
return ComputeMerkleRoot(std::move(leaves), mutated);
}
-/* This implements a constant-space merkle root/path calculator, limited to 2^32 leaves. */
-static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot, bool* pmutated, uint32_t leaf_pos, std::vector<uint256>& path)
+/* This implements a constant-space merkle path calculator, limited to 2^32 leaves. */
+static void MerkleComputation(const std::vector<uint256>& leaves, uint32_t leaf_pos, std::vector<uint256>& path)
{
path.clear();
Assume(leaves.size() <= UINT32_MAX);
if (leaves.size() == 0) {
- if (pmutated) *pmutated = false;
- if (proot) *proot = uint256();
return;
}
- bool mutated = false;
// count is the number of leaves processed so far.
uint32_t count = 0;
// inner is an array of eagerly computed subtree hashes, indexed by tree
@@ -121,7 +118,6 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
path.push_back(h);
matchh = true;
}
- mutated |= (inner[level] == h);
h = Hash(inner[level], h);
}
// Store the resulting hash at inner position level.
@@ -165,14 +161,11 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
level++;
}
}
- // Return result.
- if (pmutated) *pmutated = mutated;
- if (proot) *proot = h;
}
static std::vector<uint256> ComputeMerklePath(const std::vector<uint256>& leaves, uint32_t position) {
std::vector<uint256> ret;
- MerkleComputation(leaves, nullptr, nullptr, position, ret);
+ MerkleComputation(leaves, position, ret);
return ret;
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.