Skip to content

fix(dpp)!: propertyConstraints read empty objects as absent and follow $defs refs (PV14) - #5101

Merged
QuantumExplorer merged 2 commits into
v4.2-devfrom
claude/property-constraints-empty-objects-and-defs
Sep 28, 2026
Merged

QuantumExplorer merged 2 commits into
v4.2-devfrom
claude/property-constraints-empty-objects-and-defs

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

This fixes two mistakes in propertyConstraints, the document type rules added for protocol version 14.

  1. An empty object now counts as absent. When a document is stored, an object with nothing in it ({}, or { "inner": {} }) is dropped. The rules checked a create against the data it carried, where meta: {} was there, but checked a later transfer against the stored document, where it was gone. So the same document could pass one check and fail the other. Now present and absent see an object with nothing in it as absent everywhere.
  2. Rules now work on properties defined through $defs. A contract can define a property as { "$ref": "#/$defs/state" }. The rules looked the enum of such a property up in the wrong place and refused the whole contract with a decoding error. Now they read the definition, as the rest of the parser already does. The same fix applies to the encryptedFor key id check.

Example:

Rule: "metaOrSeller": { "anyOf": [{ "present": "meta" }, { "equal": ["sellerId", "$ownerId"] }] }

Before:

  • Alice, who is not the seller, creates an offer with meta: {}. Accepted, because meta is present.
  • Alice transfers the offer to Bob, who is not the seller either. Refused with 10422 (metaOrSeller not met), because the stored offer has no meta.

After:

  • Alice's create with meta: {} is refused with 10422, because meta has nothing in it.
  • An offer stored with meta: {} and then transferred to someone who is not the seller is refused the same way. Create and transfer agree.

Contract with "$defs": { "state": { "type": "string", "enum": ["open", "closed"] } }, a property "state": { "$ref": "#/$defs/state" } and the rule { "equal": ["state", { "const": "closed" }] }:

Before: the contract is refused with unable to get property $defs in $defs.state.

After: the contract registers. With { "const": "closd" } instead, it is refused with the usual compares "state" with "closd", which is not one of its enum values.

Value: a document's rules give the same answer whether it is being created or moved later, and contracts that share property schemas through $defs can use propertyConstraints and encryptedFor.

Risks: Low. Both changes apply only at protocol version 14, which is not released yet. A devnet already running protocol version 14 whose history contains such a create or such a contract would replay differently. That is expected for unreleased protocol version 14 changes.

Issue being fixed or feature implemented

  • present and absent counted any non-null value as present, {} included. The document encoding reads an object with no member present back as no object, recursively ({ "inner": {} } goes too). A create or replace is judged on the data it carries, while a transfer, purchase or price update is judged on the stored properties (validate_property_constraints_for_system_change). The two could disagree for the same document.
  • The generation 3 checks of string constants and defaults against a property's enum (const, string in, startsWith/endsWith, string ifAbsent defaults, contains constants), and the encryptedFor key id bounds check, resolved $ref against the bare document type schema. That schema holds no $defs, so any such property made the contract fail with a ValueDecodingError.

What was done?

  • property_constraints/mod.rs: is_present counts a value as present only if a stored document keeps it: not null, and for a map, some member that is kept, checked recursively (is_kept_in_storage, written as an iterative walk because a create's data is read before its schema validation is reported). The shipped document decoder is unchanged.
  • try_from_schema/mod.rs: apply_property_constraints and validate_encrypted_for_declarations take the contract's schema_defs. The new resolve_schema_ref resolves #/$defs/<name> (and a path below it) against them, as enrich_with_base_schema makes the core parse do, and any other local reference against the schema. schema_at_path, resolve_schema (including a $ref under items), enum_any, enum_admits and is_key_id_schema use it.
  • v3/mod.rs: parse_generation_3 passes its schema_defs to both.
  • v14.rs: PV14 note 52 describes both changes.
  • The book pages on propertyConstraints, the contract keywords table, the documents chapter and the v3 meta-schema descriptions of present/absent now say that an object with no member present counts as absent.

How Has This Been Tested?

New tests. Each one fails without the fix and passes with it:

  • dpp should_judge_presence_alike_on_the_data_and_on_the_stored_document: for meta set to {}, { "inner": {} } and { "tag": "x" }, every rule gives the same verdict on the document's data as after a serialize/deserialize round trip.
  • dpp should_tell_a_property_left_out_from_one_set_to_zero: extended with {}, { "inner": {}, "gone": null } and a path inside it.
  • dpp should_hold_string_constants_to_the_enum_of_a_referenced_definition: $ref string and typed array properties. A valid const, in, startsWith, ifAbsent default and contains register. Misspelt ones are refused with the normal enum errors. Both parse paths.
  • dpp should_read_an_encrypted_for_key_id_through_a_ref: bounded $ref key ids register, an unbounded one is refused. Both parse paths.
  • drive-abci should_judge_an_object_without_members_absent_on_create_and_transfer: creates with meta: {} and { "inner": {} } by a non-seller are refused. An offer stored with meta: {} (its owner is the seller) is refused on transfer to a non-seller. { "tag": "x" } passes both create and transfer.

Commands:

  • cargo test -p dpp --all-features --lib -- property_constraints try_from_schema meta_validators validate_schema_compatibility validate_document: 602 passed
  • cargo test -p dpp --all-features --lib -- document_type document::v0::serialize encrypted: 1588 passed
  • cargo test -p drive-abci --lib -- property_constraints encrypted_for: 33 passed. -- data_contract_create: 140 passed
  • cargo test -p platform-version: passed
  • cargo fmt --all. cargo clippy --tests -- -D warnings on dpp (all features), drive-abci and platform-version: clean

Breaking Changes

Consensus changes at protocol version 14 only (unreleased):

  • a create or replace that carried an object with no member present, and passed only because that object counted as present, is now refused (10422);
  • a contract whose rules or encryptedFor read a property through a $ref to $defs, which was refused with a decoding error, now registers if its constants are valid.

A devnet already on protocol version 14 whose history contains either would replay differently.

In-place changes to shipped generations

None. is_present is reached only through rules that parser generation 3 builds, and validate_property_constraints is None before protocol version 14. apply_property_constraints, validate_encrypted_for_declarations and the $ref helpers are called only from parser generation 3. Meta-schema v3, whose descriptions changed, is selected only at protocol version 14, and descriptions do not validate.

Checklist:

  • I have performed a self-review of my own code
  • 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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 0f61933

  • Bots — coderabbitai skipped after its own rate limit · thepastaclaw ✓
  • Self-review — post /self-reviewed
  • Within your 5 open PRs
  • Build failed
  • Approvals — you own every area touched; none needed

When every box is checked the PR Hygiene check passes and this can merge.

…w $defs refs (PV14)

present and absent now count an object with no member present ({}, or
{ "inner": {} } around one) as absent. The document encoding reads such
an object back as no object at all, so a create was judged on meta: {}
as present while its later transfer, purchase or price update, judged on
the stored document, saw it absent.

Parser generation 3 now resolves a property's $ref to the contract's
$defs when it checks rule string constants, listed strings, prefixes and
suffixes, string defaults and contains constants against the property's
enum, and when it checks an encryptedFor key id's bounds. It resolved
them against the bare document type schema, which holds no $defs, and
refused every such contract with a decoding error.

PV14 note 52 covers both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 28, 2026
@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 29 minutes.

Check out review usage here.

View limit details

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

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

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e85f108a-4833-478b-ac99-9a51e5bf25ca

📥 Commits

Reviewing files that changed from the base of the PR and between 7894963 and 0f61933.

📒 Files selected for processing (12)
  • book/src/contract-keywords.md
  • book/src/contract-keywords/property-constraints.md
  • book/src/data-model/documents.md
  • packages/rs-dpp/schema/meta_schemas/document/v3/document-meta.json
  • 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/immutable_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/property_constraints_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/property_constraints/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/property_constraints/tests.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/property_constraints.rs
  • packages/rs-platform-version/src/version/v14.rs

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

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 28, 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-09-28T03:30:38.732Z

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 28, 2026
@thepastaclaw

thepastaclaw commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 0f61933) · 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

