Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Sparse Merkle Tree #25

Open
tynes opened this issue Jun 19, 2019 · 2 comments
Open

Feature Request: Sparse Merkle Tree #25

tynes opened this issue Jun 19, 2019 · 2 comments

Comments

@tynes
Copy link
Member

tynes commented Jun 19, 2019

I think its possible to create a wrapper over lib/mrkl.js to create a sparse merkle tree with an easy to use API. This could be used to add commitments to all previous blocks in the block header, allowing for a Flyclient like construction. Light clients will be able to run even lighter as they will not need to index all previous blocks and can just keep the latest block indexed.

Potential API:

  • Constructor with hashing algo, number of leaves
  • Set an item at an index
  • Delete an item at an index
  • Get an item at an index
  • Push an item to the next index, when the consumer doesn't want to manage the index and just wants to add items to a set
  • Get root
  • Get proof (inclusion/exclusion)
  • Clear cache

It would also be cool to allow for passing custom read/write functions, similar to how bcoin has a custom createSocket function, so that different storage backends can be used/tested.

Is this something that you would consider for bcrypto?

@chjj
Copy link
Member

chjj commented Jun 20, 2019

A sparse merkle tree requires some kind of data management unless you're only going a few levels deep (unlikely).

The sparse merkle block commitment was an idea joseph and I had (as an alternative to the severely flawed way other projects are doing this). The basic notion is you allocate a sparse merkle tree 32 levels deep. You create an authenticated map of height(uint32) to hash. To get actual distribution at the leaves, you run the height through a perfect hash function before insertion (1 2 3).

32 bits is ~4.3 billion potential leaves, so that necessitates some kind of data management. This doesn't belong in bcrypto. It definitely justifies having its own repo.

We had an impl. of a sparse merkle tree to benchmark it against urkel a while ago. It's either in the urkel repo history or the btrie repo. If we decide to do this for handshake, I would probably just include it in the hsd repo.

edit: Also, note that this might be the only legitimate use-case for a sparse merkle tree in the blockchain space. It's far too slow to use for anything else.

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

No branches or pull requests

2 participants