Skip to content

fix(platform)!: bound decoded size and refuse zero-width arrays (PV15) - #6092

Merged
QuantumExplorer merged 9 commits into
v5.1-devfrom
fix/bound-typed-array-decoded-size
Nov 23, 2026
Merged

QuantumExplorer merged 9 commits into
v5.1-devfrom
fix/bound-typed-array-decoded-size

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

Closes #6070.

TypedArrayProperty::read_from in rs-dpp limited typed arrays to maxItems (up to max_typed_array_items = 1024) without bounding the decoded size by the encoded byte length. An element type encoding to zero bytes (specifically a byte array pinned to minItems: 0, maxItems: 0) allowed a short byte payload (e.g. a 1- or 2-byte varint count) to decode into up to 1024 allocated values. This impacted all consumers of the decoder, including client document queries, PV15 document history proofs, composite joins, contender page conversion, decode_private_document_payload, and moderator deletion removal records (ContractDocumentRemoval), where multiple records on a page could exhaust memory.

What was done?

  1. Schema Validation for Protocol Version 15 (try_from_schema generation 4):

    • Added TypedArrayProperty::has_zero_encoded_width_element to identify zero-width element types (ByteArray with minItems: 0, maxItems: 0).
    • Added validate_typed_array_non_zero_element_width in parser generation 4 (active for unreleased PV15 via CONTRACT_VERSIONS_V7), which rejects top-level and nested zero-width typed array properties under full_validation (contract registration and updates).
    • Shipped PV14 generation 3 remains untouched, and contracts registered at PV14 remain loadable with full_validation: false.
    • Documented the consensus rule in v7.rs and v15.rs.
  2. Bounded Property Decoding via DecodedValueBudget & DataContractError::DecodedValueBudgetExceeded:

    • Appended DataContractError::DecodedValueBudgetExceeded(String) (code 10283) to DataContractError (@append_only) and added ProofError::DecodedValueBudgetExceeded { root_hash, reason } in rs-drive, documenting both in book/src/sdk/protocol-version-15-upgrade.md.
    • Introduced DecodedValueBudget (including charge_value/charge_document/charge_documents) and DEFAULT_CLIENT_PAGE_DECODED_VALUE_BUDGET (262_144) in rs-dpp.
    • Added DocumentPropertyType::read_optionally_from_with_budget and TypedArrayProperty::read_from_with_budget, checking and charging the budget before allocating zero-width elements.
    • Added Document::from_bytes_with_budget and DocumentV0::from_bytes_with_budget (treating DecodedValueBudgetExceeded as terminal on format 0 so it never falls back to format 1), plus header-only Document::id_from_bytes sharing read_document_header_prefix with id_and_revision_from_bytes_v0 (formats 0–3), while keeping consensus from_bytes unbounded.
    • Added ContenderWithSerializedDocument::{try_to_contender_with_budget, try_into_contender_with_budget}.
    • Bounded decode_private_document_payload proportionally to the payload byte length via a single DecodedValueBudget::for_encoded_payload computation copied across both passes.
    • Preserved unbounded decode_kept_fields / ContractDocumentRemoval::kept_values for PV14 consensus replay (drive-abci and drive derived indexes) and added decode_kept_fields_with_budget / decode_kept_fields_with_default_budget / kept_values_with_budget / kept_values_with_default_budget for client callers.
  3. Shared Response-Level Budgeting & Authenticated Local Refusals in Client Proof Verification, SDKs, FFI & WASM:

    • Updated client-side document proof verifiers in rs-drive (verify_proof, verify_document_history v0 & v1, verify_chained_documents_proof, verify_composite_documents_proof, single_document::verify_proof v0 & v1, verify_start_at_document_in_proof v0 & v1, and verify_state_transition_was_executed_with_proof) to share DEFAULT_CLIENT_PAGE_DECODED_VALUE_BUDGET across each verified response and attach the reconstructed GroveDB root via ProofError::DecodedValueBudgetExceeded { root_hash, reason } on budget exhaustion (switching contract document restore ID extraction to header-only Document::id_from_bytes without looking up the contract).
    • Added MapProvedBudgetError::map_proved_budget_error in rs-drive-proof-verifier (matching map_proved_sum_error) so authenticated decode-budget refusals verify the Tenderdash quorum signature over root_hash first and surface as Error::UnusableVerifiedResult rather than retrying/banning healthy DAPI nodes, while unauthenticated or forged signatures remain node faults (Error::InvalidSignature).
    • Split PV15 history verification into header-only Drive::verify_document_history_serialized + budgeted SerializedDocumentHistoryDriveQueryExecutionResult::into_documents(..., budget: &mut DecodedValueBudget, ...) so verify_document_history_response_v1 verifies GroveDB structure, headers, and the Tenderdash signature before materializing bodies (ensuring both budget refusals and migrated pre-update revisions unreadable under the current schema surface as Error::UnusableVerifiedResult).
    • Added header-only Drive::fetch_document_history_serialized so prove_document_history_v1 and unproved Platform::query_document_history_v1 validate headers and serve stored bytes directly without decoding document properties on the node.
    • Updated DriveDocumentQuery::assemble_from_trios and assemble_documents so overlapping composite joins/page members sharing a group charge budget.charge_document(document) before cloning each additional retained copy of a proved document.
    • Updated strip_cursor_from_distinct_page (and strip_cursor_from_elements) to compare the first row's ID via Document::id_from_bytes without materializing properties.
    • Added shared page budgeting across contender conversion in Contenders::{to_contenders, to_contenders_with_budget} (rs-drive-proof-verifier), ContenderRequest::{decode, decode_with_budget} / ContestRequests::decode and MultipleChoiceProposalVote::from_contenders (rs-sdk), and delegated rs-sdk-ffi vote_state_json page decoding to ContestRequests::decode.
    • Added Rust-owned shared-budget page/join decoders in rs-drive-proof-verifier (ContractDocumentRemovals::decode_kept_values, ChainedDocuments::decode_removed_outer_kept_values, CompositeDocuments::decode_sub_result_removal_kept_values), wired rs-sdk ContractDocumentRemovalsPageQuery::fetch_with_kept_values (used by rs-sdk-ffi/Swift) to share one page budget while keeping its no-contract-fetch fast path, and updated wasm-sdk/wasm-dpp2 to delegate decoding/budgeting to Rust and only marshal values to JS.

In-place changes to shipped generations

  • packages/rs-dpp/src/document/v0/serialize/{v0,v1,v2,v3}.rs (selected across PV1–PV14): Extracted from_bytes_vN_with_budget(..., budget: Option<&mut DecodedValueBudget>, ...). Shipped consensus callers invoke from_bytes_vN, passing None, which remains bit-for-bit output-identical at every protocol version.
  • Client-only proof verifiers (never invoked during block execution or consensus state transitions; these error and budget changes affect client-side proof verification only and cannot alter consensus):
    • packages/rs-drive/src/verify/document/verify_proof/v0/mod.rs (PV1–PV14)
    • packages/rs-drive/src/verify/document/verify_document_history/v0/mod.rs (PV1–PV14)
    • packages/rs-drive/src/verify/document/verify_start_at_document_in_proof/v0/mod.rs (PV1–PV14)
    • packages/rs-drive/src/verify/single_document/verify_proof/v0/mod.rs (PV1–PV14)
    • packages/rs-drive/src/verify/chained_document/verify_chained_documents_proof/v0/mod.rs (PV14)
    • packages/rs-drive/src/verify/composite_document/verify_composite_documents_proof/v0/mod.rs (PV14)
    • packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs (PV1–PV14)

How Has This Been Tested?

  • Unit tests in rs-dpp:
    • typed_array_element_width_tests.rs: PV15 refuses zero-width byte array elements under full validation while PV14 accepts them; non-zero-width elements pass; stored contracts load with full_validation: false.
    • Typed DecodedValueBudgetExceeded tests in property/mod.rs, private_document.rs, platform_serialization_conversion/mod.rs (including format-0 terminal budget error vs format-1 fallback and Document::id_from_bytes across formats 0–3), id_and_revision_from_bytes, and document_removal.rs (using a fully validated PV14 contract with 4 nested objects × 65 zero-width arrays to test unbounded consensus kept_values vs bounded client kept_values_with_default_budget).
  • Proof verification, ABCI & SDK tests:
    • rs-drive: should_compare_start_after_cursor_from_header_without_expanding_oversized_first_row, should_strip_cursor_from_distinct_page_without_decoding_document_body (header-only bytes with no decodable body), should_read_lifecycle_current_pointer_from_header_without_decoding_properties (explicit 67-byte format-3 header with distinct stamp & revision), should_enforce_shared_decoded_value_budget_across_history_entries, should_enforce_shared_decoded_value_budget_on_pv15_document_history_proof, should_charge_shared_page_budget_for_overlapping_composite_join_clones, and should_prove_and_verify_document_collection.
    • rs-drive-proof-verifier: should_authenticate_a_decoded_value_budget_refusal_before_reporting_it, plus shared budget tests across Contenders::to_contenders, ContractDocumentRemovals, ChainedDocuments, and CompositeDocuments.
    • rs-drive-abci: signed end-to-end tests in query/document_history/v1/tests.rs covering oversized PV15 history proofs, unreadable migrated revisions (also asserting exact raw-byte preservation on serialized/unproved reads), oversized cursor documents, and oversized merged document-transfer proofs (each asserting UnusableVerifiedResult under valid quorum signature and InvalidSignature under a wrong-root signature), plus should_confirm_document_restore_without_contract_in_context_provider in contract_user_moderation/tests.rs confirming restore verification with a quorum-only provider returning no contract.
    • rs-sdk & rs-sdk-ffi: should_enforce_a_shared_decoded_value_budget_across_records_in_fetch_with_kept_values, should_stop_decoding_contender_requests_when_shared_budget_is_exhausted (testing both ContestRequests::decode_with_budget and public ContestRequests::decode crossing DEFAULT_CLIENT_PAGE_DECODED_VALUE_BUDGET), no-contract-fetch test, multiple_choice tests, and FFI vote_state / removals tests.
  • Lints & workspace checks:
    • cargo fmt --all
    • cargo clippy -p drive --no-default-features --features verify -- -D warnings
    • cargo clippy -p dpp -p drive -p drive-proof-verifier -p drive-abci -p dash-sdk -p rs-sdk-ffi -p wasm-dpp2 -p wasm-sdk --all-targets -- -D warnings
    • cargo check --workspace --all-targets

