Repository navigation
fix(proof)!: stop a capped layer with subqueries where its budget is spent (GROVE_V5) - #1058
Conversation
…spent (GROVE_V5) Under a per-instance cap (Query::limit), a V1 proof layer that has subquery branches was proven under the global budget only: the cap budgets the rows below the layer's keys, and an empty subtree spends none of it, so the layer could not be cut after `cap` keys. With no global limit, the normal case for a page merged with other queries, the layer carried every key of its range and only the descents stopped, so the proof grew with the range (#962). From GROVE_V5 the prover runs the descents, then proves the layer again at a Merk limit equal to the rows it processed before the budget ran out, and moves the rewritten row nodes over. The verifier reads such a layer with Merk's existing ProofLimitMode::UpperBound, a gap-free prefix of the layer query, and accepts an early stop only once its own accounting, from the rows it verified, shows the instance budget or the global budget spent. A layer that stops with budget left is refused. The prover keeps a layer whole once its walk has charged an empty plain Tree as a result row: the prover counts such a row and a default verifier does not (a mismatch that predates this change), so a cut by the prover's count could be refused there. A 5-row page over 200 index keys proves in 9,684 bytes under GROVE_V4 and 927 under GROVE_V5 (94,286 and 1,131 over 2,000 keys). Past about 25,000 keys the V4 layer exceeds Merk's 50,000-op cap and the proof does not verify at all; the V5 proof does. Gated by the new operations.proof.instance_cap_layer_truncation slot (0 in V1..V4, 1 in V5). GROVE_V4 and earlier generate and verify the same bytes as before: the V4 proof of the regression shape is pinned by length and digest, checked against the prover before this change. Proofs of queries without a per-instance cap are not affected. Query results do not change in any version. BREAKING CHANGE: under GROVE_V5 the proof bytes of this shape change, and a GROVE_V4 verifier refuses them. GroveDBOperationsProofVersions gains the instance_cap_layer_truncation field. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Warning Review limit reachedYou'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 5 minutes. View limit details
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. |
|
Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 3 threads unresolved — resolve them. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit b7f4c2c) · triage: normal · Phase 2 only (no Phase 1 for this repository) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1058 +/- ##
=========================================
Coverage 93.28% 93.29%
=========================================
Files 372 375 +3
Lines 116192 116460 +268
=========================================
+ Hits 108390 108650 +260
- Misses 7802 7810 +8
🚀 New features to boost your workflow:
|
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (no Phase 1 for this repository)
The V5 truncation path has multiple accounting and subset-verification defects that can make honest proofs unverifiable or expose rows outside the intended page budget. Formatting and the security audit passed, while linting and all three Ubuntu test shards were still pending; no completed code-check failure was available to adjudicate.
🔴 4 blocking | 🟡 2 suggestion(s) | 💬 1 nitpick(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Empty nested MMR descents desynchronize prover and verifier budgets
grovedb/src/operations/proof/generate.rs:2608-2627
The MMR descent marks has_a_result_at_level even when an empty MMR produces zero rows, while prove_non_merk_lower_layer_v1 charges no rows for that proof. The enclosing frame therefore sees no consumed_total change when it settles the descent, and an ancestor can charge an empty layer at generate.rs:3647-3655. The verifier does not make that charge when its Merk layer has revealed the MMR key: verify_layer_proof_v1 skips the empty-layer charge whenever merk_result.result_set is non-empty, and verify_mmr_lower_layer returns without consuming a row for an empty MMR. With a global budget, the prover can consequently truncate after that branch while the verifier still has a slot available and rejects the proof as stopping before its budget is spent. Align empty non-Merk descent accounting on both sides and add a nested empty-MMR round trip covering the mixed global/per-instance case.
source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate change to cryptographic proof generation and verification, which directly changes what authenticated data proofs are accepted as valid. - Phase 1 reviewers: not run (disabled for this repository)
- Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `grovedb/src/operations/proof/generate.rs`:
- [BLOCKING] grovedb/src/operations/proof/generate.rs:2608-2627: Empty nested MMR descents desynchronize prover and verifier budgets
The MMR descent marks `has_a_result_at_level` even when an empty MMR produces zero rows, while `prove_non_merk_lower_layer_v1` charges no rows for that proof. The enclosing frame therefore sees no `consumed_total` change when it settles the descent, and an ancestor can charge an empty layer at `generate.rs:3647-3655`. The verifier does not make that charge when its Merk layer has revealed the MMR key: `verify_layer_proof_v1` skips the empty-layer charge whenever `merk_result.result_set` is non-empty, and `verify_mmr_lower_layer` returns without consuming a row for an empty MMR. With a global budget, the prover can consequently truncate after that branch while the verifier still has a slot available and rejects the proof as stopping before its budget is spent. Align empty non-Merk descent accounting on both sides and add a nested empty-MMR round trip covering the mixed global/per-instance case.
In `grovedb/src/operations/proof/instance_cap_layer_truncation/v1.rs`:
- [BLOCKING] grovedb/src/operations/proof/instance_cap_layer_truncation/v1.rs:60-68: The empty-tree workaround preserves an incorrect budget boundary
The prover charges a terminal empty plain `Tree` as a row at `generate.rs:3588-3592`, but the ordinary verifier omits that tree when `include_empty_trees_in_result` is false (`verify.rs:2746-2756`) and only authenticates it without charging later (`verify.rs:2869-2879`). The fallback here leaves the whole layer intact instead of making the verifier charge the authenticated terminal row. That allows a later key such as `c` to be returned after the prover-side page was spent on `a`, and it defeats the V5 proof-size bound. In addition, `empty_plain_tree_rows` is stored on the walk-wide `V1LimitState` and passed to every later capped layer (`generate.rs:3666`), so an unrelated earlier empty-tree row disables truncation for independent branches and can again exceed Merk's operation limit. Charge the terminal empty tree in the V5 verifier regardless of whether it is reported, preserve the old behavior behind the V4 gate, and remove the proof-wide fallback/counter.
- [BLOCKING] grovedb/src/operations/proof/instance_cap_layer_truncation/v1.rs:87-100: A suffix containing only absence witnesses is never truncated
The truncator decides whether anything remains to hide by looking only for value-bearing rows through `proof_node_row_key`. That helper deliberately returns `None` for every `KVDigest*` boundary node. A capped multi-item query can therefore spend its page on an early populated key and then have many absent requested keys represented by digest witnesses; `reveals_a_row_past_the_budget` stays false and the original proof, including the entire absence-witness suffix, is retained. With enough absent items, the honest V5 proof still exceeds `MAX_PROOF_OPS` and cannot verify even though the page contains only one returned row. Detect key-bearing digest witnesses after the cut and regenerate the proof at the processed-row limit without counting those witnesses as result rows.
In `grovedb/src/operations/proof/verify.rs`:
- [BLOCKING] grovedb/src/operations/proof/verify.rs:1961-1965: Subset verification does not recognize a cap lifted during merge
`PathQuery::merge` v1 lifts an input's global `SizedQuery::limit` into the merged branch's `Query::limit` (`grovedb/src/query/merge/v1.rs:102-119`). The merged V5 proof can therefore truncate the descendant layer after the rows spend that lifted cap. When a caller verifies the original component with `verify_subset_query`, the original query still has only a global limit, so `frame_instance` is `None`; this code selects `ProofLimitMode::Exact` rather than the V5 prefix mode. For example, a component with a global limit of five and a first index key containing five documents can produce a merged proof containing only that first index key, but subset verification of the original component expects the index layer to be complete and Merk rejects it before GroveDB can account for the descendant rows. The existing regression passes an already instance-capped `page()` query and does not cover the original globally limited component. Apply the V5 prefix dispatch and post-descent budget check to this lifted-component subset path, while retaining exact verification for V4.
In `grovedb/src/operations/proof/instance_cap_layer_truncation/mod.rs`:
- [SUGGESTION] grovedb/src/operations/proof/instance_cap_layer_truncation/mod.rs:82-118: Centralize proof-node value classification
`proof_node_row_key` duplicates the exhaustive value-bearing versus digest-only `Node` classification already present in `GroveDb::get_key_value_from_node` at `verify.rs:5040-5072`. These copies can diverge when the proof vocabulary gains a new node variant, causing truncation to count or transfer different rows from the verifier. Add a borrowed key/value accessor on the proof `Node` type in `grovedb-query` and use it for both row extraction and truncation classification, leaving the cap accounting itself in GroveDB.
In `grovedb/src/tests/instance_cap_layer_truncation_tests.rs`:
- [SUGGESTION] grovedb/src/tests/instance_cap_layer_truncation_tests.rs:129-136: Pin the V4 prover cost as well as its proof digest
`prove_and_verify` discards the `OperationCost`, while the V4 regression only pins proof bytes and their digest. That would not detect an implementation that performs the new second Merk walk under the V4 path, discards its result, and still emits the historical bytes. Because proof-generation costs are consensus-critical, capture the base V4 cost for the fixture and assert it alongside the digest; this need not constrain V5's additional work.
In `grovedb-version/src/version/v5.rs`:
- [NITPICK] grovedb-version/src/version/v5.rs:37-45: Clarify which versions serve instance-capped queries
The V5 documentation says V1 through V4 prove this layer under the global budget, but `path_query_methods.per_instance_query_limits` is zero in V1 through V3. Those versions reject per-instance capped queries before proof dispatch; V4 retains the full-layer behavior, and V5 enables truncation. Update the compatibility wording to distinguish V1-V3 rejection, V4 full-layer proofs, and V5 truncated proofs.
…absence witnesses past the cut Review follow-up for the GROVE_V5 layer truncation. - The prover cuts a layer only when the frame's instance budget is spent. A walk that ends because the global budget ran out keeps the shape V4 gives it, which the global limit already bounds. Prover and verifier do not charge the global budget identically for every empty descent (a subtree whose only content is an empty MMR costs the prover an empty-layer slot and the verifier none, which predates the truncation), so a cut on the global budget could be refused as stopping with budget left. The instance budget counts rows only. - The cut also applies when the only thing revealed past the budget is a range bound proving a later queried key absent, not just a row. - Node::key_and_value and Node::key (grovedb-query) classify the proof nodes in one place; get_key_value_from_node and the truncation use them. - The V4 pin also asserts the prover's cost, checked against the prover before the truncation. - Docs: only V4 serves per-instance caps before V5; V1..V3 refuse them. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
On the finding that is not inline (empty nested MMR descents): Confirmed, and it predates this PR: a subtree whose only content is an empty MMR costs the prover an empty-layer slot of the global budget and the verifier none, in V4 as well. I did not change that accounting here. 61ed100 makes the cut independent of it instead: the prover now truncates only when the frame's instance budget is spent, and that budget counts rows only. A walk that ends because the global budget ran out keeps its V4 shape, which the global limit already bounds. Tests: The other six are answered on their threads. |
|
Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 2 threads unresolved — resolve them. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)
One blocking budget-accounting defect remains in the V5 proof path: an empty nested MMR can consume a global budget slot during generation without consuming one during verification, leaving an honest layer stop with verifier budget remaining. The available CI snapshot shows no failed code checks, but build, test, lint, and formatting checks are still queued or pending.
🔴 1 blocking
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Empty nested MMR descents desynchronize prover and verifier budgets
grovedb/src/operations/proof/generate.rs:2608-2627
The empty-MMR path in generate_mmr_layer_proof returns without decrementing its effective budget, while the enclosing walk can still charge a global empty-layer slot when that descent produces no rows. The V5 change only prevents truncate_instance_capped_layer from running when the instance budget is not exhausted; it does not align the verifier's global budget with that prover-side empty-layer charge. For example, with a global layer budget of two, an empty MMR can consume the first prover-side slot and a following populated subtree can consume the second, leaving the prover's layer proof stopped after those keys while the verifier still has one global slot after authenticating the empty MMR. UpperBound then reports an early stop and check_instance_capped_layer_stop rejects because neither the verifier's instance nor global budget is spent. The existing regression masks this by adding a later empty subtree that consumes the verifier's remaining slot; add coverage for an empty MMR followed directly by a populated requested subtree and align the owning prover/verifier accounting paths.
source: gpt-6.2-astra (phase2-reviewer: general)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate change to proof generation and verification that changes the cryptographic proof acceptance rules in grovedb/src/operations/proof/verify.rs and related proof-generation code. - Phase 1 reviewers: not run (disabled for this repository)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `grovedb/src/operations/proof/generate.rs`:
- [BLOCKING] grovedb/src/operations/proof/generate.rs:2608-2627: Empty nested MMR descents desynchronize prover and verifier budgets
The empty-MMR path in `generate_mmr_layer_proof` returns without decrementing its effective budget, while the enclosing walk can still charge a global empty-layer slot when that descent produces no rows. The V5 change only prevents `truncate_instance_capped_layer` from running when the instance budget is not exhausted; it does not align the verifier's global budget with that prover-side empty-layer charge. For example, with a global layer budget of two, an empty MMR can consume the first prover-side slot and a following populated subtree can consume the second, leaving the prover's layer proof stopped after those keys while the verifier still has one global slot after authenticating the empty MMR. `UpperBound` then reports an early stop and `check_instance_capped_layer_stop` rejects because neither the verifier's instance nor global budget is spent. The existing regression masks this by adding a later empty subtree that consumes the verifier's remaining slot; add coverage for an empty MMR followed directly by a populated requested subtree and align the owning prover/verifier accounting paths.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Align empty plain-tree budget accounting — The prover charges a terminal empty plain
Treerow while the default verifier authenticates it without charging a result slot. This pre-existing acceptance mismatch is intentionally deferred, but it changes verifier behavior beyond the truncated-layer path and should be handled by the tracked follow-up.- Follow-up: #1061
…4 and V5 Review follow-up. A subtree whose only content is an empty MMR costs the prover a global empty-layer slot and the verifier none, in V4 as well. The test now covers an empty MMR followed directly by populated subtrees: in every shape the V5 proof is the V4 proof byte for byte and both verifiers reach the same verdict, including the one honest proof both refuse for a missing lower layer. The truncation does not add to the mismatch; aligning the two counts is a separate change. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
On the remaining finding (empty nested MMR descents), re-reviewed at The uneven charge is real, but it is not something the V5 path adds, and the rejection described does not happen. I ran the shape from the finding and two neighbours under both versions (now in
Why The third row is the mismatch at its worst, and it is the same refusal in V4, on |
|
Waiting for bot review — coderabbitai not yet · thepastaclaw ✓. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)
The exact head adds regression coverage for uneven global-budget accounting and pins identical V4/V5 proof bytes and verdicts without changing the truncation implementation. Static review found no new in-scope correctness, security, consensus, or architecture defect; CI checks are still queued or in progress, with no failed code check reported.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate change to Merkle proof generation and verification, with grovedb/src/operations/proof/verify.rs changing what authenticated proofs are accepted and therefore affecting a cryptographic integrity boundary. - 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.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-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.
|
Bots are done — your move: post |
Conflicts: CHANGELOG.md (both entries kept) and get_key_value_from_node in grovedb/src/operations/proof/verify.rs (kept the shared Node accessor). develop removed Node::KVBackwardsReferencesValueHash (#1059), so it is dropped from Node::key_and_value, Node::key and their test as well. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
Conflict: get_key_value_from_node in grovedb/src/operations/proof/verify.rs (kept the shared Node accessor). develop added the big sum proof nodes (#1055): KVBigSum and KVRefValueHashBigSum are rows, KVDigestBigSum is a range bound, KVHashBigSum and HashWithBigSum reveal no key. They are classified in Node::key_and_value and Node::key, and covered by their test. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
Conflicts: the version tables and their test (both PRs added proof slots, all kept) and the row walk in generate.rs (kept develop's descent check). develop now carries #1061: under GROVE_V5 the verifier charges an empty plain Tree result row it does not report, as the prover does. With the two sides counting the same rows against the instance budget, the guard this branch carried for that mismatch is removed: V1LimitState's empty_plain_tree_rows counter and the truncation's early return. A page such a row helps fill is now cut like any other and verifies; the test is an_empty_tree_row_counts_toward_the_cut. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw ✓. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)
The final head correctly confines instance-capped layer truncation to GROVE_V5, keeps GROVE_V4 proof behavior intact, and aligns prover, verifier, version dispatch, and shared proof-node classification. All code-related CI checks pass; the only pending check is PR Hygiene, which is not a code failure. No new in-scope defects were found.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — This is a large and intricate proof-generation and verification change affecting versioned query behavior, but it does not directly modify the listed critical surfaces such as consensus rules, cryptography, signatures, network deserialization, or storage migrations. - Phase 1 reviewers: not run (disabled for this repository)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-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.
Takes #1058, #1057, #1060 and #1062 from develop, up to 2a79d03. Four files conflicted, all in code the Engine seam rewrote. Two conflicts were import lines. In lib.rs and run_path_query.rs upstream changed functions that the seam had moved out of their impl block: the change is applied to the moved function, and the copy the merge put back is dropped. Three pieces of upstream's new code merged cleanly and are adapted to the engine. The four entry points of the indexed trees with a 128-bit sum and the five reads of the big sum axis are methods of GroveDb<E>, and the read of a band's population takes the read transaction of its operation where it started a write transaction. The prover's cut of a layer under a per-instance cap reads its Merk through NodeStore. lignin-testkit names the new variants where a match is exhaustive and lists the two new trees as not yet produced by a workload. Part of #1052. Lignin-Tasks: SYNC-M0 Co-Authored-By: Claude Fable 5.2 <[email protected]>
…d from it Takes #1058, #1057, #1060 and #1062 from develop at the boundary of gate M0. The entry points and reads of the trees with a 128-bit sum and the prover's cut of a capped layer run on any engine, and tests run them on a second one. The cost model's storage crate has the commit and write scope errors, so check.sh passes again, and the surface list classifies the operations the Engine seam and #1062 made public. The golden corpus is recorded from the engine at 2a79d03: every trace is unchanged apart from its engine line. Part of #1052. Lignin-Tasks: SEAM-04, BASE-02
… under a limit of its query node Two workloads join the suite, after the ones that are there, for what GroveDB gained after the first corpus: - `wide-ranks` keeps the two indexed trees with a 128-bit sum (GroveDB #1062) where the grove version creates them and their counterparts with an `i64` sum elsewhere. Entries are written through the four new methods (`IndexedTree::BigSum`, `IndexedTree::CountBigSum`) and through batches, and read in the order of the big sum axis: pages, bands of values, the rank of a key, how many entries a band holds, and one page for each of several trees. An entry may be a tree whose own sum no `i64` holds. - `capped-layers` reads pages of an index with the limit on the query node that walks its keys (GroveDB #1058): alone, next to a limit of the whole query, inherited by the layer below, and on a branch of a merged query. Grove version 4 and grove version 5 return the same rows and prove them differently. `tests/upstream.rs` checks what both return against models on every grove version, pins the encoding of the new kinds, and shows that the proof of a page is shorter from grove version 5 and not accepted by grove version 4. Coverage gains three groups of operations: the methods and axis reads of the new trees, limits over subqueries, and a batch that fills a tree it creates. Two features say what a grove version does: `big_sum_axis` and `indexed_batches_in_step`. On grove versions 1 to 4 a batch that writes entries of an indexed tree can leave its rankings out of step, so there `wide-ranks` writes entries through the methods of the trees and rebuilds the rankings before it reads them. No stream that was pinned changes. The trees `element-zoo` does not hold are four now, and the suite misses no element variant and no tree type. Lignin-Tasks: BASE-01 Co-Authored-By: Claude Fable 5.2 <[email protected]>
Basic explanation
What this does: Under
GROVE_V5, a proof of a limited page no longer carries every key of the index level the page walks. When a query node has a per-instance cap (Query::limit) and subqueries below it, the proof now stops that level right after the key whose rows filled the page. Before, it listed every key of the range and only stopped fetching the rows.Value: Proof size follows the page, not the size of the data. Dash Platform's composite document queries (a feed page proven together with its related lookups) build exactly this shape, and under
GROVE_V4every index key in range adds about 47 bytes to the proof whatever the page size: roughly 470 KB for a page over 10,000 keys, and past about 25,000 keys a proof that no longer verifies at all. Fixes #962.Risks: High care needed, since this changes what a verifier accepts: a level may now end early. The verifier accepts that only after it has itself counted the page as full from rows it verified, so a prover cannot hide a row the query owes (the argument and the refusal tests are below).
GROVE_V4and earlier are untouched: same proof bytes, same verifier. AGROVE_V4verifier refuses aGROVE_V5proof of this shape, so prover and verifier have to move to V5 together.Issue being fixed or feature implemented
Fixes #962.
A per-instance cap budgets the rows found below a level's keys, not the keys. A key whose subtree is empty spends none of the cap, so a later key may still owe rows, and the level cannot simply be cut after
capkeys.GROVE_V4, the first version to serve per-instance caps, therefore proves such a level under the global limit only. A merged query has no global limit, so the level is proven with every key in range.Example:
index/<key>/doc, an ordered index whose keys each hold one document, queried for the first 5 documents and merged with one unrelated key lookup.Both versions return the same 6 rows. The proof differs:
GROVE_V4proofGROVE_V5proofThe V5 proof still grows by the height of the index tree (a few hashes per level), not by its number of keys.
Size is not the only cost under V4. Merk refuses a layer proof of more than 50,000 ops (
MAX_PROOF_OPS), which a level proven in full reaches at about 25,000 keys. Past that, the V4 proof of a 5-row page does not verify at all ("Proof exceeds maximum operation count"). The V5 proof of the same page over 26,000 keys is under 2,000 bytes and verifies.Before (
GROVE_V4), the index level of the 200-key proof:After (
GROVE_V5):What was done?
Option 1 of the issue: descend first, then prove the level truncated.
Prover (
prove_subqueries_v1). The level is walked as before and the descents run until the instance budget is spent. If the level reveals anything after that point (a row the page does not need, or a range bound proving a later queried key absent), its Merk proof is generated again with a Merk limit equal to the number of rows processed, and the nodes the walk had rewritten for those rows (resolved references, child hashes) are moved into it. A Merk proof at a limit reveals nothing after its last result, so everything past the cut is hashes. Only the instance budget triggers the cut: a walk that ends because the global budget ran out keeps its V4 shape, which the global limit already bounds.Verifier (
verify_layer_proof_v1). A level with subquery branches under a per-instance cap is read with Merk's existingProofLimitMode::UpperBound(added in #1012 for per-key aggregate pages): the result is a gap-free prefix of the level's query, and the mode reports whether the proof stopped early. After all revealed rows are verified, descents included, an early stop is accepted only if the verifier's own budget is spent.Versioning. One new slot,
operations.proof.instance_cap_layer_truncation: 0 inGROVE_V1..GROVE_V4, 1 inGROVE_V5. The versioned code is ingrovedb/src/operations/proof/instance_cap_layer_truncation/(v0.rskeeps the released behaviour,v1.rsadds the truncation and the check), and the prover and the verifier read the same slot. Merk's prover and verifier are unchanged.grovedb-querygains two accessors on the proofNode(key_and_value,key), one exhaustive classification that the truncation and the chunk verifier'sget_key_value_from_nodenow share.Scope. Only levels that have subquery branches while a per-instance cap is in force. Levels without subqueries, queries with a global limit only, and queries with no limit are not affected by the slot (a test pins that an uncapped query and a globally limited one prove the same bytes in V4 and V5).
Why a truncated level cannot drop an owed row
UpperBoundverification returns the first keys the level's query selects in the walk's direction. A hidden node between two revealed keys of a range, a revealed key after the stop, and a stop before the first result are all refused by Merk. This holds ascending and descending, and for a level with several query items.Consequences:
Cases where the prover keeps the level whole
The cut is only as good as the count behind it. There was one row the two sides counted differently against the instance budget, in every version: an empty plain
Treethat is itself a result row, which the prover charges and a default verifier (include_empty_trees_in_result = false) did not. #1061, now merged, makes aGROVE_V5verifier charge it. This PR carried a prover-side guard for that case while #1061 was open; it was removed whendevelopwas merged in, and a page such a row helps fill is now cut like any other (an_empty_tree_row_counts_toward_the_cut). The truncation is meant to be selected together withunreported_empty_tree_row_charge, asGROVE_V5does.The global budget has a similar unevenness that also predates this change: a subtree whose only content is an empty non-Merk tree (an empty MMR, say) costs the prover an empty-layer slot and the verifier none. The instance budget counts rows only and is not affected, which is why only the instance budget triggers the cut. With the instance budget unspent the V5 proof is the V4 proof, byte for byte (
an_uneven_global_charge_does_not_cut_the_layer,the_global_budget_alone_does_not_cut_the_layer).How Has This Been Tested?
New file
grovedb/src/tests/instance_cap_layer_truncation_tests.rs(21 tests). Every proved result is also compared with the trusted read.merged_page_proof_does_not_grow_with_the_range: the issue's regression. 10 and 200 keys with populated children, limit 5, merged with a disjoint limit-free branch: verifies, returns the 5 rows, the index level reveals 5 keys, and the 200-key proof is within 512 bytes of the 10-key one.descending_page_stops_below_its_last_row: the same descending.empty_children_are_walked_until_the_budget_is_spent: two empty subtrees between populated ones, in both directions; a page the data cannot fill (the level stays whole); a budget spent on the last key.a_subtree_larger_than_the_budget_ends_the_layer.conditional_branches_and_rewritten_rows_survive_the_cut: a level mixing references, subtrees reported as rows and subtrees a conditional branch descends into, cut at four different points.a_global_limit_composes_with_the_cut.a_layer_cut_for_a_smaller_page_is_refused(both directions),a_hand_abridged_layer_is_refused(the honest proof with its level replaced by one that stops two keys early; it rebuilds the same root, and only the budget check refuses it),a_cut_after_an_empty_child_with_budget_left_is_refused.v4_proves_the_layer_in_fullpins theGROVE_V4proof of the regression shape (200 keys, all revealed) by length and BLAKE3 digest, and the prover's cost (seeks, loaded bytes, hash calls), so a second walk under V4 would show. I ran that test againstdevelop'sgenerate.rs,verify.rsandproof/mod.rswith the same constants and it passes, so the V4 bytes are the ones the code before this change emits.v5_proof_is_a_fraction_of_the_v4_proof,the_two_versions_read_each_others_layers,queries_without_a_cap_prove_the_same_bytes,an_unknown_slot_value_is_a_version_error.a_page_over_a_range_too_long_to_prove_in_full_verifies: 26,000 keys. The V4 proof is refused by Merk's op count, the V5 proof verifies.a_layer_longer_than_a_merk_limit_stays_whole: 65,536 empty subtrees ahead of the page. The prover leaves the level whole, as V4 does; it is past Merk's op count either way.verify_subset_query, the way Platform reads a component before verifying the whole, and checks that a larger page is not a subset of it.an_empty_tree_row_counts_toward_the_cut: an empty plain tree as a result row, below the capped level and in it. V4 keeps the level whole; V5 cuts it and verifies.absence_witnesses_past_the_cut_are_hidden: a query naming its keys one by one, the page filled by the first; V4 leaves the absence witnesses of the later keys in the proof, V5 hides them.a_lifted_global_limit_never_lands_on_a_truncated_layer: the V5 merge refuses to lift a global limit onto a body with subqueries, and where it does lift (a body of rows) the globally limited component still verifies as a subset of the merged proof.grovedb-query:key_and_value_accessors_classify_every_family.grovedb-version:instance_cap_layer_truncation_is_gated_to_v5, and the slot added tov5_matches_v4_apart_from_its_gates.All pass locally on the final tree (after merging
developwith #1055, #1059 and #1061): 952grovedblibrary tests under those filters pluschunk,trunkand #1061's two suites (the 21 new ones, the per-instance limit, merge and limit-cut suites, and every test withproofin its path), 40 + 8 in the two integration files, 64 ingrovedb-version, 259 ingrovedb-query. Clippy with-D warningsand the format check are clean, and the verify-only build compiles. I did not run the whole workspace suite.The change was also read cold by a separate adversarial review pass (asked to build a proof that drops, reorders or misplaces a row, across directions, multi-item levels, conditional branches, nested caps, global limits, non-Merk lower layers and subset verification). It found no such proof. It did find the empty-tree count mismatch, which is how that case came to be handled above.
Merges of
develop(latest b7f4c2c): theNodeaccessors follow the proof nodes #1059 removed and #1055 added, and the empty-tree guard is gone now that #1061 is in.Review round 1 (commit 61ed100): the cut now triggers on the instance budget only, absence witnesses past the cut are hidden, the node classification moved to
Nodeaccessors ingrovedb-query, and the V4 pin also covers the prover's cost.Breaking Changes
Proofs change under
GROVE_V5only, for the shape above.GROVE_V5is unreleased.Public interface
Node::key_and_valueandNode::key(grovedb-query), additions only.GroveDBOperationsProofVersions::instance_cap_layer_truncation(grovedb-version). Code that builds that struct by hand has to supply the field. 0 selects the released behaviour, 1 the truncation, any other value is aVersionErroron both sides.GROVE_V5: a V1 proof level with subquery branches under a per-instance cap ends after the key that spent the instance budget. No new proof node, op or envelope variant; the level is an ordinary Merk proof at a limit.GROVE_V5: such a level may stop before its limit, if the frame's instance budget or the global budget is spent. New refusal:Error::InvalidProofwith "V1 proof layer under a per-instance limit stops before the limit is spent".GROVE_V4verifier refuses a truncated level ("Proof is missing data for query range"). AGROVE_V5verifier accepts a level proven in full.Not in this PR
u16) is left whole, as in V4. Such a level is past Merk's 50,000-op cap in every version, so its proof does not verify before or after this change.limitkeys when a large subtree fills the page early. That is bounded by the limit and is left as it is.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
b7f4c2c/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.