Skip to content

feat(platform)!: maxBytes, a UTF-8 byte cap on document strings (PV14) - #4957

Merged
QuantumExplorer merged 3 commits into
v4.2-devfrom
feat/max-bytes-sum-of-properties
Sep 24, 2026
Merged

QuantumExplorer merged 3 commits into
v4.2-devfrom
feat/max-bytes-sum-of-properties

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

maxLength counts characters, and a UTF-8 character is up to four bytes, so a document schema cannot cap a string's size in bytes. The moderation charter proposal needs exactly that (its description must fit 4096 bytes), and so far it lived in charter-specific Rust.

This PR adds a general maxBytes schema keyword and moves the charter description onto it.

What was done?

maxBytes is the most UTF-8 bytes a string may take. It goes on a string property, or on the items of a typed array of strings, where it bounds every element.

Before, the v3 meta-schema refused it as an unknown keyword:

"bio": { "type": "string", "maxLength": 64, "maxBytes": 16, "position": 0 }

After, the contract registers:

Value of bio Characters Bytes Result
"éééééééé" 8 16 accepted
"ééééééééé" 9 18 refused: DocumentPropertyMaxBytesExceededError (10421), Property bio is 18 bytes in UTF-8, over its maxBytes of 16

For a typed array the error names the element, e.g. tags[2].

Rules:

  • At registration: 1 to 65535, and no lower than minLength. It is refused on non-strings and on the typed array itself.
  • On update: it moves like maxLength. Raising or removing it is allowed; adding or lowering it is refused.

Where it's stored: apply_max_bytes folds it into StringPropertySizes::max_bytes, next to max_length. So size estimates, and random documents in strategy tests and fixtures, respect it. Before, maxLength: 64 with maxBytes: 16 was estimated at 256 bytes; now it's 16.

Where it's checked: inside DataContract::validate_document_properties, right after the JSON Schema. That covers every create and replace, CheckTx, and client-side validation (wasm-dpp document.validate), so an SDK refuses an oversized string before the writer pays for a consensus refusal. The version slots apply_max_bytes and validate_max_bytes are Some(0) from protocol version 14 and None before.

Moderation charters: submittedCharter.description declares "maxBytes": 4096. Before this PR, a 2049-é description (4098 bytes) was accepted at create, since the charter check wasn't wired into consensus. Now it is refused with 10421.

Removed as redundant:

  • the description check in SubmittedCharter::validate
  • ModerationCharterDescriptionTooLongError (11002)
  • SystemLimits::max_moderation_charter_description_length

The reward split rule (validate_submitted_charter, error 11001) is unchanged, so #4952 keeps compiling.

Errors:

  • BasicError discriminant 198 moves from the removed 11002 error to 10421. Both are unreleased (protocol version 14), and the frozen-tail test pins it.
  • The wasm-dpp mapping is updated.
  • wasm-dpp2 exposes DocumentMaxBytesErrorCode.MaxBytesExceeded.

Also:

  • distinctFrom's "belongs on the items" handling moved into a helper shared with maxBytes. Its messages are unchanged.
  • A lint error in wasm-dpp2/tests/unit/DocumentPropertyReference.spec.ts is fixed (a parameter shadowed schemas, from #4940).

In-place changes to shipped generations

  • DataContract::validate_document_properties v0 now calls validate_max_bytes_properties. It is inert before protocol version 14: the validate_max_bytes slot is None, and no string parsed there can carry the keyword (meta-schemas v0 to v2 refuse unknown property keywords, $defs included, and apply_max_bytes is None). A drive-abci test runs an over-cap replace at protocol version 13 (accepted) and 14 (refused).
  • max_byte_size and max_size change only for strings with max_bytes: Some, which only protocol version 14 parses produce.
  • CONTRACT_VERSIONS_V1 to V5 gain the two slots as None.
  • SYSTEM_LIMITS_V1 to V3 lose the charter description limit, which was never read below protocol version 14.
  • The compatibility rule set gains a maxBytes rule. The keyword cannot appear in a schema admitted before meta-schema v3.

How Has This Been Tested?

  • rs-dpp: full library suite, 4836 passed. New tests cover:
    • parse rules and meta-schema refusals, and the parse being ignored before protocol version 14
    • size bounds, and random values staying within the cap
    • write-time checks, including nested and typed-array element paths
    • protocol version 13 inertness
    • update compatibility on properties and typed-array items
    • the charter description at 4096 bytes (accepted) and 4098 bytes (refused)
  • drive-abci: full library suite, 3459 passed. It includes a new e2e file with 5 tests: create and replace, a string and a typed-array element, and the stored document untouched on refusal.
  • rs-drive: full library suite, 3862 passed.
  • Clippy on rs-dpp is clean. wasm-dpp, wasm-dpp2 and wasm-sdk check for wasm32. The wasm-dpp2 lint has 0 errors.
  • JS: the moderation charters contract spec against a rebuilt wasm-dpp, 72 passing. It shows document.validate refusing a 4098-byte description with 10421 and accepting 4096 bytes. Its lint passes.

Breaking Changes

Protocol version 14, which is unreleased:

  • A new keyword and a new basic error (10421).
  • The moderation charters contract bytes change.
  • Error 11002 and SystemLimits::max_moderation_charter_description_length are removed.
  • StringPropertySizes gains a max_bytes field, so struct literals must set it.

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

QuantumExplorer and others added 2 commits September 24, 2026 07:19
…PV14)

