diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-10-02 06:05:02 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-10-02 06:10:19 +0200 |
commit | 76c171033ccca628d3e563d898b38d74f3e51f5c (patch) | |
tree | 10d2b0c4bf4cacdfadd13cbd46e1112c75ed78d2 /src/main.cpp | |
parent | 471d38b01534dd786d7d3dc7a62809755c3418ed (diff) | |
parent | 584a358997e52a87e8c5402269c7fb3784ed2065 (diff) | |
download | bitcoin-76c171033ccca628d3e563d898b38d74f3e51f5c.tar.xz |
Merge pull request #4926
584a358 Do merkle root and txid duplicates check simultaneously (Pieter Wuille)
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5a5c700574..32393e5e03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2236,13 +2236,12 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo if (!CheckTransaction(tx, state)) return error("CheckBlock() : CheckTransaction failed"); - // Check for duplicate txids. This is caught by ConnectInputs(), - // but catching it earlier avoids a potential DoS attack: - set<uint256> uniqueTx; - BOOST_FOREACH(const CTransaction &tx, block.vtx) { - uniqueTx.insert(tx.GetHash()); - } - if (uniqueTx.size() != block.vtx.size()) + // Check for merkle tree malleability (CVE-2012-2459): repeating sequences + // of transactions in a block without affecting the merkle root of a block, + // while still invalidating it. + bool mutated; + uint256 hashMerkleRoot2 = block.BuildMerkleTree(&mutated); + if (mutated) return state.DoS(100, error("CheckBlock() : duplicate transaction"), REJECT_INVALID, "bad-txns-duplicate", true); @@ -2256,7 +2255,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo REJECT_INVALID, "bad-blk-sigops", true); // Check merkle root - if (fCheckMerkleRoot && block.hashMerkleRoot != block.BuildMerkleTree()) + if (fCheckMerkleRoot && block.hashMerkleRoot != hashMerkleRoot2) return state.DoS(100, error("CheckBlock() : hashMerkleRoot mismatch"), REJECT_INVALID, "bad-txnmrklroot", true); |