Skip to content

feat: range aggregates and count offsets on a ProvableCountProvableBigSumTree - #1051

Merged
QuantumExplorer merged 8 commits into
developfrom
feat/big-sum-tree-range-aggregates
Nov 17, 2026
Merged

QuantumExplorer merged 8 commits into
developfrom
feat/big-sum-tree-range-aggregates

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: Makes the range aggregates and count offsets work on a ProvableCountProvableBigSumTree (added in #1050). The count on a range, the sum on a range, both together, count-offset pages and local offsets can now be proved, verified and read on the wide tree. Sums come back as an i128.

Value: #1050 added the tree but left these queries refused on it, so a caller that needs a provable count and a sum past the i64 range could store the data but not ask "what is the count and total between these two keys", which is what an average over a range needs. This closes that gap.

Risks: Medium. The existing 64-bit entry points and their proofs are unchanged in what they accept and return, but the code underneath them is now shared with the wide path, so the narrow path was touched (see "Changes to shared code"). The new entry points are additions.

Issue being fixed or feature implemented

On a ProvableCountProvableBigSumTree, before:

let query = PathQuery::new_unsized(path, Query::new_aggregate_sum_on_range(range));
db.prove_query(&query, None, v)?;                    // Err: only valid against ProvableSumTree or ...
db.query_aggregate_sum(&query, None, v)?;            // Err

After:

let proof = db.prove_query(&query, None, v)?;        // same query, wide proof nodes
let (root, sum): (_, i128) = GroveDb::verify_aggregate_big_sum_query(&proof, &query, v)?;
let sum: i128 = db.query_aggregate_big_sum(&query, None, v)?;
GroveDb::verify_aggregate_sum_query(&proof, &query, v)?;  // Err: the i64 entry point refuses a wide proof

What was done?

Queries that carry no sum work on the wide tree through the existing entry points: AggregateCountOnRange (verify_aggregate_count_query*, query_aggregate_count*), count-offset pages, and local offsets. Their proofs carry the wide nodes, which the tree's hash needs.

Queries that return a sum are the same AggregateSumOnRange and AggregateCountAndSumOnRange query items. Proof generation picks the wide prover when the tree is wide. The result is read by new entry points that return i128:

i64 (existing, unchanged) i128 (new)
verify verify_aggregate_sum_query verify_aggregate_big_sum_query
verify per key verify_aggregate_sum_query_per_key, ..._up_to_limit verify_aggregate_big_sum_query_per_key, ..._up_to_limit
read query_aggregate_sum, query_aggregate_sum_per_key query_aggregate_big_sum, query_aggregate_big_sum_per_key
verify verify_aggregate_count_and_sum_query verify_aggregate_count_and_big_sum_query
verify per key verify_aggregate_count_and_sum_query_per_key, ..._up_to_limit verify_aggregate_count_and_big_sum_query_per_key, ..._up_to_limit
read query_aggregate_count_and_sum, ..._per_key query_aggregate_count_and_big_sum, ..._per_key

Merk gains the matching primitives: prove_aggregate_big_sum_on_range, prove_aggregate_count_and_big_sum_on_range, big_sum_aggregate_on_range, count_and_big_sum_aggregate_on_range, verify_aggregate_big_sum_on_range_proof, verify_aggregate_count_and_big_sum_on_range_proof.

The caller names the width. The i64 entry points refuse a wide tree and its proofs, and the i128 ones refuse a tree with an i64 sum. No call narrows or widens a sum silently, so a result that fits today cannot start failing once the total grows.

Not in this PR: run_path_query keeps returning i64 sums in PathQueryRun and refuses the wide tree for the two sum queries. An indexed variant of the tree is also not included.

Changes to shared code

The narrow and wide paths share one implementation, so these existing functions changed. For a tree with an i64 sum each change gives the same result as before.

  • Merk emitters and walks (aggregate_sum, aggregate_count_and_sum): sums are held as i128 from the start instead of being widened from i64 at each use. The node's own sum is computed with wrapping subtraction, which is exact whenever the own sum fits an i128. Totals are added with checked addition, which returns an overflow error where the code used saturating_add or +=. Sums of i64 values cannot reach that in a tree that fits in storage.
  • Merk verifiers: the shape walks read the wide nodes as well, with the same checked arithmetic, so a proof with sums near the ends of the i128 range is refused instead of panicking in debug builds or wrapping in release ones. A node's sums are added in the prover's order (left, own, right; the verifiers added left, right, own before), so a verifier cannot overflow on an intermediate sum the prover never formed. Each entry point's node allowlist decides which family a proof may contain: the i64 verifiers accept the narrow nodes only, as before.
  • GroveDB verifiers (aggregate_sum, aggregate_count_and_sum): the internal functions are generic over a small SumWidth / CountAndSumWidth trait that supplies the leaf verifier, the sum type and the terminal tree check. The public i64 functions instantiate it with the narrow width.
  • Count verifier and count-offset code: allowlists and count extraction gained the wide nodes.

Versioning. No version slot is added. The wide tree can only be created from GROVE_V5 (#1050), so under GROVE_V1..GROVE_V4 no terminal element of that type exists for these queries to reach, and a proof carrying wide nodes cannot hash to a root of such a chain.

How Has This Been Tested?

New tests:

  • merk/src/proofs/query/wide_tree_aggregate_tests.rs (9): count, sum, and count and sum over eight range shapes, proved and verified against the root and read without a proof; a count-offset page in both directions; the narrow and wide entry points refusing each other's trees and proofs; an empty tree; every node of a proof altered in turn; a proof whose sums overflow i128 refused; sums that cancel near the ends of the i128 range accepted.
  • grovedb/src/tests/provable_count_provable_big_sum_tree_tests.rs (9 new, 30 in the file): the three aggregates proved against the database root over six ranges; no-proof reads; the i128 entry points refusing a narrow tree; per-key aggregates over three wide trees, proved and read; per-key aggregates where one of the wide trees is empty (count 0, sum 0); every byte of a proof flipped in turn; count-offset pages in both directions; a count-offset page returning a reference row; local offsets over three wide trees.
cargo test -p grovedb -p grovedb-merk -p grovedb-query -p grovedb-element -p grovedb-version -p grovedb-costs --all-features
cargo clippy --workspace --exclude grovedb-bincode --exclude grovedb-bincode-derive --all-features --no-deps --all-targets -- -D warnings
cargo build --no-default-features --features verify -p grovedb

All pass locally: grovedb 3802 library tests (8 ignored, as before), grovedb-merk 843, grovedb-query 266, grovedb-element 229 + 37, grovedb-version 62. Clippy with -D warnings on all targets and cargo fmt --all -- --check are clean.

Breaking Changes

None beyond #1050. Every public addition is a new function. Existing functions keep their signatures.

Two existing behaviours widen, both on the tree #1050 adds: verify_aggregate_count_query* and query_aggregate_count* accept a ProvableCountProvableBigSumTree terminal, and count-offset pages and local offsets accept it as a host. #1050 refused both.

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 · f5b6982

  • Bots — coderabbitai not yet · thepastaclaw 2 threads unresolved — resolve them — /skip-bots proceeds without the ones not yet reported
  • 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.

QuantumExplorer and others added 2 commits November 18, 2026 01:20
A tree that commits both its element count and a 128-bit sum into every
node hash: the wide counterpart of ProvableCountProvableSumTree. A sum
tree's total is an i64 and refuses a write that takes it past that range;
this tree's children still contribute an i64 each and its total is an
i128.

- Element discriminant 29 with wrapper twins 157, 179 and 195; tree type
  17; feature type and link aggregate tag 9 (count varint, then 16
  big-endian sum bytes).
- node_hash_with_count_and_big_sum and five proof nodes (tags
  0x60..=0x6D) mirroring the narrow family.
- Inserts, deletes, batches, regular query proofs on V1 envelopes, trunk
  and branch chunks, chunk restore, cost sizes and estimates, and
  verify_grovedb.
- Creation is gated by the new
  operations.insert.provable_count_provable_big_sum_tree_creation slot:
  refused by GROVE_V1..GROVE_V4, allowed from GROVE_V5.
- Range aggregates and count offsets are not offered on the tree and are
  refused.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…gSumTree

AggregateCountOnRange, count-offset pages and local offsets work on the
wide tree through the existing entry points, which carry no sum.
AggregateSumOnRange and AggregateCountAndSumOnRange are the same queries
on it; their sum is an i128, returned by new entry points
(verify_aggregate_big_sum_query, verify_aggregate_count_and_big_sum_query,
query_aggregate_big_sum, query_aggregate_count_and_big_sum, their per-key
forms, and the matching Merk primitives).

The caller names the width: the i64 entry points keep refusing the wide
tree and its proofs, and the i128 ones refuse a tree with an i64 sum.

The narrow and wide paths share one implementation. Sums are held as i128
throughout the Merk emitters, walks and verifiers, with wrapping
subtraction for a node's own sum and checked addition for totals; the
GroveDB verifiers are generic over the sum width.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 17 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

  • 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: 20121e3c-1af2-4a5f-9e3c-5497f46b0fad
Commits

Reviewing files that changed from the base of the PR and between 629e4a5 and f5b6982.

Files selected for processing: 47

  • CHANGELOG.md
  • docs/book/src/appendix-a.md
  • grovedb/src/element/local_offset_read.rs
  • grovedb/src/element/path_query_push/v2.rs
  • grovedb/src/operations/get/aggregate_per_key/count_and_sum.rs
  • grovedb/src/operations/get/aggregate_per_key/sum.rs
  • grovedb/src/operations/get/query.rs
  • grovedb/src/operations/proof/aggregate_count/helpers.rs
  • grovedb/src/operations/proof/aggregate_count_and_sum/helpers.rs
  • grovedb/src/operations/proof/aggregate_count_and_sum/leaf_chain.rs
  • grovedb/src/operations/proof/aggregate_count_and_sum/mod.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/leaf_chain.rs
  • grovedb/src/operations/proof/aggregate_sum/mod.rs
  • grovedb/src/operations/proof/aggregate_sum/per_key.rs
  • grovedb/src/operations/proof/generate.rs
  • grovedb/src/operations/proof/verify.rs
  • grovedb/src/query/local_offset.rs
  • grovedb/src/query/mod.rs
  • grovedb/src/tests/provable_count_provable_big_sum_tree_tests.rs
  • merk/src/merk/get.rs
  • merk/src/merk/mod.rs
  • merk/src/merk/prove.rs
  • merk/src/merk/prove_count_offset.rs
  • merk/src/proofs/query/aggregate_count/emit.rs
  • merk/src/proofs/query/aggregate_count/mod.rs
  • merk/src/proofs/query/aggregate_count/prove.rs
  • merk/src/proofs/query/aggregate_count/verify.rs
  • merk/src/proofs/query/aggregate_count_and_sum/emit.rs
  • merk/src/proofs/query/aggregate_count_and_sum/mod.rs
  • merk/src/proofs/query/aggregate_count_and_sum/prove.rs
  • merk/src/proofs/query/aggregate_count_and_sum/verify.rs
  • merk/src/proofs/query/aggregate_count_and_sum/walk.rs
  • merk/src/proofs/query/aggregate_sum/emit.rs
  • merk/src/proofs/query/aggregate_sum/mod.rs
  • merk/src/proofs/query/aggregate_sum/prove.rs
  • merk/src/proofs/query/aggregate_sum/verify.rs
  • merk/src/proofs/query/aggregate_sum/walk.rs
  • merk/src/proofs/query/count_offset/emit.rs
  • merk/src/proofs/query/count_offset/emit_local.rs
  • merk/src/proofs/query/count_offset/mod.rs
  • merk/src/proofs/query/count_offset/pinned_view.rs
  • merk/src/proofs/query/count_offset/prove.rs
  • merk/src/proofs/query/count_offset/verify.rs
  • merk/src/proofs/query/mod.rs
  • merk/src/proofs/query/wide_tree_aggregate_tests.rs
  • 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

@thepastaclaw

thepastaclaw commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Review in progress (commit f5b6982) · live progress

@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)

The PR contains three in-scope blocking correctness/versioning defects and one diagnostic inconsistency. Empty wide hosts can produce incomplete combined aggregate carrier proofs, wide verifiers can reject valid cancellation-heavy sums due to accumulation order, and the new wide paths are not gated to GROVE_V5; the CI snapshot shows no failed code checks.

🔴 3 blocking | 🟡 1 suggestion(s)

2 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Descend into empty wide hosts for combined aggregate carriers
grovedb/src/operations/proof/generate.rs:3491-3495

The empty-host descent arm for AggregateCountAndSumOnRange matches only ProvableCountProvableSumTree(None, ..), while the corresponding count and sum arms support ProvableCountProvableBigSumTree. When a carrier query targets an empty wide host, descends_into_empty_aggregate_tree is true but this arm is skipped, so no lower layer is emitted. The per-key combined verifier then cannot find the required lower proof for that outer key and rejects an otherwise valid zero-count/zero-sum proof. Add the wide element to this match arm, including the up-to-limit path that shares it.

Ok(Element::ProvableCountProvableSumTree(None, ..))
                            | Ok(Element::ProvableCountProvableBigSumTree(None, ..))

source: gpt-6.1-sol (phase2-reviewer: general)

🟡 Suggestion: Include the wide tree in the count-offset diagnostic
grovedb/src/operations/proof/verify.rs:694-696

The predicate immediately above accepts Element::ProvableCountProvableBigSumTree(..), but the returned InvalidQuery message still lists only the three older host types. This makes diagnostics for invalid count-offset hosts incomplete and contradictory to the behavior added by the PR. The analogous messages in the count-offset generation paths should be updated as well.

"count-offset paginated queries are only valid against \
                 ProvableCountTree / ProvableCountSumTree / \
                 ProvableCountProvableSumTree / ProvableCountProvableBigSumTree merks",

source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)

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: normal by gpt-6.1-sol (effort low) — This is a broad, intricate change across GroveDB and Merk query, proof-generation, verification, aggregation, and offset paths, but it does not directly change consensus rules, funds movement, cryptographic primitives, signatures, peer-facing deserialization, or storage migrations.
  • 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.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, 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 (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:3491-3495: Descend into empty wide hosts for combined aggregate carriers
  The empty-host descent arm for `AggregateCountAndSumOnRange` matches only `ProvableCountProvableSumTree(None, ..)`, while the corresponding count and sum arms support `ProvableCountProvableBigSumTree`. When a carrier query targets an empty wide host, `descends_into_empty_aggregate_tree` is true but this arm is skipped, so no lower layer is emitted. The per-key combined verifier then cannot find the required lower proof for that outer key and rejects an otherwise valid zero-count/zero-sum proof. Add the wide element to this match arm, including the up-to-limit path that shares it.

In `merk/src/proofs/query/aggregate_sum/verify.rs`:
- [BLOCKING] merk/src/proofs/query/aggregate_sum/verify.rs:333-335: Accumulate wide range sums in prover order
  The verifier adds `left_in` and `right_in` before adding the current node contribution, but the prover accumulates in `left + self + right` order. With i128 values, a valid range can have `left_in = i128::MAX`, `self_contribution = -i128::MAX`, and `right_in = i128::MAX`: the prover obtains `i128::MAX`, while this verifier attempts `i128::MAX + i128::MAX` first and rejects the proof as overflowed. The combined count-and-sum verifier has the same ordering at `merk/src/proofs/query/aggregate_count_and_sum/verify.rs:339-341`. Mirror the prover's order in both verifiers.

In `grovedb/src/operations/proof/aggregate_sum/mod.rs`:
- [BLOCKING] grovedb/src/operations/proof/aggregate_sum/mod.rs:252-258: Gate wide aggregate verification to GROVE_V5
  `verify_aggregate_big_sum_query` checks only the existing `verify_query_with_options` capability, which is enabled in GROVE_V1 through GROVE_V5. Consequently, current code can accept a wide aggregate proof when the caller supplies GROVE_V1 through GROVE_V4. The same unversioned acceptance exists in the wide per-key and combined wide verifiers, wide no-proof reads, and widened count/count-offset host paths. The insertion gate prevents normal creation of the wide element before V5, but it does not make these public readers and verifiers fail closed for a V4 version: element deserialization and terminal validation still accept the wide variant in this code. Add a V5-only capability or equivalent checks and test that V4 rejects wide proofs/hosts while V5 accepts them.

In `grovedb/src/operations/proof/verify.rs`:
- [SUGGESTION] grovedb/src/operations/proof/verify.rs:694-696: Include the wide tree in the count-offset diagnostic
  The predicate immediately above accepts `Element::ProvableCountProvableBigSumTree(..)`, but the returned `InvalidQuery` message still lists only the three older host types. This makes diagnostics for invalid count-offset hosts incomplete and contradictory to the behavior added by the PR. The analogous messages in the count-offset generation paths should be updated as well.

Comment on lines +333 to +335
let in_range = left_in
.checked_add(right_in)
.and_then(|sum| sum.checked_add(self_contribution))

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.

🔴 Blocking: Accumulate wide range sums in prover order

The verifier adds left_in and right_in before adding the current node contribution, but the prover accumulates in left + self + right order. With i128 values, a valid range can have left_in = i128::MAX, self_contribution = -i128::MAX, and right_in = i128::MAX: the prover obtains i128::MAX, while this verifier attempts i128::MAX + i128::MAX first and rejects the proof as overflowed. The combined count-and-sum verifier has the same ordering at merk/src/proofs/query/aggregate_count_and_sum/verify.rs:339-341. Mirror the prover's order in both verifiers.

Suggested change
let in_range = left_in
.checked_add(right_in)
.and_then(|sum| sum.checked_add(self_contribution))
let in_range = left_in
.checked_add(self_contribution)
.and_then(|sum| sum.checked_add(right_in))
.ok_or_else(|| {
Error::InvalidProofError(
"aggregate-sum proof: in-range sum overflowed i128".to_string(),
)
})?;

source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f5b6982: both verifiers now add left, own, right, as the provers do, and a test covers sums that cancel (MAX - MAX + MAX). The existing overflow test's proof was being refused for its shape before it reached the additions, so it is rebuilt to reach them. The count-offset and count on range messages also name the wide tree now.

Comment on lines +252 to +258
check_grovedb_v0!(
"verify_aggregate_big_sum_query",
grove_version
.grovedb_versions
.operations
.proof
.verify_query_with_options

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.

🔴 Blocking: Gate wide aggregate verification to GROVE_V5

verify_aggregate_big_sum_query checks only the existing verify_query_with_options capability, which is enabled in GROVE_V1 through GROVE_V5. Consequently, current code can accept a wide aggregate proof when the caller supplies GROVE_V1 through GROVE_V4. The same unversioned acceptance exists in the wide per-key and combined wide verifiers, wide no-proof reads, and widened count/count-offset host paths. The insertion gate prevents normal creation of the wide element before V5, but it does not make these public readers and verifiers fail closed for a V4 version: element deserialization and terminal validation still accept the wide variant in this code. Add a V5-only capability or equivalent checks and test that V4 rejects wide proofs/hosts while V5 accepts them.

source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not adding a gate here. A chain on GROVE_V1..GROVE_V4 cannot hold a ProvableCountProvableBigSumTree, because those versions refuse to create it, so a proof carrying wide nodes cannot hash to such a chain's root and the no-proof reads have no such tree to reach. The verifiers return the root they reconstruct and the caller compares it with the root it trusts, which is what binds a proof to a chain. A second slot checked in every entry point would guard a state that cannot exist. The PR description states this under "Versioning".

QuantumExplorer and others added 2 commits November 18, 2026 03:55
…t estimators

Review follow-ups for the ProvableCountProvableBigSumTree:

- The worst-case insert and both replace element estimators price the tree
  as the layered tree it is written as, at its own cost size. The
  average-case insert estimator already did.
- `EstimatedSumTrees::SomeSumTrees` gains
  `provable_count_provable_big_sum_trees_weight`, weighed at 24 bytes by the
  mixed-layer size estimate. A weight of 0 leaves the estimate as it was.
- Trunk and branch query results read the count of a count and sum node,
  for the narrow tree (skipped before) and the wide one.
- The combined count and sum descent into an empty tree lists the wide
  tree next to the narrow one, like the count and the sum descents.
- Three test lists (merk tree types, state sync node families, proof count
  helper) include the wide tree.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…g-sum-tree-range-aggregates

Brings in the review follow-ups of the tree PR. With the combined count
and sum descent listing the wide tree, a per-key count and sum query over
an empty wide tree proves and verifies as (0, 0); a test covers it next to
the count and the sum.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@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 wide aggregate proof implementation is otherwise coherent, and the empty wide-host descent fix is present. The current head still has two blocking issues in wide verification plus one inaccurate count-offset diagnostic; no failed code checks are present in the CI snapshot, although the review check remains in progress.

🔴 2 blocking | 🟡 1 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Include the wide tree in the count-offset diagnostic
grovedb/src/operations/proof/verify.rs:694-696

The host allowlist correctly accepts Element::ProvableCountProvableBigSumTree, but the InvalidQuery message still lists only the three older host types. When a count-offset query fails this validation, the diagnostic contradicts the accepted set and makes wide-tree failures misleading to callers.

return Err(Error::InvalidQuery(
    "count-offset paginated queries are only valid against ProvableCountTree / ProvableCountSumTree / ProvableCountProvableSumTree / ProvableCountProvableBigSumTree merks",
));

source: gpt-6.2-sol (phase2-reviewer: general, platform-versioning)

Still open from earlier rounds (2)

  • 🔴 Blocking: Gate wide aggregate verification to GROVE_V5 — grovedb/src/operations/proof/aggregate_sum/mod.rs:252-258 (thread)
  • 🔴 Blocking: Accumulate wide range sums in prover order — merk/src/proofs/query/aggregate_sum/verify.rs:333-340 (thread)
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: normal by gpt-6.2-sol (effort low) — This is a large, cross-cutting change to range aggregation, proof generation and verification, and wide-tree query APIs, but it does not itself modify the explicitly critical surfaces required for the critical tier.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-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 (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`:
- [SUGGESTION] grovedb/src/operations/proof/verify.rs:694-696: Include the wide tree in the count-offset diagnostic
  The host allowlist correctly accepts `Element::ProvableCountProvableBigSumTree`, but the `InvalidQuery` message still lists only the three older host types. When a count-offset query fails this validation, the diagnostic contradicts the accepted set and makes wide-tree failures misleading to callers.

In `grovedb/src/operations/proof/aggregate_sum/mod.rs`:
- [BLOCKING] grovedb/src/operations/proof/aggregate_sum/mod.rs:252-258: Gate wide aggregate verification to GROVE_V5
  (carried; thread: https://github.com/dashpay/grovedb/pull/1051#discussion_r4604584414)

In `merk/src/proofs/query/aggregate_sum/verify.rs`:
- [BLOCKING] merk/src/proofs/query/aggregate_sum/verify.rs:333-340: Accumulate wide range sums in prover order
  (carried; thread: https://github.com/dashpay/grovedb/pull/1051#discussion_r4604584388)

QuantumExplorer and others added 2 commits November 18, 2026 04:23
…de's hash cost

`KVRefValueHashCountBigSum` hashes the referenced value and combines it
with the node's value hash before hashing the node. The cost of those two
hashes was computed and then left out of the returned cost. It is part of
it now. The hash itself is unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Base automatically changed from feat/provable-count-provable-big-sum-tree to develop November 17, 2026 21:26
develop now holds the tree PR (#1050) as one commit whose content is the
branch tip this branch already merged, so the merge changes no file.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw 2 threads unresolved — resolve them. 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 17, 2026
@github-actions

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw 2 threads unresolved — resolve them. 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 commented Nov 17, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw 2 threads unresolved — resolve them. 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.

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.83420% with 156 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.22%. Comparing base (629e4a5) to head (f5b6982).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...rc/operations/proof/aggregate_count_and_sum/mod.rs 57.53% 31 Missing ⚠️
grovedb/src/operations/proof/aggregate_sum/mod.rs 56.94% 31 Missing ⚠️
merk/src/proofs/query/count_offset/verify.rs 69.38% 15 Missing ⚠️
.../src/proofs/query/aggregate_count_and_sum/prove.rs 69.44% 11 Missing ⚠️
grovedb/src/operations/proof/generate.rs 71.42% 8 Missing ⚠️
.../operations/get/aggregate_per_key/count_and_sum.rs 86.36% 6 Missing ⚠️
...rovedb/src/operations/get/aggregate_per_key/sum.rs 82.85% 6 Missing ⚠️
grovedb/src/operations/get/query.rs 90.76% 6 Missing ⚠️
merk/src/proofs/query/aggregate_sum/prove.rs 82.85% 6 Missing ⚠️
merk/src/proofs/query/aggregate_sum/emit.rs 90.19% 5 Missing ⚠️
... and 11 more

❌ Your patch status has failed because the patch coverage (83.83%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1051      +/-   ##
===========================================
- Coverage    93.28%   93.22%   -0.07%     
===========================================
  Files          366      366              
  Lines       114084   114846     +762     
===========================================
+ Hits        106421   107061     +640     
- Misses        7663     7785     +122     
Components Coverage Δ
grovedb-core 91.44% <79.31%> (-0.08%) ⬇️
merk 94.45% <87.54%> (-0.11%) ⬇️
storage 91.94% <ø> (ø)
commitment-tree 94.86% <ø> (ø)
mmr 95.12% <ø> (ø)
bulk-append-tree 94.32% <ø> (ø)
element 97.48% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The sum and the count and sum verifiers added a node's in-range sums as
left, right, own, while the provers add left, own, right. With sums that
cancel near the ends of the i128 range the verifier could report an
overflow on an intermediate sum the prover never formed. Both verifiers
now add in the prover's order. Sums of a tree with an i64 total cannot
reach that range, so its results are unchanged.

The overflow test's proof was refused for its shape before it reached the
additions; it now reaches them, and a second test covers the order.

Also name the ProvableCountProvableBigSumTree in the count-offset and
count on range messages that list the accepted trees.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Waiting for bot review — coderabbitai not yet · thepastaclaw 2 threads unresolved — resolve them. 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.

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.

2 participants