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

Use leaf hashes only #212

Open
cmwaters opened this issue Jun 26, 2023 · 3 comments
Open

Use leaf hashes only #212

cmwaters opened this issue Jun 26, 2023 · 3 comments

Comments

@cmwaters
Copy link

NMT is built on top of some existing data structure. It is used to prove the absence or presence of some subset of data. In the case of Celestia, it is proving shares within an extended data square.

As the square already contains the underlying data, it is an unnecessary allocation of memory to also store the entire data in the leaves. Rather, in Push the hash of the contents should be provided alongside the namespace ID. Note the hashing function for the leaves can be different for the hashing function used for the rest of the tree. Doing this will keep the tree as lightweight as possible.

@cmwaters
Copy link
Author

Furthermore, we may look to remove the Get and GetWithProof methods.

@liamsi
Copy link
Member

liamsi commented Jun 28, 2023

As the square already contains the underlying data

true

it is an unnecessary allocation of memory to also store the entire data in the leaves

while I agree I wanted to note as the data is passed in as a slice, it is not really that wasteful (basically a reference).

in Push the hash of the contents should be provided alongside the namespace ID

Not sure. Counter arguments: if the hashing of the leaves is left to the caller, the tree becomes more difficult to be used correctly (e.g. no domain separation between inner and lead nodes) also this is quite uncommon as a merkle tree is supposed to hash the data.

That said, you are right that currently no one uses Get or GetWithProof and hence even the refs to the orig data are unnecessary.

@cmwaters
Copy link
Author

Not sure. Counter arguments: if the hashing of the leaves is left to the caller, the tree becomes more difficult to be used correctly (e.g. no domain separation between inner and lead nodes) also this is quite uncommon as a merkle tree is supposed to hash the data.

Yeah on second thought I think the nmt should have full control of the hashing method used

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