Skip to content

fix(proof): verify a limit-cut proof that reveals a bound key after the cut - #1009

Closed
PastaPastaPasta wants to merge 5 commits into
developfrom
fix/exact-limit-exclusive-bound
Closed

PastaPastaPasta wants to merge 5 commits into
developfrom
fix/exact-limit-exclusive-bound

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

An honest V1 proof that its limit cut short can fail to verify, even when the verifier uses the prover's own limit:

invalid proof error Cannot verify lower bound of queried range

Once its limit runs out, the prover hides the rest of the walk. It can still reveal a key it passed on the way, though (an exclusive range end, or a later query item's bound), behind the nodes it hid. The verifier checks that key as a range bound. The node before it is hidden, so the check fails.

It depends on the tree's shape, and the common case is the bad one:

  • Subtrees written in one batch: it fails at almost every limit that cuts the walk. With GroveDb::apply_batch, which is how Dash Platform writes, prove_query → verify_query on develop fails for 24/27, 54/57 and 144/147 limit-cut queries over 20, 40 and 100 items.
  • Subtrees built one insert at a time: it almost never happens. That is probably why it went unnoticed.

Affected shapes:

  • ascending walks over an exclusive upper bound (Range, RangeTo, RangeAfterTo);
  • descending walks over an exclusive lower bound (RangeAfter, RangeAfterTo);
  • a later query item's bound;
  • path queries with a subquery whose outer layer is cut by the limit.

Found while testing #1008.

What was done?

The rule. Once a V1 proof's limit is reached, the walk is complete and no later node can be a result. So later nodes are no longer checked as range bounds:

  • a node carrying a value that the query matches is still rejected as "Proof returns more data than limit";
  • anything else is accepted. These are nodes without a value, or with a value no query item matches. They prove nothing the result depends on, and their hashes still feed the root.

Keys after the limit come in strict walk order, so the match check uses its own forward cursor over the query items: the whole tail costs one pass over the items, not one scan per node. The cursor is kept apart from the verifier's main item iterator, whose position records how far the walk proved the query.

Everything that makes the result correct is decided before the limit is reached, and none of it changes: the first item's bound check, rejecting hidden nodes inside a range, the transitions between items, and key ordering. The end-of-proof absence check was already skipped once the limit is reached. For queries built through insert_item, every proof accepted before is still accepted with the same result.

Gated on the grove version. GROVE_V3 is live and already verifies V1 proofs, so accepting proofs it rejects would let upgraded and older verifiers disagree. The rule is behind a new slot, merk_versions.proof.execute_proof_limit_reached_tail: 0 for grove v1..v3 (the released rejection) and 1 for GROVE_V4, documented in GROVE_V4's gate list.

  • QueryProofVerify::execute_proof_for_grove_version dispatches on the slot and refuses unknown versions. It has a default body, so existing implementations keep compiling.
  • execute_proof keeps the released behaviour.
  • The two behaviours live in separate version-owned functions: execute_query_proof_v0 is the released body verbatim, and execute_query_proof_v1 adds the tail rule. execute_proof_for_grove_version has a default body that serves only version 0 and refuses others, so existing implementations keep compiling but don't silently verify GROVE_V4 with the old rule.
  • GroveDB's V1 verifiers that take a limit pass their grove version: path queries (verify_layer_proof_v1), the carrier aggregate outer walk, axis descent, sum-budget windows and indexed-axis ranges.
  • The indexed-axis prover replays its secondary proof to build row chains; it selects the replay from the same slot, so under GROVE_V4 it no longer aborts prove_query on a limit-cut bounded read the verifier accepts.

Proof generation is unchanged. V0 verification (proof_version = 0) is frozen and unchanged.

How Has This Been Tested?

  • merk limit_reached_tail_tests:

    • every limit that cuts the walk verifies at that limit and returns exactly the first limit matches, on batch-built merks of 20 and 40 keys. Shapes covered: Range, RangeTo and RangeAfterTo ascending; RangeAfter and RangeAfterTo descending; a Key/Range/Key/RangeFrom mix;
    • hand-built op streams: a boundary key behind a hidden node after the limit is accepted (and still rejected under V0), and a matched key with a value past the limit is rejected as "more data than limit", whether adjacent or behind a hidden node;
    • a previously accepted proof with an unmatched value node after the limit is still accepted with the same result;
    • an honest proof made at limit 0 verifies empty;
    • gating: the same limit-cut proof is rejected by execute_proof and under GROVE_V3, accepted under GROVE_V4, and an unknown slot version is refused;
    • a multi-item query's tail values are matched against the right item in both directions, including values exactly on Key, inclusive and exclusive bounds;
    • an implementation inheriting the default versioned method delegates under GROVE_V3 and is refused under GROVE_V4.
  • grovedb limit_cut_exclusive_bound_proof_tests, all on batch-written subtrees:

    • prove_query → verify_query at every cutting limit over 20 and 100 items;

    • a subquery whose outer layer the limit cuts.

    • the same limit-cut proof, made under GROVE_V3, is rejected when verified under GROVE_V3 and accepted under GROVE_V4;

    • a bounded axis read over a batch-written provable-sum indexed tree, whose secondary proof the limit cuts at a boundary key, proves and verifies (before the replay fix, prove_query aborted).

    The first two fail on develop and pass here.

  • Full suites: cargo test -p grovedb-merk --all-features and cargo test -p grovedb --all-features pass. cargo clippy -p grovedb-merk -p grovedb --all-features --tests -- -D warnings is clean, and cargo check -p grovedb --no-default-features --features verify builds.

  • Independent adversarial review with a throwaway fuzz harness, comparing develop and this branch in one binary:

    • Inputs: batch-built and incrementally built merks, dense and sparse keys, 1–90 keys. Queries of 1–4 items of every kind, in both directions, at every limit plus None.
    • Candidate proofs: honest proofs plus mutated ones (node kinds swapped with the same hash, subtrees collapsed, hidden nodes revealed), random partial proofs, honest proofs made at other limits, and a bare root hash.
    • Oracle: every accepted proof with the true root must return exactly the honest first min(limit, total) matches and the right remaining limit.
    • Results (8.9M candidate proofs over 6 seeds): 0 oracle violations, 0 honest proofs broken, and 0 proofs that develop accepts but this branch rejects. 148k proofs develop rejected are now accepted, every one returning the correct result. Of 87,990 honest limit-cut cases, develop fails 529 and this branch 47; all 47 also fail on develop and are the adjacent-items issue below.

Separate pre-existing issues the fuzz found (unchanged here, they fail on develop too)

  • Adjacent items. [RangeTo(..5), RangeFrom(5..)] is not merged by insert_item. The prover doesn't count key 5 against the limit but emits it as a result, so any limit of 6 or more fails with "Proof returns more data than limit".
  • One rare multi-item shape. [RangeAfterTo(15..16), RangeAfterToInclusive(23..=23), RangeAfterTo(38..51), RangeAfter(87..)] ascending fails with "Cannot verify lower bound" on one batch-built tree even with limit = None.

Breaking Changes

None. Under GROVE_V1..V3 verification is unchanged. Under GROVE_V4, for queries built through insert_item, it accepts a superset of what it accepted before, with the same results. QueryProofVerify gains a method with a default body, so existing implementations keep compiling. Code building MerkProofVersions by hand must set the new execute_proof_limit_reached_tail field (noted in the changelog). Proof generation is unchanged.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 83a8d1b

  • Bots — coderabbitai not yet · thepastaclaw ✓ — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed
  • Within your 5 open PRs
  • Build green
  • Approvals
    • files with no dedicated owner (CHANGELOG.md, grovedb-version/src/version/merk_versions.rs, grovedb-version/src/version/v1.rs and 16 more) — QuantumExplorer

When every box is checked the PR Hygiene check passes and this can merge.

Summary by CodeRabbit

  • New Features
    • Grove v4 can verify limited query proofs when additional nodes follow the requested results, without requiring every subsequent node to be included. Matching query values beyond the limit are still rejected.
    • Limited proofs with exclusive range bounds are supported for ascending and descending queries, including nested queries and bounded sum-index reads.
  • Compatibility
    • Grove v1–v3 retain their existing behavior and continue to reject these limit-cut proofs.

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4b97f737-7068-4873-ba24-621159a8b2e7
📥 Commits

Reviewing files that changed from the base of the PR and between ecd45eb and 83a8d1b.

📒 Files selected for processing (19)
  • CHANGELOG.md
  • grovedb-version/src/version/merk_versions.rs
  • grovedb-version/src/version/v1.rs
  • grovedb-version/src/version/v2.rs
  • grovedb-version/src/version/v3.rs
  • grovedb-version/src/version/v4.rs
  • grovedb/src/operations/proof/aggregate_common.rs
  • grovedb/src/operations/proof/aggregate_count/helpers.rs
  • grovedb/src/operations/proof/aggregate_count/per_key.rs
  • grovedb/src/operations/proof/aggregate_count_and_sum/helpers.rs
  • grovedb/src/operations/proof/aggregate_count_and_sum/per_key.rs
  • grovedb/src/operations/proof/aggregate_sum/helpers.rs
  • grovedb/src/operations/proof/aggregate_sum/per_key.rs
  • grovedb/src/operations/proof/indexed_axis/generate.rs
  • grovedb/src/operations/proof/indexed_axis/verify.rs
  • grovedb/src/operations/proof/verify.rs
  • grovedb/src/tests/limit_cut_exclusive_bound_proof_tests.rs
  • grovedb/src/tests/mod.rs
  • merk/src/proofs/query/verify.rs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ab94fba8-de20-4d13-9e2e-8dff00ed37c7
📥 Commits

Reviewing files that changed from the base of the PR and between 1099cfc and ecd45eb.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • grovedb-version/src/version/v1.rs
  • grovedb-version/src/version/v2.rs
  • grovedb-version/src/version/v3.rs
  • grovedb-version/src/version/v4.rs
  • grovedb/src/tests/mod.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

GroveDB now selects limit-reached proof-tail verification behavior by Grove version. V1–V3 retain the prior behavior, while V4 enables the updated behavior. Proof verification and indexed-proof replay receive version information, and regression tests cover limit-cut proofs.

Changes

Limit-cut proof verification

Layer / File(s) Summary
Proof-tail version policy
grovedb-version/src/version/merk_versions.rs, grovedb-version/src/version/v1.rs, grovedb-version/src/version/v2.rs, grovedb-version/src/version/v3.rs, grovedb-version/src/version/v4.rs, CHANGELOG.md
MerkProofVersions adds execute_proof_limit_reached_tail. V1–V3 set it to 0, and V4 sets it to 1. The changelog describes the versioned verification behavior and API.
Version-aware proof execution
grovedb/src/operations/proof/verify.rs, grovedb/src/operations/proof/aggregate_*/*, grovedb/src/operations/proof/indexed_axis/*
Proof verification passes the Grove version to version-aware Merk execution. Indexed-axis replay selects behavior from the proof-tail version and returns an error for unsupported values.
Limit-cut proof coverage
grovedb/src/tests/limit_cut_exclusive_bound_proof_tests.rs, grovedb/src/tests/mod.rs
Tests cover exclusive-bound walks, outer-layer subqueries, version-gated verification, bounded sum-index reads, and indexed replay version handling.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant GroveDBProofVerifier
  participant execute_proof_for_grove_version
  participant MerkProofVerifier
  GroveDBProofVerifier->>execute_proof_for_grove_version: proof bytes, limit, direction, GroveVersion
  execute_proof_for_grove_version->>MerkProofVerifier: verify using version-selected proof-tail behavior
  MerkProofVerifier-->>GroveDBProofVerifier: verification result
Loading

Suggested reviewers: thepastaclaw, quantumexplorer

Merge Risk: ⚪ Minimal · up to ecd45

No actionable merge-blocking risk remains in the supplied evidence: V4 enables the revised limit-cut behavior, while earlier versions retain their existing semantics.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ecd45

The change broadens proof acceptance only under an explicit protocol version while preserving result limits and proof-integrity checks. No introduced security bypass was identified. Production version activation and downstream trust assumptions were not established by this review.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A party supplying proof bytes can exercise the changed acceptance rule in consumers using the new policy, including ordinary, aggregate-carrier, and indexed-axis query paths. The evidenced security boundary is authenticated query-result acceptance; tenant, service, credential, and deployment exposure cannot be determined from these library paths alone.

Trust Boundaries and Controls

  • observed — The caller supplies GroveVersion separately from proof bytes. GroveDB verification returns a reconstructed root and results, so the returned root is not itself an independently trusted anchor. This is an existing contract, not an introduced vulnerability; the legacy Merk verify_proof helper explicitly compares against a caller-supplied expected hash.

Resilience and Maintainability Implications

  • observed — Released-version verification remains separated from the new implementation, limiting accidental control drift into older policies. Unsupported feature versions return errors in both Query dispatch and the trait default, preserving failure containment rather than falling back to a different acceptance rule.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: verifying a limit-cut proof that reveals a range-bound key after the cut.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 17 files. (1 skipped: …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw ✓. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 5, 2026
@thepastaclaw

thepastaclaw commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit 83a8d1b) · triage: critical · Phase 2 only (no Phase 1 for this repository)

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 2 only (no Phase 1 for this repository)

Static verification at head e152ca7 confirms the V1-only repair preserves pre-limit completeness checks, stream ordering, root reconstruction, and V0 behavior; no blocking defect was identified. One in-scope performance suggestion is confirmed: value-bearing tail nodes repeatedly scan the entire query. No local builds or tests were run; the supplied CI snapshot shows formatting and linting passing, with all three Ubuntu test shards still in progress.

🟡 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: normal by gpt-6.1-sol (effort low) — The production change in merk/src/proofs/query/verify.rs is a small, contained proof-verification guard with extensive tests, so it does not meet the large-or-intricate requirement for critical despite touching cryptographic proof acceptance.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-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:217-218: Avoid rescanning every query item for every tail value
  After the limit is reached, `self.items.iter().any(...)` restarts a full membership scan for every value-bearing tail node, introducing O(tail_nodes × query_items) work. For example, an ascending query containing `Key(0)` followed by many keys above the tree's maximum, verified at limit 1 against a fully revealed tree, scans every query item for every remaining value. This proof can reconstruct the authentic root and was previously accepted: the directional iterator remained at the next requested key, so each tail node exited after one lower-bound comparison. The 50,000-operation proof cap does not prevent this multiplicative comparison cost. Use an ordered membership lookup or a monotonic tail cursor that advances through query items without performing completeness checks, while preserving rejection of matching values beyond the limit.

Comment thread merk/src/proofs/query/verify.rs Resolved
@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.09%. Comparing base (c4362dc) to head (83a8d1b).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1009      +/-   ##
===========================================
- Coverage    93.18%   93.09%   -0.09%     
===========================================
  Files          336      336              
  Lines       105653   106501     +848     
===========================================
+ Hits         98449    99149     +700     
- Misses        7204     7352     +148     
Components Coverage Δ
grovedb-core 91.57% <100.00%> (+<0.01%) ⬆️
merk 93.62% <ø> (-0.41%) ⬇️
storage 91.94% <ø> (ø)
commitment-tree 95.62% <ø> (ø)
mmr 95.43% <ø> (ø)
bulk-append-tree 93.72% <ø> (ø)
element 97.18% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

Verified the supplied Phase-2 findings against head d7ea73f. The independent tail cursor fixes the prior multiplicative scan, but the new acceptance behavior also applies to historical GROVE_V3 verification without the feature gate required by the repository's versioning contract. Validation was static only; the supplied exact-head CI snapshot has pending or queued policy checks and no completed build/test evidence.

🔴 1 blocking

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: normal by gpt-6.1-sol (effort low) — The diff changes cryptographic proof acceptance in merk/src/proofs/query/verify.rs::execute_proof, but the production change is small and contained rather than large or intricate enough to qualify as critical.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-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`:
- [BLOCKING] merk/src/proofs/query/verify.rs:222-223: Gate the new tail acceptance independently of the V1 proof format
  This condition enables the relaxed tail verification for existing protocol snapshots, not just a new activation. GROVE_V3 already selects `prove_query_non_serialized: 1`, and `verify_layer_proof_v1` passes `PROOF_VERSION_LATEST`, which remains 1, without consulting a feature slot for this behavior. At the PR base, reaching the limit resets `in_range`, and a subsequent boundary key behind a hidden node can fail the lower-bound check. This new early return accepts that same stream. Consequently, identical proof bytes, query, limit, and GROVE_V3 produce different acceptance outcomes in old and upgraded verifiers.

  Unchanged generation and preservation of previously accepted results do not preserve historical acceptance. `grovedb-version/src/version/v4.rs:315–318` explicitly requires a feature gate for fixes that alter released accepted/rejected outcomes; its axis-descent and sum-budget documentation also distinguishes the V1 envelope from protocol activation. Add a tail-verification feature slot, retain the historical behavior for existing snapshots, and enable the relaxation in the new activation snapshot. Thread the selection through GroveDB and applicable Merk entry points with fail-closed dispatch. Add a regression using the same authentic limit-cut proof to demonstrate historical rejection under GROVE_V3 and acceptance under the newly enabled snapshot.

Comment thread merk/src/proofs/query/verify.rs Resolved
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw 1 thread unresolved — resolve it. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

The version gate and monotonic tail cursor resolve both prior findings at 3d217d7. One in-scope blocker remains: bounded-axis proof generation replays its secondary proof through the historical verifier, so affected honest proofs still fail before the newly gated verification path can consume them. Validation was static only; diff whitespace checks passed, but the supplied exact-head CI snapshot does not establish completed build or test results.

🔴 1 blocking | 🟡 4 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); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate changes in merk/src/proofs/query/verify.rs alter cryptographic proof acceptance after a query limit is reached, with version-gated dispatch across multiple GroveDB verification paths.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-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 `grovedb/src/operations/proof/verify.rs`:
- [BLOCKING] grovedb/src/operations/proof/verify.rs:1158-1164: Apply the gated semantics to the axis prover's replay too
  Bounded-axis verification now selects the new tail rule, but its production generator still cannot produce an affected payload. `indexed_axis/generate.rs::build_axis_descent_payload` generates the bounded secondary proof and calls `build_row_target_chains`, whose line 64 replays it with `execute_proof(..., 0)`. That call always retains historical tail checks, including under GROVE_V4.

  A concrete affected layout is a batch-built PSIT containing sums 0 through 19, with distinct nonempty primary keys except an empty primary key at sum 10. Empty keys pass the indexed-primary length validation. An ascending bounded query over sums [2, 9] with limit 3 lowers to an exclusive upper bound equal to the sum-10 secondary key. The sorted batch builds that key as the root; after yielding sums 2, 3 and 4, the proof includes hidden nodes before revealing this boundary. The replay therefore reaches the historical "Cannot verify lower bound" rejection and aborts `prove_query`, although the new verifier accepts the secondary stream.

  Use the caller's GroveVersion and V1 proof semantics for this V1 payload replay, matching the consumer here, and add an end-to-end bounded-axis regression for this layout. This changes a current V1 caller, not frozen V0 proof verification.

In `merk/src/proofs/query/verify.rs`:
- [SUGGESTION] merk/src/proofs/query/verify.rs:127-128: Make the provided version-aware trait method fail closed
  The concrete Query override dispatches on `execute_proof_limit_reached_tail` and rejects unknown versions, but the newly provided trait method ignores GroveVersion. A downstream wrapper implementing the existing trait methods inherits an entry point that silently uses historical behavior for slot 1 and can accept proofs for unsupported slot 2. This contradicts the version-aware method's documented selection contract and makes behavior depend on whether the receiver is Query or a delegating implementation.

  Preserve source compatibility with a default method that delegates only for slot 0 and returns `UnknownVersionMismatch` for slots it cannot implement. Implementations supporting slot 1 can override it. Add a regression with a delegating implementation that inherits the default. In-repository GroveDB callers use Query's protected override, so this is a public-API safety suggestion rather than a demonstrated live-node divergence.
- [SUGGESTION] merk/src/proofs/query/verify.rs:217-223: Isolate the historical and relaxed verifier implementations
  Feature-slot versions 0 and 1 now execute the same modified verifier body, selected by `accept_limit_reached_tail`. The false branch preserves historical checks today, but AGENTS.md lines 12–13 explicitly require separate version-owned functions and prohibit version-specific behavior in shared implementation bodies. Future changes to this body would affect both generations and require proving the released generation unchanged again.

  Dispatch the historical and activated behavior to separate generation-owned implementations, retaining the historical entry point and isolating the new V1-tail behavior in the activated implementation. Keep frozen V0 semantics unchanged. This is an implementation-isolation suggestion; no current historical acceptance divergence was found.
- [SUGGESTION] merk/src/proofs/query/verify.rs:1863-1879: Cover value-bearing tail nodes at exact item bounds
  The new tail-cursor regressions cover interior matches and gaps, but do not exercise value-bearing tail keys equal to a singleton Key or an inclusive range endpoint. Those cases directly protect the advancement predicates at lines 318–325: changing the ascending comparison from `<` to `<=` would skip Key(5), yet the current matched-tail examples at 4, 12 and 1 would still reject correctly.

  Extend the hand-built streams to reject a tail value at Key(5) in both directions and at inclusive range endpoints, and to accept unmatched values at exclusive endpoints. The current comparisons are correct; this is targeted coverage for the newly introduced cursor, not a reported verification defect.

In `grovedb-version/src/version/merk_versions.rs`:
- [SUGGESTION] grovedb-version/src/version/merk_versions.rs:82: Document the source-breaking version-table field addition
  `MerkProofVersions` is a public exhaustive struct. Adding this required field breaks existing downstream literals such as `MerkProofVersions { prove_count_offset_on_range: 0 }` and exhaustive destructuring. Deriving Default and providing a default trait method do not preserve those callers' source compatibility.

  The new changelog entry describes protocol activation but omits the Rust API break, whereas neighboring version-table additions explicitly identify their breaking impact. Add a breaking-API note explaining that callers must initialize `execute_proof_limit_reached_tail` to 0 for historical behavior, use struct-update defaults, or select an appropriate snapshot. Account for this source incompatibility in the eventual package release. No additional protocol gate is needed for the struct-schema addition.

Comment thread grovedb/src/operations/proof/verify.rs Resolved
Comment thread merk/src/proofs/query/verify.rs Resolved
Comment thread merk/src/proofs/query/verify.rs Resolved
Comment thread merk/src/proofs/query/verify.rs Resolved

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

Independent static review of the complete diff at 5ea1f13 found no actionable in-scope defects, and all seven prior findings are fixed. The GROVE_V4-only tail rule preserves historical verification, retains ordering and pre-limit completeness checks, and is consistently selected by applicable V1 consumers and indexed-axis prover replay. No builds or tests were run; the supplied exact-head CI snapshot shows change detection and security audit queued and policy reconciliation pending, so build/test completion remains unconfirmed.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(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); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate changes to execute_query_proof_v1 in merk/src/proofs/query/verify.rs alter authenticated proof acceptance rules, including post-limit value rejection and query-bound validation, and introduce version-dependent verification across multiple GroveDB proof paths.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 5, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

The complete diff at the specified head preserves historical verification, gates the relaxed tail rule to GROVE_V4, and applies that selection consistently to the affected consumers and indexed-axis prover replay. All seven prior findings are fixed, with no remaining actionable in-scope findings. Validation was static only; the supplied exact-head CI snapshot reports passing Ubuntu tests, linting, formatting, security audit, and coverage checks, while PR Hygiene remains pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(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); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate changes to merk/src/proofs/query/verify.rs alter cryptographic proof acceptance in execute_query_proof_v1 and introduce consensus-relevant version dispatch across multiple GroveDB verification paths.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 5, 2026
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/exact-limit-exclusive-bound branch from 1099cfc to ecd45eb Compare October 6, 2026 01:14
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 6, 2026
PastaPastaPasta and others added 4 commits October 5, 2026 20:39
…he cut

Once its limit runs out the prover hides the rest of the walk, but it
can still reveal a key it passed (an exclusive range end, or a later
query item's bound) behind the nodes it hid. The verifier checked that
key as a range bound and rejected the honest proof with "Cannot verify
lower bound of queried range", even at the prover's own limit. It is
the norm for subtrees written in one batch, so GroveDB's own
`prove_query` / `verify_query` disagreed for most limit-cut queries
over an exclusive bound, including subqueries whose outer layer the
limit cuts.

Once the limit is reached the walk is complete, so the V1 verifier no
longer checks later nodes as range bounds. A node carrying a value the
query matches is still rejected as a result past the limit. Every proof
accepted before is still accepted with the same result. Proof
generation and V0 verification are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
After the limit, each node carrying a value rescanned every query item
to see whether it matched, so a long tail over a query with many items
cost tail nodes x items comparisons, which the proof op cap does not
bound. Keys after the limit come in strict walk order, so a cursor over
the items only moves forward and the whole tail costs one pass. It is
kept apart from the verifier's own item iterator, whose position
records how far the walk proved the query.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
GROVE_V3 is live and already verifies V1 proofs, so accepting a
limit-cut proof it rejects would let upgraded and older verifiers
disagree on the same proof. Gate the change through a new slot,
`merk_versions.proof.execute_proof_limit_reached_tail`: 0 for grove
v1..v3, keeping the released rejection, and 1 for GROVE_V4.

`QueryProofVerify::execute_proof_for_grove_version` dispatches on the
slot and refuses unknown versions; it has a default body, so existing
implementations keep compiling. `execute_proof` keeps the released
behaviour. GroveDB's V1 path-query, carrier, axis-descent, sum-budget
and indexed-axis verifiers pass their grove version.

The same limit-cut proof is now pinned as rejected under GROVE_V3 and
accepted under GROVE_V4, at the merk and GroveDB levels.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The indexed-axis prover replays its secondary proof to build row chains
and replayed it with the released rules, so under GROVE_V4 a limit-cut
bounded read whose secondary proof reveals a boundary key aborted
`prove_query` although the verifier accepts the stream. The replay now
selects its behaviour from the same version slot as the verifier.

Also from review:
- split the verifier into version-owned functions: version 0 is the
  released body verbatim, version 1 adds the tail rule;
- the default `execute_proof_for_grove_version` body serves only
  version 0 and refuses others instead of silently using the old rule;
- cover tail values on item bounds and the fail-closed default;
- note the `MerkProofVersions` field addition in the changelog.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The indexed-axis prover replay only ran its version-1 branch in tests,
since axis reads exist from GROVE_V4. Exercise the other two with a
GROVE_V4 snapshot whose slot is set to 0 (the released replay rejects
the limit-cut proof and aborts `prove_query`) and to 2 (refused as an
unknown version), on the same batch-written provable-sum indexed tree.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/exact-limit-exclusive-bound branch from ecd45eb to 83a8d1b Compare October 6, 2026 01:43
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw ✓. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

The complete PR diff preserves historical verification and confines relaxed limit-cut tail acceptance to GROVE_V4, with consistent version selection in the affected verifiers and axis-prover replay. Independent source inspection confirms that all seven prior findings are fixed, with no remaining actionable in-scope issues. This was a static review only; the supplied exact-head CI snapshot shows successful formatting, linting, and security audit checks, while all three Ubuntu test shards remain in progress.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(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); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate changes in merk/src/proofs/query/verify.rs alter cryptographic proof acceptance in execute_query_proof_v1 and introduce version-dependent verification across multiple GroveDB proof paths.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@QuantumExplorer

Copy link
Copy Markdown
Member

This is Claude. Closing in favor of #1012, at the maintainer's request.

This PR found the problem: an honest limit-cut proof fails at its own limit with "Cannot verify lower bound of queried range". #1012 fixes it in the merk prover, where it starts. When the limit runs out, create_proof_internal clears the "is a result" flag but not the "is an exclusive bound" flag. So an ancestor the walk passes back through goes out as a KVDigest behind the nodes it hid.

From the V1 envelope on (prove_query_non_serialized = 1, grove v3+), #1012 clears that flag too, so the key is emitted as a hash and the root is unchanged.

Every verifier in this PR's test matrix that still has the released code accepts the new shape. So #1012 needs:

  • no verifier change,
  • no second copy of the verifier,
  • no new trait method,
  • no new version slot,
  • and no change to the indexed-axis replay.

Clients verify these proofs once the node serving them is upgraded. V0 proofs (grove v1/v2) keep their shape.

Your GroveDB tests are ported in #1012 and pass under GROVE_V3 and the latest version: every cutting limit over batch-written subtrees, the subquery outer layer, and the indexed-axis bounded read.

One thing #1012 doesn't cover: nodes that haven't upgraded still produce the old shape. If clients should accept those proofs too, this PR's verifier tolerance could come back as a smaller follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants