Skip to content

Commit 2d8495e

Browse files
committed
[validation] Merkle root malleation should be caught by IsBlockMutated
1 parent 66abce1 commit 2d8495e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/test/validation_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44

55
#include <chainparams.h>
66
#include <consensus/amount.h>
7+
#include <consensus/merkle.h>
8+
#include <core_io.h>
9+
#include <hash.h>
710
#include <net.h>
811
#include <signet.h>
912
#include <uint256.h>
1013
#include <util/chaintype.h>
1114
#include <validation.h>
1215

16+
#include <string>
17+
1318
#include <test/util/setup_common.h>
1419

1520
#include <boost/test/unit_test.hpp>

src/validation.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3833,7 +3833,18 @@ bool IsBlockMutated(const CBlock& block, bool check_witness_root)
38333833
}
38343834

38353835
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
3836-
return false;
3836+
// Consider the block mutated if any transaction is 64 bytes in size (see 3.1
3837+
// in "Weaknesses in Bitcoin’s Merkle Root Construction":
3838+
// https://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20190225/a27d8837/attachment-0001.pdf).
3839+
//
3840+
// Note: This is not a consensus change as this only applies to blocks that
3841+
// don't have a coinbase transaction and would therefore already be invalid.
3842+
return std::any_of(block.vtx.begin(), block.vtx.end(),
3843+
[](auto& tx) { return GetSerializeSize(TX_NO_WITNESS(tx)) == 64; });
3844+
} else {
3845+
// Theoretically it is still possible for a block with a 64 byte
3846+
// coinbase transaction to be mutated but we neglect that possibility
3847+
// here as it requires at least 224 bits of work.
38373848
}
38383849

38393850
if (!CheckWitnessMalleation(block, check_witness_root, state)) {

0 commit comments

Comments
 (0)