Verified both supplied findings against head 222ca90 and retained them as non-blocking suggestions. The fixes align presence checks with storage decoding and keep the schema-resolution changes on PV14-only paths; no blocking defect was identified. Verification used source, caller, version-table, and test inspection plus a passing diff whitespace check; reviewer-reported test runs were not independently rerun.

🟡 2 suggestion(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: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: platform-versioning); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — The diff changes consensus-visible document presence checks and contract schema reference resolution, but the implementation is contained and straightforward, with most additions being tests and documentation rather than large or intricate critical-surface changes.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — architecture-layering (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — platform-versioning (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 below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort high); agent phase2-reviewer
🤖 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-dpp/src/data_contract/document_type/property_constraints/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/data_contract/document_type/property_constraints/mod.rs:2362-2372: Avoid constructing the presence-check worklist for non-map values
  Every evaluated `present` or `absent` predicate whose path resolves now constructs a heap-backed worklist, including for scalar values and null, where the result is immediately known. This adds avoidable allocation work to document validation. Return directly for null and non-map values, retaining the iterative traversal for maps so deeply nested input remains stack-safe. This preserves the current predicate semantics.

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:2396-2399: Add regression coverage for references below a definition
  The new resolver explicitly supports references below a named definition, but the enum and `encryptedFor` regression tests use only direct references such as `#/$defs/state` and `#/$defs/recipientKey`. They do not exercise the branch that changes the resolution root and reconstructs the remaining URI. Add a case such as `#/$defs/wrapper/properties/inner` through the dispatched parser, checking both an accepted value and a rejected enum constant or key-id bound under full and partial validation. This would protect the sub-path behavior included in this fix.

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Sep 28, 2026
…efinition

present and absent answer null and every value but an object at once,
and build the iterative worklist only for an object's members, so a
scalar or null costs no allocation. The result is unchanged.

Two regression tests cover a $ref that names a schema below one of the
contract's $defs (#/$defs/wrapper/properties/inner): a rule's string
constant is held to the enum found there, and an encryptedFor key id is
read from the integer schema found there, accepted when bounded and
refused when not. Both run on the validating and the non-validating
path. The resolver already handled this case; no change to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Sep 28, 2026

@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 exact reviewed head correctly aligns property-constraint presence semantics with stored-document serialization and resolves property schemas through contract $defs, including paths below named definitions. The previously identified performance and regression-coverage suggestions are both addressed, and no new actionable in-scope defects were found.

🔴 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: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: platform-versioning); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); reviewer 9: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 10: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 11: gpt-6-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 12: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: normal by gpt-6-astra (effort low) — The diff changes consensus-relevant PV14 validation in is_present and resolve_schema_ref, but the implementation is small and contained, with most added lines devoted to tests and documentation rather than large or intricate critical-surface changes.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — architecture-layering (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — platform-versioning (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 below 15% reserve: weekly 13% left, 5h 100% left), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6-astra — general (completed, effort high); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort high); 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 bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Sep 28, 2026
@QuantumExplorer
QuantumExplorer merged commit 8d587f2 into v4.2-dev Sep 28, 2026
40 of 42 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/property-constraints-empty-objects-and-defs branch September 28, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. 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