Repository navigation
fix: descending limited append-layer reads keep the highest positions (#855) - #866
Conversation
…#855) `BulkAppendTreeProof::verify_against_query` collected matched values in ascending position order and ignored the query's `left_to_right` and `limit`, so a descending limited query handed back the opposite end of the range. It now orders by the trusted direction BEFORE applying the cap, and completeness is still checked against the full ranges so the limit cannot hide a missing tail. The GroveDB V1 verifier already orders the MMR / BulkAppend / Dense / CommitmentTree rows by direction before consuming the shared limit (#847). This adds the runtime validation the audit left outstanding: for bulk and commitment trees, windows spanning chunk blobs and the dense buffer are proved, verified, and compared against the direct range read in both directions under both global and per-instance caps, and the same proof is re-verified uncapped to show it carries the whole selected span. The bulk crate's proof tests built queries with `Query::default()`, whose derived `left_to_right` is `false`; they now use `Query::new()` so the "ascending" fixtures really are ascending. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team 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. 📝 WalkthroughWalkthrough
ChangesDirection-aware proof reads
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to Direction-aware proof ordering and limiting are covered across bulk and commitment tree reads, with completeness retained before truncation. Sequence Diagram(s)sequenceDiagram
participant DirectRead
participant ProofGeneration
participant verify_against_query
DirectRead->>ProofGeneration: select requested append-layer window
ProofGeneration->>verify_against_query: provide proof and query
verify_against_query->>verify_against_query: order results by query direction
verify_against_query->>verify_against_query: apply query.limit
verify_against_query-->>DirectRead: return verified window
🚥 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #866 +/- ##
========================================
Coverage 92.58% 92.58%
========================================
Files 297 297
Lines 92293 92299 +6
========================================
+ Hits 85448 85454 +6
Misses 6845 6845
🚀 New features to boost your workflow:
|
Closes #855.
What the audit found
Bulk range extraction sorts positions ascending, and a limit applied to that order returns the FIRST positions even when the query is descending — the opposite end of the requested range.
State on
developThe audited snapshot (
2fa0f133) predates #847, which made the GroveDB V1 verifier order the MMR / BulkAppend / Dense / CommitmentTree rows by the query direction before consuming the shared limit. The GroveDB proof path was already correct; what was missing was the runtime validation the issue lists, plus the crate-level helper the issue names as root control.Changes
BulkAppendTreeProof::verify_against_query(grovedb-bulk-append-tree): the collected values now followquery.left_to_rightand honourquery.limit, so a descending limited query yields the highest positions — the same window the GroveDB verifier and a direct read return. Completeness is still checked against the full ranges before the cap, so a limit cannot hide a missing tail (pinned by a test).Query::default(), whose derivedleft_to_rightisfalse; they now useQuery::new()so the "ascending" fixtures really are ascending.grovedb/src/tests/append_layer_direction_tests.rs— the validation the audit left outstanding. For BulkAppendTree and CommitmentTree with entries spanning two completed chunks plus the dense buffer: every window × direction × cap kind (SizedQuery::limitand per-instanceQuery::limit) is proved, verified against the live root, and compared to the direct range read (bulk_get_range/commitment_tree_get_range). The same proof is then re-verified uncapped in both directions to show it carries the whole selected span. A separate test pins that a descending cap is the reverse tail of the ascending read, never its prefix.Noted, not changed
The trusted
query_rawengine does not descend into append-only layers (it yields no rows there in either direction). That is a pre-existing read-engine gap unrelated to ordering; the new trusted-read test only pins that it never serves a different window from the proof.Verification
cargo test -p grovedb-bulk-append-tree: 120 passed.cargo test -p grovedb --all-featuresfor the new module plus the per-instance-limit, bulk, commitment, dense and MMR suites: 251 passed.--all-features --all-targets -D warnings) reports nothing in the changed files; the remaining hits are pre-existing in untouched test files under the local clippy 1.97.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests