Skip to content

fix(sdk): check document query shapes before sending them - #5558

Merged
shumkov merged 4 commits into
v5.0-devfrom
shumkov/pr4-query-shape-checks
Oct 27, 2026
Merged

shumkov merged 4 commits into
v5.0-devfrom
shumkov/pr4-query-shape-checks

Conversation

@shumkov

@shumkov shumkov commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Every document view (Document, Documents, the count / sum / average views and their split forms, DocumentRankedEntries, DocumentHavingEntries, CompositeDocuments) is fetched with the same DocumentQuery and the same getDocuments encoding. Several views checked the query's shape only inside FromProof, after a node had already answered. Nodes serve such a query as what it asks for. The view's verifier then refuses the answer because of the request alone, which the SDK reports as Error::Proof. That error is retryable, so each node that answered gets banned: up to four per call with the default three retries.

The two cases that started this:

  • A malformed ranked query (for example, a range on the GROUP BY property, or no limit). Every protocol-13 node, 4.1.2 and 5.0 alike, routes it with the v13 query table and serves it as a plain grouped aggregate. The ranked verifier then refuses it. Before protocol 14 activates, each such call bans up to four honest nodes of any version.
  • sub_queries sent through a non-composite view. ensure_no_sub_queries refused it only after the answer.

The same class also covered these cases, now fixed too:

  • DocumentCount / DocumentSplitCounts, DocumentSum / DocumentSplitSums, DocumentAverage / DocumentSplitAverages fetched with a query that selects something other than their aggregate. For example, DocumentCount::fetch without .with_select(count_star()) is sent as a plain documents query.
  • DocumentCount, DocumentSum and DocumentAverage with a containsAny over several elements of a typed array, grouped by the array. The server answers with one total per element, but these views add the entries up into one total, so their verifiers refuse the request.
  • DocumentCount, DocumentSum, DocumentAverage and their split forms with a ranked- or having-shaped query: grouped, and ordered by the aggregate or carrying a having clause. From protocol 14 the routing table sends these to the ranked or having-range executor. A node serves one only when no In or range constrains the group, because its where clauses may only pin the index properties before the grouped one. The count / sum / average verifiers refuse exactly that group shape from the request alone.
  • DocumentHavingEntries with no having clause, which is an ordinary grouped aggregate and is served.
  • Document / Documents with an aggregate select. The documents verifier rebuilds a documents query whatever the select says, so a served count can never verify.
  • CompositeDocuments without sub-queries. The encoder checks the composite shape only when sub-queries are present, so the query went out as a plain page.

What was done?

  • FromProof::check_request(&Self::Request, &PlatformVersion) (rs-drive-proof-verifier) is a new provided method that checks a request before it is sent. Its default accepts everything. The documented contract: an implementation must never refuse a request that maybe_from_proof_with_metadata can verify, at the given version or any later one.
  • Overrides for the 11 views fetched with a DocumentQuery (dash-platform-queries). Every check except one reuses a request-side helper the verifier already runs: ensure_no_sub_queries, assert_select_is_{count,sum,avg}, aggregate_where_clauses with the mode resolvers resolve_count_mode / resolve_sum_mode (through check_{count,sum,average}_request), assert_ranked_shape, assert_having_shape, check_composite_shape. The one new condition is in Document / Documents, which refuse a select function other than Documents.
    • The count / sum / average refusal of a group that no In or range constrains needs no version gate. On protocol 13 and earlier, nodes refuse that shape and any having. On protocol 14, a node serves it only as a ranked or having-range answer, which these views cannot verify. Gating on the SDK's stored version would add nothing, and an SDK pinned ahead of its network would refuse queries that the network still serves as grouped aggregates.
    • The split views key typed-array clauses the way their verifiers do (folds_entries = false). This is needed so a containsAny reads as the In the group-by mode resolver looks for. The keying refusals it adds (several elements without grouping by the array alone, or under a range) are refused by nodes too, with the same drive function, so on their own they never banned.
    • CompositeDocuments builds its request error with one helper, check_composite_request, both before sending and in the verifier. The text is the same either way.
    • COUNT / SUM / AVG are answered with aggregate proofs, so nothing that verifies is refused.
    • A projection field on the documents select is left to the server, which refuses it on V1, and to the V0 encoder, which drops it.
  • The Fetch and FetchMany trampolines (rs-sdk) call the hook after encoding and before retry(), at the protocol version the request was encoded with (settings.protocol_version). A verified answer to another request can raise sdk.version() in between. A refusal is a non-retryable Error::Config whose text is the verifier's message without the decode request: prefix. Nothing is sent and no node is banned.
  • The verifiers keep their own checks: FromProof can still be called directly.
  • Pending time-range and integer-range selections stay unresolved. They resolve against the answer (a relative time selection needs its signed block time), and resolving them only ever appends equality pins. Every grammar refusal is either about one clause or about a conflicting pair, so the check, which sees fewer clauses, refuses nothing the verifier accepts.
  • detect_ranked_mode and detect_having_mode are method version 0 in every platform version. Checking at the encoding version therefore matches the verifier, which may use a newer signed version.
View Refused before sending
Document, Documents sub-queries; a select function other than documents
DocumentCount, DocumentSum, DocumentAverage sub-queries; a select other than their aggregate; a group no In or range constrains, which covers ranked- and having-shaped queries; containsAny over several elements of a typed array
DocumentSplitCounts, DocumentSplitSums, DocumentSplitAverages sub-queries; a select other than their aggregate; a group no In or range constrains, as above; containsAny over several elements unless grouped by the array alone and without a range
DocumentRankedEntries sub-queries; anything outside the ranked grammar
DocumentHavingEntries sub-queries; anything outside the having grammar, including no having
CompositeDocuments no sub-queries, or another composite-shape violation

Surface effect. These queries already failed. They now fail locally:

  • wasm: a Config kind with isRetriable: false, where it was Proof and retriable.
  • rs-sdk: Error::Config.

No in-repo caller (wasm-sdk, rs-sdk-ffi, platform-wallet, rs-sdk internals and tests, offline vectors) builds a refused shape. wasm-sdk already pre-checked its ranked, having and composite shapes.

Not done here (follow-ups):

  • resolve_{ranked,having}_query_for_mode (covering-index resolution) still runs only after the answer. It needs the resolved time ranges and the index map, and a node refuses a query no index covers, so it does not ban.
  • Single Document::fetch turns "expected 1 element" into a retryable Error::Proof. That refusal depends on the answer, so a pre-send check cannot help; it needs a non-retryable error instead.
  • rs-sdk-ffi classifies Error::Config by substring, not with a typed arm. This is pre-existing, and no FFI document function can build a refused shape.
  • delegate_from_proof_variant! does not forward check_request. It only wraps identity request enums, which keep the default.
  • ChainedDocumentQuery already checks its shape when it is encoded.

This PR is independent of the protocol-version gate PR. When both are in, the gate runs first and this check runs after it.

How Has This Been Tested?

New tests:

  • dash-platform-queries documents::check_request_tests (12 tests) covers:
    • each view's accepted shape (guard). The split guards now constrain their group with an In, because a group nothing constrains is never verifiable;
    • sub-queries on every non-composite view;
    • a full select-mismatch matrix (8 views × 3 foreign selects);
    • the ranked grammar (a range on the group, no limit);
    • a having query with no clause;
    • ranked- and having-shaped queries through all six count / sum / average views;
    • composite without sub-queries, and a bad sub-query limit;
    • the same composite refusal text from check_request and from the verifier;
    • a folded total over several array elements refused, while the split views accept it grouped by the array and refuse it ungrouped or under a range;
    • pending time-range and integer-range selections accepted;
    • a documents projection field left alone.
  • dash-sdk sdk::document_query_shape_tests (10 tests) goes through both trampolines on a mock SDK. The wire request is registered as served, so a fetch that sends it reaches the real verifier. Each case asserts Error::Config and that the request was never sent. A guard checks that well-formed ranked and documents queries are still sent. A probe view that reports the version it was checked at, together with a query that raises the SDK's version while it is being built, pins the encoding-version check in both trampolines.
  • drive-abci real-proof guards. The signed-proof round trips in query::document_query::v1::tests now assert that every query they verify passes its view's check. These cover windowed ranked (newest and by-start) and having, integer windows (count and documents), typed-array elements (every view through through_sdk, plus the documents element page) and the composite composition.

Red → green:

  • Commit 1 (tests and hook default) against the original views: 5 of 7 unit tests and 6 of 7 SDK tests fail. Each SDK case was sent 4 times and ended in Error::Proof, which is the ban. After commit 2, everything passes; the guards pass both before and after.
  • Commit 3 (from review): against commit 2's views, the folded-total and projection-field unit tests and the folded-count SDK test fail. The SDK test again shows 4 sends ending in Error::Proof. After commit 3: 10/10 unit and 8/8 SDK pass.
  • Commit 4 (second review): against 1723b2e5f3, 3 of 12 unit tests fail (ranked/having through the aggregate views, split-view keying, composite text) and 2 of 10 SDK tests fail. DocumentSplitCounts of a ranked count was sent 4 times and ended in Error::Proof. The version probe was checked at 14 for a request encoded at 13. After commit 4: 12/12 unit and 10/10 SDK pass.

Mutation checks. Each one turned the named tests red:

Mutation Tests that went red
fetch.rs call removed 4 Fetch SDK tests
fetch_many.rs call removed 2 FetchMany SDK tests
refusal mapped to Error::Proof all SDK refusals
Documents refusing everything both guard tests
DocumentSplitSums select check dropped select-mismatch unit test
ranked grammar check dropped ranked unit and SDK tests
composite nested "SDK misconfigured" prefix kept composite unit test
ranked check refusing pending time ranges the two windowed drive-abci real-proof round trips and the unit guard
fetch_many.rs back to sdk.version() the version probe test (its fetch_many half)
check_sum_request without the mode resolver the ranked/having aggregate-view unit test (DocumentSum)

Runs:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --workspace --all-targets --all-features --locked -- --no-deps -D warnings (the CI flags): clean.
  • Transport-free cuts: cargo check -p drive-proof-verifier --locked and cargo check -p dash-platform-queries --locked are clean.
  • cargo test -p drive-proof-verifier -p dash-platform-queries -p dash-sdk --all-features --locked --lib --tests: 1070 passed, 0 failed. 28 were ignored, all network tests that were ignored already.
  • cargo test -p drive-abci --lib query::document_query::v1::tests: 113 passed, including the 16 real-proof round trips that now assert the check. These include signed count, sum, average, split-count and split-sum round trips through through_sdk, so the new group check accepts every grouped shape they verify.
  • Not run locally:
    • the full CI-equivalent workspace run, because the change is limited to these crates;
    • wasm32 and rs-sdk-ffi tests, because neither changed (both compiled under clippy).

Breaking Changes

None. check_request is a provided trait method with a default. Every query now refused locally already failed before: either a node refused it, or it was refused after the answer, with node bans. The drive-abci real-proof guards show that the verifiable shapes they cover still pass.

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 added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 5f76f73

  • Bots — coderabbitai ✓ · thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Build green
  • 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
    • Unsupported document query shapes are now rejected before a request is sent, with a configuration error instead of a later proof-verification failure.
    • Validation now covers document, aggregate, ranked, having, and composite queries, including incompatible selections and typed-array grouping or counting cases.
    • Supported queries continue through the existing request and proof-verification flow.

shumkov and others added 3 commits October 23, 2026 20:41
…nding

Every document view (Document, Documents, the count / sum / average views
and their split forms, ranked, having, composite) is fetched with the same
DocumentQuery and the same wire encoding. A query built for one view and
fetched as another is served by every node, and the view's verifier then
refuses the answer for the request alone. The SDK reports that as
Error::Proof, which is retried and bans each node that answered.

Adds FromProof::check_request with a default that accepts every request,
and tests that each view refuses, before anything is sent, the shapes its
verifier refuses after the answer, while still accepting every shape it
verifies:

- dash-platform-queries: table-driven unit tests over all eleven views.
- dash-sdk: mock-SDK tests through the Fetch and FetchMany trampolines;
  the request is registered as served, so a fetch that sends it reaches
  the real verifier.

These tests fail until the views override the hook and the trampolines
call it (next commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every document view shares one DocumentQuery and one wire encoding, and
several views checked the query only after a node had answered it. Every
node serves such a query as what it asks for; the view's verifier then
refuses the answer for the request alone, which surfaced as Error::Proof,
was retried, and banned each node that answered (up to four per call with
the default three retries). Before protocol 14 activates this hits 4.1.2
and 5.0 nodes alike.

The views now override FromProof::check_request with the request-side
checks their verifiers already run, and the Fetch and FetchMany
trampolines call it after encoding and before sending, with the SDK's
protocol version. A refusal is a non-retryable Error::Config; nothing is
sent and no node is banned. The verifiers keep their own checks.

Refused before sending now:
- DocumentRankedEntries: a query outside the ranked grammar (e.g. a range
  on the grouped property, no limit), which nodes routing with the
  protocol-13 query table serve as a plain grouped aggregate.
- DocumentHavingEntries: a query outside the having grammar, including one
  with no having clause (an ordinary grouped aggregate).
- DocumentCount / DocumentSplitCounts, DocumentSum / DocumentSplitSums,
  DocumentAverage / DocumentSplitAverages: a select of anything but their
  own aggregate.
- Document / Documents: an aggregate select (the verifier rebuilds a
  documents query whatever the select, so a served aggregate never
  verifies).
- CompositeDocuments: a query without sub-queries (the encoder checks the
  composite shape only when sub-queries are present).
- Every view but CompositeDocuments: sub-queries.

Pending time-range selections are left unresolved: they resolve against
the answer's signed block time and only ever add equality pins, which the
grammars cannot refuse a query for lacking, so the check refuses nothing
the verifier accepts.

Tests would have caught this (previous commit): ✖ before the fix, 5 of 7
dash-platform-queries check_request_tests and 6 of 7 dash-sdk
document_query_shape_tests fail; each SDK case was sent 4 times and ended
in Error::Proof. ✔ after the fix, 7/7 and 7/7 pass. The two guard tests
(views keep accepting the queries they verify; such queries are still
sent) pass both before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nding

Review of the pre-send checks found one more query that nodes serve and a
view then refuses for the request alone: DocumentCount, DocumentSum and
DocumentAverage add every verified entry up into one total, so their
verifiers refuse a containsAny over several elements of a typed array even
grouped by the array, which the server answers with one total per element.
Their checks now key the where clauses as the verifiers do (one element at
most), so the query is refused locally instead of banning each node.

The Document / Documents check now compares only the select function. A
projection field on the documents select is refused by the server on the
V1 wire and dropped by the V0 encoder, whose served documents verify; the
whole-projection comparison refused that V0 case.

Also:
- The trait contract says a check must not refuse what verifies at the
  given version or any later one, since answers verify at their signed
  version when that is newer.
- drive-abci's real signed-proof round trips (windowed ranked and having,
  integer windows, typed-array elements, composite, and every view through
  `through_sdk`) assert that each verified query passes its view's check,
  so a check that refuses a verifiable query fails there.
- Unit tests: a full select-mismatch matrix over the eight select-checked
  views, integer-range selections left pending, a composite sub-query
  error, comment accuracy fixes; the SDK helper is renamed
  check_before_sending.

Tests would have caught this: ✖ against the previous commit's views,
should_refuse_one_total_over_several_elements_of_a_typed_array and
should_leave_a_documents_projection_field_to_the_encoder_and_the_server
fail, and the SDK's
should_refuse_one_count_over_several_elements_of_a_typed_array_without_sending_it
fails with the query sent 4 times and an Error::Proof. ✔ after: 10/10 unit,
8/8 SDK. A ranked check that refused pending time ranges turns the two
windowed drive-abci round trips and the unit guard red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shumkov shumkov added this to the v5.0.0 milestone Oct 23, 2026
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 78d494f and 5f76f73.

