Skip to content

feat(platform)!: either-kind targets and slot conditions for document-named references (PV15) - #5850

Merged
QuantumExplorer merged 17 commits into
v5.1-devfrom
claude/dynamic-refers-to-when
Nov 11, 2026
Merged

QuantumExplorer merged 17 commits into
v5.1-devfrom
claude/dynamic-refers-to-when

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: #5849 lets a document point at a document of whatever contract and document type it names, as long as that type "looks right" (for example, it has a text field). This adds two things to that. The pointer may accept a document that is never removed or one that moderators can remove, instead of having to pick one. And the contract may add a condition on the field it is looking for, such as "if moderators can remove these documents, the text must go away with them".

Value: A proposal can take its description from a text hosted anywhere, and be sure of one of two things: the text stays for good, or moderators can take it down completely. What it rules out is a text that stays public after moderators removed the document, or a text field only moderators write.

Risks: Low to medium. It changes consensus at protocol version 15 only, which is unreleased, and only for the references #5849 adds. The condition is a new nested type stored in contracts and carried in consensus errors, so its decoding is depth limited and its size is capped at 16 conditions. It changes the stored form of a type #5849 introduced (merged, unreleased), so it must ship in the same protocol version, and it adds a small processing fee for judging the named type (100 credits a comparison, at most 680,000 for one reference). No full test suite, JS build or mobile build was run locally.

Issue being fixed or feature implemented

With #5849 a reference naming its target through the referring document is permanentDocument or moderatedDocument, and a documentTypeRequirements slot describes a property by name, type and size. Two things could not be said:

  • "a permanent or a moderated document, either is fine";
  • "the string must be one a removal takes with the document", which only means something when the type is a moderated one. A moderated type can keep fields public in its removal record (moderatorAbilities.deleteKeepsFields) and can reserve fields for moderators (moderatorAbilities.changeFields); a description held in either is not a text its author wrote that moderation can take down.

#5849 is merged; this is based on v5.1-dev, with it merged in.

What was done?

The vocabulary

type may list both kinds, and a slot may carry when:

"descriptionId": {
  "type": "identifier",
  "refersTo": {
    "type": ["permanentDocument", "moderatedDocument"],
    "contractId": "$self.descriptionContractId",
    "documentType": "$self.descriptionDocumentType",
    "documentTypeRequirements": {
      "properties": {
        "body": {
          "name": "$any",
          "type": "string",
          "when": {
            "ifThen": [
              { "equal": ["$kind", { "const": "moderatedDocument" }] },
              { "allOf": [
                { "not": { "contains": ["$moderatorAbilities.deleteKeepsFields", "$property"] } },
                { "not": { "contains": ["$moderatorAbilities.changeFields", "$property"] } }
              ] }
            ]
          }
        }
      }
    }
  }
}

when is written like a propertyConstraints condition and read against the referenced type's schema, never a document.

Operand Reads
"$kind" the kind of the referenced type: permanentDocument or moderatedDocument
"$property" the name of the property tried for the slot ($self is the referring document, which a when does not read)
"$moderatorAbilities.deleteKeepsFields" the type's list of fields a removal record keeps, empty when it has none
"$moderatorAbilities.changeFields" the type's list of fields only moderators write, empty when it has none
{ "const": "<string>" } the string

Conditions: equal, notEqual, in, notIn, contains, not, anyOf, allOf, ifThen, ifThenElse, with the same shape rules as in propertyConstraints (two or more operands, none listed twice, no combinator directly inside itself, no not of not or notIn). A property the condition does not hold for does not fill the slot; distinctFrom, require and the search for an assignment work as before over what is left.

Where it lives

  • rs-dpp: DynamicDocumentReferenceKind::PermanentOrModerated with checked_as, which gives the kind a reference is checked as from the kind the named type is. RequiredPropertySlot::when, a SlotCondition (new property/slot_condition.rs) judged by DocumentTypeRequirements::met_by for each candidate property. The parser (try_from_schema/dynamic_reference.rs) and the native schema check read the list and the condition.
  • SlotConditions, the list a condition holds inside it, decodes through a hand-written decoder that refuses a nesting past MAX_SLOT_CONDITION_DECODE_DEPTH (16), the way ReferenceOperands does for reference expressions: the condition is embedded in a reference target, which consensus errors carry to clients.
  • rs-platform-version: max_document_type_requirement_condition_nodes (16) and max_document_type_requirement_condition_text_length (256) in SystemLimits, backfilled; requirement_credits_per_comparison (100) in the document reference fee group; note 33 of protocol version 15 extended.
  • rs-drive-abci: document_reference_validation 1 settles the reference's kind once the named type is known, and bills the judging of the named type before it judges it: 100 credits for each property a slot tries and for each node of the slot's when for that property (DocumentTypeRequirements::comparisons), so a write refused with 40153 pays for it too.
  • wasm-dpp2: the declaration is described with its type list and each slot's when, with TypeScript types. The shape of a when is rs-dpp's (SlotCondition::to_schema_value, which the parser reads back), like the rest of the requirements since the review of feat(platform)!: document references whose target the document names (PV15) #5849.
  • Book: "A Target the Document Names" gains "Either kind" and "A condition on the property (when)"; the keyword and limit tables and the internals section follow.

Before and after

A note pointing at a document of a type it names, under the declaration above:

                                                        #5849 (one kind, no when)      this PR
The type is permanent, with a string property:          moderatedDocument: 40143       accepted
The type is moderated, removal takes its string:        accepted                       accepted
The type is moderated, its only string is kept
  by the removal record (deleteKeepsFields):            accepted                       40153
The type's documents can be deleted by their owner:     40143 (or 40122)               40122

After a moderator removes the post a note points at, with the either-kind declaration:

Editing another property of the note:   accepted (the reference resolves to the removal record)
A new note naming the removed post:     ReferencedEntityNotFoundError (40120)

A declaration that does not parse:

"type": ["permanentDocument", "deletableDocument"]              refused: the list is the two kinds, once each
"type": ["permanentDocument", "moderatedDocument"] with
  "documentType": "post" (a target named in the schema)         refused: such a reference is of one kind
{ "equal": ["$kind", { "const": "moderated" }] }                refused: not the name of a kind
{ "equal": ["title", { "const": "title" }] }                    refused: a condition reads the type, not a document
a when of 17 conditions                                         refused: at most 16

Choices a reviewer may want to question

  • $kind compares only with permanentDocument or moderatedDocument. A misspelt kind would otherwise make a condition that silently never holds.
  • An either-kind reference into a type whose documents can be deleted is refused with 40122, the error of a permanentDocument reference, since the declaration has no kind of its own to name in an error.
  • The requirements are judged before the kind, as in feat(platform)!: document references whose target the document names (PV15) #5849. So a deletable type that also fails a slot gets 40153, not 40122. Either way it is refused.
  • contains matches a whole entry of the list against the property name. A slot is only ever filled by a top-level scalar property, so a nested path in deleteKeepsFields never names one.
  • One when holds at most 16 conditions, counted with their combinators and with each string an in or a notIn lists, and no string in it is longer than 256 characters. The example above is 7. The limit also bounds the nesting, which is why it sits at the decode bound and a test holds every protocol version's limit to it.
  • A when reads the type only. It cannot read a value of the referenced document, so "the document actually has text" is still not expressible.

How Has This Been Tested?

Targeted runs only, on macOS:

  • cargo test -p dpp --lib --features all-system_contracts,fixtures-and-mocks,validation -- data_contract consensus: 3308 passed. New in try_from_schema/v3/dynamic_reference_tests.rs (8 tests: the type list and its refusals, the kind a reference is checked as, every form of a condition, every malformed condition, the node limit, a condition narrowing what fills a slot, a moderated type against a permanent one with real moderatorAbilities, and the platform serialization round trip) and in property/slot_condition.rs (5 tests: evaluation of every form, the round trip through every decoder, the refusal past the decode bound with nesting claimed by hand, and the limit held within the bound).
  • RUST_MIN_STACK=16777216 cargo test -p drive-abci --lib -- reference referenced_rules data_contract_create data_contract_update: 434 passed (with typed_array_where added to the filter). New in contract_user_moderation/tests/dynamic_document_reference.rs: should_check_a_reference_of_either_kind_as_the_kind_the_named_type_is (a moderated type whose text a removal takes, one whose removal record keeps it, a permanent type, a deletable type, a missing document, the reference kept after a removal, and a replace pointing it at a permanent type). The larger stack is for an existing contract-creation test that overflows the default test stack in a local debug build.
  • cargo test -p wasm-dpp2 --lib -- consensus_error document_type_reference, cargo test -p platform-version: passed.
  • cargo clippy --all-targets --all-features --locked -- --no-deps -D warnings on dpp, drive-abci, platform-version, wasm-dpp2 and wasm-dpp: clean. cargo check on dash-sdk and drive-proof-verifier: clean.

Not run: any full suite, the JS and wasm32 builds, the mobile builds. The JS boundary tests added to DocumentPropertyReference.spec.ts (the kind list, a nested when, a __proto__ slot) were written and syntax-checked but not run locally: there is no wasm build of this branch here, so CI is their first run.

In-place changes to shipped generations

Everything this PR reads or writes is reached only through apply_property_reference 1 and document_reference_validation 1, which CONTRACT_VERSIONS_V7 and DRIVE_ABCI_VALIDATION_VERSIONS_V11 (protocol version 15, unreleased) alone select, and which #5849 introduces.

Edited Selected by Why consensus cannot change there
SystemLimits every protocol version Two new fields, backfilled, read by apply_property_reference 1 and check_document_type_schema 1 only
FEE_DOCUMENT_REFERENCE_VERSION1, the fee group every fee schedule shares every protocol version A new field, requirement_credits_per_comparison, read by document_reference_validation 1 only, the way where_list_credits_per_element was added to it
tuple in the native schema check of constraints (visibility only) protocol version 15 No behaviour change; the native check is selected by protocol version 15 alone

DynamicDocumentReferenceKind gains a variant and RequiredPropertySlot a field. Both types were introduced by #5849, now on v5.1-dev and unreleased, so no released protocol version has stored either; this must reach v5.1-dev before protocol version 15 is released.

Breaking Changes

Consensus changes at protocol version 15 only: a refersTo naming its target through the referring document may list both kinds and its slots may carry when. Protocol version 14 and earlier are unchanged.

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 · b8b5a39

  • Bots — thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Build green
  • 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.

QuantumExplorer and others added 2 commits November 11, 2026 04:40
…(PV15)

A `permanentDocument` or `moderatedDocument` `refersTo` on an identifier
property may leave its target to the referring document: `contractIdProperty`
and `documentTypeProperty` name the properties holding the contract and the
document type, in place of `contractId` and `documentType`, and
`documentTypeRequirements` says what the named type must look like: named
slots, each a property it must have (`name`: `"$any"`, a property name, or a
name read from the referring document; `type`; `maxBytes`; `distinctFrom`),
and `require`, `anyOf` / `allOf` over slot names.

Version 1 of `apply_property_reference` (protocol version 15) parses the
declaration to `DocumentPropertyReferenceTarget::DynamicDocument`, appended,
and refuses its keys wherever else a reference sits. Nothing about the
target is known at registration, so `document_reference_validation` 1 checks
it when a document is written: the contract and the type exist, the type is
not private, meets the requirements
(`ReferencedDocumentTypeRequirementNotMetError`, 40153) and is of the
declared kind, and the document exists. A replace checks the reference
again when its value or a property it reads the target from changed.

Protocol version 14 and earlier keep `apply_property_reference` 0, which
does not read the keys.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…-named references (PV15)

A refersTo naming its target through the referring document may list both
kinds, ["permanentDocument", "moderatedDocument"]: the named type is then
either, and the reference is checked as one of the kind the type is.

A documentTypeRequirements slot may carry `when`, a condition in the forms
of a propertyConstraints condition read against the referenced type:
$kind, $self, $moderatorAbilities.deleteKeepsFields,
$moderatorAbilities.changeFields and { "const": ... }. A property the
condition does not hold for does not fill the slot. So a contract can ask
that a text it points at is one a moderator's removal takes away, only
when the type is a moderated one.

