Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Question : Are hashes being created differently. #16

Open
Vee-Emm opened this issue Feb 8, 2022 · 2 comments
Open

Question : Are hashes being created differently. #16

Vee-Emm opened this issue Feb 8, 2022 · 2 comments

Comments

@Vee-Emm
Copy link

Vee-Emm commented Feb 8, 2022

Hi ,
Apologies for posting here , had no other way of contacting or asking a question.
I am attempting to recreate a regular merkle tree using smtree in this project
https://github.com/Vee-Emm/smtreeDemo

This is a pymerkle implementation of tree generation .
https://github.com/Vee-Emm/smtreeDemo/blob/master/generateTree.py

However the hashes created from this function prints different values for the internal nodes.
https://github.com/Vee-Emm/smtreeDemo/blob/master/src/main.rs#L112

Are the hashes being created in a different way when using Sparse Merkle tree?
Is there a way to generate a regular MT using the smtree library or if there is an expectation of that being inlcuded in the future . If pointed in the right direction , I can attempt to help contribute towards that effort.
Please do let me know .

Thanks a bunch !
vee-Emm

@Vee-Emm
Copy link
Author

Vee-Emm commented Feb 10, 2022

Update : It appears that the Issue #13 was created to add support for simple merkle trees.
But it appears that there is a bug in the implementation . I am unable to find out the root cause .
Any push in the right direction would be appreciated !

@kchalkias
Copy link
Contributor

kchalkias commented Feb 12, 2022

Hi @Vee-Emm
spent some time to explore the issue and realized that pymerkle is not pure concatenation of child nodes to parents but to defend against second-preimage attacks:

  • Before computing the hash of a leaf, prepends the corresponding record with 0x00
  • Before computing the hash of any interior node, prepends both of its parents' hashes with 0x01,

While the current MTreeNodeSmt defines merging of two nodes as pure concatenation then hash (no prepending bytes). But this is normal, in our lib you can define templates based on your desired functionality by just implementing a few traits (i.e., Mergeable in our case).

Note that to be fully compatible with pymerkle (for a non balanced Merkle tree) you need to define how padding works for the non-existing right most leaves. I could create that template for you if you prefer and enable it by default to our lib.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants