Repository navigation
feat(dpp)!: find a referenced document by a string or byte array property's value - #5367
Conversation
…rty's value A string or byte array property could carry a `refersTo` only through a `findBy` function reading it (commit and reveal). It may now carry any permanentDocument or deletableDocument reference found by `findBy`, its value read as is: `"."` fills an index property holding the same kind of value (a `post` names a `handle` by its unique `name`). - Parser: `apply_revealed_reference_v0` admits any `findBy` lookup on such a property (`inList`, which holds ids, stays refused); the referring side drops the refusal of a `"."` source there. - Referenced side: `referenced_side_error` takes the property carrying the reference, so `"."` holds a string or byte array property's kind. - Write path: a value read as `"."` is judged as an identifier's value is, on every create and on the replaces `binds_a_changed_property` names; a computed key stays create-only. The value reaches the lookup as `RevealedValue`; `key_values` and `fetch_document_through_lookup` take `"."` as a `Value`. A refusal carries an all-zero entity id. - `validate_no_immutable_deletable_element_references` reads revealed references too. - Docs: meta-schema v3, v14 note 61 (in place), the book and the wasm-dpp2 findBy doc. Tests: dpp `string_find_by_key_tests` (parse, kind mismatch, immutable deletable, "." beside a function); drive-abci `handle`/`post` pipeline tests (found, not found and case-sensitive 40120 with a zero id, replace re-validation, deletable target re-checked on every replace). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-10-11T05:46:48.404Z |
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to No identified issue blocks merging after normal validation. Pre-merge checks |
|
|
🔍 Review in progress — actively reviewing now (commit aaa831e) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Verified the combined reviewer findings against exact head 107a0e1. The protocol-14 gating is consistent, but the new direct-value lookup exposes two blocking issues: oversized carriers become internal execution errors, and index-key aliases can satisfy references without actual value equality. This was a static review; the supplied CI snapshot reports successful Rust workspace tests, with the main Test Suite, browser suite (1), and PR Hygiene still pending.
🔴 2 blocking | 🟡 3 suggestion(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Verify actual property equality before accepting direct-value references
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs:1293-1294
The lookup result establishes encoded index-key equality, not the advertised byte-for-byte property equality. DocumentPropertyType::encode_value_for_tree_keys encodes both the empty string and a one-NUL string as [0]. With the new handle/post fixture, a handle whose name is empty can therefore satisfy a post whose authorHandle is "\u0000", although no handle has that name. There is also a byte-array alias: an empty byte array encodes as the empty key used for an absent property. For an optional target property with a null-searchable unique index, the query's null-key subquery can return a document that has no such property. fetch_document_through_lookup takes the first result, query_documents_v0 only deserializes it, and the subsequent agreement loop checks explicitly declared where pairs rather than the direct lookup condition. Treat the indexed document as a candidate and compare the actual property filled by the direct ReferenceValue source with the carrier using scalar/byte equality; reject absence or mismatch with 40120. Scope the check to the newly admitted direct carriers, preserve the existing index encoding, and add regressions for both aliases.
source: gpt-6.1-sol (phase2-reviewer: 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-astra (agent: phase2-reviewer, role: general); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6-astra (agent: phase2-reviewer, role: security-auditor); reviewer 11: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 12: 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 change intricately alters consensus acceptance rules across schema parsing and document creation/replacement, notably in document_reference_validation/v0/mod.rs and reference_lookup.rs. - 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 below 15% reserve: weekly 14% left, 5h 100% left),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-astra— general (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6-astra— security-auditor (completed, effort xhigh); agentphase2-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. Verify each finding against the current code and only fix it if needed.
In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs`:
- [BLOCKING] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs:1279-1285: Handle oversized direct reference values before querying Drive
The newly accepted carrier need not be indexed or share the target property's size bounds. A contract can therefore admit a non-indexed string or byte-array carrier longer than 255 bytes, while its findBy target uses a bounded unique index. Registration compares value kinds only, and this branch forwards the entire carrier into the equality query. DocumentType::serialize_value_for_key_v0 rejects an encoded key longer than MAX_INDEX_SIZE with DataContractError::FieldRequirementUnmet; fetch_document_through_lookup propagates that error rather than returning a reference miss. Transition processing consequently produces InternalError, which prepare_proposal removes from the block, instead of the paid 40120 refusal promised for a value with no matching target. Check key representability before querying and return a typed reference-validation failure for this input-specific condition, while preserving genuine storage errors. Cover create and replace with oversized bytes and strings, including multibyte UTF-8.
- [BLOCKING] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs:1293-1294: Verify actual property equality before accepting direct-value references
The lookup result establishes encoded index-key equality, not the advertised byte-for-byte property equality. DocumentPropertyType::encode_value_for_tree_keys encodes both the empty string and a one-NUL string as [0]. With the new handle/post fixture, a handle whose name is empty can therefore satisfy a post whose authorHandle is "\u0000", although no handle has that name. There is also a byte-array alias: an empty byte array encodes as the empty key used for an absent property. For an optional target property with a null-searchable unique index, the query's null-key subquery can return a document that has no such property. fetch_document_through_lookup takes the first result, query_documents_v0 only deserializes it, and the subsequent agreement loop checks explicitly declared where pairs rather than the direct lookup condition. Treat the indexed document as a candidate and compare the actual property filled by the direct ReferenceValue source with the carrier using scalar/byte equality; reject absence or mismatch with 40120. Scope the check to the newly admitted direct carriers, preserve the existing index encoding, and add regressions for both aliases.
In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/commit_reveal_lookup.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/commit_reveal_lookup.rs:1330-1338: Exercise direct byte-array references through the write pipeline
The new ABCI cases all use the string handle/post fixture. The byte-array case in string_find_by_key_tests only parses the contract and inspects its declaration, so it does not exercise the new RevealedValue path across transition serialization, stored-document decoding, index-key encoding, and replacement validation. Add a byte-array fixture through process_raw_state_transitions covering a matching create, a missing value's 40120/path/zero-id refusal, and replacement with a changed value. Include a non-32-byte key and the binary representations supported by the transition API so the tests protect byte-array behavior rather than implicitly relying on identifier-shaped data.
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/commit_reveal_lookup.rs:1354-1357: Cover replacement when only another lookup key part changes
This test changes the carrier itself, and the deletable-reference test exercises unconditional revalidation. Neither covers the new PropertyReference::Revealed branch when a permanent reference keeps its carrier but binds_a_changed_property must trigger revalidation because another findBy source changed. Existing identifier-reference tests enter a different branch and would not catch a regression in this new control flow. Add a composite unique-key fixture such as (name, scope), keep the carrier name unchanged, and replace only the referring scope. A nonexistent combination should return 40120 at the carrier path, while an existing combination should succeed.
In `packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/mod.rs:914-918: Mark the contract-admission change as consensus-breaking in release metadata
This admission change is correctly confined to unreleased protocol 14, but it still changes a protocol rule: old and new protocol-14 implementations disagree about whether the same contract declaration is valid. book/src/contributing/coding-conventions.md reserves the ! marker for protocol-rule changes that nodes must agree on, not merely incompatible client APIs. Update the PR title to feat(dpp)!: and describe the protocol-14 contract-admission change in Breaking Changes instead of saying "None for contracts". This does not require another protocol snapshot; it makes the release classification match the repository's documented convention.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…ong key finds nothing The index finds a document by the key's encoding, which reads the empty string as "\0" and an empty byte array as no value at all. So a post naming "\0" found the handle "", and an empty byte array found a handle without a tag. `fetch_document_through_lookup` now treats the document the index returns as a candidate: it must hold each string or byte array part of the key exactly (`holds_key_part`), whichever binary form either side carries, or the lookup finds nothing (40120). No extra read. A string or byte array read as is need not share the referenced property's bounds, so its key could exceed MAX_INDEX_SIZE. The query then failed with FieldRequirementUnmet, an internal error that drops the transition from the block. A key part `serialize_value_for_key` refuses now finds no document, without a read: the write is refused paid. Both checks apply to every lookup; identifiers, hashes and the other kinds encode one value one way and fit an index key, so they always pass there. Protocol version 14 only, unreleased. Tests (drive-abci, through the ABCI pipeline): the "\0" / "" alias, a 260-byte name on create and replace, a key part other than the carrier changing on replace, and a byte array carrier (20 and 7 bytes, Bytes and Bytes20 forms, missing, replaced, empty against a tagless handle, 256 bytes on create and replace). The alias and over-long tests failed before the fix. Docs: the book and v14 note 61. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
On the blocking finding without an inline thread (Verify actual property equality before accepting direct-value references): fixed in aaa831e. Regressions: a post naming 🤖 Addressed by Claude Code |
|
Reviewed |
Conflicts with #5367, which let a string or byte array property carry a findBy read as ".", in the same places: - apply_revealed_reference_v0: #5367 no longer requires a function on a string or byte array carrier, so this branch's `hash_key().is_some()` there goes; any lookup is admitted. - Meta-schema v3 findBy description and the book (refers-to-lookup, documents): #5367's string-carrier wording beside this branch's minimumAgeBlocks/consume and "$ownerId" wording. - string_find_by_key_tests: `is_checked_on_create_only(true)`, the post type being mutable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Basic explanation
What this does: A document can point at another document through a value it holds. Until now that value had to be an id, or a hash computed by a function (commit and reveal). This PR lets a plain text or binary property do it too. For example, a
postcan name its author's handle as text. Whenever the post is written, the platform checks that ahandlewith exactly that name exists, by looking the name up in the handle type's uniquenameindex.Value: Contracts can point at documents by the values people actually use, such as names, instead of storing a copy of the target's id beside them. This is the second prerequisite for DPNS name tombstones: a tombstone names the domain it buries by its label.
Risks: Medium. This changes consensus rules of protocol version 14, which is unreleased: which contracts are accepted, and how a reference found through an index is judged when a document is written.
"\0"; an empty byte array and no value), so the platform now checks that the document it finds holds exactly the value. A value too long for an index key used to fail the whole transition with an internal error; it now finds nothing, and the write is refused."Alice"does not findalice: contracts must store normalized values.Issue being fixed or feature implemented
A string or byte array property could carry a
refersToonly through afindByfunction reading it. A reference by name, the most common key a person types, needed an identifier copy of the target's id instead. AfindBywith"."on such a property was refused:What was done?
apply_revealed_reference_v0): a string or byte array property may carry anypermanentDocumentordeletableDocumentreference found byfindBy.inListis still refused, since a list holds ids."."source on such a property is removed."."to be read exactly once."."counts as a second read and is refused."."must fill an index property of the carrier's kind, a string a string and a byte array a byte array.DocumentReferenceLookup::referenced_side_erroris now told which property carries the reference."."is judged as an identifier's value is.deletableDocumenttarget (binds_a_changed_property).RevealedValue.DocumentReferenceLookup::key_valuesandfetch_document_through_lookuptake"."as aValue.fetch_document_through_lookup,holds_key_part). The index finds a document by the key's encoding, which reads the empty string as"\0"and an empty byte array as no value at all. The document the index returns is now a candidate: it must hold each string or byte array part of the key exactly, or the lookup finds nothing (40120). No extra read is made.validate_no_immutable_deletable_element_referencesnow reads revealed references too. AdeletableDocumentfound by a string value can therefore not sit under animmutableproperty, the same rule as for an identifier.DocumentReferenceFindBydoc.Before and after
Before: registration refused it:
After: it registers.
authorHandle: "alice"is accepted when a handle namedaliceexists.authorHandlewhen no such handle exists."Alice"finds nothing either, because the key is the value byte for byte.authorHandleis checked again.In-place changes to shipped generations
apply_property_reference0 andapply_revealed_reference_v0: only protocol version 14 setsapply_property_reference: Some(0), so no earlier contract reaches the changed lines.fetch_document_through_lookup: every protocol version selects them, but only the protocol version 14 parser produces a revealed reference or a lookup, so nothing before protocol version 14 reaches the changed lines. For lookups that exist today:Value::Identifierthe old code built, and a function's"."param reads the same identifier;findByfrom feat(dpp)!: refersTo finds a document with findBy and checks it with where #5197) is held to them too: it no longer accepts the aliased value, and an over-long source finds nothing instead of failing the transition. Protocol version 14 is unreleased.create_document_types_from_document_schemas1 and data contract reference validation 0:referenced_side_errorstill gives"."the identifier kind for every carrier except a string or byte array property, and only protocol version 14 parses those.How Has This Been Tested?
string_find_by_key_tests:findBy: { "<index property>": "." }into an index property of their kind, judged again on replace;"."into an index property of another kind is refused: a string into an identifier or a byte array, a byte array into a string or an identifier;deletableDocumentfound by a string on animmutableproperty is refused;"."and by a function is refused (two reads).commit_reveal_lookup.rs, ahandle/postfixture):authorHandlewith an all-zero id;"\0"does not find the handle"", which shares its key, and a post naming""does;scopeis refused for a combination no handle has and accepted for one that exists.handlewith an optional tag of up to 20 bytes, apostwhoseauthorTagholds up to 300):Value::Bytesand asValue::Bytes20;authorTag, on a create and on a replace, and a replace naming another existing tag is accepted;InternalError("... value must be less than 256 bytes long").cargo test -p dpp --libcargo test -p drive-abci --lib -- commit_reveal refers_to reference lookup dpns document moderation data_contractcargo clippy -p dpp -p drive-abci --all-targetscargo check -p wasm-dpp2cargo fmt --all -- --checkBreaking Changes
Consensus-breaking within protocol version 14, which is unreleased: nodes must agree on these rules.
refersTowithfindByreading a string or byte array property as"."is refused by earlier protocol version 14 builds and accepted by this one.DocumentReferenceLookup::referenced_side_errornow takes the property carrying the reference, andkey_valuestakes"."as a&Value.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 ·
aaa831e/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