Skip to content

fix(rotortree): check proof shape against the tree size - #64

Open
dkgoutham wants to merge 2 commits into
ethsystems:mainfrom
dkgoutham:fix/rotortree-proof-shape
Open

dkgoutham wants to merge 2 commits into
ethsystems:mainfrom
dkgoutham:fix/rotortree-proof-shape

Conversation

@dkgoutham

Copy link
Copy Markdown
Contributor

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_index and tree_size. Two functions trusted the shape that the proof carries instead:

  1. NaryProof::verify accepted any sibling_count up to N - 1 at each level. With the real root and tree_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.
  2. ConsistencyProof::update_inclusion_proof did not compare old_proof.tree_size with old_size. A consistency proof from a different-size tree with the same root passed verify_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

  • verify calculates each level's group size from leaf_index and tree_size. It rejects any other sibling_count. Honest proofs already carry that count.
  • update_inclusion_proof rejects an old_proof that does not verify, or whose tree_size is not old_size. The extra verify call adds about a third more hashing per update. An Ok result now always verifies.
  • The docs for verify_against and verify_transition now 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 return Err(MathError).

Tests

Three regression tests fail on main:

  • verify_rejects_internal_node_as_leaf: the forged proof returns Ok(true).
  • update_rejects_size_mismatch and update_rejects_malformed_old_proof: the update panics.

A fourth test, verify_rejects_spoofed_sibling_count, tries every wrong sibling_count at every level for N = 2, 3 and 4. proptest_tree passes at 2,000 cases, and the light_client example runs.

@dkgoutham
dkgoutham marked this pull request as ready for review November 17, 2026 09:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant