fix(dense): ignore inclusive queries on empty trees#745
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR fixes incorrect empty tree handling in proof query conversion. Three inclusive range query types now short-circuit immediately when ChangesEmpty tree inclusive range query fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #745 +/- ##
===========================================
+ Coverage 91.43% 91.47% +0.04%
===========================================
Files 236 240 +4
Lines 67111 67621 +510
===========================================
+ Hits 61364 61858 +494
- Misses 5747 5763 +16
🚀 New features to boost your workflow:
|
b5926a2 to
2e9b179
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
✅ Review complete (commit 2e9b179) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Targeted fix correctly addresses the empty-tree inclusive-range bug and adds regression coverage. One suggestion-level concern: the new count == 0 short-circuits in the three inclusive arms run before bytes_to_position, so malformed bounds are now silently accepted on empty trees while still being rejected on non-empty trees — a behavioral inconsistency that also propagates through verify_for_query.
🟡 1 suggestion(s)
1 additional finding(s) omitted (not in diff).
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.
In `grovedb-dense-fixed-sized-merkle-tree/src/proof/mod.rs`:
- [SUGGESTION] grovedb-dense-fixed-sized-merkle-tree/src/proof/mod.rs:66-127: Validate inclusive range bounds before the empty-tree short-circuit
The new `if count == 0 { continue; }` guards in `RangeInclusive`, `RangeToInclusive`, and `RangeAfterToInclusive` run before `bytes_to_position` is called. Every other `QueryItem` arm decodes bounds first and returns `InvalidData` for malformed encodings (non-1/2-byte keys). With this PR, a malformed inclusive bound (e.g., a 0-byte or 3-byte key) returns `Ok(empty)` when `count == 0` but `Err(InvalidData)` when `count > 0`. This makes the `Result` contract depend on the runtime tree state rather than query validity, and because `verify_for_query` reuses `query_to_positions` (verify.rs:97), a malformed inclusive query can verify successfully against an empty-tree proof instead of being rejected. Move `bytes_to_position` calls above the `count == 0` short-circuit in each of the three arms so bound validation is uniform across query items and tree states.
The count == 0 short-circuits for RangeInclusive, RangeToInclusive, and RangeAfterToInclusive previously ran before bytes_to_position, so malformed inclusive bounds (byte length != 1 or 2) silently passed on empty trees instead of returning InvalidData. Decode the bounds first, then short-circuit, so validation is consistent regardless of count. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
✅ Review complete (commit 4b859cb) Follow-up validation after the automated review suggestion:
|
Summary
RangeInclusive,RangeToInclusive, andRangeAfterToInclusiveempty-tree conversionsFixes #713.
Validation
cargo test --offline -p grovedb-dense-fixed-sized-merkle-tree --lib—177 passed
Summary by CodeRabbit
Bug Fixes
Tests