mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Merge pull request #4926
584a358 Do merkle root and txid duplicates check simultaneously (Pieter Wuille)
This commit is contained in:
15
src/main.cpp
15
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user