Breaking Changes

  • Data contract registration and updates at protocol version 15+ will reject schemas containing typed array properties with zero-width byte array elements (minItems: 0, maxItems: 0).
  • Client proof verification, private document payload decoding, contender page conversion, and client removal-record decoding now enforce decoded value budgets, refusing payloads/responses that exceed the budget:
    • Direct dpp decoders return DataContractError::DecodedValueBudgetExceeded.
    • Direct drive proof verifiers return ProofError::DecodedValueBudgetExceeded { root_hash, reason }.
    • Direct drive-proof-verifier callers authenticate root_hash against the quorum signature and receive drive_proof_verifier::Error::UnusableVerifiedResult.
    • At the dash-sdk fetch boundary, Sdk checks the authenticated response metadata for freshness first (routing stale metadata through its stale-answer path) and converts a fresh UnusableVerifiedResult refusal to dash_sdk::Error::InvalidRequest(reason).
  • Source-incompatible Rust enum additions (documented in book/src/sdk/protocol-version-15-upgrade.md):
    • dpp::data_contract::errors::DataContractError::DecodedValueBudgetExceeded(String) (consensus code 10283)
    • drive::error::proof::ProofError::DecodedValueBudgetExceeded { root_hash: [u8; 32], reason: String }
      Downstream Rust code matching either enum exhaustively must add a matching or wildcard arm.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • 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
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

PR Hygiene · c8c0961

  • Bots — thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Reviewer requests paused — your 5 review slots are occupied; this PR is excluded from reviewers' queues. Required approvals still count without a slot.
  • Build running
  • Approvals
    • files with no dedicated owner — you own it
    • dpp — you own it
    • rs-drive-abci — you own it
    • rs-drive — you own it
    • rust-sdk-ffi (packages/rs-sdk-ffi/src/contested_resource/queries/vote_state.rs) — lklimek or shumkov
    • rust-sdk (packages/rs-sdk/src/platform/contract_moderation.rs, packages/rs-sdk/src/platform/decision_proposals/multiple_choice.rs, packages/rs-sdk/src/platform/dpns_usernames/contender_request.rs and 2 more) — lklimek or shumkov
    • js-wasm-sdk (packages/wasm-sdk/src/queries/chained_document.rs, packages/wasm-sdk/src/queries/composite_document.rs, packages/wasm-sdk/src/queries/contract_moderation.rs) — shumkov

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

  • New Features
    • Document and removal-record decoding now supports shared value limits across pages and proof results.
    • Removal records in SDK and WebAssembly results now include decoded kept-field values.
    • Document IDs can be read from serialized headers without decoding the full document.
    • Document history can be fetched in serialized form.
  • Bug Fixes
    • Protocol 15 full validation rejects typed arrays with zero-byte elements; existing protocol 14 contracts remain loadable without full validation.
    • Oversized decoding returns a specific budget-exceeded error, and signed proofs exceeding the limit are reported as unusable verified results.
  • Documentation
    • Rust upgrade guidance now notes the additional error variant applications may need to handle.

- Refuse typed array properties with zero-width byte array elements during schema validation in PV15
- Introduce DecodedValueBudget to bound decoded values across documents, private payloads, and moderation records
- Apply the budget across proof verification in rs-drive and wasm-sdk to protect against memory exhaustion
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds decoded-value budgets to property, document, and kept-field decoding. Callers share budgets across query, proof, moderation, and contender results. Full contract validation rejects zero-width typed-array elements. Serialized document headers can provide IDs and history metadata without decoding document properties.

Changes: Decoded-Value Budgeting

Layer / File(s) Summary
Budget and typed-array validation
packages/rs-dpp/src/data_contract/document_type/property/*, packages/rs-dpp/src/data_contract/errors/contract.rs, packages/rs-dpp/src/errors/consensus/codes.rs, packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v4/*, packages/rs-platform-version/src/version/*, book/src/sdk/protocol-version-15-upgrade.md
Adds DecodedValueBudget, charges decoded property values and arrays, and maps budget exhaustion to a new error. Full validation rejects typed-array elements with zero encoded width.
Budgeted document decoding
packages/rs-dpp/src/document/*, packages/rs-dpp/src/data_contract/document_type/private_document.rs
Adds budget-aware document deserializers and header-only ID extraction. Private document payload decoding also uses a budget.
Kept-field decoding and result conversion
packages/rs-dpp/src/data_contract/config/moderation/*, packages/rs-drive-proof-verifier/src/proof/*, packages/rs-drive-proof-verifier/src/types/contract_moderation.rs, packages/rs-sdk/src/platform/contract_moderation.rs, packages/rs-sdk/tests/fetch/mock_fetch.rs, packages/wasm-dpp2/src/state_transitions/proof_result/data_contract.rs, packages/wasm-sdk/src/queries/*
Adds default and caller-supplied budgets for decoding kept fields. Page and proof result conversions decode kept values across records and pass the decoded maps to removal entries.
Budgeted query and history assembly
packages/rs-drive/src/query/composite_document_query/mod.rs, packages/rs-drive/src/query/document_history_drive_query*, packages/rs-drive/src/query/mod.rs, packages/rs-drive/src/drive/document/get_fetch/fetch_document_history/*, packages/rs-drive/src/drive/document/prove/prove_document_history/v1/mod.rs, packages/rs-drive-abci/src/query/document_history/v1/*, packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/composite_query_e2e_tests.rs
Passes optional budgets through composite query and history decoding. Cursor handling extracts IDs from serialized headers. History retrieval and proof creation use serialized entries. Tests cover shared-budget exhaustion in overlapping joins and history proofs.
Budgeted proof verification
packages/rs-drive/src/verify/*, packages/rs-drive/src/error/proof.rs, packages/rs-drive-proof-verifier/src/proof.rs, packages/rs-drive-proof-verifier/src/verify.rs
Applies default decoded-value budgets to document, history, chained, composite, and state-transition proof decoding. Maps budget refusals to root-aware proof errors.
Budgeted contender decoding
packages/rs-dpp/src/voting/contender_structs/contender/*, packages/rs-drive-proof-verifier/src/types.rs, packages/rs-sdk-ffi/src/contested_resource/queries/vote_state.rs, packages/rs-sdk/src/platform/decision_proposals/multiple_choice.rs, packages/rs-sdk/src/platform/dpns_usernames/contender_request.rs
Adds shared-budget contender conversions and applies them when decoding contender results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Suggested reviewers: shumkov, lklimek, romchornyi

Merge Risk: Minimal · up to b58e2

This change bounds decoded size for client-side document, proof, and removal-record decoding and rejects zero-width typed-array elements under full validation at protocol version 15 and later. The reviewed evidence shows no concrete defect at the current head, and budget refusals are authenticated against the proof root before they are reported. It is ready to merge, subject to the author's reported test runs passing.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(platform)!: bound decoded size and refuse zero-width arrays (PV15)" matches the main changes. The PR rejects zero-width typed-array elements in PV15+ full-validation schemas (try_from_s…
Linked Issues check Passed Issue #6070 (direct) asks that decoded typed-array size stay proportional to encoded size. The issue leaves the remedy open: refuse zero-width element types, or cap decoded elements by remaining input…
Out of Scope Changes check Passed The changes apply or support the decoded-value budget that issue #6070 targets. Groups: (a) DPP budget types, DataContractError::DecodedValueBudgetExceeded (code 10283), and the zero-width schema rule…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "fix(platform)!: bound decoded size and refuse zero-width arrays (PV15)" matches the main changes. The PR rejects zero-width typed-array elements in PV15+ full-validation schemas (try_from_schema v4, v15 docs, typed-array tests). It also adds decoded-value budgets across document, proof, and SDK decoding paths, which the title's 'bound decoded size' covers. The title is specific, uses a conventional commit prefix, and names the protocol version. Its only gap is that it does not mention the header-only ID extraction or the client-side budget wiring, which is expected for a title.

Full details: Linked Issues check

Explanation

Issue #6070 (direct) asks that decoded typed-array size stay proportional to encoded size. The issue leaves the remedy open: refuse zero-width element types, or cap decoded elements by remaining input. The PR implements both remedies for the affected paths. (1) Schema rule: at PV15+ full validation, TypedArrayProperty::has_zero_encoded_width_element and validate_typed_array_non_zero_element_width (try_from_schema generation 4) reject top-level and nested ByteArray elements with minItems 0 and maxItems 0. typed_array_element_width_tests.rs covers this. (2) Decoder budget: DecodedValueBudget charges zero-width elements before allocation in TypedArrayProperty::read_from_with_budget and DocumentPropertyType::read_optionally_from_with_budget. Budgeted paths cover decode_private_document_payload, document proof verification, document history, composite and chained proofs, and removal records (kept_values_with_default_budget). Tests cover budget exhaustion on these paths. Residual point: the consensus paths (from_bytes, decode_kept_fields, kept_values) stay unbounded by design for PV14 replay. Stored PV14 contracts with zero-width elements therefore still decode without a bound on those paths. The issue does not require a bound there, so this does not fail the check. The conclusion is based on the PR summary and raw summary. No full diff was read.

Full details: Out of Scope Changes check

Explanation

The changes apply or support the decoded-value budget that issue #6070 targets. Groups: (a) DPP budget types, DataContractError::DecodedValueBudgetExceeded (code 10283), and the zero-width schema rule. (b) Budget-aware decoders in document serialization (v0 to v3 extraction, with None preserving consensus output), Document::from_bytes_with_budget, and id_from_bytes. These avoid full property decoding in cursor and history paths. (c) Client verifiers in rs-drive and rs-drive-proof-verifier that share one budget per response. (d) Contender, removal, and composite decoding in rs-sdk, rs-sdk-ffi, wasm-sdk, and wasm-dpp2. These call the budgeted APIs. (e) Documentation and version notes for PV15 and the upgrade guide. (f) The drive-abci history query now fetches serialized entries, which avoids decoding server history. The PR objectives name this intent. Some items, such as the id_and_revision_from_bytes refactor and the cursor ID comparison, are supporting changes. The summary shows no unrelated change. The PR hygiene build-failure report is outside this assessment. The conclusion is based on the PR summary and raw summary, not a full diff.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 16e5866 and b58e2b7.

Files selected for processing: 22

  • packages/rs-drive-abci/src/query/document_history/v1/mod.rs
  • packages/rs-drive-abci/src/query/document_history/v1/tests.rs
  • packages/rs-drive-proof-verifier/src/proof.rs
  • packages/rs-drive-proof-verifier/src/proof/chained_document.rs
  • packages/rs-drive-proof-verifier/src/proof/composite_document.rs
  • packages/rs-drive-proof-verifier/src/verify.rs
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/composite_query_e2e_tests.rs
  • packages/rs-drive/src/drive/document/get_fetch/fetch_document_history/mod.rs
  • packages/rs-drive/src/drive/document/get_fetch/fetch_document_history/v1/mod.rs
  • packages/rs-drive/src/drive/document/prove/prove_document_history/v1/mod.rs
  • packages/rs-drive/src/error/proof.rs
  • packages/rs-drive/src/query/document_history_drive_query.rs
  • packages/rs-drive/src/query/document_history_drive_query_tests.rs
  • packages/rs-drive/src/verify/chained_document/verify_chained_documents_proof/v0/mod.rs
  • packages/rs-drive/src/verify/composite_document/verify_composite_documents_proof/v0/mod.rs
  • packages/rs-drive/src/verify/document/verify_document_history/v0/mod.rs
  • packages/rs-drive/src/verify/document/verify_document_history/v1/mod.rs
  • packages/rs-drive/src/verify/document/verify_proof/v0/mod.rs
  • packages/rs-drive/src/verify/mod.rs
  • packages/rs-drive/src/verify/single_document/verify_proof/v0/mod.rs
  • packages/rs-drive/src/verify/single_document/verify_proof/v1/mod.rs
  • packages/rs-sdk/src/platform/dpns_usernames/contender_request.rs

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

@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 22, 2026
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 22, 2026
@thepastaclaw

thepastaclaw commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit c8c0961) · triage: critical

@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

Changes requested: 7 blockers

  • PV14 block execution can fail on a removal record the previous version could read — packages/rs-dpp/src/data_contract/config/moderation/document_removal.rs:120-125 (new)
    Impact: A validator processing a reference to a removed document can now return an internal error when its stored kept fields exceed the client budget, even if the reference reads only one field.
  • A low page budget can change the values returned for a legacy document — packages/rs-dpp/src/document/v0/serialize/mod.rs:140-152 (new)
    Impact: A client reading a format-0 document can get different property values depending on how much budget earlier rows consumed.
  • A secondary-index cursor page expands its first row before the budget starts — packages/rs-drive/src/verify/document/verify_proof/v0/mod.rs:51-54 (new)
    Impact: Clients paginating with startAfter can incur an unrestricted document allocation even if that row is dropped or the bounded page read later fails.
  • Removal values can exceed the page limit when one response combines several groups — packages/wasm-sdk/src/queries/composite_document.rs:435-446 (new)
    Impact: JavaScript clients reading multiple moderated joins, and Swift clients reading removal pages after integration with the target branch, can retain more decoded kept fields than the page limit allows.
  • PV15 history proofs still decode retained revisions without a page limit — packages/rs-drive/src/query/document_history_drive_query.rs:440-445 (new; not shown inline, see below)
    Impact: Clients fetching history for an older contract can materialize an over-budget revision page before the SDK authenticates the proof root.
  • Composite proofs expand stored documents without a limit in both verification passes — packages/rs-drive/src/query/composite_document_query/mod.rs:1528-1535 (new; not shown inline, see below)
    Impact: Rust and JavaScript clients fetching a composite page can exceed the decoded-value ceiling before the SDK authenticates the proof root, even when the result has no removals.
  • Converting a contender page still expands every attached document without a limit — packages/rs-drive-proof-verifier/src/types.rs:217-223 (new; not shown inline, see below)
    Impact: An SDK caller requesting documents for a contest on a custom contract can exceed the decoded-value ceiling when converting the verified page to contenders.

This head rejects zero-width typed-array elements when registering or updating contracts at PV15 and adds decoded-value budgets to selected document, removal-record, and private-payload reads. The available CI checks show no failures, and the PR checklist reports a green build; PR Hygiene and the review check are pending.

🔴 7 blocking | 🟡 3 suggestion(s)

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

🔴 Blocking: PV15 history proofs still decode retained revisions without a page limit
Impact: Clients fetching history for an older contract can materialize an over-budget revision page before the SDK authenticates the proof root.
packages/rs-drive/src/query/document_history_drive_query.rs:440-445

The new history limit does not cover the active PV15 query. PV15 selects verify_document_history_v1, which calls decode_result; decode_entries collects unrestricted Document::from_bytes results, and lifecycle also expands the current document before the SDK checks the quorum signature. The new registration rule does not rewrite older contracts or their retained revisions. Pass a shared client budget through the v1 revision decoder and use the PV15 header reader for the current document's ID and revision. Cover the PV15 verifier with a page that exceeds the allowance only in aggregate.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

🔴 Blocking: Composite proofs expand stored documents without a limit in both verification passes
Impact: Rust and JavaScript clients fetching a composite page can exceed the decoded-value ceiling before the SDK authenticates the proof root, even when the result has no removals.
packages/rs-drive/src/query/composite_document_query/mod.rs:1528-1535

The WASM removal counter starts too late to protect stored documents. Both composite verifier generations use decode_document_trios for the bootstrap page, document subqueries used as binding sources, and the authoritative result. The stored-document arm calls unrestricted Document::from_bytes, and the bootstrap documents remain live when the authoritative result is assembled. Enforce the client limit in Drive before materializing either pass, accounting for documents retained together across passes and subqueries without changing the shared server reader's behavior.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

🔴 Blocking: Converting a contender page still expands every attached document without a limit
Impact: An SDK caller requesting documents for a contest on a custom contract can exceed the decoded-value ceiling when converting the verified page to contenders.
packages/rs-drive-proof-verifier/src/types.rs:217-223

The vote-state proof path authenticates and returns serialized contender documents, not documents read by the newly bounded collection verifier. Contenders::to_contenders then collects the entire map through try_to_contender, whose DPP implementation calls unrestricted Document::from_bytes for each attachment. Share one client allowance across the page conversion and leave contenders with no document bytes uncharged.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

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.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The cross-crate decoding changes are intricate, and validate_typed_array_non_zero_element_width in try_from_schema/v4/mod.rs changes which contract schemas consensus accepts under PV15.
  • 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)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-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 (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 `packages/rs-dpp/src/data_contract/config/moderation/document_removal.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/config/moderation/document_removal.rs:120-125: PV14 block execution can fail on a removal record the previous version could read
  Impact: A validator processing a reference to a removed document can now return an internal error when its stored kept fields exceed the client budget, even if the reference reads only one field.
  The same PV14 transition can now fail during execution where the shipped implementation continued. Both generations of Drive-ABCI's `RemovalRecord::value` call `kept_values`, which decodes the entire record and now applies the client ceiling; Drive's derived-index path also calls it and reports failures as `CorruptedDriveState`. The moderator deletion writer does not enforce this ceiling, and the per-transition byte limit does not bound the decoded size of a document whose fields accumulate over multiple moderation updates. Preserve the historical read for consensus callers and opt client readers into the bounded API. Cover both outcomes for the same stored record.
- [SUGGESTION] packages/rs-dpp/src/data_contract/config/moderation/document_removal.rs:601-604: Budget regression tests rely on the wording of the error
  Impact: Rewording the message can break four tests without changing behavior, and an error of the wrong type can pass if it renders the same substring.
  This assertion and the corresponding private-payload, document-conversion, and removal-page assertions discard the error type before checking it. Assert the typed budget failure once it is distinguishable from other decode errors. Matching `CorruptedSerialization` alone would be weaker than the current check, because unrelated malformed-input errors use that variant too.

In `packages/rs-drive/src/query/document_history_drive_query.rs`:
- [BLOCKING] packages/rs-drive/src/query/document_history_drive_query.rs:440-445: PV15 history proofs still decode retained revisions without a page limit
  Impact: Clients fetching history for an older contract can materialize an over-budget revision page before the SDK authenticates the proof root.
  The new history limit does not cover the active PV15 query. PV15 selects `verify_document_history_v1`, which calls `decode_result`; `decode_entries` collects unrestricted `Document::from_bytes` results, and `lifecycle` also expands the current document before the SDK checks the quorum signature. The new registration rule does not rewrite older contracts or their retained revisions. Pass a shared client budget through the v1 revision decoder and use the PV15 header reader for the current document's ID and revision. Cover the PV15 verifier with a page that exceeds the allowance only in aggregate.

In `packages/rs-drive/src/query/composite_document_query/mod.rs`:
- [BLOCKING] packages/rs-drive/src/query/composite_document_query/mod.rs:1528-1535: Composite proofs expand stored documents without a limit in both verification passes
  Impact: Rust and JavaScript clients fetching a composite page can exceed the decoded-value ceiling before the SDK authenticates the proof root, even when the result has no removals.
  The WASM removal counter starts too late to protect stored documents. Both composite verifier generations use `decode_document_trios` for the bootstrap page, document subqueries used as binding sources, and the authoritative result. The stored-document arm calls unrestricted `Document::from_bytes`, and the bootstrap documents remain live when the authoritative result is assembled. Enforce the client limit in Drive before materializing either pass, accounting for documents retained together across passes and subqueries without changing the shared server reader's behavior.

In `packages/rs-dpp/src/document/v0/serialize/mod.rs`:
- [BLOCKING] packages/rs-dpp/src/document/v0/serialize/mod.rs:140-152: A low page budget can change the values returned for a legacy document
  Impact: A client reading a format-0 document can get different property values depending on how much budget earlier rows consumed.
  An over-budget document can be returned with altered properties instead of a limit error. The bounded dispatcher retries format 1 on every format-0 error, including budget exhaustion. Legacy format-0 rows can be read under a contract that has since enabled sized integers. The format-1 reader then consumes different field widths, can mistake part of an integer for an optional-field marker, and can succeed without consuming the full input. Make budget exhaustion distinguishable from a format error and terminal for the decode, while retaining the compatibility retry for actual format failures. Test that a bounded read returns the historical result or a limit error, never a different document.

In `packages/rs-drive/src/verify/document/verify_proof/v0/mod.rs`:
- [BLOCKING] packages/rs-drive/src/verify/document/verify_proof/v0/mod.rs:51-54: A secondary-index cursor page expands its first row before the budget starts
  Impact: Clients paginating with `startAfter` can incur an unrestricted document allocation even if that row is dropped or the bounded page read later fails.
  `verify_proof_keep_serialized` already expands the first row of a padded page: `strip_cursor_from_distinct_page` calls `Document::from_bytes` solely to compare its ID with the cursor. The separate bounded lookup of the cursor does not protect that read, because the first matching row can be a different document when the cursor falls outside the query's clauses. Compare the ID without materializing properties, using a proved document ID where available or a header-only read that supports the relevant formats.

In `packages/wasm-sdk/src/queries/composite_document.rs`:
- [BLOCKING] packages/wasm-sdk/src/queries/composite_document.rs:435-446: Removal values can exceed the page limit when one response combines several groups
  Impact: JavaScript clients reading multiple moderated joins, and Swift clients reading removal pages after integration with the target branch, can retain more decoded kept fields than the page limit allows.
  The limit depends on how each caller groups the result. The composite WASM formatter starts a fresh allowance per subquery while retaining earlier results; the chained formatter starts another after live documents are decoded. The standalone formatter also owns its own page loop instead of using the Rust page decoder. On `v5.1-dev`, #6056 added the Swift-facing `fetch_with_kept_values` path, which collects results from a separate `kept_values` call per record. When resolving the confirmed conflict in `contract_moderation.rs`, make the Rust page and join APIs own the allowance across the values returned together and let the bindings marshal decoded fields. Preserve the SDK's no-contract-fetch path for pages with no kept bytes.

In `packages/rs-drive-proof-verifier/src/types.rs`:
- [BLOCKING] packages/rs-drive-proof-verifier/src/types.rs:217-223: Converting a contender page still expands every attached document without a limit
  Impact: An SDK caller requesting documents for a contest on a custom contract can exceed the decoded-value ceiling when converting the verified page to contenders.
  The vote-state proof path authenticates and returns serialized contender documents, not documents read by the newly bounded collection verifier. `Contenders::to_contenders` then collects the entire map through `try_to_contender`, whose DPP implementation calls unrestricted `Document::from_bytes` for each attachment. Share one client allowance across the page conversion and leave contenders with no document bytes uncharged.

In `packages/rs-dpp/src/data_contract/document_type/private_document.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/private_document.rs:386-395: Each successful private-payload decode counts the same schema twice
  Impact: Private-document scans repeat a full recursive schema walk for each payload that passes preflight, including payloads with mostly absent optional fields.
  The two passes need independent counters, not independent computations of the allowance. `for_encoded_payload` walks the schema and produces a `Copy` value containing one counter. Compute it once, then copy it before either pass begins.

In `packages/rs-dpp/src/data_contract/document_type/property/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/property/mod.rs:323: The schema-node counter exposes an implementation detail as public API
  Impact: Downstream callers can depend on a helper that only sizes the local payload budget today.
  `DecodedValueBudget::for_encoded_payload` is the only caller outside the helper's own recursion, and it is in the same module. Keep the constructor public and the schema walk private.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Standalone JavaScript document imports still use the unrestricted decoder — Document.fromBytes, fromHex, and fromBase64 still share an unbounded import path for caller-supplied documents. These are not query results or private-payload reads.
    • Follow-up: Define a Rust-owned single-document import limit and route the three WASM import methods through it without changing consensus deserialization.

- Append DataContractError::DecodedValueBudgetExceeded (code 10283) so budget
  exhaustion is distinct from CorruptedSerialization and terminal in format-0
  bounded decoding (preventing fallback to format 1).
- Restore unbounded decode_kept_fields / ContractDocumentRemoval::kept_values
  for PV14 consensus replay while opting client callers into bounded helpers.
- Read document IDs from headers via Document::id_from_bytes in
  strip_cursor_from_distinct_page / strip_cursor_from_elements instead of
  materializing properties.
- Share one decoded-value budget across combined responses in Rust
  (ContractDocumentRemovalsPageQuery::fetch_with_kept_values, ChainedDocuments,
  CompositeDocuments, and verify_composite_documents_proof) and keep WASM
  bindings marshaling-only.
- Reuse a single DecodedValueBudget::for_encoded_payload computation in
  decode_private_document_payload and make count_property_nodes private.
- Update budget regression tests to assert DecodedValueBudgetExceeded directly
  and add coverage for every review finding.
@github-actions

github-actions Bot commented Nov 22, 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 Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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 Nov 22, 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

Changes requested: 3 blockers

  • Composite results exceed the page budget when joins return the same document — packages/rs-drive/src/query/composite_document_query/mod.rs:1985-1989 (new; not shown inline, see below)
    Impact: Rust callers can receive more decoded values than the page limit allows, while JavaScript callers allocate the extra copies in WASM before the formatter rejects the same result.
  • Converting a contender page still expands every attached document without a limit — packages/rs-drive-proof-verifier/src/types.rs:217-223 (carried)
    Impact: An SDK caller converting a verified contest page with large legacy attachments can exhaust client memory instead of receiving a budget error.
  • PV15 history proofs still decode retained revisions without a page limit — packages/rs-drive/src/query/document_history_drive_query.rs:440-445 (carried)
    Impact: An SDK caller fetching PV15 history for a legacy document type can exhaust memory materializing a page that the client budget should refuse.

New on this head: This revision adds shared Rust decode budgets for proof and removal results, makes budget exhaustion a distinct error, and compares cursor IDs without decoding document properties while preserving the historical PV14 removal reader. Rust workspace tests and the JS build passed; wasm32 tests were pending when checked. The Swift SDK build reproduced the target branch’s type-check timeout in SendTransactionView.swift, and Dashmate Local Network E2E timed out waiting for Dash Core nodes to synchronize to height 1392, before document queries ran.

🔴 3 blocking | 🟡 4 suggestion(s)

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

🔴 Blocking: Converting a contender page still expands every attached document without a limit
Impact: An SDK caller converting a verified contest page with large legacy attachments can exhaust client memory instead of receiving a budget error.
packages/rs-drive-proof-verifier/src/types.rs:217-223

A vote-state request that includes documents can return a valid proof and still exhaust memory when the caller converts the result. The verifier keeps the attached documents serialized. Contenders::to_contenders then collects all converted entries, and DPP’s try_to_contender uses unbounded Document::from_bytes for each attachment. A contender count limit does not bound the decoded property values in those attachments, including documents written under PV14 contracts. Add a budget-aware DPP conversion and share one allowance across the page. Also use the bounded Rust decoder in the native vote-state path: its ContenderRequest::decode calls the same unbounded conversion independently, even though it only retains the label and timestamp.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

🔴 Blocking: PV15 history proofs still decode retained revisions without a page limit
Impact: An SDK caller fetching PV15 history for a legacy document type can exhaust memory materializing a page that the client budget should refuse.
packages/rs-drive/src/query/document_history_drive_query.rs:440-445

PV15 history fetches can expand the current document and all retained revisions in the page without hitting the client ceiling. The SDK’s V1 history response verifier dispatches to verify_document_history_v1, which passes proved rows to decode_result. lifecycle fully decodes the current document to obtain its ID and revision, and decode_entries collects retained revisions using unbounded Document::from_bytes. The row count does not limit decoded values, and the PV15 migration preserves existing revision bytes. Use the PV15 header reader for the lifecycle check and share a client budget across retained entries, keeping the shared server reader’s policy separate.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

🔴 Blocking: Composite results exceed the page budget when joins return the same document
Impact: Rust callers can receive more decoded values than the page limit allows, while JavaScript callers allocate the extra copies in WASM before the formatter rejects the same result.
packages/rs-drive/src/query/composite_document_query/mod.rs:1985-1989

CompositeDocuments::fetch can return an over-budget result from a valid proof. Two by-ID joins can share a target type and legitimately resolve to the same document; a by-ID page and a same-type join can also overlap. The new authoritative budget charges each proved document once in decode_document_trios, but assemble_from_trios and assemble_documents clone the decoded document into each matching result. The claimed set checks coverage, not how many copies are retained. When the distinct rows fit but the returned copies do not, Rust verification succeeds; the WASM formatter recounts only after assembly and after wrapping the page documents. Charge each additional retained copy in Drive before cloning, without charging the first occurrence twice, and cover an overlapping result whose distinct rows fit but whose returned copies do not.

Raised on code unchanged since the last review, and confirmed by an independent pass: A caller of CompositeDocuments::fetch can request two by-ID joins over stored documents whose two reference fields point to the same targets. For example, 70 targets with two 1,024-element boolean arrays each contribute about 144,000 decoded values to the proof, but about 287,000 to the assembled response because both joins retain a copy. Rust returns that response despite the 262,144-value cap; WASM reports DecodedValueBudgetExceeded only after Drive has allocated both sets of copies and the formatter has wrapped the page documents.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

Follow-up candidates (optional) (1)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: JavaScript sees a retryable proof error when live documents exceed the decode budget
Impact: A JavaScript caller cannot use the structured error to recognize that a composite query exceeded the local limit and needs a smaller result.
packages/rs-drive-proof-verifier/src/error.rs:192-194

The same composite query API exposes two different errors for the same limit. A kept-field decode propagates ProtocolError and reaches JavaScript as non-retryable code 10283. A live-document decode in the new bounded verifier goes through map_drive_error, whose fallback stringifies the typed failure. On a supported network version the SDK classifies it as retryable Error::Proof, which WASM returns with code -1. Preserve a typed local budget error through the verifier and SDK without treating response metadata as authenticated when verification stopped early. Test the JavaScript code and retry flag for both paths.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

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.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff changes PV15 consensus rules for contract registration and updates in try_from_schema/v4/mod.rs and intricately reworks document decoding and allocation limits across client proof-verification paths.
  • 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)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • New since the last final review (11660392): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed; 1 suggestion(s) on unchanged code listed as follow-up candidates
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-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 (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 `packages/rs-drive-proof-verifier/src/types.rs`:
- [BLOCKING] packages/rs-drive-proof-verifier/src/types.rs:217-223: Converting a contender page still expands every attached document without a limit
  Impact: An SDK caller converting a verified contest page with large legacy attachments can exhaust client memory instead of receiving a budget error.
  A vote-state request that includes documents can return a valid proof and still exhaust memory when the caller converts the result. The verifier keeps the attached documents serialized. `Contenders::to_contenders` then collects all converted entries, and DPP’s `try_to_contender` uses unbounded `Document::from_bytes` for each attachment. A contender count limit does not bound the decoded property values in those attachments, including documents written under PV14 contracts. Add a budget-aware DPP conversion and share one allowance across the page. Also use the bounded Rust decoder in the native vote-state path: its `ContenderRequest::decode` calls the same unbounded conversion independently, even though it only retains the label and timestamp.

In `packages/rs-drive/src/query/document_history_drive_query.rs`:
- [BLOCKING] packages/rs-drive/src/query/document_history_drive_query.rs:440-445: PV15 history proofs still decode retained revisions without a page limit
  Impact: An SDK caller fetching PV15 history for a legacy document type can exhaust memory materializing a page that the client budget should refuse.
  PV15 history fetches can expand the current document and all retained revisions in the page without hitting the client ceiling. The SDK’s V1 history response verifier dispatches to `verify_document_history_v1`, which passes proved rows to `decode_result`. `lifecycle` fully decodes the current document to obtain its ID and revision, and `decode_entries` collects retained revisions using unbounded `Document::from_bytes`. The row count does not limit decoded values, and the PV15 migration preserves existing revision bytes. Use the PV15 header reader for the lifecycle check and share a client budget across retained entries, keeping the shared server reader’s policy separate.

In `packages/rs-drive/src/query/composite_document_query/mod.rs`:
- [BLOCKING] packages/rs-drive/src/query/composite_document_query/mod.rs:1985-1989: Composite results exceed the page budget when joins return the same document
  Impact: Rust callers can receive more decoded values than the page limit allows, while JavaScript callers allocate the extra copies in WASM before the formatter rejects the same result.
  `CompositeDocuments::fetch` can return an over-budget result from a valid proof. Two by-ID joins can share a target type and legitimately resolve to the same document; a by-ID page and a same-type join can also overlap. The new authoritative budget charges each proved document once in `decode_document_trios`, but `assemble_from_trios` and `assemble_documents` clone the decoded document into each matching result. The `claimed` set checks coverage, not how many copies are retained. When the distinct rows fit but the returned copies do not, Rust verification succeeds; the WASM formatter recounts only after assembly and after wrapping the page documents. Charge each additional retained copy in Drive before cloning, without charging the first occurrence twice, and cover an overlapping result whose distinct rows fit but whose returned copies do not.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: A caller of `CompositeDocuments::fetch` can request two by-ID joins over stored documents whose two reference fields point to the same targets. For example, 70 targets with two 1,024-element boolean arrays each contribute about 144,000 decoded values to the proof, but about 287,000 to the assembled response because both joins retain a copy. Rust returns that response despite the 262,144-value cap; WASM reports `DecodedValueBudgetExceeded` only after Drive has allocated both sets of copies and the formatter has wrapped the page documents._

In `packages/rs-dpp/src/data_contract/config/moderation/document_removal.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/config/moderation/document_removal.rs:658-660: The PV14 replay test uses a schema that registration would reject
  Impact: The test distinguishes bounded and unbounded reads but does not demonstrate that distinction for a schema admitted on PV14.
  The new replay test declares 257 top-level properties, exceeding the document meta-schema’s limit of 100 per properties object. It constructs the type with `full_validation: false`, so that does not establish that such a record could originate from a registered contract. Group the arrays into nested objects kept whole, as the schema permits, and build the fixture through full PV14 contract validation before exercising both readers on the same record.

In `packages/rs-drive/src/verify/document/verify_proof/v0/mod.rs`:
- [SUGGESTION] packages/rs-drive/src/verify/document/verify_proof/v0/mod.rs:356-365: The cursor regression test passes even if cursor comparison decodes the document
  Impact: Reintroducing the unbounded decode in cursor comparison would not fail the new Drive regression test.
  The oversized first row has a valid body, so the old unbounded reader can decode it, compare its ID, and return exactly the serialized row asserted here. The subsequent bounded verification would still fail as expected. Keep the end-to-end budget assertion and add a direct test of `strip_cursor_from_distinct_page` with a complete ID prefix but no decodable document body. That pins the header-only behavior at the cursor call site.

In `packages/rs-dpp/src/document/v0/serialize/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/document/v0/serialize/mod.rs:118-154: Cursor and history readers parse the same document ID prefix separately
  Impact: A change to document headers can leave cursor comparison and history reads interpreting the same prefix differently.
  The new ID-only reader duplicates the format, optional contract stamp, width check, and ID parsing in `id_and_revision_from_bytes/v0`. The cursor needs an ID-only entry point that works on PV14, so it cannot call the PV15-gated public history method. Share the prefix parser privately in DPP, leaving each entry point’s version gate and error behavior intact and letting history continue from the remaining bytes.

In `packages/rs-dpp/src/data_contract/errors/contract.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/errors/contract.rs:100-102: Exhaustive Rust matches on `DataContractError` stop compiling on upgrade
  Impact: Downstream Rust callers that exhaustively match `DataContractError` need a new arm even if they never call a bounded decoder.
  Appending `DecodedValueBudgetExceeded` preserves existing wire discriminants, but `DataContractError` is public and is not marked `#[non_exhaustive]`. The breaking-changes note describes runtime refusals without calling out the source incompatibility. Document the new arm in the 5.1 SDK upgrade guide next to its existing advice for exhaustive `StaleNodeError` matches.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix.
Full checklist in the description.

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

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

📖 Book Preview built successfully.

Download the preview from the workflow artifacts.
To view locally: download the artifact, unzip, and open index.html.

Updated at 2026-11-23T03:24:22.579Z

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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 Nov 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.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 1 blocker

  • A valid PV15 history page can make the SDK ban healthy nodes — packages/rs-drive/src/verify/document/verify_document_history/v1/mod.rs:45-49 (new)
    Impact: An app fetching retained history that exceeds the SDK's local decode budget can temporarily lose access to healthy DAPI nodes for unrelated requests.

New on this head: Head 16e5866 extends shared decoded-value budgets to PV15 history verification and contender conversion, charges repeated composite join results before cloning, and shares the document header parser between cursor and history reads. All 15 prior findings are resolved. Rust workspace and wasm32 tests passed; the Swift SDK build and tests were pending, and Dashmate Local Network E2E timed out waiting for Dash Core to sync to height 1392, with no evidence tying the timeout to this diff.

🔴 1 blocking | 🟡 4 suggestion(s)

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

🟡 Suggestion: The budget-aware contender API hides why a page could not be decoded
Impact: A Rust caller cannot distinguish a page that needs a smaller limit from a malformed contender document without inspecting error text.
packages/rs-drive-proof-verifier/src/types.rs:229-246

to_contenders_with_budget receives a typed dpp::ProtocolError but converts it to crate::Error::ProtocolError { error: String }; the regression test therefore has to repeat the decode through DPP to assert DecodedValueBudgetExceeded. Return the typed error from the new budget-aware method, as decode_kept_values_with_budget does, and convert it only in the existing to_contenders wrapper to preserve that signature.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

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.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff is intricate and changes a consensus rule in try_from_schema/v4/mod.rs, where PV15 rejects zero-width typed-array elements during contract registration and updates.
  • 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)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • New since the last final review (c0eedf8c): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-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 (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 `packages/rs-drive/src/verify/document/verify_document_history/v1/mod.rs`:
- [BLOCKING] packages/rs-drive/src/verify/document/verify_document_history/v1/mod.rs:45-49: A valid PV15 history page can make the SDK ban healthy nodes
  Impact: An app fetching retained history that exceeds the SDK's local decode budget can temporarily lose access to healthy DAPI nodes for unrelated requests.
  A client can lose healthy responders from its shared address pool even though they all served a valid proof. `DocumentHistory::fetch` sends a proved V1 request on a PV15 network; a history-keeping contract admitted on PV14 can retain revisions that individually fit but together exceed the new budget, as the five-revision Drive regression demonstrates. GroveDB reconstructs the root, but `decode_result(...)?` discards it on `DecodedValueBudgetExceeded`. `verify_document_history_response_v1` then maps the failure to a generic verifier error before checking the Tenderdash signature. On known PV15 this stays retryable `Error::Proof`, so the default retry loop bans each responder it tries. The new authoritative composite clone charge has the same failure mode when individually fitting documents exceed the budget only because two joins retain them. Keep the limits, but carry the reconstructed root on these specific refusals and authenticate it before returning `UnusableVerifiedResult`, as `map_proved_sum_error` does. Invalid proofs and signatures must remain node faults.

  _Confirmed by an independent pass: On PV15, `CompositeDocuments::fetch` can request two by-ID joins whose reference fields resolve to the same normally published documents. The distinct rows fit the decode budget, but the new charge for retaining them in both results exhausts it after GroveDB reconstructs the root and before the Tenderdash signature is checked. The SDK retries the refusal as `Error::Proof` and bans each healthy responder it tries by default, which can leave a small shared address pool unavailable even for unrelated queries._

In `packages/rs-drive/src/drive/document/get_fetch/fetch_document_history/v1/mod.rs`:
- [SUGGESTION] packages/rs-drive/src/drive/document/get_fetch/fetch_document_history/v1/mod.rs:57-63: PV15 history queries fully decode every revision on the node, even for proof-only requests
  Impact: A node serving a public history page can materialize more values than the client verifier accepts for the same page.
  Both public response paths still pay to materialize the entire revision page. The server passes `None` to the changed `decode_result`, so `decode_entries` collects unrestricted `Document` values. `prove_document_history_v1` discards that collection before building the proof, while the unproved handler serializes it back into bytes. The ten-revision cap limits rows, not decoded property values, and the new regression explicitly expects the server fetch to serve a page the client refuses. Keep lifecycle and revision-key checks in Drive, but use headers to validate the proof-generation path without decoding properties. For unproved responses, reuse stored bytes where the wire contract permits it or apply a shared query budget if full decoding is required. Neither path needs to change consensus replay.

In `packages/rs-drive-proof-verifier/src/types.rs`:
- [SUGGESTION] packages/rs-drive-proof-verifier/src/types.rs:229-246: The budget-aware contender API hides why a page could not be decoded
  Impact: A Rust caller cannot distinguish a page that needs a smaller limit from a malformed contender document without inspecting error text.
  `to_contenders_with_budget` receives a typed `dpp::ProtocolError` but converts it to `crate::Error::ProtocolError { error: String }`; the regression test therefore has to repeat the decode through DPP to assert `DecodedValueBudgetExceeded`. Return the typed error from the new budget-aware method, as `decode_kept_values_with_budget` does, and convert it only in the existing `to_contenders` wrapper to preserve that signature.

In `packages/rs-drive/src/query/document_history_drive_query_tests.rs`:
- [SUGGESTION] packages/rs-drive/src/query/document_history_drive_query_tests.rs:568-575: The format-3 history test actually reads a format-0 header
  Impact: The lifecycle test can pass without checking that the reader consumes the format-3 contract stamp and stops at the revision boundary.
  `Fixture::new` loads `dashpay-contract-with-profile-history.json`, whose format-0 contract omits `config` and defaults to `DataContractConfigV0`. `DocumentV0::serialize` selects format 0 for that config even at `PlatformVersion::latest()`. The one-byte revision ends at byte 66, so the 67-byte slice includes one byte after the revision and never tests a stamp. Build a format-3 header explicitly or serialize using the format-3 serializer, assert the format prefix, and truncate exactly after the revision. Use different values for the stamp and revision.

In `packages/rs-sdk/src/platform/dpns_usernames/contender_request.rs`:
- [SUGGESTION] packages/rs-sdk/src/platform/dpns_usernames/contender_request.rs:369-385: The contest-page test passes even if the SDK resets the budget for every contender
  Impact: A regression in the SDK page decoder used by the vote-state binding could go undetected.
  The test supplies the same counter to two direct calls to `ContenderRequest::decode_with_budget`. It never exercises `ContestRequests::decode`, where production owns the budget and the loop. Replacing that loop with per-contender calls to `ContenderRequest::decode` would leave the test green. Exercise the public page decoder with a page that crosses its default allowance, or route the production loop and tight-budget test through a private budget-taking helper. Assert that the second request is empty and only the first label appears in `requested_labels`.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; 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 Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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.

@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

Changes requested: 3 blockers

  • Fetching a migrated revision the current schema cannot read can ban healthy nodes — packages/rs-drive/src/query/document_history_drive_query.rs:301-314 (new)
    Impact: An SDK app reading even one valid pre-update revision on PV15 can temporarily lose healthy DAPI addresses from its shared pool.
  • Paginating from an oversized cursor can ban healthy nodes even when the returned rows fit — packages/rs-drive-proof-verifier/src/proof.rs:2247-2252 (new)
    Impact: An app resuming a document query from a saved ID can temporarily lose healthy DAPI addresses even when every row on the requested page fits the decode budget.
  • Confirming a transfer of an oversized stored document can ban the nodes that prove it — packages/rs-drive-proof-verifier/src/proof.rs:1842-1850 (new)
    Impact: A client waiting for a completed transfer can lose healthy DAPI addresses even though those nodes returned valid confirmations.

New on this head: The follow-up carries reconstructed roots on decode-budget refusals, checks their quorum signatures before classifying them, and serves PV15 history from stored bytes without decoding document properties on the node. On this head, the Kotlin SDK build and tests and the book preview passed; PastaClaw review and PR Hygiene were pending, with no failed code checks reported. Verification was static.

A pattern across this PR's review rounds

This is review round 4, and the PR has drawn 12 blocking findings so far. 4 of them share one underlying cause. They are listed with the other findings as usual; fixing the cause is likely to be cheaper than fixing each case.

1. Document decoding can discard the proof root (3 new in this round, 1 earlier finding(s))

Drive's document verifiers reconstruct a GroveDB root, but generally return it only if they can also decode the document. The history-page fix made map_proved_budget_error authenticate one special error that carries the root, leaving each decode path responsible for preserving it. That is why an unreadable migrated revision, an oversized pagination cursor, and an oversized document in a transfer confirmation still turn into retryable Error::Proof failures that can ban healthy responders.

In this round: Fetching a migrated revision the current schema cannot read can ban healthy nodes; Paginating from an oversized cursor can ban healthy nodes even when the returned rows fit; Confirming a transfer of an oversized stored document can ban the nodes that prove it

Suggested decision (redesign the component): Make this PR separate proof authentication from document decoding at the Drive-to-rs-drive-proof-verifier boundary, rather than adding more call-site exceptions to map_proved_budget_error. Preserve the root and the decode outcome separately so that a refusal to decode proved bytes becomes a non-retryable UnusableVerifiedResult only after the relevant proof and Tenderdash signature checks pass. That refusal must not count as a verified page or confirmation of execution. At the CI check, the Rust workspace and wasm32 tests, JS build, and Drive and Dashmate helper image builds were pending.

🔴 3 blocking | 🟡 4 suggestion(s)

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

🟡 Suggestion: The budget-aware contender API hides why a page could not be decoded
Impact: A Rust caller supplying a contender-page budget cannot distinguish exhaustion from malformed document bytes without inspecting the error text.
packages/rs-drive-proof-verifier/src/types.rs:229-246

to_contenders_with_budget receives a typed dpp::ProtocolError, but its final .map_err(Into::into) stores only error.to_string() in the verifier error. The test has to repeat the DPP conversion to match the budget variant; the public page assertion can only match a substring. Return dpp::ProtocolError from the budget-taking method, as the removal-page decoder does, and convert only in the existing to_contenders wrapper to preserve its signature. This does not require changing the separate best-effort ContestRequests::decode API.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

Follow-up candidates (optional) (2)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: Counting an oversized signed document page still reports a generic proof failure
Impact: Callers counting an ordinary document proof cannot distinguish a local decode limit from a bad proof, even though fetching the same page as Documents makes that distinction.
packages/rs-drive-proof-verifier/src/proof/document_count.rs:47-56

The materialize-and-count verifier calls the same DriveDocumentQuery::verify_proof as Documents, which now returns a root-bearing budget error for oversized result rows. This caller still sends the error through map_drive_error, which stringifies it and exits before the signature check. Use map_proved_budget_error here too and cover both matching and mismatched signatures. This is the GetDocuments path that materializes rows to count them, not the count-tree aggregate verifier.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

🟡 Suggestion: Swift document lists report an oversized verified page as an internal SDK error
Impact: A Swift app cannot tell from the error code that narrowing a document list would resolve a page-budget refusal.
packages/rs-sdk-ffi/src/document/queries/search.rs:217

The new proof mapper turns an authenticated page-budget refusal into SDK InvalidRequest, but dash_sdk_document_search replaces that type with FFIError::InternalError. Swift's consumeStringResult preserves the C error code it receives, so it cannot recover the classification. Pass the error through FFIError::from, whose existing mapping emits InvalidParameter. The single-document documentGet wrapper loses the same classification one layer later: its C call already preserves the code, but Swift throws .internalError instead of converting it with SDKError.fromDashSDKError before freeing it.

            .map_err(FFIError::from)?;

source: gpt-6.2-astra (phase2-reviewer: ffi-engineer)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff changes PV15 consensus rules for contract registration and updates in try_from_schema/v4 and introduces shared decode budgets across multiple proof-verification and client paths while preserving historical replay behavior.
  • 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)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • New since the last final review (16e5866e): 3 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 3 confirmed; 2 suggestion(s) on unchanged code listed as follow-up candidates
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
Several findings on this PR share an underlying cause (the review's "pattern" section): Document decoding can discard the proof root. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Make this PR separate proof authentication from document decoding at the Drive-to-`rs-drive-proof-verifier` boundary, rather than adding more call-site exceptions to `map_proved_budget_error`. Preserve the root and the decode outcome separately so that a refusal to decode proved bytes becomes a non-retryable `UnusableVerifiedResult` only after the relevant proof and Tenderdash signature checks pass. That refusal must not count as a verified page or confirmation of execution. At the CI check, the Rust workspace and wasm32 tests, JS build, and Drive and Dashmate helper image builds were pending. If that decision is not yours to make, say so to the PR's author or maintainer.

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 `packages/rs-drive/src/query/document_history_drive_query.rs`:
- [BLOCKING] packages/rs-drive/src/query/document_history_drive_query.rs:301-314: Fetching a migrated revision the current schema cannot read can ban healthy nodes
  Impact: An SDK app reading even one valid pre-update revision on PV15 can temporarily lose healthy DAPI addresses from its shared pool.
  The SDK can penalize every responder it tries for a valid history proof. The existing `should_migrate_revisions_stored_before_a_nested_property_change` fixture shows how this state arises: PV14 accepts a nested schema update, the updated type cannot decode the old revision, and migration preserves its bytes. The new header-only prover can now serve that revision because its ID and revision still match. On `DocumentHistory::fetch`, the client passes those same header checks, then fails to decode the body with the current type. That error is not `DecodedValueBudgetExceeded`, so the reconstructed root is discarded and, on known PV15, the SDK retries it as `Error::Proof` and bans the responder by default. Keep the server header-only. Authenticate the root and structurally validated rows separately from materializing the documents, then use the historical schema where available or report an unusable verified result. Keep bad keys, lifecycle data, and signatures as proof failures.

  _Confirmed by an independent pass: A caller using `DocumentHistory::fetch` on PV15 can request a migrated revision written before a nested schema change that PV14 accepted. The node now serves a valid signed proof because the revision header still matches, but the client cannot decode the body with the current schema and retries and bans healthy responders instead of reporting an unreadable verified revision._
- [SUGGESTION] packages/rs-drive/src/query/document_history_drive_query.rs:531-561: History tests do not distinguish a header-only read from full revision decoding
  Impact: A regression that restores server-side property decoding can leave the unproved-response test green, while the direct key tests keep running a separate test-only body decoder.
  The unproved-response assertion in `rs-drive-abci/src/query/document_history/v1/tests.rs:1080–1091` only counts five valid entries; the previous full reader would also return five. Meanwhile, test-only `decode_entries` duplicates body decoding and entry construction from `decode_result`, although its callers only assert the key width and revision already checked by `decode_entries_serialized`. Point those tests at the production serialized decoder and remove the duplicate. Add a Drive serialized-fetch test that compares the returned bytes with a stored revision with a valid header but an unreadable body; that test would fail if the public server path started decoding bodies again.

In `packages/rs-drive-proof-verifier/src/proof.rs`:
- [BLOCKING] packages/rs-drive-proof-verifier/src/proof.rs:2247-2252: Paginating from an oversized cursor can ban healthy nodes even when the returned rows fit
  Impact: An app resuming a document query from a saved ID can temporarily lose healthy DAPI addresses even when every row on the requested page fits the decode budget.
  The new mapper handles oversized result rows but still treats an oversized cursor as a node fault. A saved `startAfter` ID can point to a document that grew after the ID was saved: a type registered on PV14 can retain properties added by separate moderator field updates. `Document::fetch_many` reaches `verify_proof_keep_serialized`, which proves the named cursor before constructing the page query. Both generations of `verify_start_at_document_in_proof` reconstruct the cursor root, then return a plain protocol error if the bounded decode fails. The new mapper depends on that branch preserving the root; without it, the SDK retries `Error::Proof` and bans the responder by default. Attach the cursor root at both decode sites and verify its signature before returning the local refusal. Test a signed page whose cursor itself exceeds the budget, rather than one whose first returned row does.

  _Confirmed by an independent pass: A caller can resume `Document::fetch_many` with a saved `startAfter` ID after separate authorized moderator edits have grown the cursor document of a PV14-admitted type beyond the client decode budget. The node can prove the page, but the SDK rejects and bans the responder while decoding the cursor, even when all rows after it fit the budget._
- [BLOCKING] packages/rs-drive-proof-verifier/src/proof.rs:1842-1850: Confirming a transfer of an oversized stored document can ban the nodes that prove it
  Impact: A client waiting for a completed transfer can lose healthy DAPI addresses even though those nodes returned valid confirmations.
  A transfer can commit while the SDK retries and bans the nodes confirming it. A transferable document on a type admitted at PV14 can grow across separate moderator field updates; transferring it names the stored document without resending its properties. With a PV14 or later proof producer, the wait path verifies the merged document-and-owner-balance query. The bounded decode at `verify_state_transition_was_executed_with_proof/v0/mod.rs:475–483` returns a plain protocol error after GroveDB has already reconstructed the merged root. The new mapper therefore falls back to generic `Error::Proof`, and `wait_for_outcome_with_metadata` retries against the shared address pool with banning enabled by default. Preserve the merged root on budget exhaustion, and test that a signed merged proof produces an unusable verified result while a signature over the wrong root still fails verification.

  _Confirmed by an independent pass: A caller can transfer a document whose stored properties grew beyond the client decode budget through authorized moderator edits on a PV14-admitted type. The transfer can commit because it references the stored document by ID and revision without resending its properties, but the SDK wait cannot confirm it and retries and bans healthy nodes that return the valid merged proof._

In `packages/rs-drive-proof-verifier/src/types.rs`:
- [SUGGESTION] packages/rs-drive-proof-verifier/src/types.rs:229-246: The budget-aware contender API hides why a page could not be decoded
  Impact: A Rust caller supplying a contender-page budget cannot distinguish exhaustion from malformed document bytes without inspecting the error text.
  `to_contenders_with_budget` receives a typed `dpp::ProtocolError`, but its final `.map_err(Into::into)` stores only `error.to_string()` in the verifier error. The test has to repeat the DPP conversion to match the budget variant; the public page assertion can only match a substring. Return `dpp::ProtocolError` from the budget-taking method, as the removal-page decoder does, and convert only in the existing `to_contenders` wrapper to preserve its signature. This does not require changing the separate best-effort `ContestRequests::decode` API.

In `packages/rs-drive/src/error/proof.rs`:
- [SUGGESTION] packages/rs-drive/src/error/proof.rs:114-120: The 5.1 guide omits the new variant that breaks exhaustive Drive proof-error matches
  Impact: Downstream Rust code exhaustively matching `drive::error::proof::ProofError` needs a new arm even if it never verifies an oversized page.
  `ProofError` is public and not `#[non_exhaustive]`, so the new variant breaks exhaustive matches at compile time. The upgrade guide covers the analogous `DataContractError` addition but not this one. List `ProofError::DecodedValueBudgetExceeded { .. }` in the same note, distinguishing the direct Drive error from the authenticated `UnusableVerifiedResult` produced by the higher-level verifier.

In `packages/rs-drive/src/verify/document/verify_document_history/v0/mod.rs`:
- [SUGGESTION] packages/rs-drive/src/verify/document/verify_document_history/v0/mod.rs:82-90: The shipped-generation inventory omits the changed legacy history verifier
  Impact: A reviewer relying on the PR's in-place-change inventory cannot see that verification on PV14 now returns a different client error.
  The follow-up changes the decode refusal returned by history verifier generation 0, selected through PV14. The book requires the PR's in-place-change section to list each edited shipped generation, its selecting protocol versions, and why consensus cannot change. The existing section names the composite verifier but not the legacy history verifier. List the shipped verifier generations touched by the follow-up and note that these error changes concern client proof verification, not block execution. The history dispatcher does not need a version bump for this.

Comment thread packages/rs-drive/src/error/proof.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; 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 Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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 Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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.

@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

New on this head: This follow-up authenticates PV15 history proofs before decoding revision bodies, preserves reconstructed roots on cursor and transition-proof budget refusals, and updates the SDK version-tampering test for the new history dispatcher. Rust workspace and wasm32 tests, JS package checks, Docker builds, and Kotlin checks passed; the Swift build and tests, package functional tests, and platform test suites were still pending.

🟡 4 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

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

🟡 Suggestion: The budget-aware contender API hides why a page could not be decoded
Impact: A Rust caller supplying a contender-page budget cannot distinguish exhaustion from malformed document bytes without parsing an error message.
packages/rs-drive-proof-verifier/src/types.rs:229-246

to_contenders_with_budget enforces the shared limit but loses the typed reason for refusing the page. It collects a dpp::ProtocolError, then .map_err(Into::into) invokes error.rs:199–204, which stores only the error text in crate::Error::ProtocolError. The page regression consequently checks a substring, while the direct DPP check can match DecodedValueBudgetExceeded. Return dpp::ProtocolError from the new budget-taking method, as the removal-page decoder does, and move the conversion to the existing to_contenders wrapper to preserve its signature.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality, security-auditor)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff is large and intricate, and try_from_schema/v4/mod.rs changes PV15 consensus rules by rejecting top-level and nested typed arrays with zero-width elements during contract validation.
  • 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)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-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 (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 `packages/rs-drive-proof-verifier/src/types.rs`:
- [SUGGESTION] packages/rs-drive-proof-verifier/src/types.rs:229-246: The budget-aware contender API hides why a page could not be decoded
  Impact: A Rust caller supplying a contender-page budget cannot distinguish exhaustion from malformed document bytes without parsing an error message.
  `to_contenders_with_budget` enforces the shared limit but loses the typed reason for refusing the page. It collects a `dpp::ProtocolError`, then `.map_err(Into::into)` invokes `error.rs:199–204`, which stores only the error text in `crate::Error::ProtocolError`. The page regression consequently checks a substring, while the direct DPP check can match `DecodedValueBudgetExceeded`. Return `dpp::ProtocolError` from the new budget-taking method, as the removal-page decoder does, and move the conversion to the existing `to_contenders` wrapper to preserve its signature.

In `book/src/sdk/protocol-version-15-upgrade.md`:
- [SUGGESTION] book/src/sdk/protocol-version-15-upgrade.md:76-78: The upgrade guide names an error variant that SDK fetch callers do not receive
  Impact: Rust apps following the guide to handle an oversized authenticated response will look for the wrong error at the `dash-sdk` boundary.
  A direct `drive-proof-verifier` caller receives `UnusableVerifiedResult`, but an SDK fetch does not return that variant. `Sdk::classify_verifier_error` first checks the authenticated response metadata for freshness; for a fresh response, `rs-sdk/src/error.rs:411–414` converts the refusal to `dash_sdk::Error::InvalidRequest(reason)`. Stale metadata follows the SDK's stale-answer path instead. Distinguish those layers in the guide and the PR's breaking-change note.

In `packages/rs-drive/src/query/document_history_drive_query.rs`:
- [SUGGESTION] packages/rs-drive/src/query/document_history_drive_query.rs:145-169: The public history decoder has no page limit when callers pass `None`
  Impact: A direct Drive client using the new serialized history verifier can authenticate a page and materialize all its revisions without the ordinary verifier's decode limit.
  Authentication establishes the origin of the bytes, not the cost of decoding them. The new public `into_documents` method accepts `None`, which calls unbounded `Document::from_bytes` for every revision. Both built-in verification paths pass the default budget today; the only production use of `None` is server-side. Give the public conversion a bounded default or require `&mut DecodedValueBudget`, and keep unbounded materialization in a private server helper.

In `packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs`:
- [SUGGESTION] packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs:3581-3588: Restore confirmation fails when the provider lacks a contract the verifier no longer needs
  Impact: A caller with the proof and quorum context but no contract entry gets an unknown-contract error before the removal proof is checked.
  The switch to `Document::id_from_bytes` removes the schema dependency, but the restore branch still resolves the contract and type before discarding `_document_type`. The removal query uses the transition's contract ID and type name, and the verifier checks the proved record against the header ID, the hash of the full transition document bytes, and the restoring moderator. Remove the lookup from this branch, update the comment above it, and cover a valid restore confirmation with a provider that has quorum context but returns no contract.

Comment thread packages/rs-drive/src/error/proof.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 Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — 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 Nov 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.

Re-review — Final validation — Phase 1 + Phase 2

New on this head: This update requires a shared decode budget for public history conversion, removes the unused contract lookup from restore confirmation, and clarifies which errors Drive, the proof verifier, and SDK fetch callers receive. Kotlin emulator tests, Rust WASM tests, and the book preview passed; Rust workspace tests, the JS build, and some Docker builds were still pending, with no failed code checks reported.

🟡 2 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

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

🟡 Suggestion: The budget-aware contender API hides why a page could not be decoded
Impact: Rust callers supplying a contender-page budget cannot distinguish exhaustion from malformed contender data without matching error text.
packages/rs-drive-proof-verifier/src/types.rs:245-246

to_contenders_with_budget enforces the limit but discards the typed reason for stopping. It collects a dpp::ProtocolError, then map_err(Into::into) converts it to crate::Error::ProtocolError { error: String }. The regression test repeats the DPP loop to match DecodedValueBudgetExceeded by variant, then checks a substring on the convenience method's result. Return dpp::ProtocolError from to_contenders_with_budget, as the removal-page budget API does, and keep the conversion in to_contenders to preserve its existing signature. The SDK's best-effort DPNS decoder calls DPP directly, so its empty-request behavior is separate from this conversion.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff is large and intricate, and validate_typed_array_non_zero_element_width in try_from_schema/v4/mod.rs changes PV15 consensus rules by rejecting zero-width typed arrays during contract registration and updates.
  • 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)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-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 (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 `packages/rs-drive-proof-verifier/src/types.rs`:
- [SUGGESTION] packages/rs-drive-proof-verifier/src/types.rs:245-246: The budget-aware contender API hides why a page could not be decoded
  Impact: Rust callers supplying a contender-page budget cannot distinguish exhaustion from malformed contender data without matching error text.
  `to_contenders_with_budget` enforces the limit but discards the typed reason for stopping. It collects a `dpp::ProtocolError`, then `map_err(Into::into)` converts it to `crate::Error::ProtocolError { error: String }`. The regression test repeats the DPP loop to match `DecodedValueBudgetExceeded` by variant, then checks a substring on the convenience method's result. Return `dpp::ProtocolError` from `to_contenders_with_budget`, as the removal-page budget API does, and keep the conversion in `to_contenders` to preserve its existing signature. The SDK's best-effort DPNS decoder calls DPP directly, so its empty-request behavior is separate from this conversion.

In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests.rs:4237-4270: The restore regression test duplicates the shared proof signer
  Impact: When the signed proof fixture changes, maintainers must also update the restore test even though it tests contract lookup, not signing.
  The restore regression has a second place to maintain the signed proof format. It constructs the state ID, canonical precommit, digest, and proof envelope inline, but `crate::query::tests::signed_proof` already does this with the same inputs. Its fixed quorum type is sufficient because `QuorumOnlyProvider` returns the supplied key regardless of type. Reuse the helper and keep the no-contract provider and both outcome assertions.

Comment on lines +4237 to +4270
let state_id = StateId {
app_version: metadata.protocol_version as u64,
core_chain_locked_height: metadata.core_chain_locked_height,
time: metadata.time_ms,
app_hash: root.to_vec(),
height: metadata.height,
};
let commit = CanonicalVote {
r#type: SignedMsgType::Precommit.into(),
block_id: vec![7; 32],
chain_id: metadata.chain_id.clone(),
height: metadata.height as i64,
round: 0,
state_id: state_id
.calculate_msg_hash(&metadata.chain_id, metadata.height as i64, 0)
.expect("state_id hash"),
};
let digest = commit
.calculate_sign_hash(
&metadata.chain_id,
quorum_type.try_into().expect("quorum type"),
&[9; 32],
metadata.height as i64,
0,
)
.expect("sign hash");
let signed_proof = Proof {
grovedb_proof,
quorum_hash: vec![9; 32],
signature: key.sign(&digest).expect("sign").to_bytes().to_vec(),
round: 0,
block_id_hash: vec![7; 32],
quorum_type,
};

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.

🟡 Suggestion: The restore regression test duplicates the shared proof signer
Impact: When the signed proof fixture changes, maintainers must also update the restore test even though it tests contract lookup, not signing.

The restore regression has a second place to maintain the signed proof format. It constructs the state ID, canonical precommit, digest, and proof envelope inline, but crate::query::tests::signed_proof already does this with the same inputs. Its fixed quorum type is sufficient because QuorumOnlyProvider returns the supplied key regardless of type. Reuse the helper and keep the no-contract provider and both outcome assertions.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

@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 Nov 23, 2026
@QuantumExplorer
QuantumExplorer merged commit ed63eda into v5.1-dev Nov 23, 2026
41 of 43 checks passed
@QuantumExplorer
QuantumExplorer deleted the fix/bound-typed-array-decoded-size branch November 23, 2026 06:19
shumkov added a commit that referenced this pull request Nov 23, 2026
…d-update-rules-followup

Brings in #6092 (bound decoded size and refuse zero-width typed-array
elements, PV15). Its two conflicts with this branch were doc comments only:
the try_from_schema 4 module doc and the try_from_schema line of
CONTRACT_VERSIONS_V7's doc. Both keep #6092's zero-width typed-array
refusal and drop the clause saying generation 4 holds member positions,
which this branch moved out of the parse (MemberPositionOrder). #6092's
check, its order and every version field are kept as merged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

dpp: bound the decoded size of typed array properties by their encoded size

2 participants