Skip to content

feat(platform)!: bound the summed values of a contested document type (PV14) - #5240

Merged
QuantumExplorer merged 1 commit into
v5.0-devfrom
feat/contested-summed-value-bounds
Oct 1, 2026
Merged

QuantumExplorer merged 1 commit into
v5.0-devfrom
feat/contested-summed-value-bounds

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

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's minimum and maximum.

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?

  • The rule: validate_contested_summed_value_bounds in packages/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).
    • It applies when a type has a contested index and any summed declaration (summable, averageable, documentsSummable, documentsAverageable; all name the same property).
    • It reads minimum and maximum from the property's schema, following $ref into $defs, so the answer does not depend on sizedIntegerTypes. A missing bound is refused.
  • The number: SystemLimits::max_contested_summed_value_magnitude: Some(1 << 27) in SYSTEM_LIMITS_V4, None in V1 to V3 and in the v2_test mock.
  • Docs: note 70 in v14.rs; a registration rule in the book's contested.md and aggregates.md; a row in the limits table of contract-keywords.md.

Example, a contested type summing amount:

"name": {
  "type": "object",
  "documentsMutable": false,
  "canBeDeleted": false,
  "documentsSummable": "amount",
  "properties": {
    "label": { "type": "string", "maxLength": 20, "position": 0 },
    "amount": { "type": "integer", "position": 1 }
  },
  "required": ["label", "amount"],
  "indices": [{
    "name": "byLabel",
    "properties": [{ "label": "asc" }],
    "unique": true,
    "contested": {
      "fieldMatches": [{ "field": "label", "regexPattern": "^[a-z]{3,5}$" }],
      "resolution": 0
    }
  }],
  "additionalProperties": false
}

Before (and still at protocol version 13): registers.

After, at protocol version 14: refused, paid, with a nonce bump:

InvalidContractStructure: document type "name" sums "amount" and has the contested index
"byLabel": awarding a contest adds the winner's value to the type's sums, so the property
must declare a minimum of at least -134217728 and a maximum of at most 134217728

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):
    • refusal through each summed keyword, and with only one bound;
    • ±2^27 accepted inclusive, and bounds read through a $ref;
    • a contested type without a sum, or a summed type without a contested index, is unaffected;
    • a stored contract parses without full validation, and protocol version 13 registers.
  • packages/rs-drive-abci/.../data_contract_create/contract_structure_error_tests.rs: a registration through check_tx and a block. At the latest version, check_tx admits 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_balance funds 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_V2 and SYSTEM_LIMITS_V3 (protocol versions 1 to 13) gain max_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.
  • Parser generation 3 and SYSTEM_LIMITS_V4 are amended in place: both are selected only by protocol version 14, which is not live on mainnet.

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 · 629d4f7

  • Bots — coderabbitai ✓ · thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed once the bots are done
  • Within your 5 open PRs
  • Build running
  • Approvals — you own every area touched; none needed

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

Summary by CodeRabbit

  • New Features
    • Protocol version 14 limits summed-property bounds to ±2^27 for document types with a contested index.
    • Contract registration now checks these bounds, including when they are specified through a schema reference. Existing stored contracts remain readable.
    • Earlier protocol versions retain their existing behavior.

… (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]>
@github-actions github-actions Bot added this to the v5.0.0 milestone Oct 1, 2026
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 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-10-01T13:57:01.537Z

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

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: 38125353-e177-4527-8075-2011cbadb5f7

📥 Commits

Reviewing files that changed from the base of the PR and between 1df377b and 629d4f7.

📒 Files selected for processing (14)
  • book/src/contract-keywords.md
  • book/src/contract-keywords/aggregates.md
  • book/src/contract-keywords/contested.md
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/contested_summed_value_bounds_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_common/contract_structure_test_harness.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/contract_structure_error_tests.rs
  • packages/rs-platform-version/src/version/mocks/v2_test.rs
  • packages/rs-platform-version/src/version/system_limits/mod.rs
  • packages/rs-platform-version/src/version/system_limits/v1.rs
  • packages/rs-platform-version/src/version/system_limits/v2.rs
  • packages/rs-platform-version/src/version/system_limits/v3.rs
  • packages/rs-platform-version/src/version/system_limits/v4.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

Protocol 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.

Changes

Contested summed-value validation

Layer / File(s) Summary
Versioned limit and documented rule
packages/rs-platform-version/src/version/system_limits/*, packages/rs-platform-version/src/version/mocks/v2_test.rs, packages/rs-platform-version/src/version/v14.rs, book/src/contract-keywords.md, book/src/contract-keywords/*
SystemLimits adds an optional magnitude cap. Protocol version 14 sets it to 2^27; earlier versions leave it unset. The documentation describes the bound for summed properties on contested-index document types.
Parser validation and schema tests
packages/rs-dpp/src/data_contract/document_type/class_methods/try_from_schema/v3/*
Generation 3 full validation requires both integer bounds to stay within the configured limit when a document type has a contested index and a summed property. Tests cover bounds, $ref resolution, skipped-validation cases, and protocol version 13.
Contract registration transition tests
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_common/contract_structure_test_harness.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/contract_structure_error_tests.rs
State-transition tests check that the latest protocol rejects a contract with an unbounded contested sum during block processing, while protocol version 13 registers the same schema successfully.

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
Loading

Merge Risk: ⚪ Minimal · up to 629d4

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 Review

Security architecture risk: 🔵 Low · up to 629d4

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The relevant failure-containment boundary is shared consensus-state processing, not merely an individual client's schema parser. An award insertion error propagates out of ended-poll processing before the finished-poll record and cleanup steps.

Trust Boundaries and Controls

  • observed — Schema authors supply the property declarations and bounds, but enforcement reads the magnitude cap from platform-version configuration. Dotted paths and references are resolved before checking both bounds, preventing those schema representations from simply avoiding the check.

Resilience and Maintainability Implications

  • observed — Winning-document insertion, finished-poll recording, and cleanup receive the same transaction argument and execute in that order. This establishes local ordering, but the reviewed excerpts do not establish transaction-wide rollback, retry idempotency, or recovery after interruption.

Hardening Proposals

  • proposed — Before activation, establish an end-to-end case for a PV13-registered unbounded contested-summed contract completing under PV14, including aggregate insertion failure, rollback, and retry. This would clarify legacy safety without treating the registration bound as a universal migration guarantee.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: bounding summed values for contested document types in protocol version 14. The breaking-change marker is appropriate.
Docstring Coverage ✅ Passed Docstring coverage is 80.77% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 11 files. (3 skipped: 3…
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.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@QuantumExplorer
QuantumExplorer merged commit b4bd5b1 into v5.0-dev Oct 1, 2026
42 of 44 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/contested-summed-value-bounds branch October 1, 2026 14:14
@thepastaclaw

thepastaclaw commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 8th in line, estimated start in ~2.0 h (commit 629d4f7)
Estimated review time once started: ~1.3 h (two-phase automated review; median of recent runs).

  • Request priority review — click to move this review to the front of the queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants