Skip to content

fix(drive): verify composite page and lookup components under their lifted limits - #4729

Merged
QuantumExplorer merged 3 commits into
v4.2-devfrom
claude/github-issue-4728-30fa6f
Sep 13, 2026
Merged

QuantumExplorer merged 3 commits into
v4.2-devfrom
claude/github-issue-4728-30fa6f

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 13, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Fixes #4728.

A documents.composite query whose page is an ordered range over a compound index (Yappr's feed: language == en, $createdAt > 0, ordered by [language, $createdAt desc], limit 20) plus a bound count sub-query is refused by the proof-verifying SDK with:

grovedb: invalid proof: Invalid V1 proof verification parameters:
invalid proof error Proof returns more data than limit Some(20)

The same page verifies through the ordinary documents.query, and the same sub-query verifies when the page is selected by exact ids.

What was done?

Root cause. The merged proof is built by PathQuery::merge, which lifts a component's global SizedQuery::limit into the per-instance cap (Query::limit) of its branch. The GroveDB prover budgets the two differently at a layer that has subquery branches: a global limit truncates the children the layer emits, while an instance cap only budgets the descendant rows, so the layer is emitted in full and descents stop once the budget is spent. An ordered timeline page has exactly such a layer (the $createdAt keys under the fixed language), and every key in range is emitted there.

The verifier's bootstrap pass, which reads the page (and any sub-query that feeds a later binding) out of the merged proof with verify_subset_query, used the component's raw path query, with its limit still global. As soon as the index level held more keys than the limit, the merk verifier rejected the layer with "more data than limit". Pages by id, and pages on a single-property index, have no such intermediate layer, so their global and instance budgets coincide, which is why the existing coverage passed.

Fix (rs-drive only). Composite components now author their budget as the per-instance cap of their root query at construction (budget_as_instance_cap, applied in page_path_query and sub_query_path_query_with_direction) and never carry the global SizedQuery::limit the plain documents lowering emits. Nothing composite ever read that field: materialization runs the DriveDocumentQuery itself, and the only consumers of a component's top-level limit were the merge (which lifted it), the limited flag in validate_component_paths (which now reads the cap) and the verifier's subset passes (which were the bug). With one form everywhere:

  • the merge carries the authored caps along on their branches and produces the same merged query as before, byte for byte;
  • the verifier's bootstrap subset passes read the page and the binding-source sub-queries exactly as built;
  • a page alone is proven in the very form it would have inside a merge, so a page's proof shape does not depend on whether its bound sub-queries derived anything. The prover proves merged_path_query(...) directly, the same builder the verifier re-merges with (identical to prove_query_many for two or more components).

No GroveDB change: authored per-instance caps are already served by the pinned revision, and the composite proofs that work today reach the same machinery through the merge's lift.

Materialization follows the same budget (review follow-up). The server materialized the page, and any sub-query feeding a later binding, through the plain documents lowering, whose global limit grovedb also charges for an empty index branch (a preallocated bucket nobody wrote to yet). The proof's per-instance cap charges rows only, so past such a branch the materialized page could stop one row short of the proven page, and a count derived from the shorter page left the proof missing a branch. materialize_component now executes the component's own proof path query (trios for indexOnly types, the reference-following serialized read for stored documents), so selection, budget and order are the proof's by construction. should_materialize_the_page_under_the_proofs_budget_past_an_empty_index_branch pins it with a preallocated like.byHashtagPost bucket on the fixture: the page walks C's empty bucket first, and both a bare page and one with a bound count agree between the no-proof and proved paths.

No wire, SDK, or protocol change: the proof format and the merged query for every previously accepted composition are unchanged, and the previously failing shape now verifies.

Tests. The yappr-feed fixture gains a byHashtagCreated [hashtag, $createdAt] index (and posts now carry $createdAt), and three e2e tests in composite_query_e2e_tests.rs:

  • should_prove_an_ordered_timeline_page_with_a_bound_count: the issue's shape, once with a limit the page does not fill and once with a limit it does (the latter reproduced the failure before the fix).
  • should_prove_a_timeline_page_alone_in_the_merged_limit_form: a timeline page whose only bound sub-query derives nothing, with more keys than its limit (page-only proof path).
  • should_bootstrap_a_limited_lookup_that_feeds_a_later_binding: a limited non-unique lookup that is a binding source, with more index keys than its limit (fails without the sub-query lift; verified by toggling it off).

cargo test -p drive --lib composite (24 tests) and cargo test -p drive-abci composite pass; cargo clippy -p drive --all-targets -- -D warnings is clean.

Follow-up worth noting

Under an instance cap, the GroveDB prover emits an intermediate layer with subquery branches in full (generate.rs, the layer-limit rule) and only stops descending once the budget is spent. For a composite timeline page that means the proof carries every $createdAt key in range, so its size grows with the number of posts under the fixed prefix rather than with the page. Correctness is unaffected, but a feed over a large index will pay for it; truncating that layer once the instance budget is spent needs a matching prover/verifier rule in GroveDB; tracked in dashpay/grovedb#962 (dashpay/grovedb#961, the twin report of this failure, is closed).

How Has This Been Tested?

Targeted suites above; the fixture change is shared with the drive-abci composite tests and the rs-sdk mock composite test, which build documents from the fixture and are unaffected.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

🤖 Generated with Claude Code

…ifted limits

The merge lifts a component's global limit into its branch's per-instance
cap, and the prover budgets an intermediate index layer differently under
the two: a global limit truncates the children it emits, an instance cap
only the descendant rows. The verifier's bootstrap subset passes read the
page and binding-source sub-queries with their limits still global, so an
ordered timeline page whose index level held more keys than its limit was
rejected with "Proof returns more data than limit" (#4728).

Read every component under the lifted cap the merge gives it, and build a
page-only proof in the same form so the proof's shape does not depend on
what the bound sub-queries derived. Cover the feed's timeline shape, the
page-only case and a limited lookup feeding a later binding.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 13, 2026
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 3ff05765-3570-4815-af09-b6170c540548

📥 Commits

Reviewing files that changed from the base of the PR and between 2c0b811 and 817a6d4.

📒 Files selected for processing (4)
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/composite_query_e2e_tests.rs
  • packages/rs-drive/src/query/composite_document_query/mod.rs
  • packages/rs-drive/src/verify/composite_document/verify_composite_documents_proof/v0/mod.rs
  • packages/rs-drive/tests/supporting_files/contract/yappr-feed/yappr-feed-contract.json

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds an ordered timeline index and end-to-end coverage. Composite proof generation and bootstrap verification now lift page and sub-query limits into branch caps before proving and verifying merged queries.

Changes

Composite timeline proofs

Layer / File(s) Summary
Timeline contract and end-to-end coverage
packages/rs-drive/tests/supporting_files/contract/yappr-feed/yappr-feed-contract.json, packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/composite_query_e2e_tests.rs
The post schema adds the byHashtagCreated index and requires $createdAt. Test helpers create ordered posts and cover bound counts, page-only proofs, and limited lookups that feed later bindings.
Shared merged proof query
packages/rs-drive/src/query/composite_document_query/mod.rs
lift_limit_into_branch_cap preserves tighter branch caps. Composite proof generation uses the shared merged_path_query builder and one prove_query call.
Bootstrap subset verification
packages/rs-drive/src/verify/composite_document/verify_composite_documents_proof/v0/mod.rs
Page and sub-query bootstrap verification uses lifted branch-cap limits before subset verification.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 817a6

The ordered composite timeline proof path preserves page limits while allowing bound queries to operate on returned documents, with matching proof construction and verification behavior. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The change addresses #4728. merged_path_query lifts each component limit into its branch cap for both merged and page-only proofs. Proof generation and verification use the same lifted query form. V…
Out of Scope Changes check ✅ Passed The changes stay within #4728. The test contract adds the $createdAt field and the compound timeline index required to reproduce the ordered range query. Seed data and test helpers support the regre…
Docstring Coverage ✅ Passed Docstring coverage is 81.25% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 3 files. (1 skipped: 1 …
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing Drive composite page and lookup verification to use lifted limits. It is concise and specific enough for the changeset.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/github-issue-4728-30fa6f

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.

@thepastaclaw

thepastaclaw commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress — actively reviewing now (commit 7b8dc46) · triage: normal

@codecov

codecov Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 49.05660% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.96%. Comparing base (2c0b811) to head (7b8dc46).

Files with missing lines Patch % Lines
...rs-drive/src/query/composite_document_query/mod.rs 50.48% 51 Missing ⚠️
...ocument/verify_composite_documents_proof/v0/mod.rs 0.00% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (49.05%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4729      +/-   ##
============================================
- Coverage     79.67%   78.96%   -0.71%     
============================================
  Files          2828     2828              
  Lines        399753   400450     +697     
============================================
- Hits         318517   316231    -2286     
- Misses        81236    84219    +2983     
Components Coverage Δ
dpp 77.03% <ø> (-0.30%) ⬇️
drive 81.29% <49.05%> (-0.32%) ⬇️
drive-abci 82.25% <ø> (-1.07%) ⬇️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 65.54% <ø> (-4.69%) ⬇️
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 31.50% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

QuantumExplorer and others added 2 commits September 14, 2026 03:23
Composite components never read the global SizedQuery::limit the plain
documents lowering emits: the merge lifted it into the branch's
per-instance cap, validation only asked whether it was set, and the
verifier's subset passes were the bug. Move the limit onto the root
query's Query::limit at construction in page_path_query and the
sub-query builder so validation, the merge, the prover and every subset
pass see one form, and drop the mirror of the merge's lift.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The server materialized the page, and any sub-query feeding a later
binding, through the plain documents lowering, whose global limit
grovedb also charges for an empty index branch such as a preallocated
bucket nobody wrote to yet. The proof's per-instance cap charges rows
only, so past such a branch the materialized page stopped one row short
of the proven page and a count derived from it left the proof missing a
branch. Execute each component's own proof path query instead: trios
for indexOnly types, the reference-following serialized read for stored
documents. Pin it with a preallocated like bucket on the feed fixture.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@QuantumExplorer
QuantumExplorer merged commit 0db4c36 into v4.2-dev Sep 13, 2026
20 of 23 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/github-issue-4728-30fa6f branch September 13, 2026 21:49
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.

Composite ordered timeline proof rejects valid page with "more data than limit"

2 participants