Skip to content

fix(dpp)!: refuse a byte array of integers that are not bytes from protocol version 15 - #5964

Merged
QuantumExplorer merged 7 commits into
v5.1-devfrom
claude/byte-array-consensus-check-pv15-5b8143
Nov 17, 2026
Merged

QuantumExplorer merged 7 commits into
v5.1-devfrom
claude/byte-array-consensus-check-pv15-5b8143

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

A document whose byte array property holds a list of integers that are not stored as bytes (for example a JavaScript Uint8Array that a client converts to 64-bit integers) passed document validation and then failed to serialize, so check_tx answered with an internal error instead of a consensus error. From protocol version 15 such a document is refused with a consensus error that names the member. The refusal is unpaid: nobody is charged, a proposer drops the batch, and validators reject a block that holds it, exactly as they do today. This is item 1 of #5940.

Issue being fixed or feature implemented

Item 1 of #5940, found on the palmatum devnet: a document create with "data": [U64(1), U64(2), ...] for a byteArray property made check_tx return Drive(Protocol(ValueError(StructureError("not an array of bytes")))).

Members above 255, negative or not an integer were already refused by the schema check at protocol versions 14 and 15 (maximum / type). The gap is a list of in-range integers whose type is not Value::U8. The schema check reads the document's JSON form, which does not tell an integer's type, so it passes them; the document serializer and index keys (to_binary_bytes / to_identifier_bytes) read a list only when every member is Value::U8.

Before / after

Protocol version 15, data is { "type": "array", "byteArray": true }, document { "data": [U64(1), U64(2), U64(3)] }:

Before:

check_tx -> Err(Drive(Protocol(ValueError(StructureError("not an array of bytes")))))
in a block -> InternalError

After:

check_tx -> JsonSchemaError (code 10101) {
  keyword: "byteArray",
  instance_path: "/data/0",
  "/data/0 is U64(1), not a byte: each member of a byte array must be written as an 8-bit unsigned integer"
}
in a block -> UnpaidConsensusError (the proposer drops it; validators reject a block holding it, as before)

Value::Bytes([1, 2, 3]), [U8(1), U8(2), U8(3)], Value::Identifier(..) and Value::Bytes32(..) are accepted as before.

What was done?

  • validate_document 2 (selected only by protocol version 15, CONTRACT_VERSIONS_V7), once the schema check passes, reads every byte array and identifier the way the serializer does: plain byte arrays, identifiers, byte arrays inside nested objects, typed arrays, and lists of byte arrays or identifiers. It refuses the first one the serializer could not read, so validation and serialization agree by construction (new validate_document/v2/byte_arrays.rs).
  • The refusal reuses JsonSchemaError with keyword byteArray and an instance path naming the member, the error the native validator already gives a member that is not an integer. No new error variant or code.
  • The error order is unchanged: any schema violation is still reported first.
  • A batch failing this check is refused unpaid (batch advanced_structure 2, selected only by protocol version 15): its result carries no nonce-bump action. check_tx gives the refusal, so no honest proposer holds such a batch, and charging for it would pay a proposer to add what check_tx refused. Every other advanced structure failure, including a member above 255, stays paid.
  • A moderator's document field change runs the same document check while it is transformed, which check_tx does too, so it is refused unpaid in the same way (contract user moderation transform_into_action 1, selected only by protocol version 15).
  • Docs: protocol version 15 note 6 (v15.rs) and the validate_document: 2 doc in dpp_contract_versions/v7.rs.

In-place changes to shipped generations

None. Only validate_document 2 is touched, which only the unreleased protocol version 15 selects. Protocol version 14 (validate_document 1) is unchanged and a test pins its behaviour.

