Repository navigation
fix(proof): bound bulk-append extraction before the root is bound - #990
Conversation
The V1 BulkAppendTree / CommitmentTree lower-layer verifier took total_count and height from element bytes carried in the proof, computed an unbound root, and extracted values before its caller compared the root with a trusted one. A 9-byte fixed-format chunk blob can declare 2^20 zero-sized entries, and under a forged height of 1 every blob's positions overlapped the query window, so a proof of a few KB made the verifier decode 2^20 entries per blob and return one row per blob per queried position (520,256 duplicate rows for 64 blobs over an 8192-position window). Incomplete fix of #856 (#872). - deserialize_completed_chunk_blob refuses a completed-chunk blob whose entry count is not exactly 2^height, before allocating. A resource bound, not the soundness length check rejected in #688 / #729. - BulkAppendTreeProofResult::values_in_ranges extracts only the query's position intervals, skips chunks no interval touches without decoding them, and refuses repeated, descending or buffer-reaching chunk indices. The GroveDB glue passes the exact PositionIntervals instead of a bounding span. - The MMR, dense, bulk and commitment-tree lower layers bind their computed root to the parent row's value hash before extracting rows. Client-side verifier only; honest proofs never trigger the refusals, so no GroveVersion gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🕓 Queued for automated review — 5th in line, estimated start in ~1.4 h (commit 46d76bf)
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #990 +/- ##
===========================================
+ Coverage 92.95% 93.04% +0.08%
===========================================
Files 331 331
Lines 104500 104804 +304
===========================================
+ Hits 97138 97513 +375
+ Misses 7362 7291 -71
🚀 New features to boost your workflow:
|
…action Code-review follow-up. The exact chunk count still let a broad query over a forged total_count extract 2^height values per carried chunk (a 1 KB proof gave about 4M values) before completeness or the row limit applied. - Completeness is checked first, on the spans the proof's chunk indices and buffer entries cover (proved_position_spans, missing_from_spans), without decoding anything. - values_in_ranges_directed walks the query's intervals in its direction, stops at the row limit, and copies only the entries it returns (completed_chunk_entries). Variable-format blobs are parsed once, via a walker shared with the general decoder. - A bad chunk blob in a proof result is reported as InvalidProof. - Each lower-layer arm binds its root to the parent exactly once; the MMR, dense, bulk and commitment-tree verifiers bind before reporting any row. The V1 trunk verifier shares ParentCommitment::check. - Tests: incomplete forged chunks refused before decoding, limited queries decode only what they report, deterministic signals instead of 1 s timing asserts, shared blob and CT-root helpers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…pend-verify-resource-bound # Conflicts: # CHANGELOG.md
A subset query that stops at an MMR or dense tree consumes the lower layer for its root alone. Pin that the honest element verifies there and that a lower root the parent row does not commit to is refused; codecov flagged the dense root-only bind as uncovered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Issue being fixed or feature implemented
This is an incomplete fix of #856 (PR #872). The 2026-09-23 audit found it, and it has not been filed separately.
A malicious proof supplier could make a
BulkAppendTree/CommitmentTreeproof verifier allocate gigabytes and run billions of iterations before the proof was bound to any trusted root. Dash Platform's shielded-note verification is exposed:rs-drive-proof-verifier,verify_shielded_encrypted_notes. It runsverify_querywithlimit: Noneover a window of up to 8192 positions, before the tenderdash root check, so a malicious DAPI node could run wallets and light clients out of memory. CommitmentTree is live on mainnet, and the V1 verifier runs under every grove version.How the bug works:
verify_bulk_append_lower_layertakestotal_countandheightfrom the element carried in the proof, which is not yet authenticated.verify_and_compute_root, which computes a root and compares it with nothing, then extracts values. The parentcombine_hashcheck ran only afterwards. The root itself is authenticated only when the caller compares the returned root with a trusted one.[01][count = 2^20][entry_size = 0]is 9 bytes. The payload check passes (0 == 0), sodeserialize_chunk_blobbuilds 1,048,576 empty entries, about 24 MB.values_in_range. It had no count bound tied tochunk_item_countand no dedup across blobs. Under a forgedheight = 1, each blob's positions[2i, 2i + 2^20)overlap the query window, so every blob contributes the whole window.Reproduced against
develop. A forged envelope under 4 KB (64 such blobs, an 8192-position window, no limit) madeGroveDb::verify_queryreturn 520,256 duplicate rows under a root nobody holds. Completeness passed because the overlapping blobs covered the window. The damage grows linearly with the blob count.What was done?
This change touches only the client-side verifier. Honest proofs never trigger the new refusals, so there is no
GroveVersiongate.completed_chunk_entries(blob, expected_count, wanted)refuses a completed-chunk blob whose entry count is not exactly2^height. For the fixed format it reads the header count. For the variable format it walks the length prefixes once, through a walker shared with the general decoder. It copies only thewantedentries, so touching one position of a chunk costs one entry.deserialize_completed_chunk_blobis the all-entries wrapper. Compaction always writes exactly2^heightentries, so honest chunks pass, including chunks of zero-sized entries, which are appendable.verify_and_compute_root. The [audit][high] Bulk chunk proofs can verify incomplete chunk results #688 note there now explains why both hold.BulkAppendTreeProofResult::proved_position_spans()returns the positions the proof's chunk indices and buffer entries cover, without decoding anything. It also refuses chunk indices that repeat, descend or reachbuffer_start, and buffer entries that repeat or passtotal_count. The GroveDB glue checks completeness against these spans (PositionIntervals::missing_from_spans) before extracting, so an incomplete forged proof is refused in O(intervals + carried chunks).values_in_ranges_directed(ranges, left_to_right, limit)then walks the query's exact intervals in its direction and stops at the row limit. It skips untouched chunks and decodes only the entries it returns.values_in_range,values_in_rangesand the standaloneverify_against_queryall use it.PositionIntervalsinstead of a bounding span, which removesextract_range_from_query_items.total_countextract2^heightvalues per carried chunk: a 1 KB proof of 64 honest-shaped zero-size chunks at height 16 gave about 4M values. A bad chunk blob in a proof result is now reported asInvalidProof, in the crate and in GroveDB alike.verify_bulk_append_lower_layeris split intodecode_bulk_append_lower_layerandreport_bulk_append_entries.ParentCommitment.ct_state(sinsemilla, bulk_root). This matches whatverify_against_queryalready did.ParentCommitment::checkand keeps its own error text. V0 is untouched.ParentCommitmentdoc says so.How Has This Been Tested?
grovedb-bulk-append-tree/tests/forged_chunk_blob_resource_bound.rs, using only the public API:verify_against_queryrefuses the same blob.chunk.rs,proof/tests.rsandposition_intervals.rscover:proved_position_spanswithout decoding, and malformed result shapes;missing_from_spansmatchingmissing_fromexactly.grovedb/src/tests/non_merk_completeness_budget_tests.rs:forged_chunk_blob_counts_refused_before_expansioncovers BulkAppendTree and CommitmentTree with a complete forged proof. Ondevelopa forged proof of this shape was accepted with duplicate rows: 520,256 attotal_count = 8192.incomplete_forged_chunks_refused_before_decodingrefuses by completeness before touching the carried garbage chunks.limited_query_decodes_only_what_it_reportsruns a RangeFull query with limit 2, from either end, over 64 chunks of which 63 are garbage.lower_layer_root_bound_before_rows_are_extractedcovers bulk, CommitmentTree and MMR. It fails ondevelop, where the completeness error fires before the binding.element_only_subset_query_binds_mmr_and_dense_lower_layerscovers the root-only bind of MMR and dense layers.honest_bulk_queries_across_chunks_and_bufferpasses on both. It covers disjoint keys and ranges across chunks and the buffer, both directions, a limit, and both variable-format and zero-size chunks.develop):cargo test -p grovedb-bulk-append-treeandcargo test -p grovedb --libpass: 134 unit and 5 integration tests in the crate, and 3,501 passed, 0 failed, 8 ignored in GroveDB, including the slow CommitmentTree cost tests.cargo clippy -p grovedb -p grovedb-bulk-append-tree -- -D warnings,cargo fmt --all -- --checkandcargo check -p grovedb --no-default-features --features verifyare clean.Breaking Changes
None. Honest proofs verify as before. The refusals, and errors that now come from the binding or the completeness check rather than a later step, only affect forged proofs.
values_in_rangekeeps its signature. It now reports a bad chunk blob asInvalidProofrather thanCorruptedData, because a proof result is proof input.values_in_ranges,values_in_ranges_directed,proved_position_spans,completed_chunk_entriesanddeserialize_completed_chunk_blobare new public items.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code