aboutsummaryrefslogtreecommitdiff
path: root/src/merkleblock.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-01-02 17:59:54 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2015-01-02 18:06:52 +0100
commitf55c5e9749b4d010003d667421f0313e75372ddb (patch)
tree33157763bf245f55b947fdfb1001aae867e2f006 /src/merkleblock.cpp
parentc986972ad77242664c41c5e6fe07214e84aadd82 (diff)
parent012598880cf69a6a4d4d495c78e40ab4abb4eb39 (diff)
Merge pull request #5349
0125988 Implement test for merkle tree malleability in CPartialMerkleTree (Pieter Wuille)
Diffstat (limited to 'src/merkleblock.cpp')
-rw-r--r--src/merkleblock.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp
index 1b7ee27e02..f9006d46d5 100644
--- a/src/merkleblock.cpp
+++ b/src/merkleblock.cpp
@@ -93,10 +93,16 @@ uint256 CPartialMerkleTree::TraverseAndExtract(int height, unsigned int pos, uns
} else {
// otherwise, descend into the subtrees to extract matched txids and hashes
uint256 left = TraverseAndExtract(height-1, pos*2, nBitsUsed, nHashUsed, vMatch), right;
- if (pos*2+1 < CalcTreeWidth(height-1))
+ if (pos*2+1 < CalcTreeWidth(height-1)) {
right = TraverseAndExtract(height-1, pos*2+1, nBitsUsed, nHashUsed, vMatch);
- else
+ if (right == left) {
+ // If the left and right branch should never be identical as the transaction
+ // hashes covered by them must be unique.
+ fBad = true;
+ }
+ } else {
right = left;
+ }
// and combine them before returning
return Hash(BEGIN(left), END(left), BEGIN(right), END(right));
}