fix(proofs): version trailing-byte proof decoding - #739
Conversation
📝 WalkthroughWalkthroughThis PR replaces unconditional trailing-byte rejection during proof deserialization with a version-aware policy flag. Version definitions add ChangesVersion-aware proof decoding
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
grovedb/src/operations/proof/mod.rs (1)
31-37:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winDoc comment still says trailing bytes are always rejected.
The comment now conflicts with the versioned policy (v1/v2 can accept trailing bytes, v3 rejects). Please update this block to describe conditional rejection.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@grovedb/src/operations/proof/mod.rs` around lines 31 - 37, Update the module doc comment in grovedb/src/operations/proof/mod.rs that currently states "trailing bytes beyond the encoded envelope are rejected" to explain the conditional behavior by version: state that v1/v2 proofs may accept trailing bytes while v3 (and later) enforces canonical decoding by rejecting any trailing bytes; keep the rationale about equality-bytes assumptions and note the versioned policy decision. Target the top-of-file doc block in this module (the proof decoding/canonicality paragraph) and amend the wording to mention v1/v2 vs v3 behavior explicitly.
🧹 Nitpick comments (2)
grovedb/src/operations/proof/aggregate_sum/mod.rs (2)
190-190: ⚡ Quick winConsider adding error context per coding guidelines.
The bare
?operator doesn't provide context about where the decode failure occurred. As per coding guidelines, wrap errors with context to aid debugging.Suggested fix
- let grovedb_proof = super::decode_grovedb_proof_versioned(proof, grove_version)?; + let grovedb_proof = super::decode_grovedb_proof_versioned(proof, grove_version) + .map_err(|e| Error::CorruptedData(format!("verify_aggregate_sum_query_per_key decode: {}", e)))?;As per coding guidelines: Wrap errors with context using
.map_err(|e| Error::CorruptedData(format!("context: {}", e)))pattern in Rust source files🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@grovedb/src/operations/proof/aggregate_sum/mod.rs` at line 190, The call to decode_grovedb_proof_versioned(proof, grove_version) uses the bare ? and should be wrapped with contextual error mapping; replace the bare `?` on the result used to assign grovedb_proof with `.map_err(|e| Error::CorruptedData(format!("decoding grovedb proof failed: {}", e)))?` (i.e., map the error from decode_grovedb_proof_versioned into Error::CorruptedData with a clear message) so failures include where the decode failed.
119-119: ⚡ Quick winConsider adding error context per coding guidelines.
The bare
?operator doesn't provide context about where the decode failure occurred. As per coding guidelines, wrap errors with context to aid debugging.Suggested fix
- let grovedb_proof = super::decode_grovedb_proof_versioned(proof, grove_version)?; + let grovedb_proof = super::decode_grovedb_proof_versioned(proof, grove_version) + .map_err(|e| Error::CorruptedData(format!("verify_aggregate_sum_query decode: {}", e)))?;As per coding guidelines: Wrap errors with context using
.map_err(|e| Error::CorruptedData(format!("context: {}", e)))pattern in Rust source files🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@grovedb/src/operations/proof/aggregate_sum/mod.rs` at line 119, The call to decode_grovedb_proof_versioned(proof, grove_version) uses a bare `?` and should be wrapped to add context; replace the `?` on that call so errors are mapped (e.g., via .map_err(|e| Error::CorruptedData(format!("decoding grovedb proof (versioned) failed: {}", e)))) to preserve the original error while adding the descriptive message — update the assignment to `grovedb_proof` accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@grovedb/src/operations/proof/mod.rs`:
- Around line 31-37: Update the module doc comment in
grovedb/src/operations/proof/mod.rs that currently states "trailing bytes beyond
the encoded envelope are rejected" to explain the conditional behavior by
version: state that v1/v2 proofs may accept trailing bytes while v3 (and later)
enforces canonical decoding by rejecting any trailing bytes; keep the rationale
about equality-bytes assumptions and note the versioned policy decision. Target
the top-of-file doc block in this module (the proof decoding/canonicality
paragraph) and amend the wording to mention v1/v2 vs v3 behavior explicitly.
---
Nitpick comments:
In `@grovedb/src/operations/proof/aggregate_sum/mod.rs`:
- Line 190: The call to decode_grovedb_proof_versioned(proof, grove_version)
uses the bare ? and should be wrapped with contextual error mapping; replace the
bare `?` on the result used to assign grovedb_proof with `.map_err(|e|
Error::CorruptedData(format!("decoding grovedb proof failed: {}", e)))?` (i.e.,
map the error from decode_grovedb_proof_versioned into Error::CorruptedData with
a clear message) so failures include where the decode failed.
- Line 119: The call to decode_grovedb_proof_versioned(proof, grove_version)
uses a bare `?` and should be wrapped to add context; replace the `?` on that
call so errors are mapped (e.g., via .map_err(|e|
Error::CorruptedData(format!("decoding grovedb proof (versioned) failed: {}",
e)))) to preserve the original error while adding the descriptive message —
update the assignment to `grovedb_proof` accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ddda047d-74dd-4a1d-9a3e-d62ddd713ea2
📒 Files selected for processing (11)
grovedb-version/src/version/grovedb_versions.rsgrovedb-version/src/version/v1.rsgrovedb-version/src/version/v2.rsgrovedb-version/src/version/v3.rsgrovedb/src/operations/proof/aggregate_count/mod.rsgrovedb/src/operations/proof/aggregate_count_and_sum/mod.rsgrovedb/src/operations/proof/aggregate_sum/mod.rsgrovedb/src/operations/proof/mod.rsgrovedb/src/operations/proof/verify.rsgrovedb/src/tests/proof_advanced_tests.rsgrovedb/src/tests/provable_count_provable_sum_tree_tests.rs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #739 +/- ##
========================================
Coverage 91.43% 91.43%
========================================
Files 236 236
Lines 67114 67130 +16
========================================
+ Hits 61366 61382 +16
Misses 5748 5748
🚀 New features to boost your workflow:
|
* feat(version): add GROVE_V4, behaviourally identical to V3 GROVE_V3 is live, so a fix that changes an accepted/rejected outcome, a committed root hash, or a tracked cost cannot be applied unconditionally — nodes carrying it would diverge from nodes that do not. There is currently nowhere for such a fix to land, which has left several of them stuck: - #776: overwriting an indexed tree with a bare Reference skips the per-axis secondary cleanup. Closing it costs an extra stored-element read on EVERY reference overwrite (+1 seek, +79 storage_loaded_bytes, measured by the refresh-reference cost tests), and references over plain trees are shipped functionality. - Batch DeleteTree treats the caller-declared tree type as authoritative when selecting cleanup namespaces. Reading the stored element instead fixes both an indexed type-confusion and a live CommitmentTree wrong-emptiness-path bug, but adds a read to a released path. - Per project notes, five audit-fix PRs (#726, #730, #732, #734, #739) are gated on v3 and need re-gating before they can merge. This adds the version and nothing else. Every method-version slot is copied from V3 unchanged, so activating protocol version 4 today is a no-op; each gate is a deliberate, separately-reviewable slot bump. Verified rather than assumed: registering V4 changes what `GroveVersion::latest()` resolves to, and the whole test suite defaults to latest. The full workspace suite passes with V4 as latest (2459 grovedb + 705 merk + the rest), and the only two failures were the version registry's own self-describing tests — `grove_version_latest_returns_v3` and `grove_versions_count` — which are updated here. That is the evidence the change is inert. Adds `grove_v4_is_behaviourally_identical_to_v3_until_a_gate_is_added`, which compares every slot and fails the moment one is bumped. That failure is the intended prompt to document the gate rather than let V4 accrete behaviour silently. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test(version): drop the V3/V4 slot-identity assertion It pinned V4's initial state as inert, which was worth verifying once but becomes churn the moment a gate is added — and the DeleteTree read and #776 are both queued to gate on V4 next, so it would fail immediately and be deleted anyway. The evidence it provided is preserved where it belongs: the PR description records that the full workspace suite passed with V4 as latest and that only the registry's own self-describing tests changed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Summary
Tests
Summary by CodeRabbit
New Features
Tests