How Has This Been Tested?

  • cargo test -p dpp --lib validate_document: new tests refuse U64, I8, U16 and I64 members in a plain byte array, an identifier, a nested object and a list of identifiers, each also failing to serialize; accept bytes, U8 lists, Identifier and Bytes32, each also serializing; show out-of-range members refused by the schema check at both 14 and 15; and show protocol version 14 still passes the list. One existing case in should_validate_documents_at_protocol_version_15_as_at_14 now writes [1, 2] as U8 members, since an I32 list is refused from 15. The predicate takes only the refusal as built (empty schema path and property name), not another error under the byteArray keyword.
  • cargo test -p drive-abci --lib byte_array_members: at PlatformVersion::latest() check_tx returns the byteArray consensus error for a byte array and an identifier, and in a block the create is an unpaid consensus error; a member above 255 is still a paid consensus error; a byte array written as bytes succeeds; at protocol version 14 the create still ends as an internal error. A replace writing such a list is refused by check_tx and unpaid in a block as a create is, and stored when written as bytes. A create and a replace carrying a transient byte array written as such a list succeed at the latest protocol version and at 14: a transient value is dropped before the document is written, so the check does not read it.
  • cargo test -p drive-abci --lib moderator_fields: a moderator change writing a U64 list to a byte array is refused by check_tx and unpaid in a block, with the moderator's balance unchanged; a member above 255 is still paid; the change written as bytes is stored. At protocol version 14 the same change still ends as an internal error in a block.
  • Mutation check: with the refusal disabled, the latest-version drive-abci test fails with the devnet error above.

Breaking Changes

For a batch (document create, replace, index-only delete), blocks are unchanged: a batch carrying a byte array or identifier written as a list of integers that are not U8 is kept out of every block at protocol version 15 (unpaid consensus error) as at 14 (internal error). What changes is check_tx's answer, a JsonSchemaError (10101) in place of an internal error. A moderator's field change writing such a list is refused unpaid in the same way at protocol version 15; its protocol version 14 outcome is not covered by a test here. Clients should send byte arrays as bytes; the evo-sdk Uint8Array conversion is tracked separately in #5940.

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

🤖 Generated with Claude Code

PR Hygiene · 24bb1e5

  • Bots — thepastaclaw 2 threads unresolved — resolve them
  • Self-review — post /self-reviewed
  • Build running
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Bug Fixes
    • Document validation now rejects byte arrays and identifiers containing values that cannot be read as bytes, with an error pointing to the invalid value.
    • Valid byte-encoded arrays and identifiers continue to pass validation. Schema-invalid values continue to be reported as schema errors.
    • At protocol version 15, invalid byte-array values are rejected during validation rather than failing later during processing.
    • Unreadable byte-array values in batch and moderator changes are refused without a charge; other validation errors retain their existing handling.

…otocol version 15

The schema check reads a document's JSON form, where a byte array or
identifier written as a list of in-range integers passes whatever integer
type each member has (`Value::U64` from a JavaScript `Uint8Array`, `I32`
from `platform_value!([1, 2])`). The document serializer and the index
key encoder read such a list only when every member is a `Value::U8`, so
the document failed to serialize after validation passed and check_tx
returned an internal error (#5940, item 1).

`validate_document` 2 (protocol version 15) now reads every byte array
and identifier of the document as the serializer reads it
(`to_binary_bytes` / `to_identifier_bytes`), walking nested objects and
lists, and once the schema check passes refuses the first it cannot read
with a `JsonSchemaError` (keyword `byteArray`) whose instance path names
the member, for example `/data/0`. Members above 255, negative or not an
integer were already refused by the schema check at 14 and 15 and still
are. Protocol version 14 (`validate_document` 1) is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Document validation now detects byte arrays and identifiers that contain values the serializer cannot read. It reports the first unreadable value when schema validation has no error. Batch and moderator field-change validation apply the resulting refusal, with tests for protocol versions 14 and 15.

Changes: Byte-array validation

Layer / File(s) Summary
Detect unreadable byte-array values
packages/rs-dpp/src/data_contract/methods/validate_document/*
packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v7.rs, packages/rs-platform-version/src/version/v15.rs
A recursive check examines declared byte-array and identifier properties, including nested objects and arrays. It reports an unreadable value only when schema validation has no error. Tests cover supported and unreadable values, nested paths, schema errors, and protocol-version 14 behavior.
Apply refusals to batch validation
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v2/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/*, packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v11.rs
Batch validation returns a sole unreadable-byte-array error without an action. Tests cover create and replacement processing at the latest protocol version and protocol version 14.
Apply refusals to moderator field changes
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/state/v1/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/moderator_fields.rs, packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v11.rs
Moderator field-change validation returns a sole unreadable-byte-array error without an action. Tests cover invalid and valid values at the latest protocol version and protocol-version 14 behavior.

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

Change: Bug fix

Possibly related issues

Suggested reviewers: shumkov, thepastaclaw

Merge Risk: Minimal · up to 6a1eb

From protocol version 15, documents whose byte arrays or identifiers contain non-byte integers are refused with a schema error instead of failing later with an internal error in check_tx. The change is version-gated and tested across both the batch and moderator paths, so no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: document validation for protocol version 15 now refuses byte arrays containing integers that are not bytes, returning a JsonSchemaError instead of an internal serializ…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: document validation for protocol version 15 now refuses byte arrays containing integers that are not bytes, returning a JsonSchemaError instead of an internal serialization error. The changeset matches this: a new byte_arrays validator, its wiring into validate_document_properties_v2, unpaid refusal handling in batch advanced-structure and moderation paths, and tests at protocol versions 14 and 15. The title is specific and uses the conventional commit form. The ! marks a breaking change, which fits the protocol-level behavior change.

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 96425ac and 6a1eb49.

Files selected for processing: 10

  • packages/rs-dpp/src/data_contract/methods/validate_document/mod.rs
  • packages/rs-dpp/src/data_contract/methods/validate_document/v2/byte_arrays.rs
  • packages/rs-dpp/src/data_contract/methods/validate_document/v2/mod.rs
  • packages/rs-dpp/src/data_contract/methods/validate_document/v2/tests.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v2/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/byte_array_members.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/state/v1/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/moderator_fields.rs
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v11.rs
  • packages/rs-platform-version/src/version/v15.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 commented Nov 17, 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 17, 2026
@thepastaclaw

thepastaclaw commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress (commit 24bb1e5) · live progress

…st (clippy single_match)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 17, 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.

…t protocol version 15

check_tx gives the refusal, so no honest proposer holds such a batch. Charging
for it would pay a proposer to add what check_tx refused. Refused unpaid, a
proposer drops the batch and validators reject a block holding it, as through
protocol version 14, where serializing the document fails internally.

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

github-actions Bot commented Nov 17, 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.

…ay unpaid at protocol version 15

The mempool transforms a moderator's field change and gives the refusal too, so
it is refused unpaid like the batch: a proposer drops it and validators reject a
block holding it.

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

github-actions Bot commented Nov 17, 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 commented Nov 17, 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.

Final validation — Phase 1 + Phase 2

The protocol-15 validation and unpaid routing are correctly version-gated and align with the serializer paths. No blocking correctness or security issue was found; the remaining in-scope items are test coverage and defensive checks around assumptions documented by the new code. Rust workspace, JS, and wasm checks were still in progress, with no failed code checks in the supplied CI snapshot.

🟡 5 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.

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate change that modifies consensus-critical document validation, protocol-version activation, and unpaid batch/moderation refusal behavior in rs-dpp and rs-drive-abci.
  • 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.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort xhigh); 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/methods/validate_document/v2/byte_arrays.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/methods/validate_document/v2/byte_arrays.rs:23-30: Make the unpaid-refusal predicate identify the exact error shape
  The predicate currently classifies every JsonSchemaError whose keyword is `byteArray` as the special unpaid refusal. That is correct for the current producers because the native validator reports its byte-array violations as `type` or `maximum`, and this constructor uses empty schema and property paths. However, another producer using the existing `byteArray` keyword would silently become unpaid and bypass the nonce bump. Match the empty schema and property paths set by `unreadable_byte_array` so the carve-out remains specific if additional byte-array validation is added.

In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v2/mod.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v2/mod.rs:69-75: Require the unpaid carve-out to receive exactly one error
  The batch carve-out checks only `result.errors.first()`. The current validation paths return one error for this case, but the unpaid classification depends on that invariant: if a future validation result contains the byte-array refusal together with another paid error, the entire batch would lose its nonce bump. Match a single-element result in this location and in the analogous moderator path at `contract_user_moderation/state/v1/mod.rs:124-129`, failing closed to the normal paid handling if the result shape changes.

In `packages/rs-dpp/src/data_contract/methods/validate_document/v2/tests.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/methods/validate_document/v2/tests.rs:1105-1115: Cover typed arrays whose elements are byte arrays
  The traversal explicitly recurses through `DocumentPropertyType::TypedArray` and supports a typed array whose scalar element type is `ByteArray`, but the tests cover only a regular array of byte-array/identifier elements. Add a reachable schema with `items: { type: "array", byteArray: true }` and verify that a nested non-`U8` member is refused at the element path while an all-`U8` value remains serializable. This exercises the distinct typed-array recursion path.

In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/byte_array_members.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/byte_array_members.rs:183-210: Cover replace transitions with an unreadable byte array
  The block-level test currently proves the unpaid protocol-15 behavior only for document creation. Replace validation also calls `validate_document_properties`, and the batch v2 carve-out is intended to classify that refusal as unpaid. Add a replace fixture asserting both check_tx's `byteArray` error and `UnpaidConsensusError` during block processing, so the claimed behavior is pinned for both document write forms.

In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/moderator_fields.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/moderator_fields.rs:1278-1285: Add protocol-14 regression coverage for moderator byte-array changes
  The moderation test uses `PlatformVersion::latest()` and verifies only the new protocol-15 unpaid path. The change also adds a protocol-15 moderation dispatcher while claiming protocol-14 behavior remains unchanged, but there is no moderator fixture proving that protocol 14 still follows the legacy internal-error/paid behavior for an in-range non-`U8` byte-array member. Add the analogous protocol-14 case to document the old-generation compatibility contract.
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.

  • Track the existing byte-array encoding-flip chain-halt vulnerability — Existing compatibility tests document that widening a fixed-size byteArray can change its on-disk encoding, allowing an accepted contract update to make existing documents fail to decode or decode to corrupted values. This is pre-existing and is not introduced by the protocol-15 non-U8 validation fix, but it warrants a separate security follow-up.
    • Follow-up: Open a separate security issue or follow-up PR to stabilize byte-array encoding across compatible schema changes and add migration or rejection checks before permitting an encoding-changing update.

Comment on lines +23 to +30
/// Whether `error` is the refusal [`unreadable_byte_array`] gives.
pub(in crate::data_contract::methods::validate_document) fn is_refusal(
error: &ConsensusError,
) -> bool {
matches!(
error,
ConsensusError::BasicError(BasicError::JsonSchemaError(error)) if error.keyword() == KEYWORD
)

@thepastaclaw thepastaclaw Nov 17, 2026 •

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.

✅ Resolved at 6a1eb498; see the replies below.

🟡 Suggestion: Make the unpaid-refusal predicate identify the exact error shape

The predicate currently classifies every JsonSchemaError whose keyword is byteArray as the special unpaid refusal. That is correct for the current producers because the native validator reports its byte-array violations as type or maximum, and this constructor uses empty schema and property paths. However, another producer using the existing byteArray keyword would silently become unpaid and bypass the nonce bump. Match the empty schema and property paths set by unreadable_byte_array so the carve-out remains specific if additional byte-array validation is added.

Suggested change
/// Whether `error` is the refusal [`unreadable_byte_array`] gives.
pub(in crate::data_contract::methods::validate_document) fn is_refusal(
error: &ConsensusError,
) -> bool {
matches!(
error,
ConsensusError::BasicError(BasicError::JsonSchemaError(error)) if error.keyword() == KEYWORD
)
matches!(
error,
ConsensusError::BasicError(BasicError::JsonSchemaError(error))
if error.keyword() == KEYWORD
&& error.schema_path().is_empty()
&& error.property_name().is_empty()
)

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

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.

Resolved (re-reviewed at 6a1eb498): The refusal predicate now requires the dedicated keyword together with empty schema-path and property-name fields, and the tests distinguish lookalike schema errors.

Comment on lines 69 to +75
if !result.is_valid() {
if result
.errors
.first()
.is_some_and(is_unreadable_byte_array_refusal)
{
return Ok(ConsensusValidationResult::new_with_errors(result.errors));

@thepastaclaw thepastaclaw Nov 17, 2026 •

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.

✅ Resolved at 6a1eb498; see the replies below.

🟡 Suggestion: Require the unpaid carve-out to receive exactly one error

The batch carve-out checks only result.errors.first(). The current validation paths return one error for this case, but the unpaid classification depends on that invariant: if a future validation result contains the byte-array refusal together with another paid error, the entire batch would lose its nonce bump. Match a single-element result in this location and in the analogous moderator path at contract_user_moderation/state/v1/mod.rs:124-129, failing closed to the normal paid handling if the result shape changes.

Suggested change
if !result.is_valid() {
if result
.errors
.first()
.is_some_and(is_unreadable_byte_array_refusal)
{
return Ok(ConsensusValidationResult::new_with_errors(result.errors));
if matches!(result.errors.as_slice(), [error] if is_unreadable_byte_array_refusal(error)) {
return Ok(ConsensusValidationResult::new_with_errors(result.errors));
}

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

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.

Resolved (re-reviewed at 6a1eb498): The batch and moderator guards now require an error slice containing exactly one matching refusal instead of inspecting only the first error.

Comment on lines +1105 to +1115
"members": {
"type": "array",
"items": {
"type": "array",
"byteArray": true,
"minItems": 32,
"maxItems": 32,
"contentMediaType": "application/x.dash.dpp.identifier",
},
"maxItems": 4,
"position": 3,

@thepastaclaw thepastaclaw Nov 17, 2026 •

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.

✅ Resolved at 6a1eb498; see the replies below.

🟡 Suggestion: Cover typed arrays whose elements are byte arrays

The traversal explicitly recurses through DocumentPropertyType::TypedArray and supports a typed array whose scalar element type is ByteArray, but the tests cover only a regular array of byte-array/identifier elements. Add a reachable schema with items: { type: "array", byteArray: true } and verify that a nested non-U8 member is refused at the element path while an all-U8 value remains serializable. This exercises the distinct typed-array recursion path.

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

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.

Resolved (re-reviewed at 6a1eb498): The members schema now exercises a typed array whose item type is a byte array, with tests for a non-byte nested member and valid byte or identifier representations.

Comment on lines +183 to +210
#[tokio::test(flavor = "multi_thread")]
async fn should_refuse_at_check_tx_a_byte_array_of_integers_that_are_not_bytes() {
let fixture = Fixture::new(PlatformVersion::latest());
for (properties, path) in [
(
platform_value!({ "data": u64_members(&[1, 2, 3]) }),
"/data/0",
),
(
platform_value!({ "target": u64_members(&[7; 32]) }),
"/target/0",
),
] {
let raw = fixture.creation(properties.clone()).await;
let errors = fixture
.check_tx(&raw)
.expect("expected check_tx to return a consensus error, not an internal error");
assert_eq!(byte_array_refusal(&errors), Some(path), "{errors:?}");
assert_eq!(errors[0].code(), JSON_SCHEMA_ERROR);

// In a block the refusal is unpaid: nobody is charged, so no proposer gains by
// adding what check_tx refused, and a block holding it is rejected
match fixture.process(raw) {
StateTransitionExecutionResult::UnpaidConsensusError(error) => {
assert_eq!(byte_array_refusal(&[error]), Some(path))
}
other => panic!("expected an unpaid consensus error for {properties:?}, got {other:?}"),
}

@thepastaclaw thepastaclaw Nov 17, 2026 •

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.

✅ Resolved at 6a1eb498; see the replies below.

🟡 Suggestion: Cover replace transitions with an unreadable byte array

The block-level test currently proves the unpaid protocol-15 behavior only for document creation. Replace validation also calls validate_document_properties, and the batch v2 carve-out is intended to classify that refusal as unpaid. Add a replace fixture asserting both check_tx's byteArray error and UnpaidConsensusError during block processing, so the claimed behavior is pinned for both document write forms.

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

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.

Resolved (re-reviewed at 6a1eb498): Replace coverage is now present and checks protocol-15 mempool refusal, unpaid block handling, and successful storage when the replacement uses a byte-encoded value.

Comment on lines +1278 to +1285
#[tokio::test]
async fn should_refuse_unpaid_a_moderator_change_writing_a_byte_array_of_integers_that_are_not_bytes(
) {
let setup = Setup::new_at_with(
Some(moderators_without_lists()),
PlatformVersion::latest(),
|contract| add_document_type(contract, SEAL, seal_schema()),
)

@thepastaclaw thepastaclaw Nov 17, 2026 •

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.

✅ Resolved at 6a1eb498; see the replies below.

🟡 Suggestion: Add protocol-14 regression coverage for moderator byte-array changes

The moderation test uses PlatformVersion::latest() and verifies only the new protocol-15 unpaid path. The change also adds a protocol-15 moderation dispatcher while claiming protocol-14 behavior remains unchanged, but there is no moderator fixture proving that protocol 14 still follows the legacy internal-error/paid behavior for an in-range non-U8 byte-array member. Add the analogous protocol-14 case to document the old-generation compatibility contract.

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

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.

Resolved (re-reviewed at 6a1eb498): The requested protocol-14 moderator regression is now present: the test submits the unreadable byte-array change and asserts that it still ends as an internal error.

@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 17, 2026
The predicate that tells the refusal from other errors now also requires the
empty schema path and property name the refusal is built with, and the batch
and the moderator change are refused unpaid only when the refusal is the
single error of the result. Neither changes a result today.

Tests: a replace writing such a byte array is refused unpaid as a create is,
and at protocol version 14 a moderator change writing one still ends as an
internal error.

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

github-actions Bot commented Nov 17, 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 17, 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

Static review of the current head confirms two blocking correctness defects in the new unpaid-refusal handling. The byte-array walk also inspects transient properties that are removed before persistence, and both the batch and moderator carve-outs can mistake an early single error for the only failure because their delegated validation returns at the first error. CI checks remain in progress; no local builds or tests were run.

🔴 2 blocking

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — The large, intricate diff changes consensus-critical document validation and unpaid batch/moderation refusal behavior in rs-drive-abci, directly affecting which transactions and blocks validators accept.
  • 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.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort xhigh); 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/methods/validate_document/v2/byte_arrays.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/methods/validate_document/v2/byte_arrays.rs:76-81: Do not reject unreadable values in transient properties
  The new walk traverses every declared property without excluding transient fields. Create and replace advanced-structure validation passes the action's original data to `validate_document_properties`, so an optional transient `byteArray` or `identifier` containing `[Value::U64(1)]` is classified as the new refusal. The corresponding document action later removes top-level transient values before constructing the persisted document (`drop_transient_values`), meaning this value can never reach document serialization or state. Protocol-15 create and replace transitions with otherwise valid transient data are therefore rejected unpaid even though the transient value is intentionally not persisted. Run the check on the post-transient-removal representation or skip transient properties, and add create and replace regression coverage.

In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v2/mod.rs`:
- [BLOCKING] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/advanced_structure/v2/mod.rs:69-75: Do not infer a sole failure from a one-element validation result
  Checking `result.errors` for exactly one byte-array refusal does not prove that the refusal is the batch's only paid failure. `validate_advanced_structure_from_state_v1` returns immediately when the first document transition fails, so a batch whose first document has the unreadable-byte refusal and whose later transition has another paid structural failure—such as a token configuration update failing its readonly, tradeability, or compiled-size check—never validates the later transition. The v2 code then removes the nonce-bump action and returns `UnpaidConsensusError` for the whole batch. The mirrored guard in `contract_user_moderation/state/v1/mod.rs` has the same issue: `transform_document_fields_change_v0` returns at the first document-validation error, before later distinctness, encrypted-shape, or uniqueness checks can report a paid failure. Validate all relevant checks before applying the unpaid carve-out, or otherwise establish that no other paid failure remains at both call sites.

Comment on lines +76 to +81
declared.iter().find_map(|(name, property)| {
let member = entries.iter().find_map(|(key, member)| {
matches!(key, Value::Text(key) if key == name).then_some(member)
})?;
path.push(name.clone());
let refusal = in_property(&property.property_type, member, path);

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.

🔴 Blocking: Do not reject unreadable values in transient properties

The new walk traverses every declared property without excluding transient fields. Create and replace advanced-structure validation passes the action's original data to validate_document_properties, so an optional transient byteArray or identifier containing [Value::U64(1)] is classified as the new refusal. The corresponding document action later removes top-level transient values before constructing the persisted document (drop_transient_values), meaning this value can never reach document serialization or state. Protocol-15 create and replace transitions with otherwise valid transient data are therefore rejected unpaid even though the transient value is intentionally not persisted. Run the check on the post-transient-removal representation or skip transient properties, and add create and replace regression coverage.

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

Comment on lines 69 to 75
if !result.is_valid() {
// Only the refusal alone: beside any other error the batch is charged as before
if matches!(result.errors.as_slice(), [error] if is_unreadable_byte_array_refusal(error))
{
return Ok(ConsensusValidationResult::new_with_errors(result.errors));
}
return Ok(result);

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.

🔴 Blocking: Do not infer a sole failure from a one-element validation result

Checking result.errors for exactly one byte-array refusal does not prove that the refusal is the batch's only paid failure. validate_advanced_structure_from_state_v1 returns immediately when the first document transition fails, so a batch whose first document has the unreadable-byte refusal and whose later transition has another paid structural failure—such as a token configuration update failing its readonly, tradeability, or compiled-size check—never validates the later transition. The v2 code then removes the nonce-bump action and returns UnpaidConsensusError for the whole batch. The mirrored guard in contract_user_moderation/state/v1/mod.rs has the same issue: transform_document_fields_change_v0 returns at the first document-validation error, before later distinctness, encrypted-shape, or uniqueness checks can report a paid failure. Validate all relevant checks before applying the unpaid carve-out, or otherwise establish that no other paid failure remains at both call sites.

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Declining: unpaid is the intended result for that batch. check_tx runs this same validation, stops at the same first error and refuses the batch, so whatever else it carries it never belongs in a block; a proposer drops it and validators reject a block holding it. Charging for it would pay a proposer to add what check_tx refused, and the same holds for the moderator change, which the mempool transforms too.

@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 17, 2026
A write drops a transient property, by its top-level name, before the document
is built, so the document serializer never reads its value. The byte reading
of protocol version 15 read it all the same and refused a create or replace
carrying a transient byte array written as a list of integers that are not
bytes, which protocol version 14 accepts. It now skips the properties the
write drops.

Tests: a create and a replace carrying such a transient byte array succeed at
the latest protocol version and at 14.

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

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

@QuantumExplorer
QuantumExplorer merged commit 9da740b into v5.1-dev Nov 17, 2026
8 of 11 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/byte-array-consensus-check-pv15-5b8143 branch November 17, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants