Skip to content

fix(proof): check the tree type when verifying a count-offset page - #1036

Merged
QuantumExplorer merged 1 commit into
developfrom
fix/count-offset-host-tree-type
Nov 11, 2026
Merged

QuantumExplorer merged 1 commit into
developfrom
fix/count-offset-host-tree-type

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: A query can ask for a page of rows that starts after an offset ("skip 5, give me the next 3"). GroveDB only produces proofs for such a page when the tree being paged counts its rows in a provable way (ProvableCountTree, ProvableCountSumTree, ProvableCountProvableSumTree). The side that produces the proof enforced that rule; the side that checks the proof did not. This PR makes the checking side apply the same rule.

Value: The prover and the verifier now agree on which trees an offset page can be read from, and they report the same error. A client that verifies an offset page against any other tree type gets a clear InvalidQuery error instead of a result that depends on the proof bytes.

Risks: Low. No proof the prover produces changes verdict, because the prover has always refused these trees. One result changes for callers: verifying an offset query against an empty tree of another type returned Ok with no rows and now returns InvalidQuery, which is what the prover already answered for the same query. Proof verification is not part of block execution, so there is no consensus impact.

Issue being fixed or feature implemented

check_count_offset_target_tree_type and prove_count_offset_layer_v1 accept a query with a non-zero offset only when the tree it reads is a ProvableCountTree, a ProvableCountSumTree or a ProvableCountProvableSumTree. A page is a statement about counts, so the counts it is checked against have to be the ones the tree commits to.

The verifier's envelope gate carried a comment saying the tree-type check happened later in the V1 walk, but the walk had no such check: the count-offset dispatch ran on whatever tree the path led to.

What was done?

  • Added validate_count_offset_host in grovedb/src/operations/proof/verify.rs. For a query with a non-zero offset, the V1 walk calls it on every proved row; when the row is the tree the page reads (the last segment of the query path, under the matching parent path), its element must be one of the three tree types above. Any other element returns the prover's own error text.
  • The type is read from the parent layer, where the row's bytes are bound to the root hash, and after the row's wrappers are removed.
  • Every V1 entry point (verify_query, verify_query_raw, verify_subset_query, and the recursion into lower layers) goes through this row loop, so the check covers all of them.
  • The check is not gated by grove version, because it only refuses proofs the prover never produces.
  • Corrected the comment at the envelope gate so it names the function that does the check.

Before and after

host is any tree that is not one of the three types above (Tree, SumTree, BigSumTree, CountTree, CountSumTree, ProvableSumTree). proof is the proof of the same range without an offset.

let query = PathQuery::new(
    vec![b"host".to_vec()],
    SizedQuery::new(range_full, Some(3), Some(1)), // limit 3, offset 1
);

// Prover, before and after:
db.prove_query(&query, None, grove_version)
// Err(InvalidQuery("count-offset paginated queries are only valid against
//     ProvableCountTree / ProvableCountSumTree / ProvableCountProvableSumTree merks"))

// Verifier:
GroveDb::verify_query(&proof, &query, grove_version)
host Before After
empty Ok((root_hash, vec![])) Err(InvalidQuery("count-offset paginated queries are only valid against ..."))
has rows Err(InvalidProof(..)) from the page verifier, which never looked at the tree's type Err(InvalidQuery("count-offset paginated queries are only valid against ..."))

A ProvableCountTree next to such a tree is unaffected: offset 1, limit 3 over rows a..e still verifies and returns b, c, d.

How Has This Been Tested?

Three new tests in grovedb/src/tests/count_offset_paginated_tests.rs:

  • verifier_refuses_offset_on_populated_non_count_hosts
  • verifier_refuses_offset_on_empty_non_count_hosts
  • verifier_refuses_offset_on_nested_provable_sum_tree

They cover the six tree types listed above, with rows and empty, on GROVE_V4 and the latest grove version, through verify_query_raw, verify_query and verify_subset_query. Each case first shows that the prover refuses the offset query and that the proof verifies for the query without an offset. The nested test puts the tree one level down and checks that a sibling ProvableCountTree still serves an offset page.

With the new call disabled, all three tests fail; with it, they pass.

Also run locally:

  • cargo test -p grovedb --lib count_offset_paginated_tests (56 passed)
  • cargo test -p grovedb --lib offset (142 passed)
  • cargo test -p grovedb --lib proof (749 passed)
  • cargo clippy -p grovedb --all-targets (clean)
  • cargo check -p grovedb --no-default-features --features verify

Breaking Changes

None for consensus. For callers of the verifier: an offset query against an empty tree that is not a provable count tree now returns InvalidQuery instead of Ok with no rows.

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 · 03a7c08

  • Bots — coderabbitai ✓ · thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Build running
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Bug Fixes
    • Count-offset queries are now rejected when used with unsupported tree types, including when those trees are empty or nested.
    • Count-offset pagination continues to verify successfully for supported count-based trees.

The prover serves a page with a non-zero offset only from a ProvableCountTree, a ProvableCountSumTree or a ProvableCountProvableSumTree. The verifier now applies the same rule: in the V1 walk it checks the proved row of the tree the page reads and returns the prover's InvalidQuery error for any other tree type, including an empty one.

The check is not gated by grove version: the prover has always refused these trees, so no proof it produces changes verdict.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The V1 proof verifier now checks the proved host row when a query uses a non-zero offset. Tests cover unsupported host types, empty and populated hosts, nested hosts, and a supported sibling host.

Changes: Count-offset host validation

Layer / File(s) Summary
Validate the proved host in the V1 walk
grovedb/src/operations/proof/verify.rs
The verifier documentation lists the supported count host types. For queries with a non-zero offset, the V1 walk checks the proved host row and returns InvalidQuery when its type is unsupported.
Test host-type validation
grovedb/src/tests/count_offset_paginated_tests.rs
Tests cover six unsupported host types, empty and populated hosts, and raw, deserialized, and subset verification. Nested-host tests also check that a sibling ProvableCountTree verifies the offset page.

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

Change: Bug fix

Possibly related PRs

  • dashpay/grovedb#1025: Adds branch-local count-offset proving and verification for count-bearing trees, which this PR complements with V1 host-type validation.

Suggested reviewers: thepastaclaw

Merge Risk: Minimal · up to 03a7c

This change makes proof verification reject offset queries against tree types that do not support them, matching what the prover already does. The only behavior change is that offset queries on an empty tree of another type now return an error. No merge-blocking risk was identified.

Pre-merge checks: Passed 5

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: validating the tree type when verifying a count-offset page.
Docstring Coverage Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 2 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bcd37972-0fe1-43be-8c84-f5d5db7c4dee
Commits

Reviewing files that changed from the base of the PR and between fa92511 and 03a7c08.

Files selected for processing: 2

  • grovedb/src/operations/proof/verify.rs
  • grovedb/src/tests/count_offset_paginated_tests.rs

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

@github-actions

github-actions Bot commented Nov 11, 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 the waiting-bots Waiting for the review bots to report on this head label Nov 11, 2026
@thepastaclaw

thepastaclaw commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit 03a7c08) · triage: low · Phase 2 only (no Phase 1 for this repository)

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.26%. Comparing base (9274f11) to head (03a7c08).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
grovedb/src/operations/proof/verify.rs 96.29% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1036      +/-   ##
===========================================
- Coverage    93.36%   93.26%   -0.10%     
===========================================
  Files          366      366              
  Lines       113016   112498     -518     
===========================================
- Hits        105512   104922     -590     
- Misses        7504     7576      +72     
Components Coverage Δ
grovedb-core 91.64% <90.62%> (-0.18%) ⬇️
merk 94.21% <ø> (-0.05%) ⬇️
storage 91.68% <ø> (ø)
commitment-tree 95.62% <ø> (ø)
mmr 95.24% <ø> (ø)
bulk-append-tree 94.48% <ø> (ø)
element 97.39% <ø> (-0.02%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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 of head 03a7c08 confirms that the shared V1 verifier now enforces the prover's existing host-type restriction, including empty and nested hosts, without changing proof generation or parent-child authentication. No actionable findings remain. Current CI shows all three Ubuntu test shards, linting, formatting, and security audit passing; the review and PR Hygiene checks remain pending.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The production diff adds a small, localized tree-type validation to an existing verifier loop, with focused regression tests, and is not 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 medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer

@github-actions

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 Nov 11, 2026
@QuantumExplorer
QuantumExplorer merged commit 31e75c4 into develop Nov 11, 2026
15 of 17 checks passed
@QuantumExplorer
QuantumExplorer deleted the fix/count-offset-host-tree-type branch November 11, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants