AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 62 Bitcoin

bitcoin: reject ambiguous merkle trees in MerkleNode::calculate_root

Public commit record

What the developer wrote

Authored by Andrew Poelstra

86/100 · Strong
bitcoin: reject ambiguous merkle trees in MerkleNode::calculate_root

CVE 2012-2459 is about an ambiguity in Bitcoin's merkle root calculation
used to embed transactions in blocks. It is possible to take a valid
block, duplicate some sets of transactions, and obtain an invalid block
with the same hash. This can confuse nodes into incorrectly rejecting
the valid block.

Instead, following Core, when we detect duplicated transactions that
would cause this bug, we just refuse to return the Merkle root. Then
there is nothing that the node can get confused by; it will reject the
bad block (which is definitely bad, since it has duplicate transactions)
and move on with its life.

This patch is really just three lines (well, one line in an if guard)
plus a bunch of comments.

Fixes #5023

Thanks to Github user tm0, who responsibly disclosed this issue (though
I decided it was outside of our security boundary and requested that
they open a public issue).
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a bug in how the library calculates the Merkle root, a fingerprint used to summarize all transactions in a Bitcoin block. An old Bitcoin vulnerability (CVE 2012-2459) lets someone craft a block with duplicate transactions that produces the same fingerprint as a valid block, potentially tricking software into rejecting the real block. The patch makes the library refuse to compute the root whenever it sees the duplicate pattern, so the invalid block is simply rejected and no confusion can occur.

Recommended action

Review downstream callers of `compute_merkle_root`, `compute_witness_root`, and `MerkleNode::calculate_root` to ensure they handle the new `None` case rather than unwrapping, since the patch now returns `None` for duplicate transaction patterns as well as empty iterators. Consider whether the trait bound change from `Copy` to `Copy + PartialEq` breaks any external implementers.

Security signals we found

01

Fixes CVE 2012-2459 duplicate-transaction Merkle-root ambiguity

02

Adds equality-based rejection of duplicate sibling hashes in Merkle tree construction

03

Changes public API return semantics from empty-only None to also None on duplicate patterns

04

Tightens trait bound to PartialEq to support the new check

05

Updates test to assert that a forged duplicate block now fails validation

Risk score

Why this scored 62/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.