Skip to content

fix(sdk): mirror the COUNT dispatcher's outer-walk limit when verifying range-outer carrier proofs - #4432

Closed
PastaPastaPasta wants to merge 2 commits into
v5.0-devfrom
fix/aggregate-verifier-limit-parity
Closed

PastaPastaPasta wants to merge 2 commits into
v5.0-devfrom
fix/aggregate-verifier-limit-parity

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

A grouped COUNT over two range clauses on distinct fields cannot be verified by the SDK once the outer range holds more than ten distinct keys. The server answers with a valid proof; the client rejects it.

The shape is any rangeCountable index of at least two properties queried as

SELECT COUNT(*) WHERE outer > X AND inner > Y GROUP BY outer   (prove = true)

Drive serves this with the range-outer carrier-aggregate proof and caps the outer walk at the compile-time MAX_CARRIER_AGGREGATE_OUTER_RANGE_LIMIT (10). When the request leaves the limit unset the dispatcher lowers it to the cap, the prover walks ten outer keys and abridges the rest of the tree, and that Some(10) becomes part of the path query the proof commits to.

The SDK verifier rebuilt the path query with limit: None for every carrier shape. With eleven or more outer keys the merk walker expected an unbounded walk, reached the abridged region, and failed with:

carrier aggregate-count multi-key proof failed to verify: Proof is missing data for query range

Ten keys or fewer verified by accident because the prover never truncated, which is why this was not caught: the cap only matters once real data exceeds it, and no prove-then-verify test for this shape existed. The only caller of the carrier count verifier is the SDK, and the SDK's tests for this shape run through a mock transport that never executes it.

Why it matters

  • Every grouped range-over-range COUNT stops working at scale. A trending or leaderboard query of this shape is fine in a demo with a handful of groups and breaks in production as soon as an eleventh group appears. The failure surfaces as a proof error, so it looks like a compromised node rather than a client bug.
  • The limit is proof-sensitive. SizedQuery::limit is committed to by the proof. A client that reconstructs it differently from the server cannot verify honest answers, and a client that accepts limits the server refuses can be handed a proof for a narrower query than it asked for. Both sides must derive the value from the same rule.

What was done?

The SDK COUNT verifier now derives the outer-walk limit exactly as the dispatcher does, keyed on the request's where-clause shape:

  • Range-outer (two range clauses): unset lowers to MAX_CARRIER_AGGREGATE_OUTER_RANGE_LIMIT; explicit limits pass through up to the cap; anything above the cap is refused before a proof is inspected, because the server refuses those requests and no proof can belong to them.
  • In-outer (one In, one range): unset stays None because the In array already bounds the walk; every explicit limit is refused, as on the server.

The rule lives in one place: DriveDocumentCountQuery::carrier_aggregate_outer_limit in rs-drive's mode_detection.rs, next to detect_mode, built for both server and verify. The dispatcher's RangeAggregateCarrierProof arm calls it, with the same behaviour and error messages as the inline code it replaces. The SDK's carrier_walk_limit is a thin adapter that maps its 0 "unset" sentinel to None and wraps the Drive error. Sharing it means prover and verifier cannot drift on this rule again, which is how this bug arose. SUM and AVG are untouched: their dispatchers do not apply the range-outer lowering, so their verifiers already agree with the server.

Tests

  • rs-drive, test_range_outer_carrier_proof_verifies_with_capped_limit_not_none: the first prove-then-verify round trip for this proof shape. Twelve outer keys, unset limit. Pins that the dispatcher lowers to the cap, that the limit the verifier derives through the shared helper is that cap and verifies to exactly ten entries, and that the same bytes fail under limit: None.
  • dash-platform-queries: unit tests that the translation matches the dispatcher on both carrier shapes, including the refusals, asserting on the typed RequestError.

Verified on testnet

Reproduced against testnet (Drive 4.1.0, protocol 13) with contract 6TjweyPbxLNB4BhyVBcAzTxo54jDn33s5Y5j78WKM43Z (bucketed document type, index (bucket, score) marked rangeCountable) holding twelve documents with distinct bucket values, query COUNT(*) WHERE bucket > 0 AND score > 0 GROUP BY bucket:

SDK limit result
before (v4.2-dev) unset fails: "Proof is missing data for query range"
after unset verified, 10 entries
before / after 5 verified, 5 entries
before / after 10 verified, 10 entries
either 11 rejected by the server with InvalidLimit

Follow-ups deliberately not in this PR

An earlier revision of this PR also added a client-side gate at the compile-time default of max_query_limit for all three aggregate verifiers. Review pointed out that max_query_limit is operator-configurable and the server compares against the runtime value, so a fixed client-side cap would reject authentic proofs from nodes configured above the default and still admit limits nodes configured below it refuse. That gate is dropped; the existing u16 narrowing plus server-side rejection is the honest amount of validation the client can do without an authenticated view of server configuration.

Still open, unchanged from before:

  • Wire-version gating for the aggregate verify entry points (COUNT/SUM/AVG and the split variants), which take an already-decoded DocumentQuery with no wire-request wrapper.
  • Mode-aware limit-absence enforcement for the plain Aggregate mode and for SUM/AVG, where a limit: 50 request still verifies against a proof produced for limit: None.

Breaking Changes

None. Requests an honest server serves verify exactly as before, plus the range-outer shape now verifies past ten keys. The newly rejected requests are ones the server already refuses with InvalidLimit.

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
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

Summary by CodeRabbit

  • Bug Fixes

    • Carrier aggregate proof verification now applies limits according to query shape.
    • Range-outer queries use a capped default when no limit is provided, accept explicit limits up to the cap, and reject limits outside the allowed range.
    • In-outer queries remain unlimited by default and reject explicitly provided limits.
  • Tests

    • Added coverage for capped range-outer proof verification, expected results, and failure when verification omits the required limit.

PR Hygiene · b36acbd

  • Bots — coderabbitai ✓ · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — posted; again after any push
  • Within your 5 open PRs
  • Build green
  • Approvals
    • files with no dedicated owner (packages/dash-platform-queries/src/documents/count_proof_helpers.rs) — QuantumExplorer or shumkov
    • rs-drive (packages/rs-drive/src/query/drive_document_count_query/drive_dispatcher.rs, packages/rs-drive/src/query/drive_document_count_query/mode_detection.rs, packages/rs-drive/src/query/drive_document_count_query/tests.rs) — QuantumExplorer or shumkov

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

@coderabbitai

coderabbitai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: dashpay/platform/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 42a0eaca-e97c-4a90-94c4-853f66c6149f
📥 Commits

Reviewing files that changed from the base of the PR and between 2c0234e and b36acbd.

📒 Files selected for processing (2)
  • packages/dash-platform-queries/src/documents/count_proof_helpers.rs
  • packages/rs-drive/src/query/drive_document_count_query/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.


📝 Walkthrough

Walkthrough

Carrier aggregate proof verification now uses server-matching limits for range-outer and In-outer queries. Tests cover default and explicit limits, rejected limits, and capped range-outer proof verification.

Changes

Carrier proof limit handling

Layer / File(s) Summary
Shape-dependent limit resolution
packages/rs-drive/src/query/drive_document_count_query/mode_detection.rs, packages/rs-drive/src/query/drive_document_count_query/drive_dispatcher.rs, packages/dash-platform-queries/src/documents/count_proof_helpers.rs
The server derives and validates the outer-walk limit by query shape. The dispatcher and verifier use the same limit rules.
Carrier proof limit tests
packages/dash-platform-queries/src/documents/count_proof_helpers.rs, packages/rs-drive/src/query/drive_document_count_query/tests.rs
Tests cover unset and explicit limits for both query shapes. The range-outer proof test verifies capped entries and fails verification with no limit.

Priority: ➖ Normal

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to b36ac

The SDK now accepts valid proofs for grouped COUNT queries with two range clauses when the outer range has more than ten keys. It does this by using the same limit rule as the server. Tests cover the change, and no blocking issues remain.

Architecture Summary

Architecture risk: 🔵 Low · up to b36ac

The change affects 2 systems.

Changed systems: packages/rs-drive, packages/dash-platform-queries

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/rs-drive (library) was modified; 3 changed files map to changed impact.
  • observed — packages/dash-platform-queries (library) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/rs-drive/src/query/drive_document_count_query/drive_dispatcher.rs: The carrier-proof branch replaces inline limit handling with carrier_aggregate_outer_limit, passing the where clauses and requested limit and propagating the helper’s result or error. The removed logic separately left In-outer limits unset and rejected supplied limits, while range-outer queries defaulted to the configured cap and rejected values above the cap or equal to zero.
  • observed — Modified behavior in packages/rs-drive/src/query/drive_document_count_query/mode_detection.rs: Added carrier_aggregate_outer_limit. With exactly two range operators, it returns the configured cap for an omitted limit, accepts explicit limits from 1 through the cap, and rejects zero or larger values with InvalidLimit. With any other range-operator count, it returns None if no limit was supplied and rejects a supplied limit with InvalidLimit.
  • observed — Modified behavior in packages/dash-platform-queries/src/documents/count_proof_helpers.rs: The query imports now include WhereClause.
  • observed — Modified behavior in packages/dash-platform-queries/src/documents/count_proof_helpers.rs: Adds carrier_walk_limit, translating the SDK’s 0 sentinel to None and delegating to the dispatcher’s shape-specific outer-limit rules. Dispatcher refusals become RequestErrors with a carrier-aggregate limit message.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: aligning SDK proof verification with the COUNT dispatcher's outer-walk limit for range-outer carrier proofs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@thepastaclaw

thepastaclaw commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

⚠️ Automated review could not complete (commit b36acbd)
Reason: phase2/general lane failed twice: [infra] lane exit 1: API Error: 400 unknown provider for model gpt-6.1-sol

@github-actions github-actions Bot added this to the v4.2.0 milestone Aug 20, 2026
@codecov

codecov Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.70%. Comparing base (d8b7944) to head (7a9991d).
⚠️ Report is 109 commits behind head on v4.2-dev.

Files with missing lines Patch % Lines
...tform-queries/src/documents/count_proof_helpers.rs 0.00% 40 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4432      +/-   ##
============================================
- Coverage     78.02%   77.70%   -0.32%     
============================================
  Files          2914     2914              
  Lines        417863   419815    +1952     
============================================
+ Hits         326025   326218     +193     
- Misses        91838    93597    +1759     
Components Coverage Δ
dpp 76.41% <ø> (-0.29%) ⬇️
drive 79.65% <ø> (-0.03%) ⬇️
drive-abci 77.04% <ø> (-0.75%) ⬇️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 86.60% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 27.80% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Preliminary review — Codex only

The COUNT carrier conversion now matches the server's G7/G8 path-query shapes, but the new shared gate treats the configurable default of 100 as a universal server ceiling. This rejects valid proofs from servers configured above 100 and cannot establish the claimed request/server parity for servers configured below 100, so the limit policy must be made fixed on the server or conveyed to the verifier through authenticated input. Source: Codex reviewer lanes codex-general, codex-security-auditor, and codex-rust-quality (exact backend model identifiers were not present in the supplied evidence); final verifier: Anthropic Claude Agent SDK (exact model identifier not exposed); openclaw-agent/cliproxy/gpt-5.6-sol is orchestration-only and not reviewer evidence.

Validated blockers were found in the Codex precheck. Opus is deferred until a fresh Codex revalidation clears the blocker gate.

Review provenance

  • Codex reviewers: gpt-5.6-sol — general (completed), gpt-5.6-sol — security-auditor (completed), gpt-5.6-sol — rust-quality (completed)
  • Verifier: gpt-5.6-sol — verifier
  • Sonnet: not run (deferred by blocker gate)

🔴 1 blocking | 🟡 2 suggestion(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/dash-platform-queries/src/documents/aggregate_limit.rs`:
- [BLOCKING] packages/dash-platform-queries/src/documents/aggregate_limit.rs:62-68: The default limit is not the server's actual cap
  `DEFAULT_MAX_QUERY_LIMIT` is only the default for the environment-configurable `DriveConfig::max_query_limit`; `PlatformConfig` flattens that configuration and the COUNT, SUM, and AVG proof dispatchers compare requests against `request.drive_config.max_query_limit`. For example, a server configured with `max_query_limit = 200` can legitimately produce a RangeDistinctProof for an explicit limit of 101, but this verifier rejects that authentic response before verification. Conversely, a server configured with a cap of 50 refuses a limit of 75 while this gate accepts it, so the gate does not provide the claimed server-policy binding. Make the proof-serving policy a shared compile-time ceiling on the server as well, or provide the effective policy to the verifier through authenticated input; using the configuration default as though it were every server's runtime value is neither parity-preserving nor backward-compatible.

In `packages/dash-platform-queries/src/documents/count_proof_helpers.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/documents/count_proof_helpers.rs:282-288: Exercise COUNT carrier shape translation through the real verifier path
  The proof-sensitive behavior depends on both deriving `has_outer_range` from the request clauses and passing the converted limit into `verify_carrier_aggregate_count_proof`. The new unit tests bypass that composition by supplying `true` or `false` directly, while the integration test only exercises the shared over-100 gate before mode detection. A transposed predicate, incorrect mode route, or wrong argument at the proof call would therefore leave all new tests passing while valid G7/G8 proofs fail. Add entry-point coverage for G8 with unset, 10, and 11 limits and G7 with unset and explicit limits; server-produced or checked-in proof fixtures should also verify that the reconstructed `SizedQuery::limit` matches end to end.

In `packages/dash-platform-queries/tests/aggregate_limit_parity.rs`:
- [SUGGESTION] packages/dash-platform-queries/tests/aggregate_limit_parity.rs:93-98: Assert the typed RequestError instead of only its Display text
  The regression test checks only the formatted error text, so another error variant containing the same substring would satisfy it. Destructure `drive_proof_verifier::Error::RequestError` first and then inspect its payload; this pins both the typed API result and the intended limit-gate message.

@PastaPastaPasta
PastaPastaPasta marked this pull request as draft August 21, 2026 17:47
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/aggregate-verifier-limit-parity branch from 7769e31 to 7a9991d Compare September 17, 2026 06:28
@PastaPastaPasta PastaPastaPasta changed the title fix(sdk): enforce server limit parity in the aggregate proof verifiers fix(sdk): mirror the COUNT dispatcher's outer-walk limit when verifying range-outer carrier proofs Sep 17, 2026
@PastaPastaPasta
PastaPastaPasta marked this pull request as ready for review September 17, 2026 06:28

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

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 (queue backlog)

At head 7a9991d, the SDK's carrier-limit translation matches the server's range-outer and In-outer policies; no blocking correctness or security issues were identified. Local validation passed all 59 dash-platform-queries library tests and the new Drive capped-proof regression test. One non-blocking maintainability suggestion remains: share the proof-sensitive limit policy between the dispatcher and SDK adapter.

🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — This is a contained SDK proof-verification logic fix with substantial targeted tests, but it does not modify consensus rules, cryptography, signatures, funds, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: not run (skipped for throughput: 20 PRs queued, above the 10 limit)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/dash-platform-queries/src/documents/count_proof_helpers.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/documents/count_proof_helpers.rs:125-138: Share carrier-limit lowering with the Drive dispatcher
  This helper duplicates the shape predicate and limit defaulting/rejection rules in `rs-drive/src/query/drive_document_count_query/drive_dispatcher.rs:510–552`. The implementations agree today, but sharing only the cap constant leaves two independently maintained versions of the proof-sensitive policy whose disagreement caused this bug. The helper tests and Drive round-trip test cover each implementation separately rather than enforcing their equivalence. Extract this calculation into a pure helper under `rs-drive::query::drive_document_count_query`, available with both `server` and `verify`, and call it from both locations. Accept `Option<u32>` and return a Drive query error, leaving the SDK's zero-to-None conversion and error mapping here. Keep the low-level proof verifier's explicit effective-limit contract unchanged.

@llbartekll llbartekll modified the milestones: v4.2.0, v4.3.0 Sep 18, 2026
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 20, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
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 Sep 24, 2026
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/aggregate-verifier-limit-parity branch from 7a9991d to 2c0234e Compare September 26, 2026 21:21
@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Sep 26, 2026
@github-actions github-actions Bot modified the milestones: v4.3.0, v4.2.0 Sep 26, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

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 1 + Phase 2

Independently reviewed the complete four-file diff at 2c0234e and found no in-scope defects. The shared Drive helper preserves the server's limit policy and error behavior while correcting SDK reconstruction of capped carrier COUNT proofs, resolving the prior architecture finding. Local validation passed all 59 dash-platform-queries library tests, all 69 Drive COUNT-query tests, and git diff --check; the worktree remains unchanged.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: security-auditor); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 10: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 11: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 12: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — The diff changes proof-query limit reconstruction and shares dispatcher validation across Drive and the SDK with regression tests, but it is a contained logic fix rather than a large or intricate change to cryptography or consensus rules.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — architecture-layering (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

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

@github-actions

Copy link
Copy Markdown
Contributor

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 Sep 26, 2026
PastaPastaPasta and others added 2 commits October 5, 2026 00:11
…ng range-outer carrier proofs

A grouped COUNT with two range clauses on distinct fields (`bucket > X
AND score > Y`, `GROUP BY bucket`, proofs on) is served by the
range-outer carrier-aggregate proof. On that shape the server caps the
outer walk at the compile-time MAX_CARRIER_AGGREGATE_OUTER_RANGE_LIMIT
(10): an unset request limit is lowered to the cap and the prover stops
after ten outer keys, abridging the rest of the tree. The SDK verifier
rebuilt the path query with `limit: None` for every carrier shape, so
once the outer range held more than ten keys the merk walker expected an
unbounded walk, ran into the abridged region, and rejected an honest
proof with "proof is missing data for query range". Ranges of ten keys
or fewer verified by accident because the prover never truncated.

Derive the outer-walk limit the way the dispatcher does. Range-outer:
unset lowers to the cap, explicit limits pass through up to the cap,
anything above the cap is refused before a proof is inspected (the
server refuses those requests too, so no proof can belong to them).
In-outer: unset stays `None` because the In array already bounds the
walk, and every explicit limit is refused, as on the server.

Add an rs-drive prove-then-verify round trip over twelve outer keys that
pins the dispatcher lowering, verifies with the capped limit, and shows
the same bytes failing under `limit: None`. No such round trip existed;
the only caller of the carrier count verifier was the SDK, and the SDK's
own tests for this shape go through a mock transport that never runs it.

Reproduced on testnet (Drive 4.1.0, protocol 13) against contract
6TjweyPbxLNB4BhyVBcAzTxo54jDn33s5Y5j78WKM43Z with twelve documents:
the previous verifier fails on the unset-limit query and passes with
explicit limits 5 and 10; this verifier passes all three and returns
ten entries for the unset case.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e SDK verifier

The range-outer carrier COUNT bug came from the SDK verifier and the
COUNT dispatcher deriving `SizedQuery::limit` independently. The previous
commit fixed it by mirroring the dispatcher's rule in the SDK, which
still left two copies of a proof-sensitive policy to keep in sync.

Move the rule into `DriveDocumentCountQuery::carrier_aggregate_outer_limit`
in `mode_detection.rs`, next to `detect_mode`, built for both `server`
and `verify` like the rest of that module. The dispatcher's
`RangeAggregateCarrierProof` arm now calls it; its behaviour and error
messages are unchanged. The SDK's `carrier_walk_limit` becomes a thin
adapter that maps its `0` sentinel to `None` and wraps the Drive error.
The rs-drive round-trip test derives its verify limit through the same
helper, so a proof produced by the dispatcher is now checked against
the limit the verifier actually computes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/aggregate-verifier-limit-parity branch from 2c0234e to b36acbd Compare October 5, 2026 05:12
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Copy link
Copy Markdown
Member Author

/self-reviewed

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

@thepastaclaw review

No review for b36acbd1 yet, so PR Hygiene is asking once. If nothing arrives, the requirement is dropped for this commit and the pull request is labelled bot-review-skipped.

@PastaPastaPasta

Copy link
Copy Markdown
Member Author

Closing this in favour of a different approach. The issue itself is still real: a grouped range-over-range COUNT (outer > X AND inner > Y GROUP BY outer, prove = true) with the limit unset still fails to verify in the SDK once the outer range holds more than ten keys. The server proves with limit = Some(MAX_CARRIER_AGGREGATE_OUTER_RANGE_LIMIT), the SDK verifies with None, and the honest proof is rejected with "Proof is missing data for query range".

The fix here makes the SDK reproduce the server's limit exactly. That works, but only because GroveDB's verifier treats SizedQuery::limit as an exact expectation, and it ties every released SDK to the server's limit policy. Raising the cap, making it configurable, or changing which shapes accept an explicit limit would each break existing clients, and the client-side refusals in this PR would add to that.

One correction to the description above: the limit is not hashed into the proof. It only tells the verifier where a hidden tail is allowed. The proof already shows where the prover stopped, so the client doesn't need to know the server's limit to verify it.

New approach:

  • GroveDB: an opt-in verification mode where the limit is an upper bound ("at most n") rather than an exact expectation. The proof may end at the first hidden subtree inside the range, no result may follow that point, and the verifier reports whether the range was proven exhausted.
  • Platform: bump GroveDB. The SDK verifies range-outer carrier COUNT proofs with at most the requested limit (no ceiling when unset), and returns the "range exhausted / more may exist" flag, so callers don't treat a short page as the complete set.

The prove-then-verify test from this PR (test_range_outer_carrier_proof_verifies_with_capped_limit_not_none) will carry over to the new Platform PR. I'll link the GroveDB PR here once it's open.


🤖 Posted autonomously by Codex on behalf of pasta.

@PastaPastaPasta

Copy link
Copy Markdown
Member Author

The GroveDB side of the new approach is up: dashpay/grovedb#1008 adds an opt-in verification mode where SizedQuery::limit is a ceiling rather than the exact limit the prover used, plus verify_aggregate_{count,sum,count_and_sum}_query_per_key_up_to_limit returning (root_hash, entries, exhausted). Once it lands, the Platform follow-up bumps GroveDB and switches the SDK carrier verifiers to it, with no server limit policy on the client.


🤖 Posted autonomously by Codex on behalf of pasta.

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

Labels

Client Only 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.

4 participants