The condition is stored in the compiled contract and carried by consensus
errors, so its decoders refuse a nesting past 16, and the parser holds one
`when` to max_document_type_requirement_condition_nodes (16).

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

coderabbitai Bot commented Nov 10, 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 20 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 40b76db and b8b5a39.

Files selected for processing: 25

  • book/src/contract-keywords.md
  • book/src/contract-keywords/refers-to-dynamic.md
  • book/src/data-model/documents.md
  • 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/native_schema/constraints.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/native_schema/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/native_schema/references.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/dynamic_reference_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/property/dynamic_document_reference.rs
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/property/slot_condition.rs
  • packages/rs-dpp/src/errors/consensus/state/document/referenced_entity_not_found_error.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v1/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/contract_user_moderation/tests/dynamic_document_reference.rs
  • packages/rs-platform-version/src/version/fee/document_reference/mod.rs
  • packages/rs-platform-version/src/version/fee/document_reference/v1.rs
  • packages/rs-platform-version/src/version/mocks/v2_test.rs
  • packages/rs-platform-version/src/version/system_limits/mod.rs
  • packages/rs-platform-version/src/version/system_limits/v1.rs
  • packages/rs-platform-version/src/version/system_limits/v2.rs
  • packages/rs-platform-version/src/version/system_limits/v3.rs
  • packages/rs-platform-version/src/version/system_limits/v4.rs
  • packages/rs-platform-version/src/version/v15.rs
  • packages/wasm-dpp2/src/data_contract/document_type_reference.rs
  • packages/wasm-dpp2/tests/unit/DocumentPropertyReference.spec.ts
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • 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 10, 2026 •

Copy link
Copy Markdown
Contributor

📖 Book Preview built successfully.

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

Updated at 2026-11-11T13:36:42.548Z

@thepastaclaw

thepastaclaw commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

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

QuantumExplorer and others added 4 commits November 11, 2026 06:43
…n reference inputs

Review of the references whose target the document names:

- A document naming an indexOnly document type is refused, paid, with
  ReferencedDocumentTypeIndexOnlyError (40146) before anything is fetched.
  Drive refuses to fetch such a document by its id, which failed the
  transition with an internal error and no fee.
- The properties a dynamic reference reads its target from (the contract
  id, the document type name, a slot's name property) can no longer be
  listed under moderatorAbilities.changeFields: a moderator's change checks
  no reference again.
- A rule reading through a dynamic reference is refused with a message
  that says why.
- The schema shape of documentTypeRequirements is written by rs-dpp
  (to_schema_value, which the parser reads back); wasm-dpp2 delegates.
- A replace changing a slot's name property is covered by a test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…-when

Brings in the review fixes of the base: the indexOnly refusal (40146), the
reference inputs a moderator may not write, the rule message, and the
schema shape of documentTypeRequirements written by rs-dpp.

A slot's `when` follows that shape into rs-dpp
(SlotCondition::to_schema_value, which the parser reads back), so
wasm-dpp2 no longer builds it itself.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The message refusing a refersTo that names its target through the
referring document on a property that is not an identifier held a run of
spaces where its two lines join. It travels in a consensus error, so it is
fixed before protocol version 15 ships, and its test now holds the whole
sentence.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…laude/dynamic-refers-to-when

Brings in the restored line continuation of a dynamic reference refusal.

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

@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 PV15 activation and layer ownership are consistent with the intended feature, but the new condition evaluation adds repeated validation work without corresponding processing charges. Three non-blocking findings cover consensus-error payload bounds, protocol-limit ownership, and WASM boundary coverage. This was a static review of head 60eef82; current CI has no failed checks, with Kotlin and book checks passing, but provides no Rust or wasm32 validation results.

🔴 1 blocking | 🟡 3 suggestion(s)

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: ffi-engineer); 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-astra (agent: phase2-reviewer, role: general); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 10: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 11: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 12: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 13: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 14: 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 intricate diff adds schema-condition parsing and evaluation in packages/rs-dpp/src/data_contract/document_type/property/slot_condition.rs and changes consensus-enforced document-reference acceptance in packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v1/mod.rs.
  • 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 — ffi-engineer (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-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort xhigh); agent phase2-reviewer
  • Model comparison: every Phase-2 reviewer also ran on gpt-6-astra; the verifier weighed both sets without knowing which model wrote which
