Repository navigation
fix(dpp)!: refuse a byte array of integers that are not bytes from protocol version 15 - #5964
Conversation
…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]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
🔍 Review in progress (commit 24bb1e5) · live progress |
…st (clippy single_match) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
…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]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
…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]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
…b8143 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
criticalbygpt-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); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— tenderdash-consensus-security (completed, effort xhigh); agentphase2-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
byteArraycan 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-U8validation 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.
| /// 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 | ||
| ) |
There was a problem hiding this comment.
✅ 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.
| /// 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)
There was a problem hiding this comment.
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.
| if !result.is_valid() { | ||
| if result | ||
| .errors | ||
| .first() | ||
| .is_some_and(is_unreadable_byte_array_refusal) | ||
| { | ||
| return Ok(ConsensusValidationResult::new_with_errors(result.errors)); |
There was a problem hiding this comment.
✅ 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.
| 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)
There was a problem hiding this comment.
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.
| "members": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "array", | ||
| "byteArray": true, | ||
| "minItems": 32, | ||
| "maxItems": 32, | ||
| "contentMediaType": "application/x.dash.dpp.identifier", | ||
| }, | ||
| "maxItems": 4, | ||
| "position": 3, |
There was a problem hiding this comment.
✅ 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)
There was a problem hiding this comment.
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.
| #[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:?}"), | ||
| } |
There was a problem hiding this comment.
✅ 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)
There was a problem hiding this comment.
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.
| #[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()), | ||
| ) |
There was a problem hiding this comment.
✅ 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)
There was a problem hiding this comment.
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.
|
Bots are done — your move: post |
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]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
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:
criticalbygpt-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); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— tenderdash-consensus-security (completed, effort xhigh); agentphase2-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.
| 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); |
There was a problem hiding this comment.
🔴 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)
| 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); |
There was a problem hiding this comment.
🔴 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)
There was a problem hiding this comment.
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.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
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]>
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
Basic explanation
A document whose byte array property holds a list of integers that are not stored as bytes (for example a JavaScript
Uint8Arraythat 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 abyteArrayproperty made check_tx returnDrive(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 notValue::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 isValue::U8.Before / after
Protocol version 15,
datais{ "type": "array", "byteArray": true }, document{ "data": [U64(1), U64(2), U64(3)] }:Before:
After:
Value::Bytes([1, 2, 3]),[U8(1), U8(2), U8(3)],Value::Identifier(..)andValue::Bytes32(..)are accepted as before.What was done?
validate_document2 (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 (newvalidate_document/v2/byte_arrays.rs).JsonSchemaErrorwith keywordbyteArrayand 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.advanced_structure2, 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.transform_into_action1, selected only by protocol version 15).v15.rs) and thevalidate_document: 2doc indpp_contract_versions/v7.rs.In-place changes to shipped generations
None. Only
validate_document2 is touched, which only the unreleased protocol version 15 selects. Protocol version 14 (validate_document1) is unchanged and a test pins its behaviour.How Has This Been Tested?
cargo test -p dpp --lib validate_document: new tests refuseU64,I8,U16andI64members in a plain byte array, an identifier, a nested object and a list of identifiers, each also failing to serialize; accept bytes,U8lists,IdentifierandBytes32, 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 inshould_validate_documents_at_protocol_version_15_as_at_14now writes[1, 2]asU8members, since anI32list is refused from 15. The predicate takes only the refusal as built (empty schema path and property name), not another error under thebyteArraykeyword.cargo test -p drive-abci --lib byte_array_members: atPlatformVersion::latest()check_tx returns thebyteArrayconsensus 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 aU64list 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.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
U8is kept out of every block at protocol version 15 (unpaid consensus error) as at 14 (internal error). What changes is check_tx's answer, aJsonSchemaError(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-sdkUint8Arrayconversion is tracked separately in #5940.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
24bb1e5/self-reviewedWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit