Repository navigation
fix(proof): hide a range bound a V1 proof passes after its limit - #1012
Conversation
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]>
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (18)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (5)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughMerk proof generation now handles range boundaries according to the proof-envelope version when a query limit is reached. New Merk and GroveDB tests check proof shapes, verification, and returned results. ChangesLimit-cut proof behavior
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to This change makes limited exclusive-bound proofs at the newer proof version verifiable at their own limit. Older proof versions keep their existing shape. No actionable merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is narrowly version-gated and preserves existing verification controls. No introduced security issue was identified in the inspected proof paths, but coverage does not establish every downstream application's handling of proofs and trusted roots. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 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 |
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit f574d92) · triage: normal · Phase 2 only (no Phase 1 for this repository) |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1012 +/- ##
===========================================
+ Coverage 93.18% 93.20% +0.02%
===========================================
Files 336 336
Lines 105653 106238 +585
===========================================
+ Hits 98449 99018 +569
- Misses 7204 7220 +16
🚀 New features to boost your workflow:
|
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]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (no Phase 1 for this repository)
Static verification of f574d92 confirms the Phase-2 reviewers’ clean assessment: the shared Merk prover preserves V0 behavior and hides post-limit boundary keys in V1 using node forms the unchanged verifier already accepts, while preserving root reconstruction. Regression coverage includes both traversal directions, nested queries, indexed-axis replay, and version compatibility; the supplied exact-head CI snapshot reports successful tests, formatting, linting, security audit, and coverage checks, with PR Hygiene pending.
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:
normalbygpt-6.1-sol(effort low) — The change modifies version-dependent proof generation in merk/src/proofs/query/mod.rs, but its narrowly scoped limit-exhaustion fix is not large or intricate enough to meet the critical tier despite touching cryptographic proofs. - 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 high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer
|
Bots are done — your move: post |
#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]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
Issue being fixed or feature implemented
An honest V1 proof that its limit cuts short can fail to verify, even when the verifier uses the prover's own limit:
The cause is in the merk prover. Once its limit runs out, the walk hides everything it hasn't reached, but it still passes back up through the ancestors of its last result. One of them can be a range bound: an exclusive range end, or a later query item's bound.
create_proof_internalclears the "is a result" flag and the child query items when the limit hits 0. It never clears the "is an exclusive bound" flag, so that ancestor goes out as aKVDigestbehind the nodes the walk hid. The verifier's query pointer is still on the range the limit cut, so it reads the key as the first node of that range and needs the node before it to be revealed. That node is a hidden hash, so the proof is rejected.Example:
[2, 10)ascending at limit 3, with key 10 above the cut. The proof is2, 3, 4, <hidden 5..=9>, KVDigest(10).It depends on tree shape, and is common for subtrees written in one batch, which is how Dash Platform writes. Merk-level sweep on
develop, 20 and 40 keys: 8–10% of the cuts that end on an exclusive bound fail (Range,RangeAfter,RangeAfterTo); inclusive bounds never do. #1009 reports 24/27 failing cuts over 20 batch-written GroveDB items.#1009 fixes this in the verifier. This PR fixes it where it starts, in the prover.
What was done?
merk: the grove version picks the proof shape.
create_proofreads the grove version's proof envelope version,prove_query_non_serialized. That's the same valueValidatedPathQuery::proof_version()returns, and the proof version the matching verifier passes toexecute_proof. It's passed down the walk.create_proof_internalalso clears the exclusive-bound flag in both places it handles a used-up limit: on entering a node with the limit at 0, and when the limit ran out in the node's first child. The key is then emitted as a hash like the rest of the unwalked tree, and the root hash is unchanged.grovedb: no prover changes.
prove_queryon a limit-cut bounded read. With the bound hidden it passes, without changing the replay.No new gate: GROVE_V3 gets the fix. The shape follows the existing envelope version, so it changes under GROVE_V3, which is live. That's deliberate. The verifier is unchanged, and the released verifier accepts the new shape: every test below verifies with it, including under GROVE_V3. So no client, old or new, rejects a proof it used to accept. A query proof is one node's response, not state the network agrees on. Gating this to GROVE_V4 with a new slot would keep the bug on GROVE_V3 networks until V4 activates. Without a gate, clients verify these proofs as soon as the node serving them runs this code. Proofs the limit doesn't cut are byte-identical.
V0 proofs (grove v1 and v2) keep their shape, per the V0 lock.
Relation to #1009 and #1008. This replaces #1009's core change: no second copy of the verifier, no new trait method, no new version slot, no change to the indexed-axis replay, and no GroveDB code changes. #1009's GroveDB tests are ported here. Nodes that haven't upgraded still produce the old shape until they do; accepting their proofs on new clients would need #1009's tolerance on top. #1008 (upper-bound limit verification) is independent of this PR.
How Has This Been Tested?
merklimit_cut_bound_tests:[2, 10)at limit 3, the grove v2 proof ends inKVDigest(10)and fails at its own limit. The grove v3 proof reveals only the three results and verifies to them, and the latest version gives the same bytes. Both rebuild the merk's root, andMerk::provefollows the grove version the same way.Range,RangeTo,RangeAfter,RangeAfterTo,RangeInclusiveand aKey/Range/Key/RangeAftermix, both directions, every cutting limit. Each grove v3 proof verifies at its own limit with the released verifier and returns the firstlimitmatches. The test also asserts that some grove v2 proofs of the same cuts fail, so it reaches the broken shape.Noneor above the match count) are byte-identical under grove v2 and v3.prove_query_non_serializedis refused.grovedblimit_cut_bound_proof_tests, ported from fix(proof): verify a limit-cut proof that reveals a bound key after the cut #1009:prove_query→verify_queryat every cutting limit over 20 and 100 batch-written items, exclusive bounds ascending and descending, under GROVE_V3 and the latest version.prove_query).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. The verifier is unchanged and accepts both shapes it can now see. No public signature changes. Under grove v3 and later, merk proof bytes change only for limit-cut proofs that hit this bug, and only by replacing a
KVDigestwith a hash. Grove v1 and v2 output is unchanged.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
f37f5c3/skip-botsproceeds without the ones not yet reported/self-reviewedWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit