Skip to content

fix(bulk-append): reject short completed chunk proofs - #729

Closed
QuantumExplorer wants to merge 2 commits into
developfrom
codex/fix-688-bulk-chunk-proof-length
Closed

QuantumExplorer wants to merge 2 commits into
developfrom
codex/fix-688-bulk-chunk-proof-length

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Summary

  • validate every verified completed chunk blob has exactly the expected chunk item count
  • reject out-of-range chunk indices before exposing verified proof results
  • add a forged one-leaf proof regression where a short authenticated chunk would otherwise verify and omit queried positions

Fixes #688.

Verification

  • cargo test -p grovedb-bulk-append-tree test_verify_against_query_rejects_short_completed_chunk_blob
  • cargo test -p grovedb-bulk-append-tree verify_against_query
  • cargo test -p grovedb-bulk-append-tree

@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 48 minutes and 40 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5051c551-7c0e-4a20-a798-ff0b7d78d96a

📥 Commits

Reviewing files that changed from the base of the PR and between a2129a9 and 57c431e.

📒 Files selected for processing (7)
  • grovedb-bulk-append-tree/src/proof/mod.rs
  • grovedb-bulk-append-tree/src/proof/tests.rs
  • grovedb-version/src/version/grovedb_versions.rs
  • grovedb-version/src/version/v1.rs
  • grovedb-version/src/version/v2.rs
  • grovedb-version/src/version/v3.rs
  • grovedb/src/operations/proof/verify.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-688-bulk-chunk-proof-length

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (60f2968) to head (57c431e).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #729      +/-   ##
===========================================
+ Coverage    91.42%   91.43%   +0.01%     
===========================================
  Files          236      236              
  Lines        67053    67147      +94     
===========================================
+ Hits         61305    61399      +94     
  Misses        5748     5748              
Components Coverage Δ
grovedb-core 88.94% <100.00%> (+<0.01%) ⬆️
merk 92.26% <ø> (ø)
storage 86.36% <ø> (ø)
commitment-tree 96.43% <ø> (ø)
mmr 96.79% <ø> (+0.03%) ⬆️
bulk-append-tree 89.67% <100.00%> (+0.40%) ⬆️
element 97.38% <ø> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@QuantumExplorer QuantumExplorer changed the title Reject short completed chunk proofs fix(bulk-append): reject short completed chunk proofs May 21, 2026
@QuantumExplorer
QuantumExplorer force-pushed the codex/fix-688-bulk-chunk-proof-length branch from e9ce676 to af1c808 Compare May 21, 2026 04:34
@QuantumExplorer

Copy link
Copy Markdown
Member Author

This is Claude (AI-assisted review).

Closing in favor of #740, which adds a code comment instead of the runtime check.

Rationale: the completed-chunk-length validation here is cryptographically redundant. A completed chunk's contents are already bound to the state root (the MMR recomputes leaf_hash(blob) from the blob bytes → mmr_root → compute_state_root), so a short/truncated/tampered blob produces a different computed root. Every caller binds that root to a trusted value — verify/verify_against_query compare against expected_state_root, and the GroveDB path folds it into the parent Merk hash up to the consensus root and also runs an independent completeness check. So a bad blob is rejected by the root comparison, never reaching a length check (the existing test_verify_and_compute_root_rejects_corrupted_chunk_leaf already shows internally-consistent-but-wrong data is caught by the root comparison).

It only differs from the genuinely-needed dense_count == 0 empty-buffer check because that one guards unbound data (unused buffer bytes aren't hashed into the root); completed chunk bytes are bound. The only case the length check would help is a caller that trusts total_count but verifies against an attacker-chosen root, which is outside the trust model. BulkAppendTree/CommitmentTree are also unreleased, so there's no live exposure regardless.

#740 documents this at the verification site so future audits don't re-flag it.

QuantumExplorer added a commit that referenced this pull request May 21, 2026
…ded (#740)

Document at the verification site that the "validate completed chunk blob
holds exactly chunk_item_count entries" check (issue #688) is intentionally
omitted because completed chunk content is already bound to the state root
via leaf_hash -> mmr_root -> state_root, and every caller compares the
computed root against a trusted value. Prevents future (AI) audits from
re-flagging it. Closes the need for PR #729.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
QuantumExplorer added a commit that referenced this pull request Sep 23, 2026
* fix(proof): bound bulk-append extraction before the root is bound

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]>

* fix(proof): check bulk completeness before decoding; limit-aware extraction

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]>

* test(proof): cover element-only binding of MMR and dense lower layers

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]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

[audit][high] Bulk chunk proofs can verify incomplete chunk results

1 participant