fix(core/merkle): reject over-long SMT inclusion proofs (panic/DoS)#429
Open
dsmfa10 wants to merge 1 commit into
Open
fix(core/merkle): reject over-long SMT inclusion proofs (panic/DoS)#429dsmfa10 wants to merge 1 commit into
dsmfa10 wants to merge 1 commit into
Conversation
`verify_proof_against_root` computed `level = 255 - i` while iterating `proof.siblings` with no upper bound. For a peer-supplied proof with more than 256 siblings, `i == 256` underflows `255 - i` (debug panic; release wraparound -> out-of-bounds `get_bit` panic) — a crash from an untrusted proof reachable on the BLE acceptance path. The SMT is fixed-depth (256 levels), so reject any proof with more than 256 siblings before the fold. Well-formed 256-sibling proofs are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Problem
SparseMerkleTree::verify_proof_against_rootfolds the proof's siblings from leafto root, computing the tree level as
255 - i:There is no bound on
proof.siblings.len(). For a peer-supplied proof with morethan 256 siblings, at
i == 256the expression255 - iunderflowsusize(panic in debug; in release it wraps to a huge value and the subsequent
get_bitindexes out of bounds → panic). This is reachable from the BLEacceptance path:
receipts::deserialize_inclusion_proofdecodes au32siblingcount with no
<= 256cap and feeds the result here.Impact
A malicious peer can crash the verifier (and thus the receiving node/handler)
with a single oversized inclusion proof.
Fix
The SMT is fixed-depth (256 levels), so a valid inclusion proof has at most 256
siblings. Reject longer proofs before the fold.
Verification
cargo check -p dsmclean. Well-formed 256-sibling proofs are unaffected; onlyover-long proofs (which could never be valid anyway) are now rejected instead of
panicking.
Notes
The sibling-cap divergence between the struct's own
from_bytesandreceipts::deserialize_inclusion_proof(two byte-identical decoders) is noted inthe audit; consolidating them is a separate cleanup.
CI gates & coverage
Full verification for this PR runs in CI — Rust (
cargo fmt --check,clippy -D warnings, workspace tests), Frontend, Android Unit Tests,Coverage, SPDX headers, CodeQL (see the PR's Checks tab). The local
check noted above is a subset; the broader mandated gates (full workspace test
suite, codegen/scan, Android, Frontend) run in CI, not locally — none is
silently skipped.