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

Tree corruption when leaves have identical hashes #3

Open
kaxxa123 opened this issue Nov 7, 2024 · 1 comment
Open

Tree corruption when leaves have identical hashes #3

kaxxa123 opened this issue Nov 7, 2024 · 1 comment
Labels
bug Something isn't working merkle-h0 Merkle tree implementing the H(0 | 0) = 0 optimization. merkle-naive Naive merkle tree implementation merkle-single-leaf Merkle tree implementing basic optimization for single non-zero leaf subtrees.

Comments

@kaxxa123
Copy link
Owner

kaxxa123 commented Nov 7, 2024

In SMTHashZero, SMTNaive and SMTSingleLeaf the leaf hash is simply computed as Hash(value), where value is directly provided on calling addLeaf. This can easily lead to leaves and subtrees to have identical hashes.

In these cases different trees branches will end up sharing common nodes.

Editing one such "repeated" leaf can corrupt the SMT as the shared nodes are deleted on replacing.

The same problem is not present in SMTSingleLeafEx whose hashes leaves as Hash(index | value | 1).

@kaxxa123 kaxxa123 added bug Something isn't working merkle-naive Naive merkle tree implementation merkle-h0 Merkle tree implementing the H(0 | 0) = 0 optimization. merkle-single-leaf Merkle tree implementing basic optimization for single non-zero leaf subtrees. labels Nov 7, 2024
@kaxxa123
Copy link
Owner Author

kaxxa123 commented Nov 8, 2024

Can be fixed in one of the following ways:

  1. Remove node deletion code. Node deletion is only done to cleanup resources.
  2. Ensure all leaves have a unique hash as in SMTSingleLeafEx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working merkle-h0 Merkle tree implementing the H(0 | 0) = 0 optimization. merkle-naive Naive merkle tree implementation merkle-single-leaf Merkle tree implementing basic optimization for single non-zero leaf subtrees.
Projects
None yet
Development

No branches or pull requests

1 participant