Skip to content

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

Open
SomberNight wants to merge 1 commit intospesmilo:masterfrom
SomberNight:202604_verifier_left_sibling_duplicates
Open

verifier.py: fix CVE-2012-2459: reject left-sibling duplicates#10568
SomberNight wants to merge 1 commit intospesmilo:masterfrom
SomberNight:202604_verifier_left_sibling_duplicates

Conversation

@SomberNight
Copy link
Copy Markdown
Member

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 Electron-Cash@1651463

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 Electron-Cash@1651463

Co-authored-by: bitcoincashautist <80100588+A60AB5450353F40E@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant