Repository navigation
fix(dpp)!: refuse updating a contract whose stored schema repeats a key (PV15) - #5947
Conversation
…ey (PV15) From protocol version 15 registration already refuses a document type schema, or the contract's `$defs`, that names a key twice in any object. A contract stored earlier may still hold one. `DataContract::validate_update` generation 2, selected only by protocol version 15, runs generation 1 once no stored document type schema (with the stored `$defs` its parse reads) repeats a key, using the same walk as registration, and refuses the update with `DocumentTypeUpdateError` otherwise. Also adds regression tests for the registration refusal: a repeated key in either order at the root, in a nested object, in an array's `items`, in an index and in a definition, and contract create and update in a block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ad it once (PV15) Follow-up to the refusal of an update of a contract whose stored schema repeats a key (`validate_update` 2, protocol version 15 only): - the stored `$defs` are walked once, not once per document type, and a key they repeat is reported on the contract (`DataContractUpdateActionNotAllowedError`) instead of on whichever document type sorts first; a type's own schema is still reported on the type (`DocumentTypeUpdateError`); - the walk is split into `first_repeated_key_of_schema` and `first_repeated_key_of_definitions`, which share the wording of the place with registration's refusal; - generation 1's tests are pinned to protocol version 14; - the version gate is tested by behaviour on both sides of it; - a block test registers the contract under protocol version 14, runs the first block of the latest version and updates it; - the block test fixture registers its starting schema under full validation again; - the wasm `validateUpdate` doc names the rule. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
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 not started yet because the new head is waiting for the 30-minute push debounce.
Commit 1da8a51. Normal review starts when eligible; priority review starts as soon as a slot is available. |
|
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 2 only (queue backlog)
The protocol-15 validation generation correctly preserves earlier behavior, but the duplicate-key invariant is incomplete and the new stored-schema scan is not included in processing-fee accounting. A version-snapshot comment also omits the newly selected validation generation. CI has no reported code failures; Kotlin SDK and PR hygiene checks remain pending.
🔴 3 blocking | 🟡 1 suggestion(s)
2 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Token-only contract creation bypasses the duplicate-key check
packages/rs-dpp/src/data_contract/document_type/class_methods/create_document_types_from_document_schemas/v1/mod.rs:44-48
Protocol 15 permits an empty documentSchemas map when has_tokens is true. The new duplicate-key check is invoked from the per-document-type parser, so the loop beginning at line 65 is skipped for a token-only contract and the contract-level $defs are never traversed. validate_schema_patterns does not reject repeated map keys; it only counts pattern values. Consequently, a raw token-only contract with a repeated key inside a $defs value can pass full validation and be stored, even though the PR claims registration refuses duplicate keys in the contract's $defs. Run the shared contract-level definitions walk before the document-type loop and account for its reads consistently.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality, security-auditor)
🟡 Suggestion: Snapshot comment omits the newly selected validate_update generation
packages/rs-platform-version/src/version/v15.rs:957
CONTRACT_VERSIONS_V7.methods.validate_update changes from generation 1 to generation 2 in this PR, but the PLATFORM_V15.contract_versions // changed: comment lists the other contract-version changes without mentioning validate_update. The version selection is correct and this does not affect consensus, but the snapshot comment is incomplete for auditing the protocol-15 behavior. Add the new validate_update 2 change and its note reference to this comment.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality, security-auditor)
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: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is a large change to consensus-critical contract validation and protocol-version dispatch in rs-dpp and rs-drive-abci, changing which state transitions are accepted at protocol version 15. - Phase 1 reviewers: not run (skipped for throughput: 12 PRs queued, above the 10 limit)
- Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
- 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— 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
🤖 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_update/v2/mod.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/methods/validate_update/v2/mod.rs:37-42: Token configuration updates bypass the stored-schema check
`validate_update_v2` is reached by the ordinary `DataContractUpdateTransition` state-validation path, but token configuration updates use a separate batch-action path. That path validates token-specific authorization and state rules, then `updated_contract()` increments the contract version and changes the token configuration; the operation converter subsequently emits `ApplyContract` for that copy. It never calls this stored-schema gate. Therefore, on protocol 15, a legacy contract whose stored document schema or `$defs` contains a repeated key can still be changed and re-stored through a token configuration update, contradicting the PR's stated invariant that no such contract can be changed. Apply the shared, versioned stored-schema check to the token-update validation path without duplicating the traversal.
- [BLOCKING] packages/rs-dpp/src/data_contract/methods/validate_update/v2/mod.rs:50-56: The stored-schema validation walk is not charged
Every protocol-15 update now recursively scans all stored document schemas and stored `$defs`, but `validate_update_stored_schemas_repeat_no_key` only increments `read` and then discards it. The production ordinary-update caller adds the GroveDB fetch fee and later charges validation operations for parsing and compiling the submitted contract, but it emits no operation for this additional in-memory traversal of the old contract. The fetch fee accounts for storage access, not the CPU work of walking the stored values, so a large valid legacy contract can impose an uncharged O(stored-contract-size) scan; the paid refusal path is likewise undercharged. Extend the versioned validation/cost interface with an explicit operation for this walk and propagate it through the execution context so estimation and execution charge the same work.
In `packages/rs-dpp/src/data_contract/document_type/class_methods/create_document_types_from_document_schemas/v1/mod.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/document_type/class_methods/create_document_types_from_document_schemas/v1/mod.rs:44-48: Token-only contract creation bypasses the duplicate-key check
Protocol 15 permits an empty `documentSchemas` map when `has_tokens` is true. The new duplicate-key check is invoked from the per-document-type parser, so the loop beginning at line 65 is skipped for a token-only contract and the contract-level `$defs` are never traversed. `validate_schema_patterns` does not reject repeated map keys; it only counts pattern values. Consequently, a raw token-only contract with a repeated key inside a `$defs` value can pass full validation and be stored, even though the PR claims registration refuses duplicate keys in the contract's `$defs`. Run the shared contract-level definitions walk before the document-type loop and account for its reads consistently.
In `packages/rs-platform-version/src/version/v15.rs`:
- [SUGGESTION] packages/rs-platform-version/src/version/v15.rs:957: Snapshot comment omits the newly selected validate_update generation
`CONTRACT_VERSIONS_V7.methods.validate_update` changes from generation 1 to generation 2 in this PR, but the `PLATFORM_V15.contract_versions` `// changed:` comment lists the other contract-version changes without mentioning `validate_update`. The version selection is correct and this does not affect consensus, but the snapshot comment is incomplete for auditing the protocol-15 behavior. Add the new `validate_update 2` change and its note reference to this comment.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…, scope the rule to updates that submit schemas The `contract_versions` comment of `PLATFORM_V15` listed every change of `CONTRACT_VERSIONS_V7` but `validate_update` 2. Generation 2's doc comment said a contract stored with a repeated schema key stays as it was stored: its schemas do, a token configuration update still changes its token configuration. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Replies to the two findings of the PastaClaw review that have no inline thread:
|
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
Basic explanation
From protocol version 15, registration refuses a document type schema, or contract
$defs, that names a key twice in one object (#5702). A contract stored before protocol version 15 may still hold such a schema. This PR completes the rule: from protocol version 15 a data contract update of a contract whose stored schema or stored$defsrepeat a key is refused, so no document type can be registered with a repeated schema key and none stored with one can have its schema replaced.Scope: the rule covers the
$defsa document type's parse reads, so the$defsof a contract without document types are stored as sent, as before. A token configuration update submits no schema and stores the stored schemas as they are, so it is not refused.No JSON can express a repeated key, so only a contract built from a raw value map can hold one. None of the 81 contract create and update transitions on mainnet, or the 5,026 on testnet, carries such a schema (checked 2026-11-16), so the rule touches no existing contract.
What was done?
DataContract::validate_updategeneration 2, selected byCONTRACT_VERSIONS_V7(protocol version 15) only: it walks the stored document type schemas and the stored$defsonce, refuses the update when one repeats a key, then runs generation 1.first_repeated_key_of_schemaandfirst_repeated_key_of_definitions, shared by both; registration's refusal and its message are unchanged.rs-platform-versionname the rule.Issue being fixed: before and after (
PlatformVersion::latest())A contract stored with a document type whose schema names
propertiestwice, then any update of it:DocumentTypeUpdateError(40212), "its stored schema declarespropertiesmore than once at its root, and a contract whose schema repeats a key can not be updated"$defsrepeat a keyDataContractUpdateActionNotAllowedError(40004), "update a contract whose stored$defsdeclarepropertiesmore than once at$defs.word"At protocol version 14 and earlier nothing changes.
Public interface changes
A data contract update can now fail, from protocol version 15, with
DocumentTypeUpdateError(40212) when a stored document type schema repeats a key, orDataContractUpdateActionNotAllowedError(40004) when the stored$defsdo.Both codes exist already; only a new cause is added.
DataContract.validateUpdatein wasm-dpp2 returns the same errors (it calls the same check); its doc comment names the rule.No wire format, storage format or SDK signature changes.
In-place changes to shipped generations
None. Generations 0 and 1 of
validate_updateare untouched; generation 1's tests are now pinned to protocol version 14.Breaking Changes
Consensus change at protocol version 15 (unreleased): an update that earlier versions judge by the usual update rules is refused when the stored contract repeats a schema key.
How Has This Been Tested?
cargo test -p dpp --lib -- validate_update repeated_doctype_key(154 passed): generation 2 refuses a stored repeat at the root, nested and in$defs, reports a type's schema before the$defs, admits a stored schema naming each key once, and the dispatcher admits the same update at protocol version 14 and refuses it at the latest.cargo test -p drive-abci --lib -- data_contract_update repeated_properties_update(87 passed), including a block test that registers the contract under protocol version 14, runs the first block of the latest version, and updates it: the update is refused and paid, and the stored contract is unchanged.cargo clippy -p dpp -p drive-abci --lib --testsclean.Not run locally: the strategy tests and the full suites.
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 ·
1da8a51/skip-botsproceeds without the ones not yet reported/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
$defs.$defs.