Repository navigation
fix(proof)!: count and report tree result rows as the trusted read does (GROVE_V5) - #1061
Conversation
…ROVE_V5) An empty plain `Tree` that is itself a result row is counted against the limit by the trusted read and charged one row by the V1 prover. A verifier that leaves empty trees out of its results (the default of `verify_query` and `verify_subset_query`) bound the row and charged nothing, so its budget ran ahead of the prover's: it refused the honest proof of a page whose budget such a row spent, or reported an item past the page. From GROVE_V5 the verifier charges the row against the global limit and the per-instance cap and stops where the budget is spent. The new slot `proof.unreported_empty_tree_row_charge` is 0 in V1..V4, which verify as 6.1.1 does, and 1 in V5. The prover does not read it: proof bytes are the same. 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 35 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 not yet. Wait for the missing reviews, or a writer can post |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
|
✅ Final review complete — no blockers (commit dbfa8d3) · triage: normal · Phase 2 only (no Phase 1 for this repository) |
Conflict in CHANGELOG.md: both Fixed entries kept. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 1 thread unresolved — resolve it. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (no Phase 1 for this repository)
The PR fixes ordinary terminal empty-tree accounting under GROVE_V5, but it misses conditional branches whose matching branch is (None, None). In that case, the query executor treats the tree as a terminal result while proof generation and verification classify it as an empty child, so per-instance pagination can still diverge from the trusted read. The issue is blocking because it leaves the stated verifier/prover budget invariant incomplete; current CI has no reported failures, but two test jobs remain in progress.
🔴 1 blocking
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 version-gated Merkle proof verification behavior, directly affecting cryptographic proof acceptance and query-result correctness in GROVE_V5. - 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/verify.rs`:
- [BLOCKING] grovedb/src/operations/proof/verify.rs:2866-2871: Terminal empty trees on `(None, None)` conditional branches bypass V5 row charging
`has_subquery_or_matching_in_path_on_key` returns true for any matching conditional key, even when `add_conditional_subquery(item, None, None)` provides neither a subquery nor a subquery path. Therefore this helper is not reached: the preceding empty-tree branch treats the tree as an empty child and calls `charge_empty_layer()`, which does not consume the frame's per-instance row budget. However, `terminal_keys_v1` explicitly treats the `(None, None)` branch as terminal, and the trusted read falls through to `basic_push`, which returns the tree row and charges an instance slot. A limited query can consequently continue past the trusted page under GROVE_V5 and return inconsistent pagination results. The prover has the same classification at `generate.rs:3552`, so this is an uncovered sibling of the accounting mismatch addressed by this PR. Distinguish an actual descent/path branch from a matching terminal conditional branch in both proof generation and verification, and add a regression test with a matching `(None, None)` branch and an empty tree.
…result row (GROVE_V5) The V1 prover and verifier read every key a conditional branch matched as a descent, even a branch with neither a subquery nor a subquery path, which the trusted read treats as "return this element". An empty tree at such a key was proved as an empty child: never reported, and charged against the global limit only, so a page under a per-instance cap ran past the trusted read's. A populated tree there could not be proved. From GROVE_V5 both sides ask whether the query has anything below the key, through one versioned function. The new slot `proof.subquery_descent_on_key` is 0 in V1..V4, which prove and verify as 6.1.1 does, and 1 in V5. Raised by review on #1061. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — coderabbitai not yet · thepastaclaw 1 thread unresolved — resolve it. Wait for the missing reviews, or a writer can post |
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
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 current head correctly aligns GROVE_V5 proof generation and verification for conditional branches without subqueries and for unreported empty plain-tree rows. The prior terminal empty-tree charging issue is fixed, historical GROVE_V1–V4 behavior remains explicitly gated, and no new in-scope correctness, security, architecture, or quality findings were identified. Build, test, lint, and formatting checks were still pending in the supplied CI snapshot, with no failed code checks reported.
🔴 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); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 8: 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 substantial, cross-cutting proof-generation and verification behavior change with extensive version-gated tests, but it does not directly modify the listed critical surfaces such as consensus rules, cryptography, key handling, or storage migrations. - 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-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,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.
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
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]>
Takes develop up to f101691: #1056 (a failed parent read is a storage error), #1059 (the referrer list of a bidirectional-reference target is out of node hashes), #1055 (CountBigSumTree and ProvableBigSumTree) and #1061 (a verifier counts tree result rows as the trusted read does). #1056 and the NodeStore seam both rewrote the two direct element reads in merk/src/element/get.rs. The reads stay on the seam (`get_node_for_read`, the same storage call and cost), and the seam's error mapping now keeps a storage error typed, as #1056 requires, while a record that does not decode is still `CorruptedData` with the same text. The adapter test of that mapping and the error paragraph of the NodeStore contract follow. git merged merk/src/merk/restore.rs without a conflict and wrongly: #1055's new `KVBigSum` arm took the lines the seam had rewritten in the `KVCountBigSum` arm before it, which was left writing through a batch that no longer exists. Both arms now write through the change set. lignin-testkit names the two new element variants and tree types where it lists every one (`workload::coverage`, the stream encoding of a tree type), and its coverage test expects them as not yet produced. Part of #1052. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…d from it Takes #1056, #1059, #1055 and #1061 from develop. The seams keep their behaviour and upstream's: a failed parent read is a storage error through the NodeStore read, and the restore arms of the new big sum trees write through the change set. The layout observer reads a record whose referrer list changed under an unchanged hash, the cost model knows the two new aggregates, and the golden corpus is recorded from the engine at f101691; it replays 290 of 290 and 5 of 5 on the merged tree. Part of #1052. Lignin-Tasks: SEAM-01, BASE-02
Basic explanation
When a query has a limit, the prover and the verifier each count rows as they walk the proof, and they must stop at the same row. For one kind of row they did not count alike: an empty plain tree that is itself a result (nothing in the query descends into it). The prover counts it. A verifier that leaves empty trees out of its results, which is what
verify_queryandverify_subset_querydo, skipped it without counting. From that row on the verifier believed it had one more slot than the prover had, so it either refused an honest proof or reported a row that belongs to the next page.From
GROVE_V5the verifier counts that row too, even though it still does not report it.GROVE_V4and earlier verify exactly as before.Before and after
State:
Query: every child of
index, everything below each child,SizedQuerylimit 2.query_raw(trusted read)a/d,a/tverify_query, GROVE_V4 and GROVE_V5 before this changeInvalidProof("V1 proof is missing lower layer for non-empty tree at key 62")verify_query, GROVE_V5 aftera/dverify_query_with_optionswithinclude_empty_trees_in_result: true, every versiona/d,a/tThe same happens when the 2 is a per-instance cap (
Query::limiton theindexquery) instead of a global limit.If
index/bis an item instead of a tree, the old verifier does not refuse the proof. It returnsa/dandb, although the page the trusted read returns ends ata/t. UnderGROVE_V5it now returnsa/d.Second fix, raised in review: a conditional branch without a subquery
add_conditional_subquery(item, None, None)is how a query says "do not go below these keys": the trusted read returns the element at such a key and stops. Prover and verifier read every key a conditional branch matched as a key to descend into. So a tree at such a key was never treated as the row it is. FromGROVE_V5both sides ask whether the query has anything below the key.State as above, but the query exempts
afrom its subquery (Key(a)with no subquery and no path), andc/dis a third item:index/aisquery_rawa,b/d,b/e,c/db/d,b/e,c/da,b/d,b/e,c/dQuery::limit2a,b/db/d,b/ea,b/dQuery::limit1ab/dawithinclude_empty_trees_in_result: true)a, ...prove_queryfails withCorruptedPatha, ...Under
GROVE_V4the empty tree is not reported by any verifier, whateverinclude_empty_trees_in_resultsays, and it takes a slot of the global limit but not of a per-instance cap. This predates the PR and has a different cause from the first fix: here prover and verifier agree with each other and both disagree with the trusted read.Issue being fixed or feature implemented
Found while fixing #962 (PR #1058), which works around it on the prover side. Confirmed by a test on
developunderGROVE_V4andGROVE_V5before any code changed: the fourGROVE_V5tests of the new module failed there and theGROVE_V4pins passed.The two sides:
prove_subqueries_v1callscharge_row_with_instancefor the row.verify_layer_proof_v1(an empty plainTreeat a terminal position while the caller excludes empty trees) binds the row withverify_empty_tree_bindingand charges nothing.Which side is right
The prover. Three things point the same way:
query_raw) returns the empty tree as a row and counts it against the limit. A proof exists to attest that read, so the page it proves has to end where the read ends.verify_query_rawandinclude_empty_trees_in_result: truereport the row and already charge it, and those verifiers accepted the same proof bytes all along. A budget that depends on a reporting option cannot match a single proof.GROVE_V5local count page (run_local_count_offset_layer_dispatch) charges every returned row and reports the empty tree only on request.So the fix is on the verifier: charge the row it does not report, and stop where the budget is spent, as after any reported row.
Why this cannot hide a row the query owes
The row is charged only after
verify_empty_tree_bindinghas tied its bytes to the committed value hash. It is therefore a key the state holds, that the query selects, and that really is an empty tree. A prover cannot invent such rows to use up the budget, and cannot pass off a populated tree as empty (that is refused as before, issue #869). The trusted read spends a slot on the same row, so whatever comes after the stop belongs to a later page.a_proof_one_row_short_of_the_limit_is_refused_under_v5checks that a proof of a 2-row page is still refused for a 3-row query.What was done?
operations.proof.unreported_empty_tree_row_charge: 0 inGROVE_V1..GROVE_V4, 1 inGROVE_V5.grovedb/src/operations/proof/unreported_empty_tree_row_charge/{mod,v0,v1}.rs.v0charges nothing and never stops the walk.v1charges one row against the global limit and the frame's per-instance cap and reports whether a budget is now spent.verify_layer_proof_v1calls the dispatch right after binding the row, and breaks out of the layer when it says so. That is the whole change to the verifier (12 lines).operations.proof.subquery_descent_on_key: 0 inGROVE_V1..GROVE_V4, 1 inGROVE_V5, read by prover and verifier through one function,GroveDb::query_descends_on_key, ingrovedb/src/operations/proof/subquery_descent_on_key/{mod,v0,v1}.rs.v0is the released test (has_subquery_or_matching_in_path_on_key).v1is that test and, in addition,PathQuery::query_items_at_pathresolving to something below the key, which picks the branch the way the trusted read does.v1can only turn a descent into a row, never the reverse.prove_subqueries_v1computes the answer once per tree and its 13 descent guards read it, so a tree the query does not go below falls through to the arms that already prove a tree as a result row (child hash for a populated tree, a charged row for an empty one).verify_layer_proof_v1uses the same answer in its three branches for a tree without a lower layer. The V0 prover and verifier are not touched.GROVE_V5the proof of a query with such a branch changes when a tree sits at the exempt key. Proofs of every other query are byte for byte the same: the two tests differ only for a key whose branch has neither a subquery nor a path.CHANGELOG.mdand thegrovedb-version/src/version/v5.rsmodule doc list the gate.v5_matches_v4_apart_from_its_gateslists the slot.What changes for a caller of
verify_queryunder GROVE_V5Only limited queries (a
SizedQuerylimit or aQuery::limitcap) whose result rows include an empty plainTree, verified with empty trees excluded. For those:every_page_matches_the_trusted_read_without_its_empty_trees_under_v5checks, for budgets 1 to 10, both directions, global limit and per-instance cap, that the verifier's rows are exactly the trusted read's rows minus its empty plain trees.a_single_layer_page_counts_the_empty_tree_under_both_versions). A caller that needs "fewer rows than the limit means last page" should verify withinclude_empty_trees_in_result: trueand filter.Queries without a limit, queries whose budget the empty tree does not exhaust, and verifiers that report empty trees return the same rows as before.
No caller inside GroveDB reads the verifier's budget after the walk; the absence-proof path takes its row count from the query's limit, not from the walk.
Dash Platform, read from its code and not tested: PV15 selects
GROVE_V5, PV14 keepsGROVE_V4, so adoption is the pin bump. The one query family that can meet the condition is the contested-resource listing (verify_contests_proof) when it lists a level of the index that is not the last one and a value tree there was left empty after its polls were cleaned up. No caller in the repository infers "last page" from a short page for that shape.PR #1058
#1058 is not merged. It adds a prover-side guard for this mismatch (
V1LimitState::empty_plain_tree_rows, read bytruncate_instance_capped_layer_v1, which keeps a capped layer whole once such a row was charged). This PR is based ondevelopand leaves that guard alone. Once both have merged the guard is no longer needed underGROVE_V5and can be removed, together with an update of its testan_empty_tree_row_keeps_the_layer_whole, in a follow-up.How Has This Been Tested?
grovedb/src/tests/conditional_branch_without_subquery_tests.rs, 10 tests for the second fix (the sixGROVE_V5ones failed before the code changed, the fourGROVE_V4pins passed):GROVE_V5: six kinds of element at the exempt key (empty plain, sum, MMR and count-indexed trees, populated plain and sum trees), two query shapes (a default subquery with an exemption, and conditional branches only), both directions, no budget and every global limit and per-instance cap from 1 to 6. With empty trees reported the verified rows equal the trusted rows; without, they equal the trusted rows minus the empty plain tree. The same sweep fails underGROVE_V4and underGROVE_V5with only this slot set back to 0.GROVE_V4pins: the empty tree is never reported, it takes no slot of a per-instance cap, and a populated tree at the exempt key cannot be proved.GROVE_V5verifier. An unknown slot value is aVersionErrorfrom prover and verifier.grovedb/src/tests/unreported_empty_tree_row_budget_tests.rs, 15 tests for the first fix:GROVE_V5, and is refused underGROVE_V4with the exact released message.GROVE_V5, reported underGROVE_V4as released.GROVE_V5, refused underGROVE_V4.verify_subset_querycounts the same way.GROVE_V5, and the same sweep failing underGROVE_V4and underGROVE_V5with only this slot set back to 0.VersionError.Run locally:
cargo test -p grovedb --lib -- conditional_branch_without_subquery unreported_empty_tree_row_budget: 25 passed.cargo test -p grovedb --lib -- proof query verify subquery conditional per_instance limit empty_tree indexed aggregate mmr bulk dense commitment non_merk merge private_document_store count_offset reference axis sum_budget: 2858 passed, 1 ignored.cargo test -p grovedb --test branch_count_offset --test proof_breadth --test proof_formatting --test untrusted_decode: 54 passed.cargo test -p grovedb-version: 62 passed.cargo clippy -p grovedb -p grovedb-version --all-targets -- -D warnings: clean.cargo check -p grovedb --no-default-features --features verify: builds.cargo fmt --all -- --check: clean.The full workspace suite was not run locally.
Breaking Changes
Under
GROVE_V5only (unreleased).GROVE_V1..GROVE_V4are unchanged.include_empty_trees_in_result: true), a page under a per-instance cap ends one row earlier for each such empty tree, andprove_queryserves a query it refused when the tree is populated. AGROVE_V5proof of such a query made before this change no longer verifies.Public interface
GroveDBOperationsProofVersionsgains two public fields,unreported_empty_tree_row_charge: FeatureVersionandsubquery_descent_on_key: FeatureVersion. Code that builds the struct with an exhaustive literal must add them (0 for the released behaviour, 1 for the new one).GROVE_V5proof carries changes only for a query with a conditional branch that has neither a subquery nor a path.GroveDb::prove_queryand the other proving entry points: underGROVE_V5such a query is proved with the tree at the exempt key as a result row, and no longer fails withCorruptedPathwhen that tree is populated.GroveDb::verify_query,verify_subset_query,verify_query_with_absence_proof,verify_subset_query_with_absence_proof,verify_query_with_optionswithinclude_empty_trees_in_result: false, theGroveDBProof::verify*methods with the same setting, andverify_path_querychanges underGROVE_V5as described above.verify_query_rawand any verifier withinclude_empty_trees_in_result: trueare not affected by the first fix. The second fix changes them as well: they now return the tree at an exempt key.Checklist:
🤖 Generated with Claude Code
PR Hygiene ·
dbfa8d3/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.