📒 Files selected for processing: 22
  • packages/dash-platform-queries/src/documents/array_element_clauses.rs
  • packages/dash-platform-queries/src/documents/average_proof_helpers.rs
  • packages/dash-platform-queries/src/documents/check_request_tests.rs
  • packages/dash-platform-queries/src/documents/composite_document_query.rs
  • packages/dash-platform-queries/src/documents/count_proof_helpers.rs
  • packages/dash-platform-queries/src/documents/document_average.rs
  • packages/dash-platform-queries/src/documents/document_count.rs
  • packages/dash-platform-queries/src/documents/document_having_entries.rs
  • packages/dash-platform-queries/src/documents/document_query.rs
  • packages/dash-platform-queries/src/documents/document_ranked_entries.rs
  • packages/dash-platform-queries/src/documents/document_split_averages.rs
  • packages/dash-platform-queries/src/documents/document_split_counts.rs
  • packages/dash-platform-queries/src/documents/document_split_sums.rs
  • packages/dash-platform-queries/src/documents/document_sum.rs
  • packages/dash-platform-queries/src/documents/mod.rs
  • packages/dash-platform-queries/src/documents/sum_proof_helpers.rs
  • packages/rs-drive-abci/src/query/document_query/v1/tests.rs
  • packages/rs-drive-proof-verifier/src/proof.rs
  • packages/rs-sdk/src/platform/fetch.rs
  • packages/rs-sdk/src/platform/fetch_many.rs
  • packages/rs-sdk/src/sdk.rs
  • packages/rs-sdk/src/sdk/document_query_shape_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

Proof result types now expose request-shape validation. The SDK runs these checks against the selected protocol version before sending fetch and fetch-many requests. Tests cover query acceptance, local refusal, and protocol-version handling.

Changes: Document query validation

Layer / File(s) Summary
Request-check contract and clause preparation
packages/rs-drive-proof-verifier/src/proof.rs, packages/dash-platform-queries/src/documents/array_element_clauses.rs
FromProof gains a default check_request method. Shared helpers prepare aggregate request clauses and resolve named document types.
Proof result shape checks
packages/dash-platform-queries/src/documents/*, packages/rs-drive-abci/src/query/document_query/v1/tests.rs
Document, ranked, having, composite, count, sum, and average result types add request-shape checks. Tests cover accepted and rejected shapes, including typed-array grouping and pending selections.
SDK checks before sending
packages/rs-sdk/src/platform/fetch.rs, packages/rs-sdk/src/platform/fetch_many.rs, packages/rs-sdk/src/sdk.rs, packages/rs-sdk/src/sdk/document_query_shape_tests.rs
Fetch paths validate requests before wire execution and map validation failures to Error::Config. Mock tests cover local refusal, accepted requests, and protocol-version handling.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Fetch
  participant check_before_sending
  participant FromProof
  participant Platform
  Fetch->>check_before_sending: query and protocol version
  check_before_sending->>FromProof: check_request
  FromProof-->>check_before_sending: validation result
  check_before_sending-->>Fetch: success or configuration error
  Fetch->>Platform: execute wire request after successful check
Loading

Suggested reviewers: quantumexplorer

Merge Risk: ⚪ Minimal · up to 5f76f

No identified issue needs resolution before merge; proceed with normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 64.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 100 functions across 22 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
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 document query shapes before sending them.
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: 💡 1
📝 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

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

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai skipped after its own rate limit · 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 Oct 23, 2026
@thepastaclaw

thepastaclaw commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 5f76f73) · triage: normal

@shumkov

shumkov commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions github-actions Bot added the bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. label Oct 23, 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.

Final validation — Phase 1 + Phase 2

The pre-send verification hook is correctly integrated into both Fetch paths and preserves valid document, ranked, having, and composite query shapes. Three in-scope gaps remain: split aggregate views do not validate typed-array ContainsAny shapes, aggregate views do not reject ranked/having-shaped requests that route to different proof formats, and preflight validation can use a different protocol-version snapshot from request encoding. CI has no reported code failure, although the Swift build and PR Hygiene checks remain in progress.

🟡 4 suggestion(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: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a substantial cross-cutting Rust change spanning SDK request validation, proof-verifier hooks, multiple document-query views, protocol-versioned query handling, and extensive tests, but it does not itself modify consensus rules, cryptography, funds movement, key handling, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (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 quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • 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 — 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/document_split_counts.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/documents/document_split_counts.rs:53-59: Validate typed-array ContainsAny shapes for split aggregate views
  This preflight checks only sub-queries and the select function. The verifier later calls `aggregate_where_clauses(..., folds_entries = false, ...)`, which still rejects typed-array `ContainsAny` shapes unless the query is grouped by exactly the constrained array field and has no conflicting range clause. Consequently, a split count request with `containsAny(["dash", "news"])` and no matching `group_by`, or with an additional range/grouping shape, passes `check_request` but is rejected only after a node answers. The same omission exists in `document_split_sums.rs` and `document_split_averages.rs`, leaving the SDK able to retry and ban honest nodes for these request-determined failures. Reuse `grouped_by_in_field` and `key_element_clauses` (or a shared aggregate-shape helper) in all three split-view checks.

In `packages/dash-platform-queries/src/documents/document_count.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/documents/document_count.rs:37-51: Reject ranked and having-shaped requests in aggregate preflight checks
  The aggregate checks validate the select, sub-query absence, and array-element keying, but do not inspect `order_by` or `having`. On protocol versions using the newer aggregate routing tables, a grouped aggregate with `order_by` naming the selected aggregate is routed as `Ranked`, while a grouped aggregate with one `having` clause is routed as `HavingRange`. The count, sum, and average verifiers instead derive their modes from `group_by` and `where_clauses` and do not verify those ranked/having proof formats. Such requests therefore reach a node, receive a ranked or having proof, fail as `Error::Proof`, and are retried against additional honest nodes. The check must account for the routing-table version: these shapes are not necessarily invalid on older versions where the routing table ignores `order_by` or rejects `having` differently. Apply the same version-aware guard to `DocumentSum`, `DocumentAverage`, and all three split aggregate views.

In `packages/rs-sdk/src/platform/fetch.rs`:
- [SUGGESTION] packages/rs-sdk/src/platform/fetch.rs:294-301: Validate against the protocol-version snapshot used for encoding
  Both fetch trampolines capture `settings.protocol_version`, encode the rich query and wire request with that snapshot, and then call `check_before_sending`, which reads `sdk.version()` again. The SDK protocol version is an upward-ratcheting atomic value, so another verified response can update it between encoding and preflight. A version-sensitive shape can consequently be checked using a different version from the one used to encode the request, producing a false refusal or allowing a shape inconsistent with the encoded request. Pass the captured `settings.protocol_version` into `check_before_sending` and make the same change at the `FetchMany` call site.

In `packages/dash-platform-queries/src/documents/composite_document_query.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/documents/composite_document_query.rs:410-421: Use one composite-shape error mapping for preflight and proof verification
  The new preflight path strips the `SDK misconfigured: ` display prefix when `check_composite_shape()` returns `Error::Config`, while the post-response verifier maps the same failure with `e.to_string()` and retains that prefix. The same composite-shape failure therefore produces different text depending on whether it is caught before transmission or after a response. Since downstream integrations already classify configuration failures using error text in some paths, keep the mapping consistent by extracting a shared helper and using it from both `check_request` and `maybe_from_proof_with_metadata`.

Comment thread packages/rs-sdk/src/platform/fetch.rs Resolved
@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 Oct 23, 2026
…the encoding version

Second round of review on the pre-send document query checks.

- Count, sum and average views and their split forms now run the
  request-only part of their verifier before sending: typed-array keying
  (aggregate_where_clauses) and the group-by mode resolver
  (resolve_count_mode / resolve_sum_mode). From protocol 14 a grouped
  aggregate ordered by its aggregate, or with a having clause, is routed
  to the ranked or having-range executor. A node serves it only when no
  In or range constrains the group, which these verifiers refuse from the
  request alone, so each such fetch banned every node that answered.
  Protocol 13 nodes refuse the same shapes, so no version gate is needed.
  The split views now key typed-array clauses like their verifiers
  (needed so containsAny reads as the In the resolver looks for).
- check_before_sending takes the protocol version the request was encoded
  with instead of re-reading sdk.version(), which a verified answer to
  another request can raise in between.
- CompositeDocuments builds its composite-shape request error with one
  helper before sending and in the verifier, so the text is the same.

The split-view guard fixtures now constrain their group with an In: a
group nothing constrains is never verifiable.

Tests would have caught this (red at 1723b2e, green here):
- dash-platform-queries check_request_tests: 3 of 12 fail before
  (ranked/having through the aggregate views, split-view keying,
  composite text); 12/12 after.
- dash-sdk document_query_shape_tests: 2 of 10 fail before. Split counts
  of a ranked count were sent 4 times and ended in Error::Proof; a probe
  view was checked at 14 for a request encoded at 13. 10/10 after.
- Mutations: fetch_many back to sdk.version() fails the probe's
  fetch_many half; check_sum_request without the resolver fails the
  aggregate-view unit test for DocumentSum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 23, 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 bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Oct 23, 2026
@shumkov

shumkov commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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

The complete diff adds request-shape preflight validation at the proof-verifier boundary, invokes it before retryable SDK transport using the encoding-time protocol version, and retains all post-response proof checks. The four prior findings are fixed, and no new correctness, security, layering, or consensus issues were found. Rust workspace tests and JS package builds were still in progress at the supplied CI snapshot.

🔴 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: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 11: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 12: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 13: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 14: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a substantial cross-cutting Rust change spanning request validation, proof verification, SDK fetching, protocol-version behavior, and extensive tests, but it does not itself alter consensus rules, cryptography, funds movement, or persistent storage.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (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 quota lookup failed), 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.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 — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (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, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (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 Oct 23, 2026
@shumkov
shumkov merged commit 52a4b57 into v5.0-dev Oct 27, 2026
35 of 36 checks passed
@shumkov
shumkov deleted the shumkov/pr4-query-shape-checks branch October 27, 2026 07:05
shumkov added a commit that referenced this pull request Oct 27, 2026
…pv14-requests

Brings in the 5.0.0 release, #5557 and #5558. No textual conflicts; the
fetch trampolines auto-merged with #5558's check before the protocol
gate, which the next commit reorders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thepastaclaw pushed a commit to thepastaclaw/platform that referenced this pull request Nov 2, 2026
Brings 5.0.1 (v5.0-dev 093268c) into v5.1-dev: the 5.0.0 release
(dashpay#5594, with dashpay#5352, dashpay#5582, dashpay#5583), dashpay#5557, dashpay#5558, dashpay#5560, dashpay#5561, dashpay#5559 and
the 5.0.1 release bump (dashpay#5606).

Conflict resolutions:
- CHANGELOG.md: [Unreleased] on top, then the 5.0.1 and 5.0.0 entries.
- rs-sdk error.rs: both sides added methods to Error; kept v5.1's
  consensus_error and dashpay#5560's spares_responder and into_exhausted_error.
- rs-drive-abci tests/signed_response/mod.rs, moved from
  drive-proof-verifier by dashpay#5559: dashpay#5559's location, doc and
  drive_proof_verifier ContextProvider import, with v5.1's dpp::bls port.

Semantic conflicts resolved:
- rs-drive-abci tests/older_node_answers.rs (dashpay#5561): ported to dpp::bls,
  since v5.1-dev no longer ships blsful (dashpay#5320). The key is the scalar
  blsful's SecretKey::from_hash derived from the same label, so the
  public key and Basic-scheme signature bytes are unchanged.
- rs-sdk protocol_gate_tests.rs (dashpay#5561):
  should_ask_a_fresh_sdk_network_for_its_version_once_then_send expected
  the SDK at 14 after its calls. The mock answers every expectation at
  the latest version, which was 14 on v5.0-dev and is 15 here, so the
  mocked fee-pots answers raise an unpinned SDK on to 15 (left: 15,
  right: 14). The test now expects the higher of 14 and the latest
  version; that the probe raised the SDK to 14 is shown by the first
  call being sent at all. Fails on the merge without this change, passes
  with it.

Workspace and package versions follow v5.0-dev to 5.0.1, as the previous
forward merges did. rust-dashcore stays on dev aca02026.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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