Preserve duplicate leaves in Merkle proofs - #4
Closed
a-shannon wants to merge 1 commit into
Closed
Conversation
Author
|
Superseded by #5, which implements the same duplicate-leaf invariant using the selected single-structure design and is now merged. Closing this alternative. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
topNodeelementsHashIndexfor element lookup while verifying that the returned proof matches the requested hashRoot cause
MerkleTree.applykeeps duplicate leaves intopNode, butelementsHashIndexis amap from leaf hash to one index. Equal hashes therefore collapse in the map while
remaining separate positions in the tree.
length,proofByIndex, andproofByIndicesused that deduplicated map as if itwere the ordered leaf sequence. With duplicate leaves, traversal could return a
proof for another leaf that still validated against the root, while batch proofs
could reject valid indices or use the wrong leaf hashes.
This change traverses
topNodeonce to retain every leaf hash in order. Elementlookup continues to use the existing map and now fails closed if a manually
constructed map points at a leaf with a different hash.
Compatibility
rootHashare unchangedMerkleTreecase-class parameters and callable public JVM signature are unchangedMerkleProofandBatchMerkleProofformats and serializers are unchangedTests
sbt "+scryptoJVM/Test/testOnly scorex.crypto.authds.merkle.MerkleTreeSpecification"— 17 passed on each of Scala 2.11, 2.12, 2.13, and 3sbt "+scryptoJS/Test/testOnly scorex.crypto.authds.merkle.MerkleTreeSpecification"— 17 passed on each of Scala 2.13 and 3sbt "scryptoJVM/test" "scryptoJS/test"— JVM 171 passed; JS 128 passedgit diff --checkRelated work
Follow-up to
ergoplatform/ergo#2463and the node-local hotfixergoplatform/ergo#2469.