Skip to content

Fix bitcoin's broken merkle tree #5

Closed

Description

@chjj

Bitcoin's merkle tree hashes odd nodes with themselves (or nodes without a right sibling, I should say), leading to the duplicate txid vulnerability (a duplicate txid placed after an odd leaf ends up creating the same root as the valid block's commitment).

Switching to the type of merkle tree described in RFC6962 would be preferrable (it simply propagates odd nodes up a level without hashing them). It also has some other benefits: i.e. the ability to prove a leaf vs. an internal node.

We could also require the leaves to be sorted for non-existence proofs.

edit: RFC6962: https://tools.ietf.org/html/rfc6962#section-2.1

Activity

  1. chjj commented on Jun 8, 2018

    @chjj
    ContributorAuthor

    RFC7574 is also an option. It looks like it pads the leaves with zero hashes until the amount of leaves reaches the nearest power of two (?). This is nicer than rfc6962 in that all the leaves are guaranteed to be the same depth. Might make dealing with proofs more sane.

    Though, if we just wanted the leaves to be the same depth, we could do a combination of both. RFC6962-style, but if the leaves are odd, we pad them with a single zero-hash. This ensures that the odd leaf never gets propagated up. For all levels above the leaves, we propagate the odd hash up.

    edit: See also, bittorrent's BEP 0030: http://bittorrent.org/beps/bep_0030.html

  2. chjj commented on Jun 8, 2018

    @chjj
    ContributorAuthor

    Note that changing any of this will also require changing the bip37-style SPV (which we should remove in the future anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions