Repository navigation
Conversation
This branch has not been deployed
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.
I reported this bug first through the repository's private security advisory form. This PR contains the fix.
Problem
A LeanIMT root does not commit to the leaf count. So a verifier must calculate each level's group size from
leaf_indexandtree_size. Two functions trusted the shape that the proof carries instead:NaryProof::verifyaccepted anysibling_countup toN - 1at each level. With the real root andtree_size, a forged proof could make an internal node verify as a leaf. Where the real group is a lift, one half of a leaf's 64-byte preimage could verify as that leaf.ConsistencyProof::update_inclusion_proofdid not compareold_proof.tree_sizewithold_size. A consistency proof from a different-size tree with the same root passedverify_transition. The update then sliced past the boundary group and panicked.A forged proof can only prove a value that is already a node under the root. This fix does not help a verifier that ignores
tree_size. Without a leaf/node domain tag (deliberate, for LeanIMT compatibility), a node is also a leaf of a smaller tree with the same root.Fix
verifycalculates each level's group size fromleaf_indexandtree_size. It rejects any othersibling_count. Honest proofs already carry that count.update_inclusion_proofrejects anold_proofthat does not verify, or whosetree_sizeis notold_size. The extraverifycall adds about a third more hashing per update. AnOkresult now always verifies.verify_againstandverify_transitionnow say that a root does not bind the leaf count. Callers must also compare the size with one they trust.This PR does not change a hash, the proof format or the public API. Malformed shapes that returned
Ok(false)now returnErr(MathError).Tests
Three regression tests fail on
main:verify_rejects_internal_node_as_leaf: the forged proof returnsOk(true).update_rejects_size_mismatchandupdate_rejects_malformed_old_proof: the update panics.A fourth test,
verify_rejects_spoofed_sibling_count, tries every wrongsibling_countat every level for N = 2, 3 and 4.proptest_treepasses at 2,000 cases, and thelight_clientexample runs.