Repository navigation
fix(platform)!: refersTo agreements compare values, not index keys (PV14) - #5102
Conversation
…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]>
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-09-28T15:40:15.257Z |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (17)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughProperty 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. ChangesProperty agreement values
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
Merge Risk: ⚪ Minimal · up to The changed agreement and preallocation paths show no actionable merge-blocking issue; the PR is mergeable after normal checks. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to 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 Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
🔍 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]>
…ers-to-agreement-typed-and-bounded
…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]>
…ers-to-agreement-typed-and-bounded
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
a410611
into
claude/platform-value-same-scalar-data
Basic explanation
What this does: A
refersToreference can declare apropertyAgreement, 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 helperDocumentPropertyType::values_are_equalthat 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:
ReferencedDocumentPropertyMismatchError(40127)"\0"on a post with hashtag""U8values instead of bytesValue: 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 ofU8s 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
refersTopropertyAgreementcompared index key encodings (from #4505). It is reachable only from protocol version 14: an agreement only parses whenapply_property_referenceisSome(0),CONTRACT_VERSIONS_V6.document_reference_validationv0 ran each side throughserialize_value_for_keyand compared the bytes. That encoder maps""to[0](DocumentPropertyType::encode_value_for_tree_keys), the same bytes as"\0", and returns an error aboveMAX_INDEX_SIZE(255 bytes), which the check treated as a mismatch. Only agreement properties that are not indexed can hold such values: a string withmaxLength64 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?
document_reference_validationv0 compares each pair withValue::same_scalar_data(feat: add Value::same_scalar_data for comparing single values across variants #5125). Registration already made the two sides one value kind (same_value_kind), so the comparison needs no property type: bytes-like values compare by their bytes (anIdentifierand the sameBytes32are equal), integers by value at any width (a transition can carryU64where the stored document decodesU16), floats by theirf64bits with an integer on the other side read as the float it converts to (anumberstored as a float against the same number carried as an integer), and text, booleans and nulls with==. An array ofU8s is the bytes it lists; a map, or any other array, never agrees. The per-pair lookup of the referring property's type, which only fed the dpp helper, is gone with it.data_contract_reference_validationv0: comment only. The comment on the typed-array refusal now says the write-time check compares single values, not key encodings.packages/rs-platform-version/src/version/v14.rs, now after note 55 and namingValue::same_scalar_data. 53 went to feat(platform)!: generatedFrom, string properties the platform generates with a system function (PV14) #5099, 54 is claimed by an open pull request and 55 went to fix(platform)!: a preallocated agreement source must fit a tree key (PV14) #5123; 56 is taken by no other open pull request.contract-keywords/refers-to.md) states how agreement values compare, floats bit for bit.Value::same_scalar_data's doc comment (feat: add Value::same_scalar_data for comparing single values across variants #5125) now names this caller and asks that a change to its results be a new method, asequal_underlying_data's does.Before and after, for the long-values fixture (
post.hashtagandlike.hashtagboth strings of up to 280 characters, not indexed):In-place changes to shipped generations
document_reference_validation0 (drive-abci), selected by everyDRIVE_ABCI_VALIDATION_VERSIONS_*table, protocol versions 1 to 14. The edit only replaces the comparison inside thepropertyAgreementloop of a document reference. A pair only exists on arefersTodocument reference, which the document type parser only builds whenapply_property_referenceisSome(0), and onlyCONTRACT_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 removedDocumentTypeV0Methodsimport was used only by the old comparison.data_contract_reference_validation0 (drive-abci): a comment changed, no code.Value::same_scalar_datais 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_…: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 aU128pasti128::MAX.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.should_register_an_agreement_on_strings_longer_than_a_tree_key.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 ofU8s still agrees with the same bytes. Protocol versions 1 to 13 are unchanged.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
Summary by CodeRabbit