Skip to content

refactor(drive-abci): share the v1 document-query wire decoders and bound dpp document field reads - #4618

Open
PastaPastaPasta wants to merge 2 commits into
v4.2-devfrom
refactor/platform-query-wire-and-dpp-bounds
Open

refactor(drive-abci): share the v1 document-query wire decoders and bound dpp document field reads#4618
PastaPastaPasta wants to merge 2 commits into
v4.2-devfrom
refactor/platform-query-wire-and-dpp-bounds

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

First of three PRs replacing the transport-free-embedder series (#4464, #4478, #4389, #4433, #4416), rebuilt after a review of that stack found it duplicating code the workspace already has and carrying two remotely triggerable aborts in the C++ bridge. This PR is the server-side and dpp half; the SDK verification/builders and the C++ crate follow in stacked PRs.

Two independent changes that both sit below the client crates:

  1. The v1 getDocuments wire decode becomes a shared crate. A client that verifies a proof against the request it actually sent must reconstruct the query exactly as the server did. Today that decode lives only inside rs-drive-abci, so the earlier client-side PR carried a byte-for-byte copy with a "keep in lockstep" comment. Supersedes refactor(drive-abci): extract v1 document-query wire decoders into platform-query-wire #4464, re-derived from the current server file (which had grown the time-range decoders since refactor(drive-abci): extract v1 document-query wire decoders into platform-query-wire #4464 was cut).
  2. A pre-authentication remote abort in dpp document deserialization. Document decoding read a varint length from the serialized bytes and immediately allocated a Vec of that size, for variable-size string/byte-array fields and for nested object payloads. A proved response's documents are decoded before its quorum signature is checked (the root hash only exists after replay), so ~70 bytes of self-consistent proof carrying a document whose length prefix claims 2^62 bytes aborted every proof-verifying client (rs-sdk, wasm-sdk, the Dash Core embedder) on allocation failure.

What was done?

  • New packages/rs-platform-query-wire (platform-query-wire): the wire-proto → drive-type decoders for getDocuments v1 (where / order-by / having / select / time-range clauses), moved verbatim from rs-drive-abci/src/query/document_query/v1/conversions.rs, with a neutral DecodeError { InvalidArgument, Unsupported }. Its dependency graph (dapi-grpc, dpp, drive) is a strict subset of what drive-abci already carries, so the consensus server does not gain client-flavoured dependencies.
  • rs-drive-abci's v1/conversions.rs is now a thin adapter mapping DecodeError onto QueryError, preserving every existing message string.
  • rs-dpp DocumentPropertyType::read_varint_value and the Object arm check the declared length against the bytes remaining in the reader before allocating, and reject with CorruptedSerialization otherwise.
  • Workspace, Dockerfile COPY --parents, package filters, and the transport-free CI cut gain the new crate.

How Has This Been Tested?

  • cargo test -p drive-abci --lib -- query::document_query::v1: 97 passed (the server's own decode tests now exercise the shared crate through the adapter).
  • cargo test -p dpp --lib -- read_optionally_from: all pass, including the new test_read_optionally_from_rejects_length_prefix_longer_than_input, which feeds a 2^62 varint to both the string and object arms and asserts the rejection message.
  • cargo check -p platform-query-wire --locked and cargo clippy --all-targets --all-features -- -D warnings on the touched crates: clean. cargo machete: clean.

Breaking Changes

None. Server error strings are unchanged; the dpp change only turns an abort into an error.

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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

…atform-query-wire

Pure move: the wire-proto -> drive-type decoders for the v1 getDocuments surface now live in a new packages/rs-platform-query-wire micro-crate (crate name platform-query-wire) behind a neutral DecodeError { InvalidArgument, Unsupported }, and drive-abci's v1/conversions.rs becomes a thin adapter mapping DecodeError onto its QueryError surface with the exact same message strings (including the aggregate ORDER BY arm, which maps Unsupported onto QuerySyntaxError::Unsupported). No behavior change to server request decoding.

The decode of a wire request into a rich query is an equivalence contract at a trust boundary: a client-side proof verifier must interpret a request exactly as the server does, or a proof could verify against a different query than the server answered. Hosting the shared decoders in a neutral crate lets both rs-drive-abci and (in a follow-up) the client-side SDK decoders run the same functions, without making the consensus server depend on SDK-branded code: the new crate's dependencies (dapi-grpc platform+client without transport, dpp, drive/verify, thiserror) are a strict subset of what drive-abci already carries.
Document deserialization read a varint length from the (untrusted) serialized bytes and immediately allocated a Vec of that size, for both variable-size string/byte-array fields and nested object payloads. A proved getDocuments response is decoded before its quorum signature is checked, so a self-consistent GroveDB proof carrying a document whose length prefix claims gigabytes made every client that verifies proofs (rs-sdk, wasm-sdk, and the Dash Core embedder) abort on allocation failure from ~70 bytes of input.

Both sites now check the declared length against the bytes remaining in the reader and reject with CorruptedSerialization before allocating. A regression test feeds a 2^62 length prefix to both the string and object arms.
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 29 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 6ec4b829-53d7-4e04-8bf7-b77f418ab8c5

📥 Commits

Reviewing files that changed from the base of the PR and between 658aec5 and ffb791d.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • .github/package-filters/rs-packages-direct.yml
  • .github/package-filters/rs-packages-no-workflows.yml
  • .github/package-filters/rs-packages.yml
  • Cargo.toml
  • Dockerfile
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-drive-abci/Cargo.toml
  • packages/rs-drive-abci/src/query/document_query/v1/conversions.rs
  • packages/rs-platform-query-wire/Cargo.toml
  • packages/rs-platform-query-wire/README.md
  • packages/rs-platform-query-wire/src/lib.rs
  • packages/rs-platform-query-wire/src/proto_conversions.rs

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.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.34104% with 113 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.35%. Comparing base (658aec5) to head (ffb791d).
⚠️ Report is 2 commits behind head on v4.2-dev.

Files with missing lines Patch % Lines
...es/rs-platform-query-wire/src/proto_conversions.rs 70.11% 78 Missing ⚠️
...pp/src/data_contract/document_type/property/mod.rs 62.50% 24 Missing ⚠️
...ve-abci/src/query/document_query/v1/conversions.rs 47.61% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v4.2-dev    #4618      +/-   ##
============================================
- Coverage     87.72%   85.35%   -2.37%     
============================================
  Files          2762     2793      +31     
  Lines        360146   371086   +10940     
============================================
+ Hits         315922   316737     +815     
- Misses        44224    54349   +10125     
Components Coverage Δ
dpp 85.73% <62.50%> (-3.35%) ⬇️
drive 84.20% <ø> (-2.37%) ⬇️
drive-abci 88.23% <47.61%> (-1.25%) ⬇️
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.92% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 48.81% <ø> (-0.25%) ⬇️
🚀 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.

@PastaPastaPasta PastaPastaPasta added the ready for final review Ready for the final review. If AI was involved in producing this PR, it has already had a reviewer. label Sep 8, 2026
@thepastaclaw

thepastaclaw commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 50th in line, estimated start in ~69 h (commit ffb791d)
Estimated review time once started: ~2.8 h (two-phase automated review; median of recent runs).

  • Request priority review — tick this box and the review moves to the front of the queue.

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

Labels

ready for final review Ready for the final review. If AI was involved in producing this PR, it has already had a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants