Skip to content

fix(platform)!: refersTo agreements compare values, not index keys (PV14) - #5102

Merged
QuantumExplorer merged 8 commits into
claude/platform-value-same-scalar-datafrom
claude/refers-to-agreement-typed-and-bounded
Sep 28, 2026
Merged

QuantumExplorer merged 8 commits into
claude/platform-value-same-scalar-datafrom
claude/refers-to-agreement-typed-and-bounded

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does: A refersTo reference can declare a propertyAgreement, for example "a like must carry the same hashtag as the post it likes". Platform checked that rule by turning both values into the form they take as index keys and comparing those. That form has two quirks: the empty text and the one-character text "\0" come out the same, and a value over 255 bytes has no key form at all. So "" agreed with "\0", and two identical long values never agreed. From protocol version 14 the two values are compared as values: text as text, bytes as bytes, numbers as numbers.

Stacked on #5125, which adds the comparison to platform-value as Value::same_scalar_data. This pull request calls it; the dpp helper DocumentPropertyType::values_are_equal that an earlier revision added is gone, and its tests moved to #5125. Merge #5125 first.

This pull request used to also carry a second fix, the rule that a preallocated index's agreement source must fit a tree key. That rule moved unchanged to #5123, since merged.

Example:

Before After
A like whose 70-emoji hashtag (280 bytes) equals its post's refused, ReferencedDocumentPropertyMismatchError (40127) accepted
A like with hashtag "\0" on a post with hashtag "" accepted refused (40127)
A like whose agreed identifier is carried as an array of 32 U8 values instead of bytes accepted accepted (unchanged)

Value: Agreements behave as documented, "the two sides are equal", for every value an unindexed property can hold.

Risks: Consensus change at protocol version 14, which is not on mainnet or testnet. Replaying devnet history that contains such writes gives different results: likes refused before for long equal values are accepted, and ""/"\0" pairs accepted before are refused. An identifier or byte array carried as an array of U8s still agrees with the same bytes, as it did under key encoding (a moderation charter application may write its target contract that way). The drive-abci module whose code changed in place is selected at older protocol versions too; the section below says why the edit cannot run there.

Issue being fixed or feature implemented

The write-time check of refersTo propertyAgreement compared index key encodings (from #4505). It is reachable only from protocol version 14: an agreement only parses when apply_property_reference is Some(0), CONTRACT_VERSIONS_V6.

document_reference_validation v0 ran each side through serialize_value_for_key and compared the bytes. That encoder maps "" to [0] (DocumentPropertyType::encode_value_for_tree_keys), the same bytes as "\0", and returns an error above MAX_INDEX_SIZE (255 bytes), which the check treated as a mismatch. Only agreement properties that are not indexed can hold such values: a string with maxLength 64 or more (up to four bytes a character) or a byte array longer than 255. For those, equal values over 255 bytes were always refused with 40127.

What was done?

Before and after, for the long-values fixture (post.hashtag and like.hashtag both strings of up to 280 characters, not indexed):

post.hashtag = "😀" × 70 (280 bytes), like.hashtag = the same
  before: PaidConsensusError ReferencedDocumentPropertyMismatchError (40127)
  after:  SuccessfulExecution

post.hashtag = "", like.hashtag = "\0"
  before: SuccessfulExecution
  after:  PaidConsensusError ReferencedDocumentPropertyMismatchError (40127)

In-place changes to shipped generations

  • document_reference_validation 0 (drive-abci), selected by every DRIVE_ABCI_VALIDATION_VERSIONS_* table, protocol versions 1 to 14. The edit only replaces the comparison inside the propertyAgreement loop of a document reference. A pair only exists on a refersTo document reference, which the document type parser only builds when apply_property_reference is Some(0), and only CONTRACT_VERSIONS_V6 (protocol version 14) sets that. Under protocol versions 1 to 13 no document type carries a pair, the loop runs zero times, and the edited lines cannot execute. A line comment at the edit says so. The removed DocumentTypeV0Methods import was used only by the old comparison.
  • data_contract_reference_validation 0 (drive-abci): a comment changed, no code.
  • Value::same_scalar_data is new (feat: add Value::same_scalar_data for comparing single values across variants #5125) and is called only from the edited agreement comparison.

How Has This Been Tested?

Tests, all named should_…:

  • platform-value, in feat: add Value::same_scalar_data for comparing single values across variants #5125 (eq::same_scalar_data_tests): the seven dpp tests of the removed helper, ported, plus floats by bits, integers against floats, maps and arrays, and a U128 past i128::MAX.
  • drive-abci, batch/tests/document/agreement_values.rs (full ABCI pipeline), unchanged:
    • should_agree_on_equal_strings_longer_than_a_tree_key: 256 ASCII bytes, 64 and 70 emoji agree; unequal long values are still refused.
    • should_refuse_an_empty_string_against_a_nul_character: both directions refused, two empty strings agree.
  • drive-abci, contract create: should_register_an_agreement_on_strings_longer_than_a_tree_key.
cargo test -p dpp --lib document_type::property                               # 552 passed
cargo test -p drive-abci --lib -- agreement reference contract_owner_requirement \
  batch::tests::document::replacement batch::tests::document::index_only       # 263 passed
cargo test -p platform-version                                                 # 23 + 2 passed
cargo test -p platform-value --lib --tests                                     # 1060 + 239 + 3 passed
cargo fmt --all
cargo clippy -p platform-value -p dpp -p drive-abci --tests -- -D warnings

Breaking Changes

Consensus change at protocol version 14 (unreleased), PV14 note 56. At protocol version 14 an agreement pair holds exactly when its two values are the same single value, so "" no longer agrees with "\0", equal values over 255 bytes now agree, and an array of U8s still agrees with the same bytes. Protocol versions 1 to 13 are unchanged.

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

Summary by CodeRabbit

  • New Features
    • Property agreements now compare values according to their data type, rather than comparing encoded index keys. Long values can match when they are not used to key a preallocated index.
  • Bug Fixes
    • Preallocated indexes are no longer created when a referenced value exceeds the referring property’s capacity.
  • Documentation
    • Clarified that referenced properties used to key preallocated indexes must have a maximum size of 255 bytes; registrations exceeding this limit are rejected.

…agreement sources fit a tree key (PV14)

A propertyAgreement pair is now judged as two values of the referring
property's type (DocumentPropertyType::values_are_equal): strings as text,
byte arrays and identifiers as bytes, integers as numbers, floats by their
bits, booleans as booleans. It compared the two sides' index key
encodings, under which "" agreed with "\0" and two equal values over 255
bytes were always refused with ReferencedDocumentPropertyMismatchError.

Contract create and update now refuse, with
ReferencedDocumentPropertyAgreementInvalidError, a pair through which a
preallocated index is keyed when the referenced property can hold more
than 255 bytes: creating a referenced document writes that value as a
tree key, which failed with an internal error. The preallocation insert
now sizes that layer's estimate from the referring property, as an entry
insert does, and preallocates nothing for a referenced value wider than
the referring property can hold, which no referring document can agree
with. PV14 note 53.

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
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 28, 2026
@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-28T15:40:15.257Z

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: 16f1e48d-3c21-460d-8711-e0a9bf14961b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: 702290ea-5f52-4bb9-b29c-15b41ea5638a

📥 Commits

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

📒 Files selected for processing (17)
  • book/src/contract-keywords/index-only.md
  • book/src/contract-keywords/refers-to.md
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/agreement_values.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_common/data_contract_reference_validation/v0/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-agreement-long-values.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-agreement-preallocated-fits.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-agreement-preallocated-too-wide-update-v1.json
  • packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/reference-validation-contract-agreement-preallocated-too-wide.json
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/preallocated_index_e2e_tests.rs
  • packages/rs-drive/src/drive/document/insert/add_preallocated_index_tree_operations/mod.rs
  • packages/rs-drive/src/drive/document/insert/add_preallocated_index_tree_operations/tests.rs
  • packages/rs-platform-version/src/version/v14.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Property agreements now compare typed values rather than encoded index keys. Contract validation checks the width of referenced properties used by preallocated indexes. Preallocation skips agreement-bound trees when referenced values exceed the referring property’s capacity.

Changes

Property agreement values

Layer / File(s) Summary
Typed value comparisons and document validation
packages/rs-dpp/src/data_contract/document_type/property/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/document/document_reference_validation/v0/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/*, book/src/contract-keywords/refers-to.md, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/mod.rs
Property agreements compare values using the referring property’s type. Tests cover type-specific equality, long values, empty strings, and mismatches.
Registration width validation and contract fixtures
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_common/data_contract_reference_validation/v0/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/mod.rs, packages/rs-drive-abci/tests/supporting_files/contract/reference-validation/*, book/src/contract-keywords/refers-to.md
Registration rejects agreement-bound preallocated indexes if the referenced property’s maximum width is unknown or exceeds 255 bytes. Tests cover accepted and rejected contracts.
Preallocation width handling and estimates
packages/rs-drive/src/drive/document/insert/add_preallocated_index_tree_operations/*, packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/preallocated_index_e2e_tests.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/agreement_values.rs, book/src/contract-keywords/index-only.md, packages/rs-platform-version/src/version/v14.rs
Preallocation skips an agreement-bound index when its value exceeds the referring property’s capacity. Estimated layer sizes use the referring property’s size. Tests check skipped and created trees, fee estimates, and consistency.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant add_preallocated_index_tree_operations
  participant bound_value_fits_referring_property
  add_preallocated_index_tree_operations->>bound_value_fits_referring_property: Check encoded value against referring property width
  alt Value fits
    bound_value_fits_referring_property-->>add_preallocated_index_tree_operations: Continue resolving the binding
  else Value does not fit
    bound_value_fits_referring_property-->>add_preallocated_index_tree_operations: Skip preallocation for the binding
  end
Loading

Merge Risk: ⚪ Minimal · up to d374c

The changed agreement and preallocation paths show no actionable merge-blocking issue; the PR is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to d374c

The changes affect which documents and contracts the platform accepts and how index trees are created. The inspected controls address the identified value-comparison and key-width problems, but the change spans validation and persistent state.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The exposed scope is contract-authored reference and index declarations and document values processed by validation and insertion for their contract's document types; these paths can affect acceptance and persisted index structure.

Trust Boundaries and Controls

  • observed — Contract validation checks same-kind agreement properties and rejects a preallocated binding when its referenced property has no usable maximum width or can exceed the tree-key limit.
  • observed — Document validation uses the referring side's declared type for equality and retains the mismatch result when the required value is absent or does not compare equal.

Resilience and Maintainability Implications

  • inferred — Checking width before queuing a binding's tree operations limits partial planning for unfit values. The inspected file does not establish rollback guarantees for an interruption after a larger insertion batch begins executing.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 89.47% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 38 functions across 11 files. (6 skipped: 6…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: PV14 refersTo agreements now compare values instead of index keys.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@thepastaclaw

thepastaclaw commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress — actively reviewing now (commit 25cbce4) · triage: normal

…agreement-typed-and-bounded

# Conflicts:
#	packages/rs-platform-version/src/version/v14.rs


This pull request now only makes propertyAgreement pairs compare values
instead of index keys. The registration rule that a preallocated
index's agreement source fits a tree key, and the Drive preallocation
changes that go with it, move unchanged to #5123 with their tests and
fixtures.

The PV14 note is renumbered from 53, which #5099 took on v4.2-dev, to
56 (54 is claimed by an open pull request, 55 by #5123), and now covers
only the comparison.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@QuantumExplorer QuantumExplorer changed the title fix(platform)!: refersTo agreements compare values, and preallocated agreement sources fit a tree key (PV14) fix(platform)!: refersTo agreements compare values, not index keys (PV14) Sep 28, 2026
QuantumExplorer and others added 2 commits September 28, 2026 19:27
…data

The propertyAgreement check in document reference validation 0 now
compares its two sides with `Value::same_scalar_data` from platform-value.
Registration already made both sides one value kind, so the check no
longer looks up the referring property's type, and the dpp helper
`DocumentPropertyType::values_are_equal` and its tests are removed; the
tests moved to platform-value with the comparison.

Unlike the dpp helper, a side carried as an array, even of byte values,
agrees with nothing. PV14 note 56 names the new method, says so, and now
follows note 55. The book says floats compare bit for bit, and the
method's doc comment names its caller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@QuantumExplorer
QuantumExplorer changed the base branch from v4.2-dev to claude/platform-value-same-scalar-data September 28, 2026 12:42
@github-actions github-actions Bot removed the waiting-bots Waiting for the review bots to report on this head label Sep 28, 2026
QuantumExplorer and others added 3 commits September 28, 2026 22:29
Value::same_scalar_data now reads an array of U8 values as the bytes it
lists (#5125), as the index key comparison did, so a moderation charter
application that writes its target contract that way agrees with the
stored identifier again. Note 56, the check's comment and the book say
so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r-data' into claude/refers-to-agreement-typed-and-bounded
@QuantumExplorer
QuantumExplorer merged commit a410611 into claude/platform-value-same-scalar-data Sep 28, 2026
7 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/refers-to-agreement-typed-and-bounded branch September 28, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants