Skip to content

fix(dpp): read a refersTo as dynamic only where protocol version 14 cannot read it - #5887

Merged
shumkov merged 1 commit into
v5.1-devfrom
shumkov/v51-dynamic-target-document-refs-only
Nov 12, 2026
Merged

shumkov merged 1 commit into
v5.1-devfrom
shumkov/v51-dynamic-target-document-refs-only

Conversation

@shumkov

@shumkov shumkov commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Follow-up to #5849, document references whose target the document names (protocol version 15).

Version 1 of apply_property_reference read a refersTo as naming its target through the referring document whenever its contractId or documentType was a "$self." string, whatever its type. Version 0, which protocol version 14 runs, never reads contractId or documentType on an identity, contract, token or identityPublicKey reference. On a document reference it reads documentType as a plain document type name. So a contract stored before protocol version 15 with these keys on such a declaration loaded at 14 and was refused at 15. With this change it loads as it did.

What was done?

  • Detection (declares_dynamic_target). A declaration now gets the dynamic reading only when version 0 cannot read it at all:

    • a reference to a document (permanentDocument, moderatedDocument or deletableDocument) whose contractId is a "$self." string. That is never an identifier, so version 0 refuses it.
    • a type that is a list. Version 0 reads type only as a string.

    Every declaration version 0 can read is read exactly as version 0 reads it. The same predicate drives the refusal of a dynamic target in an expression operand, on a string or byte array property, on typed-array elements, and in ownerRefersTo / creatorRefersTo, so those narrow the same way.

  • Registration is unchanged. At protocol version 15 the native schema check already refuses these declarations before the parser runs:

    • "$self." keys on a non-document reference: its type must then be permanentDocument or moderatedDocument.
    • a documentType read from the document next to a contractId that is not read from it: contractId is then required and must be "$self." too.

    I kept the refusal in that registration check rather than ignoring the keys there, because a new contract then cannot carry them. Meanwhile the parser itself never refuses them, so loading a stored contract never does.

  • deletableDocument with a "$self." contractId still reaches the dynamic parser, which refuses it with its explicit message. Version 0 refuses it too.

  • Doc comments updated to match: declares_dynamic_target, apply_property_reference_v1, parse_doctype_reference, and note 33 of v15.rs.

How Has This Been Tested?

New tests, red on v5.1-dev and green with the fix:

  • rs-dpp should_load_a_stored_non_document_reference_with_self_target_keys_as_it_did.
    • Covers identity, contract and token references on a property, and an identity reference in an anyOf operand and in ownerRefersTo.
    • Each contract is parsed as protocol version 14 reads a stored contract, serialized, and loaded at the latest version; both read every reference alike. Registration at the latest version refuses each, at the path of its type.
    • Before the fix: invalid contract structure: identity refersTo reads no contractId or documentType from the referring document and takes no documentTypeRequirements: …
  • rs-dpp should_load_a_stored_document_reference_whose_document_type_alone_is_written_self_as_it_did.
    • Covers permanentDocument and moderatedDocument with documentType: "$self.…" and a contractId left out or given as an id, and the same in an anyOf operand.
    • Each loads as version 14 reads it, and registration refuses each on its contractId.
    • Before the fix: invalid contract structure: permanentDocument refersTo naming its target through the referring document reads both contractId and documentType from it: contractId must be "$self.<a top-level property>"
  • drive-abci should_load_judge_and_expire_documents_of_a_contract_registered_at_protocol_version_14_with_self_keys_on_identity_references.
    • A chain at protocol version 14 registers such a contract through a DataContractCreate, then writes an expiring note and refuses a note naming a missing identity.
    • It then runs the first block of protocol version 15. The contract loads. A note is accepted, and one naming a missing identity is refused with the same code as at 14. The note written at 14 expires.
    • Before the fix: the contract should load at the latest protocol version: Protocol(ConsensusError(BasicError(ContractError(InvalidContractStructure("identity refersTo reads no contractId or documentType from the referring document …")))))
  • should_refuse_what_cannot_sit_beside_a_dynamic_target. A contractId given in the schema, or left out, next to a "$self." documentType is now refused by registration rather than by the parser, which reads it as version 0 does. The documentType cases still go through the parser's own refusal.
  • Existing tests. The dynamic reference tests in rs-dpp (dynamic_reference_tests, native_schema) and drive-abci (dynamic_document_reference) pass unchanged.

Commands run:

  • cargo test -p dpp --all-features --lib --tests: 6,096 lib and 44 integration tests passed, the contract corpus loads included.
  • RUST_MIN_STACK=4194304 cargo test -p drive-abci --lib: 4,631 passed.
  • cargo clippy -p dpp -p drive-abci -p platform-version --all-features --all-targets -- -D warnings and cargo fmt --all -- --check: clean.
  • After rebasing onto 78d691dd4e: the try_from_schema tests and the related drive-abci tests again.

Breaking Changes

None. Only protocol version 15 behaviour changes, and protocol version 15 is unreleased and not activated on testnet or mainnet, which both run 14. At 15 no registration verdict changes. A contract stored before 15 with these keys on a declaration version 0 reads now loads, where it was refused.

In-place changes to shipped generations

None. The edited code is reached only through apply_property_reference 1 and the Some(1) arms beside it, which only protocol version 15 selects (CONTRACT_VERSIONS_V7). Protocol version 14 and earlier keep apply_property_reference 0 and never call declares_dynamic_target.

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 · 1fcc98d

  • Bots — thepastaclaw ✓
  • 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.

…annot read it

Version 1 of apply_property_reference (protocol version 15) read a refersTo
as naming its target through the referring document whenever its contractId
or documentType was a "$self." string, whatever its type. Version 0
(protocol version 14) never reads those keys on an identity, contract, token
or identityPublicKey reference, and reads a document reference's
documentType as a type name. A contract stored before protocol version 15
with these keys on such a declaration therefore loaded at 14 and was refused
at 15.

declares_dynamic_target now holds only for a declaration version 0 cannot
read at all: a reference to a document whose contractId is a "$self."
string, or a type that lists kinds. Every other declaration is read as
version 0 read it, so such a contract loads as it did. Registration at 15 is
unchanged: before the parser runs, the native schema check refuses "$self."
keys on a non-document reference, and a documentType read from the document
beside a contractId that is not.

Follow-up to #5849.

Test would have caught this in CI: ✖ before fix, ✔ after:
- should_load_a_stored_non_document_reference_with_self_target_keys_as_it_did
  before: "identity refersTo reads no contractId or documentType from the
  referring document ..."
- should_load_a_stored_document_reference_whose_document_type_alone_is_written_self_as_it_did
  before: "... reads both contractId and documentType from it: contractId
  must be ..."
- should_load_judge_and_expire_documents_of_a_contract_registered_at_protocol_version_14_with_self_keys_on_identity_references
  before: loading the contract at protocol version 15 failed with the
  identity refersTo error

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

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next included review available in 39 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8b4ca80 and 1fcc98d.

Files selected for processing: 6

  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/dynamic_reference_tests.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/stored_non_document_reference.rs
  • packages/rs-platform-version/src/version/v15.rs
  • 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

@github-actions

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

thepastaclaw commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 1fcc98d) · triage: normal

@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

Static verification of head 1fcc98d found no actionable defects. The duplicate-key fixture exercises historical binary-schema behavior intentionally, and the predicate change remains isolated to protocol version 15 while registration restrictions remain unchanged. Current CI shows all executed code checks passing, including the previously queued JavaScript suites; only review and hygiene checks remain pending.

Review provenance

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

  • Triage: normal by gpt-6.1-sol (effort low) — The production change is a small, contained adjustment to declares_dynamic_target in dynamic_reference.rs, with extensive compatibility tests, rather than a large or intricate modification qualifying as critical.
  • 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)
  • 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; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer

@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 12, 2026
@shumkov
shumkov merged commit 97fb5f9 into v5.1-dev Nov 12, 2026
29 of 30 checks passed
@shumkov
shumkov deleted the shumkov/v51-dynamic-target-document-refs-only branch November 12, 2026 11:07
QuantumExplorer added a commit that referenced this pull request Nov 12, 2026
…roposal-contract-1db678

Brings in v5.1-dev at 97fb5f9: a refersTo is read as dynamic only where
protocol version 14 cannot read it (#5887). The merge is clean and no root
pin, fee pin or stored contract fixture line changes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
QuantumExplorer added a commit that referenced this pull request Nov 12, 2026
…ecision-proposal-description-reference

Brings in v5.1-dev at 97fb5f9: a refersTo is read as dynamic only where
protocol version 14 cannot read it (#5887).

The one conflict is protocol version 15 note 33, where both sides added a
sentence: it keeps this branch's use of the reference by the decision
proposals contract and the base's statement of which declarations version 1
reads as dynamic. The parser and its tests merge cleanly: the description
reference is a `moderatedDocument` whose `contractId` is written `$self.`,
which stays dynamic. No root pin, fee pin or stored contract fixture line
changes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants