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

Introduce SimpleMerkleTree & migrate to ethers.js #31

Closed
wants to merge 27 commits into from

Conversation

Amxx
Copy link
Contributor

@Amxx Amxx commented Dec 16, 2023

Fixes #30
Partially Fixes #13

This PR:

  • Replaces previous tooling with ethers.js
    • Core now support BytesLike (hex strings and Uint8Arrays)
    • All values are returnes as hex strings (proofs, leaf hashes, ...)
  • Fixe the Bytes (now BytesLike) compare function. (See Compare bytes does not correctly compare array of different length #30)
  • Introduce a SimpleMerkleTree (in parallele to the existing StandardMerkleTree)
    • No encoding
    • Leafs are all BytesLike with length 32bytes
    • Provides the same interface as StandardMerkleTree, with the exception of leafHash which is irrelevant
    • This can be used to in conjunction with a custom hashing function to represent trees that don't do the recommanded double hashing.

Rational:

Merkle tree have been built using other tools before this library was available. Some of these trees do not use double hashing, and are thus not representable using the existing StandardMerkleTree class. This prevents devs that have to deal with these trees from using this library.
The goal is NOT to encourage not using double hashes. StandardMerkleTree should be prefered for new trees. The goal is to provide a migration path to user that would want to manipulate old trees with this new library.

TODO

  • Documentation

@frangio
Copy link
Contributor

frangio commented Dec 17, 2023

Using the ethers package increases the installation size from 7.2M to 24M... I would not do that. It's heavy and a lot of people are using Viem now, so I think it would be better for this library to stay agnostic.

We can install the bytes utilities only with the package @ethersproject/bytes. Note that it's Ethers v5 code but it should be fine.

@Amxx
Copy link
Contributor Author

Amxx commented Dec 18, 2023

Is there an easy way to check the install size of a package you are working on ?

@frangio
Copy link
Contributor

frangio commented Dec 18, 2023

Not that I know of. I did npm pack and then installed the tarball in a fresh directory after npm init -y.


Is there an issue with native bigint?

@Amxx
Copy link
Contributor Author

Amxx commented Dec 18, 2023

Is there an issue with native bigint?

The issue is that I don't think about them

@Amxx Amxx marked this pull request as ready for review January 11, 2024 13:05
@ernestognw ernestognw mentioned this pull request Feb 23, 2024
@Amxx
Copy link
Contributor Author

Amxx commented Feb 26, 2024

Replaced by #36

@Amxx Amxx closed this Feb 26, 2024
@Amxx Amxx deleted the support-raw-leaves branch February 27, 2024 19:58
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.

Compare bytes does not correctly compare array of different length Customize leaf hash function
2 participants