Repository navigation
fix(drive): verify composite page and lookup components under their lifted limits - #4729
Conversation
…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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe 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. ChangesComposite timeline proofs
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to 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)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
🔍 Review in progress — actively reviewing now (commit 7b8dc46) · triage: normal |
Codecov Report❌ Patch coverage is
❌ 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
🚀 New features to boost your workflow:
|
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]>
Issue being fixed or feature implemented
Fixes #4728.
A
documents.compositequery 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: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 globalSizedQuery::limitinto 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$createdAtkeys under the fixedlanguage), 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 inpage_path_queryandsub_query_path_query_with_direction) and never carry the globalSizedQuery::limitthe plain documents lowering emits. Nothing composite ever read that field: materialization runs theDriveDocumentQueryitself, and the only consumers of a component's top-level limit were the merge (which lifted it), the limited flag invalidate_component_paths(which now reads the cap) and the verifier's subset passes (which were the bug). With one form everywhere:merged_path_query(...)directly, the same builder the verifier re-merges with (identical toprove_query_manyfor 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_componentnow 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_branchpins it with a preallocatedlike.byHashtagPostbucket 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-feedfixture gains abyHashtagCreated[hashtag, $createdAt]index (and posts now carry$createdAt), and three e2e tests incomposite_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) andcargo test -p drive-abci compositepass;cargo clippy -p drive --all-targets -- -D warningsis 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$createdAtkey 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:
🤖 Generated with Claude Code