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

verifier.py: fix CVE-2012-2459: reject left-sibling duplicates

Public commit record

What the developer wrote

Authored by SomberNight

93/100 · Strong
verifier.py: fix CVE-2012-2459: reject left-sibling duplicates

Due to how the txid-commitment merkle tree used in the block headers is constructed, we need an extra check to be able to validate the *position* of a txid in a block.

I think this is low severity for us.

See https://bitcointalk.org/?topic=102395 :

> The Merkle hash implementation that Bitcoin uses to calculate the Merkle
> root in a block header is flawed in that one can easily construct multiple
> lists of hashes that map to the same Merkle root.
> For example, merkle_hash([a, b, c]) and merkle_hash([a, b, c, c]) yield
> the same result. This is because, at every iteration, the Merkle hash
> function pads its intermediate list of hashes with the last hash if the
> list is of odd length, in order to make it of even length.
>
> And so, the Merkle root function can be effectively preimaged by
> changing the input so that one of the intermediate lists is of even
> length with the last two elements equal (where originally it was
> of odd length with a last element equal to the earlier mentioned two).
> As was later noted, this extends to any input length that is
> not a power of two:
> merkle_hash([a, b, c, d, e, f]) == merkle_hash([a, b, c, d, e, f, e, f]).
> Note that to maintain the same root hash, the only flexibility that
> exists is duplication of elements.

Ported from https://github.com/Electron-Cash/Electron-Cash/commit/165146362b4cb0ad74770b36aca1f9acb2800195

Co-authored-by: bitcoincashautist <80100588+A60AB5450353F40E@users.noreply.github.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a known Bitcoin weakness (CVE-2012-2459) in Electrum's light-client verification. Because Bitcoin's Merkle tree duplicates the last hash when a level has an odd number of items, an attacker can craft a block proof that makes a transaction appear to be at a different position than it really is. The patch rejects proofs where a duplicated value appears on the left side of a hash pair, which only happens in forged proofs. The commit also adds tests for the fix and re-labels an existing related defense for CVE-2017-12842.

Recommended action

Apply this patch and run the new verifier tests. Users relying on SPV verification should upgrade to a release containing this fix. No immediate user action beyond updating is required.

Security signals we found

01

Fixes CVE-2012-2459 (Merkle tree duplicate-node weakness)

02

Adds explicit LeftSiblingDuplicate exception

03

Strengthens SPV Merkle proof verification

04

Includes regression tests using testnet3 block 4909055

05

References prior CVE-2017-12842 defense already present in same function

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.