Repository navigation
feat(proof): verify a limit as an upper bound (#1008 rebuilt on #1012) - #1013
QuantumExplorer merged 5 commits into
Conversation
A verifier had to know the exact `SizedQuery::limit` the prover used:
a hidden node inside a queried range was only accepted once exactly
`limit` results had been returned. Clients therefore had to mirror the
server's limit policy, and any change to it broke them.
Add `ProofLimitMode::UpperBound` and
`QueryProofVerify::execute_proof_with_limit_mode`. In upper-bound mode
`limit` is a ceiling: once the proof has returned a result, the walk
stops at the first point the proof leaves unrevealed (a hidden node in
a range, a boundary key reached across hidden nodes, or the end of the
proof with items unproven). After the stop only value-free nodes are
accepted, so the results stay a gap-free prefix. V1 proofs only;
`execute_proof` keeps the exact behaviour.
`ProofVerificationResult` gains `exhausted`, true when the proof shows
nothing further matches. The carrier aggregate verifiers gain
`verify_aggregate_{count,sum,count_and_sum}_query_per_key_up_to_limit`,
returning `(root_hash, entries, exhausted)`. Existing verification
calls behave as before.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Require a result before a hidden node inside a range ends an upper-bound walk, as the other two stopping points already do. The condition already held (`in_range` is only set by a result), so this makes the rule explicit rather than changing behaviour. Pin `exhausted` for verified empty results: a proof that shows nothing matches is exhausted, and a limit of 0 leaves the query unwalked and not exhausted, in both modes and directions. Record the new mode in the changelog. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
`QueryProofVerify` is public and unsealed, so a downstream crate can implement it for its own type. A new required method would stop those implementations compiling. The default body serves exact mode through `execute_proof` and refuses upper-bound mode; `Query` overrides it and supports both. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
#1012 makes a V1 prover reveal no key once its limit runs out, not even a range bound it passes. Upper-bound verification no longer needs to tolerate that bound: its "boundary key reached across hidden nodes" stopping point is gone, and after a stop any node revealing a key is rejected, with or without a value. The walk still stops at the first hidden node inside a range or at the end of the proof, after at least one result. A proof that still reveals a bound after its cut, as provers before #1012 did, is rejected in this mode, as exact mode rejects it. Tests: the hand-built stream now accepts only a hidden node after the stop; the old revealed-bound shape is rejected under every ceiling; and a sweep over every V1 cut verifies in upper-bound mode at no ceiling, the prover's limit and above, which also pins that a V1 proof reveals nothing after its last result. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`*_per_key_up_to_limit` returned `(root_hash, entries, exhausted)`, and a
caller that ignored the bool read a partial page as every match. They now
return the root hash with a `CarrierAggregatePage`: `Complete(entries)`
when the proof shows no further outer key matches, otherwise
`MoreAfter { entries, last_key }`, never empty, where the next page
starts. The type is `#[must_use]` with `entries()` and `resume_after()`.
A ceiling of `Some(0)` is refused, since such a page could never move. A
leaf query returns a complete page with its single entry.
New tests page a capped range-outer walk to the end from an unset limit,
and refuse a zero ceiling.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
✅ Final review complete — no blockers (commit 7ea6111) · triage: critical · Phase 2 only (no Phase 1 for this repository) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (no Phase 1 for this repository)
Static verification against head 7ea6111 confirms that existing verification entry points retain exact-mode behavior and all three aggregate carriers propagate upper-bound mode and page completeness consistently. One API-compatibility documentation suggestion is valid; no supplied blocking finding remains. No builds or tests were run, and the supplied CI snapshot reports successful policy and CodeRabbit checks but contains no Rust build or test results.
🟡 1 suggestion(s)
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The intricate changes to Query::execute_proof_with_limit_mode in merk/src/proofs/query/verify.rs alter cryptographic proof acceptance rules, including hidden-node handling and authenticated query completeness. - Phase 1 reviewers: not run (disabled for this repository)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer
🤖 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 `merk/src/proofs/query/verify.rs`:
- [SUGGESTION] merk/src/proofs/query/verify.rs:1050: Classify the new result field as a breaking crate API change
Adding `exhausted` to the publicly exported, exhaustively constructible `ProofVerificationResult` breaks existing struct literals and exhaustive destructuring. This also affects downstream `QueryProofVerify` implementations that construct the result: the new trait method's default body avoids requiring another method implementation, but does not preserve those implementations' source compatibility. CHANGELOG.md documents the required migration under Added without the explicit BREAKING designation used for other unreleased API changes, while the PR's Breaking Changes section begins with "None for existing callers." Explicitly classify this field addition as a breaking Rust API change and include it in the next major package release, or preserve the legacy result type and expose completeness through a separate result type. The current manifest version need not be bumped in this feature PR; this concerns release classification, not GroveVersion activation.
| /// revealing the query; later results may then exist. This covers this | ||
| /// merk layer's query only, not a whole GroveDB path query with | ||
| /// subqueries. | ||
| pub exhausted: bool, |
There was a problem hiding this comment.
🟡 Suggestion: Classify the new result field as a breaking crate API change
Adding exhausted to the publicly exported, exhaustively constructible ProofVerificationResult breaks existing struct literals and exhaustive destructuring. This also affects downstream QueryProofVerify implementations that construct the result: the new trait method's default body avoids requiring another method implementation, but does not preserve those implementations' source compatibility. CHANGELOG.md documents the required migration under Added without the explicit BREAKING designation used for other unreleased API changes, while the PR's Breaking Changes section begins with "None for existing callers." Explicitly classify this field addition as a breaking Rust API change and include it in the next major package release, or preserve the legacy result type and expose completeness through a separate result type. The current manifest version need not be bumped in this feature PR; this concerns release classification, not GroveVersion activation.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)
f37f5c3
into
fix/limit-cut-boundary-reveal
* fix(proof): hide a range bound a V1 proof passes after its limit An honest V1 proof that its limit cut short could fail to verify at the prover's own limit with "Cannot verify lower bound of queried range". Once the limit runs out the merk walk hides what it has not reached, but still passes back up through the ancestors of its last result. When one of them is an exclusive range end or a later item's bound, the prover kept its "exclusive bound" flag and revealed the key as a KVDigest behind the nodes it hid, where the verifier cannot check it as a bound. It is common for subtrees written in one batch. From proof version 1 the prover clears that flag past the limit, so the key is hidden like the rest of the unwalked tree; the root hash is unchanged. Merk gains `prove_unchecked_query_items_for_proof_version`; its existing prove methods keep the V0 shape. GroveDB's V1 path-query, sum-budget window and indexed-axis provers use the V1 shape, which also lets the indexed-axis row replay accept a limit-cut bounded read instead of aborting `prove_query`. V0 proofs are unchanged. The verifier is unchanged and the released verifier accepts the new shape, so this needs no version slot: clients verify these proofs as soon as the serving node is upgraded. Proofs the limit does not cut are byte-identical. Co-Authored-By: Claude Opus 5.5 <[email protected]> * refactor(proof): take the merk proof shape from the grove version The proof version a merk proof is shaped for was a separate parameter next to the grove version, though the grove version already decides it: `prove_query_non_serialized` is the envelope version GroveDB proves with (`ValidatedPathQuery::proof_version`). A caller could pair a V1 merk shape with a V0 envelope, and the V1 call sites had to be picked by hand. `create_proof` now reads that slot and passes it down the walk, refusing an unknown value. `prove_unchecked_query_items_for_proof_version` and `generate_merk_proof_v1` go, and the GroveDB provers are unchanged: grove v1 and v2 keep the V0 shape, and every prover under grove v3 and later, including the indexed-axis secondary proofs, gets the V1 shape. Tests now pick the shape by grove version and cover the unknown-version refusal. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(proof): verify a limit as an upper bound (#1008 rebuilt on #1012) (#1013) * feat(proof): verify a limit as an upper bound A verifier had to know the exact `SizedQuery::limit` the prover used: a hidden node inside a queried range was only accepted once exactly `limit` results had been returned. Clients therefore had to mirror the server's limit policy, and any change to it broke them. Add `ProofLimitMode::UpperBound` and `QueryProofVerify::execute_proof_with_limit_mode`. In upper-bound mode `limit` is a ceiling: once the proof has returned a result, the walk stops at the first point the proof leaves unrevealed (a hidden node in a range, a boundary key reached across hidden nodes, or the end of the proof with items unproven). After the stop only value-free nodes are accepted, so the results stay a gap-free prefix. V1 proofs only; `execute_proof` keeps the exact behaviour. `ProofVerificationResult` gains `exhausted`, true when the proof shows nothing further matches. The carrier aggregate verifiers gain `verify_aggregate_{count,sum,count_and_sum}_query_per_key_up_to_limit`, returning `(root_hash, entries, exhausted)`. Existing verification calls behave as before. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(proof): address review on upper-bound limit verification Require a result before a hidden node inside a range ends an upper-bound walk, as the other two stopping points already do. The condition already held (`in_range` is only set by a result), so this makes the rule explicit rather than changing behaviour. Pin `exhausted` for verified empty results: a proof that shows nothing matches is exhausted, and a limit of 0 leaves the query unwalked and not exhausted, in both modes and directions. Record the new mode in the changelog. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(proof): give execute_proof_with_limit_mode a default body `QueryProofVerify` is public and unsealed, so a downstream crate can implement it for its own type. A new required method would stop those implementations compiling. The default body serves exact mode through `execute_proof` and refuses upper-bound mode; `Query` overrides it and supports both. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(proof): accept only hidden nodes after an upper-bound stop #1012 makes a V1 prover reveal no key once its limit runs out, not even a range bound it passes. Upper-bound verification no longer needs to tolerate that bound: its "boundary key reached across hidden nodes" stopping point is gone, and after a stop any node revealing a key is rejected, with or without a value. The walk still stops at the first hidden node inside a range or at the end of the proof, after at least one result. A proof that still reveals a bound after its cut, as provers before #1012 did, is rejected in this mode, as exact mode rejects it. Tests: the hand-built stream now accepts only a hidden node after the stop; the old revealed-bound shape is rejected under every ceiling; and a sweep over every V1 cut verifies in upper-bound mode at no ceiling, the prover's limit and above, which also pins that a V1 proof reveals nothing after its last result. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(proof): return a typed page from the up-to-limit carrier verifiers `*_per_key_up_to_limit` returned `(root_hash, entries, exhausted)`, and a caller that ignored the bool read a partial page as every match. They now return the root hash with a `CarrierAggregatePage`: `Complete(entries)` when the proof shows no further outer key matches, otherwise `MoreAfter { entries, last_key }`, never empty, where the next page starts. The type is `#[must_use]` with `entries()` and `resume_after()`. A ceiling of `Some(0)` is refused, since such a page could never move. A leaf query returns a complete page with its single entry. New tests page a capped range-outer walk to the end from an unset limit, and refuse a zero ceiling. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: pasta <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: pasta <[email protected]>
Issue being fixed or feature implemented
This is #1008 rebuilt on top of #1012. Its first three commits are #1008's, cherry-picked unchanged with their authorship. The rest is in the commits after them.
A proof verifier today has to know the exact
SizedQuery::limitthe prover used. Dash Platform hit this (dashpay/platform#4432): the server caps a range-outer carrier COUNT at 10 outer keys when the request leaves the limit unset. The SDK verified withNone, so every grouped range-over-range COUNT failed once more than ten groups existed. #1008 adds a verification mode that reads the stopping point from the proof, so a client doesn't have to copy the server's limit policy. See #1008 for the full motivation.#1012 changed what an honest V1 proof looks like after its cut. Once the limit runs out, the prover no longer reveals a range bound it passes. That lets upper-bound verification get stricter and simpler. This PR also replaces the bare
exhaustedbool in the carrier API with a type a caller has to handle.What was done?
From #1008 (unchanged):
ProofLimitMode::{Exact, UpperBound}andQueryProofVerify::execute_proof_with_limit_mode, which has a default body.ProofVerificationResult::exhausted.*_per_key_up_to_limitcarrier verifiers.Upper-bound mode accepts only the V1 shape after its stop.
The carrier verifiers return a
CarrierAggregatePage, not(root_hash, entries, exhausted).CarrierAggregatePage::Complete(entries): the proof shows no further outer key matches.CarrierAggregatePage::MoreAfter { entries, last_key }: later outer keys may match; the next page starts afterlast_key. This variant is never empty.#[must_use], withentries()andresume_after()accessors.Some(0)is refused, since such a page could never move.grovedb::operations::proof::CarrierAggregatePage.How Has This Been Tested?
merklimit_mode_tests(feat(proof): verify a limit as an upper bound #1008's, updated):merklimit_cut_bound_tests(fix(proof): hide a range bound a V1 proof passes after its limit #1012's), newupper_bound_verifies_every_v1_cut:limitmatches as not exhausted. It's refused below the prover's limit.grovedbcarrier tests (feat(proof): verify a limit as an upper bound #1008's, moved to the page type):Keysouter and exclusive-bound outer walks giveMoreAfterwith the rightlast_key.Complete.grovedb, new:carrier_range_outer_pages_to_the_end_up_to_limit: a client with no limit pages through a walk the prover caps at 2 per proof, continuing after eachlast_keyuntil a page isComplete. Every match comes back exactly once.carrier_zero_ceiling_is_refused_up_to_limit.cargo test -p grovedb-merk -p grovedbpass.cargo clippy -p grovedb-merk -p grovedb --all-features --tests -- -D warningsis clean, andcargo check -p grovedb --no-default-features --features verifybuilds.Breaking Changes
None for existing callers: every existing verification call behaves as before. Relative to #1008, which never released, the
*_per_key_up_to_limitreturn type changed and upper-bound mode rejects the old revealed-bound shape. Code outside the crate that builds aProofVerificationResultor destructures it exhaustively must account forexhausted, as noted in #1008.Depends on #1012 (base branch). Retarget to
developonce #1012 merges.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code