Repository navigation
feat(platform)!: bound the summed values of a contested document type (PV14) - #5240
Conversation
… (PV14) Parser generation 3 refuses, under full validation, a document type with a contested index and a summed property (summable, averageable, documentsSummable or documentsAverageable) unless the property's schema declares a minimum of at least -2^27 and a maximum of at most 2^27. The end of a contest adds the winner's value to the type's sums after any number of other documents were written, so the values must be small enough that the sums stay in i64, which they do short of 2^36 documents. The bound is SystemLimits::max_contested_summed_value_magnitude, Some(2^27) in SYSTEM_LIMITS_V4 and None in the earlier tables, whose parsers never read it. A stored contract still parses; protocol version 13 keeps registering any bounds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-10-01T13:57:01.537Z |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)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 (14)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughProtocol version 14 adds a magnitude limit of 2^27 for summed properties on document types with a contested index. Generation 3 full validation enforces the required schema bounds during contract registration. Tests cover parser validation and contract registration behavior across protocol versions. ChangesContested summed-value validation
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant ContractRegistration
participant Generation3Parser
participant SystemLimits
ContractRegistration->>Generation3Parser: Parse contract with full validation
Generation3Parser->>SystemLimits: Read contested summed-value magnitude limit
Generation3Parser-->>ContractRegistration: Return validation result
Merge Risk: ⚪ Minimal · up to This change adds a protocol-version-14-only registration rule for summed properties on contested document types. Earlier protocol versions and stored contracts are unaffected. No merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change strengthens schema validation without granting additional privileges. Remaining uncertainty concerns older contracts and contest completion across the protocol upgrade, rather than a demonstrated new vulnerability. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 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 |
|
🕓 Queued for automated review — 8th in line, estimated start in ~2.0 h (commit 629d4f7)
|
Basic explanation
What this does: A document type can keep running totals of one of its number properties (a "summed" property, for example
documentsSummable: "amount"). It can also have a contested index, where a scarce value is handed out by a masternode vote instead of first come, first served. From protocol version 14, a document type that has both must keep the summed number between -134,217,728 and 134,217,728 (±2^27), written as the property'sminimumandmaximum.Value: When a contest ends, the platform itself writes the winning document into the type's totals. No user transition is left at that point to refuse a total that no longer fits a signed 64-bit integer. With every value within ±2^27, a total stays in range until the type holds more than about 68.7 billion (2^36) documents, so the write at the end of a contest always fits.
Risks: Low. It only changes which contracts register at protocol version 14, which is not live on mainnet. A contract combining a contested index with a summed property outside those bounds is refused, paid, with
InvalidContractStructure(10231). Contracts already stored keep parsing, because the rule runs only when a contract is registered or updated, and protocol version 13 registers exactly as before. A contested summed type that needs values beyond ±2^27 can no longer be registered from 14 on.Issue being fixed or feature implemented
Registration checks that each summed value fits a signed 64-bit integer, but nothing bounded the sums of a contested type. Its documents enter those sums when a contest is awarded, not through a write that state validation can refuse, so the bound has to come from the schema.
What was done?
validate_contested_summed_value_boundsinpackages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs(parser generation 3, full validation only, beside the typed array cap).summable,averageable,documentsSummable,documentsAverageable; all name the same property).minimumandmaximumfrom the property's schema, following$refinto$defs, so the answer does not depend onsizedIntegerTypes. A missing bound is refused.SystemLimits::max_contested_summed_value_magnitude:Some(1 << 27)inSYSTEM_LIMITS_V4,Nonein V1 to V3 and in thev2_testmock.v14.rs; a registration rule in the book'scontested.mdandaggregates.md; a row in the limits table ofcontract-keywords.md.Example, a contested type summing
amount:Before (and still at protocol version 13): registers.
After, at protocol version 14: refused, paid, with a nonce bump:
With
"amount": { "type": "integer", "minimum": 0, "maximum": 134217728, "position": 1 }it registers, before and after.How Has This Been Tested?
packages/rs-dpp/.../try_from_schema/v3/contested_summed_value_bounds_tests.rs(10 tests):$ref;packages/rs-drive-abci/.../data_contract_create/contract_structure_error_tests.rs: a registration throughcheck_txand a block. At the latest version,check_txadmits it (it parses without full validation), and the block refuses it paid and bumps the nonce. Protocol version 13 registers.register_contract_with_schema_and_balancefunds the owner for a contested index's registration fee.cargo test -p dpp --all-features --lib document_type(1,789 passed),cargo test -p drive-abci --lib -- contested data_contract_create data_contract_update,cargo test -p platform-version.cargo clippy -p platform-version -p dpp -p drive-abci --all-features --all-targets -- -D warnings,cargo check --workspace --all-targets,cargo check -p drive --no-default-features --features verify,cargo fmt --all -- --check.Breaking Changes
Consensus, at protocol version 14 only: a contract whose document type combines a contested index with a summed property not bounded within ±2^27 is refused at registration and update. Earlier protocol versions are unchanged, and stored contracts still parse.
In-place changes to shipped generations
SYSTEM_LIMITS_V1,SYSTEM_LIMITS_V2andSYSTEM_LIMITS_V3(protocol versions 1 to 13) gainmax_contested_summed_value_magnitude: None. Only parser generation 3 reads the field, and no protocol version selecting those tables runs generation 3, so consensus cannot change there.SYSTEM_LIMITS_V4are amended in place: both are selected only by protocol version 14, which is not live on mainnet.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 ·
629d4f7/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are doneWhen every box is checked the
PR Hygienecheck passes and this can merge.Summary by CodeRabbit