Skip to content

fix: accept empty append-layer selections in the V1 verifier; validate limit accounting (#865) - #875

Merged
QuantumExplorer merged 1 commit into
developfrom
claude/issue-865
Sep 6, 2026
Merged

QuantumExplorer merged 1 commit into
developfrom
claude/issue-865

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Closes #865.

What the audit found

The bulk proof generator charged the shared limit for the bounding span of the selection, so gaps in a disjoint selection consumed budget, and empty or reversed selections could hit unsafe subtraction. The commitment-tree generator shares the path.

State on develop

The audited snapshot (2fa0f133) predates #847. Since then the generator charges the normalized cardinality of the selected positions (a deduplicated set), so gaps, out-of-range spans and reversed ranges charge nothing, and the subtraction saturates. The commitment-tree generator delegates to the same function. The MMR and dense generators charge proved leaves/entries, so all four adapters agree with the verifier.

What was still wrong

Running the audit's validation matrix surfaced one real prover/verifier divergence: a subquery with no items (or only a key at u64::MAX, a position no tree can hold). The prover proves and charges it as empty; the verifier's range extraction rejected it as "No valid range items", so an honest proof failed to verify.

Changes

  • extract_range_from_query_items (V1 verifier): an empty span is now returned as an explicit empty selection instead of an error, so the caller extracts no values, expects no positions and charges nothing, mirroring the prover. This only turns a rejection of honest proofs into acceptance; proof bytes and the prover are unchanged, so no version gate is needed (same treatment as the fix: follow-ups from the per-instance limits reviews (#844/#845) #847 verifier fixes).
  • New grovedb/src/tests/append_layer_limit_accounting_tests.rs — the outstanding runtime validation. For BulkAppendTree and CommitmentTree layers (ten entries across two completed chunks plus the dense buffer) beside a Merk sibling under a global limit, it proves and verifies disjoint, beyond-count, absent-key, reversed (Range and RangeInclusive), mixed and overlapping selections at limits 1, 3, 6 and 50 under both empty-layer prove options, asserting the layer yields exactly the normalized selection and the sibling receives limit minus matched rows.
  • A contrast test pins that limit 1 starves the sibling through the root Merk proof's key cap (at most limit keys are proven, and the sibling is the second root key), identically for a plain empty Merk child, and that admitting both keys hands the sibling the whole budget when the selection is empty.

Verification

  • cargo test -p grovedb --all-features: 3005 passed, 0 failed.
  • Clippy (--all-features --all-targets -D warnings) reports nothing in the changed files; the remaining hits are pre-existing in untouched test files under local clippy 1.97.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 6db1c302-c115-4323-aae4-bedaf57df102

📥 Commits

Reviewing files that changed from the base of the PR and between 3be2eb6 and 479d367.

📒 Files selected for processing (3)
  • grovedb/src/operations/proof/verify.rs
  • grovedb/src/tests/append_layer_limit_accounting_tests.rs
  • grovedb/src/tests/mod.rs

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.

…e limit accounting (#865)

The V1 verifier's bulk/commitment range extraction rejected a selection
with no items (or only a key at u64::MAX) as "No valid range items",
while the prover proves and charges that selection as empty — an honest
proof failed to verify. Any empty span is now returned as an explicit
empty selection: no values are extracted, no positions are expected,
and nothing is charged, mirroring the prover.

The span-based charge the audit describes predates #847: the generator
already charges the normalized cardinality of the selected positions
(a deduplicated set), so gaps in disjoint selections, out-of-range
spans and reversed ranges charge nothing and the arithmetic saturates.
The commitment-tree generator shares that path. This adds the runtime
validation the audit left outstanding: for bulk and commitment layers
beside a Merk sibling under a global limit, disjoint, empty, reversed,
mixed and overlapping selections are proved, verified, and the
sibling's remaining budget is checked to be limit minus matched rows
at every limit and under both empty-layer prove options. A contrast
test pins that limit 1 starves the sibling through the root Merk
proof's key cap — identically for a plain empty Merk child — not
through any charge by the layer.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@codecov

codecov Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.58%. Comparing base (3be2eb6) to head (479d367).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #875   +/-   ##
========================================
  Coverage    92.58%   92.58%           
========================================
  Files          297      297           
  Lines        92299    92297    -2     
========================================
+ Hits         85454    85455    +1     
+ Misses        6845     6842    -3     
Components Coverage Δ
grovedb-core 90.81% <100.00%> (+<0.01%) ⬆️
merk 93.27% <ø> (ø)
storage 91.70% <ø> (ø)
commitment-tree 96.38% <ø> (ø)
mmr 95.12% <ø> (ø)
bulk-append-tree 92.78% <ø> (ø)
element 97.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed

@QuantumExplorer
QuantumExplorer merged commit efbe900 into develop Sep 6, 2026
11 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/issue-865 branch September 6, 2026 18:15
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][P17] Bulk and commitment proof generation consumes limits for unselected range gaps

1 participant