Two document schema keywords for bounds plain JSON Schema cannot count:
`maxBytes` caps a string's UTF-8 length (maxLength counts characters) and
`sumOfProperties` is the total an object's integer members must add up to.
Parsed by the v3 parser, checked on document create and replace after the
schema validation (DocumentPropertyMaxBytesExceededError 10421,
DocumentPropertySumMismatchError 10422); replace structure validation 0 is
extended in place and inert before protocol version 14.

The moderation charters contract declares both on the proposal's
description and reward split, replacing validate_submitted_charter, its
errors 11001 and 11002 and SystemLimits::max_moderation_charter_description_length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m-of-properties

# Conflicts:
#	book/src/data-model/documents.md
#	docs/protocol/moderation-charters.md
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 24, 2026
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 44 seconds.

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: 5c35d48b-1d1c-4e47-aab4-47804f5dc8ba

📥 Commits

Reviewing files that changed from the base of the PR and between 342b720 and 1fd989d.

📒 Files selected for processing (50)
  • book/src/data-model/documents.md
  • book/src/error-handling/error-codes.md
  • docs/protocol/moderation-charters.md
  • packages/moderation-charters-contract/README.md
  • packages/moderation-charters-contract/schema/v1/moderation-charters-contract-documents.json
  • packages/moderation-charters-contract/test/unit/moderationChartersContract.spec.js
  • packages/rs-dpp/schema/meta_schemas/document/v3/document-meta.json
  • packages/rs-dpp/src/data_contract/document_type/class_methods/parse_typed_array/mod.rs
  • 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/max_bytes_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/typed_array_tests.rs
  • packages/rs-dpp/src/data_contract/document_type/index/preallocation.rs
  • packages/rs-dpp/src/data_contract/document_type/methods/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/methods/validate_update/common/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs
  • packages/rs-dpp/src/data_contract/document_type/v0/random_document_type.rs
  • packages/rs-dpp/src/data_contract/methods/validate_document/v0/mod.rs
  • packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
  • packages/rs-dpp/src/errors/consensus/basic/document/document_property_max_bytes_exceeded_error.rs
  • packages/rs-dpp/src/errors/consensus/basic/document/mod.rs
  • packages/rs-dpp/src/errors/consensus/basic/moderation_charter/mod.rs
  • packages/rs-dpp/src/errors/consensus/basic/moderation_charter/moderation_charter_description_too_long_error.rs
  • packages/rs-dpp/src/errors/consensus/codes.rs
  • packages/rs-dpp/src/moderation_charter/mod.rs
  • packages/rs-dpp/src/moderation_charter/tests.rs
  • packages/rs-dpp/src/moderation_charter/v0/mod.rs
  • packages/rs-dpp/src/system_data_contracts.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/max_bytes.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/document/mod.rs
  • packages/rs-drive/src/query/conditions.rs
  • packages/rs-json-schema-compatibility-validator/src/rules/rule_set.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/mod.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v1.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v2.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v3.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v4.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v5.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v6.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
  • packages/wasm-dpp/src/errors/consensus/consensus_error.rs
  • packages/wasm-dpp2/src/consensus_error.rs
  • packages/wasm-dpp2/tests/unit/DocumentPropertyReference.spec.ts

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 24, 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-24T01:26:14.505Z

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

thepastaclaw commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 9th in line, estimated start in ~1.8 h (commit 1fd989d)
Estimated review time once started: ~25 min (two-phase automated review; median of recent runs).

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

Drop sumOfProperties (keyword, error 10422, version slots, compatibility
rule); the charter's reward split rule goes back to validate_submitted_charter
and error 11001, unchanged from the base branch.

maxBytes review fixes:
- the bound lives in StringPropertySizes::max_bytes, so max_byte_size,
  max_size and random documents respect it
- the check runs inside DataContract::validate_document_properties, so
  client-side validation (wasm-dpp document.validate) refuses an oversized
  string before broadcast; the create and replace structure validations
  are back to the base branch
- typed_array_items_keyword shared by distinctFrom and maxBytes
- book: maxLength alone is bounded by the 5120-byte field cap
- wasm-dpp2 DocumentMaxBytesErrorCode; test names start with "should"
- tests for typed-array items compatibility and a typed-array element
  refusal end to end

Also fixes a wasm-dpp2 lint error (a parameter shadowing `schemas` in
DocumentPropertyReference.spec.ts) that failed the lint job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@QuantumExplorer QuantumExplorer changed the title feat(platform)!: maxBytes on strings and sumOfProperties on objects (PV14) feat(platform)!: maxBytes, a UTF-8 byte cap on document strings (PV14) Sep 24, 2026

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@QuantumExplorer
QuantumExplorer merged commit db2fad6 into v4.2-dev Sep 24, 2026
20 of 21 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/max-bytes-sum-of-properties branch September 24, 2026 01:29
@github-actions github-actions Bot removed the waiting-bots Waiting for the review bots to report on this head label Sep 24, 2026
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