🤖 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/document_type/property/dynamic_document_reference.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/document_type/property/dynamic_document_reference.rs:436-445: Charge for repeated slot-condition evaluation
  Every candidate property admitted by a slot now evaluates its `when` tree. The 16-node cap bounds one tree, not the total work: each reference can have four slots, wildcard slots scan the target type's properties, and a document can carry up to 256 references. References naming the same target share the existing contract/document fetch charges but repeat these evaluations; a same-contract requirements failure also returns before a document fetch adds any charge. `met_by` reports only a boolean, and its caller in `document_reference_validation/v1/mod.rs` records no operation for this added work. Consequently, increasing condition complexity and repeating references increases validation CPU without a corresponding processing fee. The existing `bill_where_list_elements` path already accounts for analogous repeated comparison work. Expose deterministic evaluation-work counts from DPP and bill them in Drive-ABCI through the named PV15 fee schedule, including rejection paths and the applicable fee-estimation treatment, with fee regression coverage.

In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs:544-558: Keep admitted condition payloads within the consensus-error decoder budget
  Membership lists have no aggregate-size bound, so a valid new condition can exceed the shared client error-decoding budget. For example, `in` comparing `$self` against a list containing `text` and nine distinct 256-character ASCII strings passes this parser and consumes only one condition node; a target with a string property named `text` satisfies it. If the referenced document is missing, `document_reference_validation/v1/mod.rs` embeds the complete declaration in `ReferencedEntityNotFoundError`. Those strings alone exceed the 2000-byte limit on `ConsensusError`, whose generated untrusted deserializer uses `with_limit::<2000>()`. Both WASM error deserializers and the Rust SDK's gRPC-error conversion use that bounded decoder, so consumers receive a decoding failure instead of the intended 40120 consensus error. Reconcile the admitted declaration size with the shared error budget in Rust, through a compact error representation or a suitable aggregate bound, and add an admitted-condition error round-trip regression. The node/depth limit does not constrain total string bytes.
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs:44-46: Put the slot-condition string-length limit in SystemLimits
  The 256-character cap controls protocol admission for condition constants and membership-list entries, rather than representing an invariant encoding width. The native schema checker independently repeats it in `slot_condition` and `slot_condition_string`. The book assigns numeric protocol limits to `rs-platform-version` and requires version-selected `SystemLimits` values, so these checks should read one named field instead of separate implementation literals. Add the field, populate the historical and mock tables, and use the active snapshot in both validation paths. The bounds agree today and are reached only through PV15, so this is a maintainability issue rather than a current historical-consensus regression.

In `packages/wasm-dpp2/src/data_contract/document_type_reference.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/data_contract/document_type_reference.rs:964-977: Test either-kind declarations and nested conditions across the WASM boundary
  The DPP tests cover parsing and schema-value round trips, but none exercises the new JavaScript `type` array or the conversion of slot `when` objects through `platform_value_to_object`. `DocumentPropertyReference.spec.ts` contains no dynamic-reference fixture, and the PR explicitly identifies this conversion as untested. Extend that suite with a PV15 declaration containing both kinds and a nested `when`, then assert that `documentTypeReferences()` returns the exact two-element array and preserves the condition object. Include a single-kind declaration to protect the existing string representation and a `__proto__`-named slot to exercise the own-property conversion with the new condition payload.

QuantumExplorer and others added 8 commits November 11, 2026 15:35
Second review of the references whose target the document names:

- `require` is judged on every write that checks the reference, and only
  the number of slots was bounded. It now names nothing twice: no term, no
  slot within a group, no group with its slots in another order. With at
  most four slots that is at most fifteen terms, where a contract could
  repeat one slot thousands of times.
- The book's rule for which property fills which slot now starts by
  choosing the set of slots, as consensus does, so a client reads every
  reference Platform accepts.
- A test makes the assignment search take a property back and then
  succeed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…laude/dynamic-refers-to-when

Brings in the second review's fixes of the base: `require` names nothing
twice, the book's client assignment rule chooses the set of slots first,
and a test of the assignment search taking a property back.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…Id and documentType

A refersTo whose target the referring document names no longer has keys of
its own for it. It writes the keys every document reference has, read from
the document:

    "contractId": "$self.descriptionContractId",
    "documentType": "$self.descriptionDocumentType"

in place of contractIdProperty and documentTypeProperty. `$self` is the
document being written, as `$old` is the stored one in a rule. A slot's
name read from the document follows: "$self.bodyProperty" in place of
{ "property": "bodyProperty" }.

Both are read from the document or neither: one of them literal, or left
out, beside the other is refused, as is documentTypeRequirements beside a
target the schema names. Protocol version 14 gives the prefix no meaning
and refuses such a declaration. What is stored is unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…laude/dynamic-refers-to-when

Brings in the target read through `$self.` on contractId and documentType,
and a slot name read as "$self.<property>".

With `$self` now the referring document, the operand of a slot's `when`
that reads the property tried for the slot is renamed `$property`:

    { "not": { "contains": ["$moderatorAbilities.deleteKeepsFields", "$property"] } }

so each word means one thing in a declaration. `$self` in a `when` is
refused: a condition on the referenced type does not read the referring
document.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A string property declaring both maxLength and maxBytes was held to its
maxBytes alone when a slot's maxBytes was checked, so one of at most two
characters (eight bytes) with a maxBytes of 100 failed a slot of eight
bytes it can never exceed. The bound is now the smaller of maxBytes and
four bytes a character of maxLength.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…laude/dynamic-refers-to-when

Brings in the tighter of a string property's two bounds when a slot's
maxBytes is checked.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…rors decodable

Review of the references whose target the document names:

- Only a contractId or documentType written "$self.<property>" selects
  the reading this version adds. A contract stored under an earlier
  protocol version is parsed again whenever it is loaded, and a
  declaration naming its target in the schema could carry a
  documentTypeRequirements key that version never read: it made the stored
  contract fail to load. The key stays unread on a load and is refused at
  registration, by the native schema check.
- ReferencedEntityNotFoundError carries such a target without its
  requirements. A declaration can be larger than the 2000 bytes a client
  decodes a consensus error within, and the requirements say nothing of a
  missing document.
- The wasm description of a document-named target, its requirements and a
  slot named __proto__ are covered at the JS boundary.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…laude/dynamic-refers-to-when

Brings in the reading of stored references as registered, the error that
carries a document-named target without its requirements, and the wasm
boundary tests of the base.

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

@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

The current head incorporates the $self. target spelling and tighter string-slot bounds while preserving the unreleased PV15 activation boundary; no additional issue was confirmed beyond the four carried findings. Verification was static against 2d7a341, without running builds or tests. Current CI reports Kotlin tests and the book preview passing, no failed code checks, and the review check pending; it provides no Rust or WASM test results.

🔴 1 blocking | 🟡 3 suggestion(s)

Still open from earlier rounds (4)

  • 🔴 Blocking: Charge for repeated slot-condition evaluation — packages/rs-dpp/src/data_contract/document_type/property/dynamic_document_reference.rs:462-471 (thread)
  • 🟡 Suggestion: Keep admitted condition payloads within the consensus-error decoder budget — packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs:549-564 (thread)
  • 🟡 Suggestion: Put the slot-condition string-length limit in SystemLimits — packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs:53-55 (thread)
  • 🟡 Suggestion: Test either-kind declarations and nested conditions across the WASM boundary — packages/wasm-dpp2/src/data_contract/document_type_reference.rs:964-977 (thread)
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: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The large, intricate change adds slot-condition evaluation and either-kind reference matching in rs-dpp's dynamic_reference.rs and slot_condition.rs and changes consensus document-reference validation in rs-drive-abci's document_reference_validation/v1/mod.rs.
  • 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 — ffi-engineer (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
🤖 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/document_type/property/dynamic_document_reference.rs`:
- [BLOCKING] packages/rs-dpp/src/data_contract/document_type/property/dynamic_document_reference.rs:462-471: Charge for repeated slot-condition evaluation
  (carried; thread: https://github.com/dashpay/platform/pull/5850#discussion_r4532867450)

In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs:549-564: Keep admitted condition payloads within the consensus-error decoder budget
  (carried; thread: https://github.com/dashpay/platform/pull/5850#discussion_r4532867464)
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/dynamic_reference.rs:53-55: Put the slot-condition string-length limit in SystemLimits
  (carried; thread: https://github.com/dashpay/platform/pull/5850#discussion_r4532867474)

In `packages/wasm-dpp2/src/data_contract/document_type_reference.rs`:
- [SUGGESTION] packages/wasm-dpp2/src/data_contract/document_type_reference.rs:964-977: Test either-kind declarations and nested conditions across the WASM boundary
  (carried; thread: https://github.com/dashpay/platform/pull/5850#discussion_r4532867481)

Base automatically changed from claude/dynamic-refers-to to v5.1-dev November 11, 2026 11:32
@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

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 the waiting-self-review Waiting for the author to post /self-reviewed label Nov 11, 2026
QuantumExplorer and others added 2 commits November 11, 2026 18:35
Review of the either-kind targets and slot conditions:

- Judging the document type a reference names against its
  documentTypeRequirements is billed by the comparisons it may take
  (each property a slot tries, and each node of the slot's `when` for it),
  100 credits each, before the type is judged, so a write refused for a
  type that does not meet them pays for it too. The work grows with the
  type's properties, the slots and their conditions, and nothing was
  charged for it.
- Each string an `in` or a `notIn` lists counts toward the node limit of
  a `when`, checked before the list is read: one condition could otherwise
  hold any number of them.
- The length of a string a `when` is written with is a SystemLimits value,
  read by the parser and by the native schema check, in place of a literal
  repeated in both.
- The kind list and nested conditions are covered at the JS boundary, and
  the spec casts a property before reading its reference, which the
  type-checked run of the base's spec needs.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…fers-to-when

The references whose target the document names are merged into v5.1-dev
(#5849), which this branch is now based on. Every file this branch touches
holds on v5.1-dev exactly what this branch already merged from that pull
request's head, so each keeps this branch's version; the rest of v5.1-dev
comes in unchanged.

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

github-actions Bot commented Nov 11, 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 11, 2026
…fers-to-when

Brings in the keys with a budget or an expiry that sign no data contract
(#5861). No conflict.

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

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

At b8b5a39, the either-kind and slot-condition changes remain isolated to unreleased PV15 and respect the protocol, state-validation and binding boundaries; no remaining actionable defects were found. This was static verification only, with no local builds or tests run. Current CI reports passing Rust workspace, wasm32, JS, mobile, Docker, functional and E2E checks; review and hygiene gates remain pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

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: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 11: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 12: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 13: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 14: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The change adds an intricate condition evaluator and alters consensus-critical reference acceptance in packages/rs-dpp/src/data_contract/document_type/property/slot_condition.rs and packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v1/mod.rs.
  • 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 final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • 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 — ffi-engineer (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 — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (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
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@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 11, 2026
@QuantumExplorer
QuantumExplorer merged commit 3ae864d into v5.1-dev Nov 11, 2026
35 of 36 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/dynamic-refers-to-when branch November 11, 2026 22:49
QuantumExplorer added a commit that referenced this pull request Nov 12, 2026
…ecision-proposal-description-reference

Brings in v5.1-dev at 78d691d, which now holds the either-kind targets and
slot `when` change (#5850) as a squash, together with the multiple choice
proposals branch this one is built on.

- Files #5850's squash left identical to its last head keep this branch's
  version, which adds the type-level `when`, `$electedAbilities` and the
  `present`/`absent` conditions on top of it.
- document_reference_validation 1 keeps reading the elected team's abilities
  for the named type before judging its requirements.
- Protocol version 15 notes read 33 (reference whose target the document
  names, with the type-level `when`), 34 (keys with a budget), 35 (composite
  document history), 36 (a contest among documents).
- The ten nullifier_batch_guard roots and the activation root are recomputed
  for this branch's decision proposals schema on the new base.

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