fix: add domain separation and depth bound to Merkle verification - #830
Open
Awesome254 wants to merge 5 commits into
Open
fix: add domain separation and depth bound to Merkle verification#830Awesome254 wants to merge 5 commits into
Awesome254 wants to merge 5 commits into
Conversation
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.
Overview
This PR hardens
merkle::verify_merkle_proofagainst second-preimage attacks and excessive proof lengths. Leaf hashes are now prefixed with0x00, internal node hashes with0x01, and proof iteration is capped atMAX_PROOF_DEPTH = 32. The Rust merkle implementation andscripts/merkle.tsare aligned, and the encoding/depth behavior is documented with cross-implementation test vectors.Related Issue
Changes
🔒 Merkle Verification Hardening
[MODIFY]
src/constants.rsMERKLE_LEAF_PREFIX = 0x00,MERKLE_INTERNAL_PREFIX = 0x01, andMAX_PROOF_DEPTH = 32.[MODIFY]
src/errors.rsMerkleProofTooLongerror for proofs longer thanMAX_PROOF_DEPTH.[MODIFY]
src/merkle.rsverify_merkle_proof; reject longer proofs withMerkleProofTooLong.verify_merkle_proofreturnsleaf == rootfor a single-member tree.[MODIFY]
src/merkle_test.rsMAX_PROOF_DEPTHrejection, empty-proof behavior, and cross-implementation vectors.[MODIFY]
scripts/merkle.ts0x00 ‖ leaf_dataand internal nodes as0x01 ‖ left ‖ right.📚 Documentation
docs/whitelist-merkle.md0x00/0x01encodings and the 32-level depth bound.🧪 Cross-Implementation Test Vectors
Verification Results
scripts/merkle.ts0x00leaf /0x01internal prefixes in Rust and TypeScript; test vectors matchMAX_PROOF_DEPTHare rejected with a dedicated errorMerkleProofTooLongreturned for depth > 32docs/whitelist-merkle.mddocuments the encoding and the depth boundMAX_PROOF_DEPTHdocumentedCloses #650