Skip to content

fix(dpp): hold arrays to the maximum schema depth in validate_max_depth v2 - #5881

Merged
shumkov merged 1 commit into
v5.1-devfrom
shumkov/v51-max-depth-arrays
Nov 12, 2026
Merged

shumkov merged 1 commit into
v5.1-devfrom
shumkov/v51-max-depth-arrays

Conversation

@shumkov

@shumkov shumkov commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Follow-up to #5871, from the thepastaclaw suggestion on it (comment).

validate_max_depth 2, the schema depth and cycle check that #5871 added and that only protocol version 15 selects, raised the reached depth for an array but compared only maps with the maximum. A schema whose deepest levels are all arrays, such as a nested const or enum value, could therefore go past the maximum depth and still pass, as long as no deeper map triggered the map branch's check.

What was done?

  • The array branch of validate_max_depth_v2 now refuses one level past the maximum with the same DataContractMaxDepthExceedError as the map branch. Like the map branch, the result carries the size measured so far, which the registration helper reads on the rejection path to bill the schema. Both branches build that result through one helper, max_depth_exceeded.
  • Generations 0 and 1 are unchanged.
  • The v15 note on validate_max_depth 2 and the CONTRACT_VERSIONS_V7 comment now say that a schema whose array nesting alone exceeds the maximum depth is refused at registration and update.

Generation 2 exists only in protocol version 15. That version is unreleased and not active on testnet or mainnet (both run protocol version 14), so it is fixed in place. No shipped generation changes.

How Has This Been Tested?

New tests in validate_max_depth/v2, built on a document type schema whose const holds arrays nested around a scalar:

  • should_accept_an_array_only_tail_reaching_exactly_the_depth_limit: arrays alone reach exactly the maximum depth; the schema is accepted and its exact depth and size are checked.
  • should_refuse_an_array_only_tail_past_the_depth_limit_from_protocol_version_15: arrays alone reach one level past the maximum. Protocol version 14 (generation 1) still accepts it and reports a depth past the maximum. The latest version refuses it with DataContractMaxDepthExceedError and the size measured before that level.

Red to green: before the fix, the over-limit test failed because the latest-version result had no errors. It passes after the fix.

Also run locally on the rebased branch:

  • cargo test -p dpp --all-features --lib --tests: 6105 passed, plus all integration tests, including the contract corpus loading at protocol versions 13, 14 and latest.
  • cargo clippy -p dpp -p platform-version --all-features --all-targets -- -D warnings: clean.
  • cargo fmt --all -- --check: clean.

Breaking Changes

None for any released or active protocol version. At unreleased protocol version 15, a contract whose schema has array nesting alone past the maximum depth is now refused at registration and update.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • 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
  • If I added or changed a system contract's document schemas, I checked the contract 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 · 6e18118

  • Bots — thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed
  • Build running
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • Bug Fixes
    • Schema depth validation now counts array nesting as well as map nesting. Contracts that exceed the limit through arrays are rejected during registration or update with a depth-limit error.
    • Validation now handles $ref pointers consistently with JSON Pointer rules, rejecting pointers whose interpretation differs under those rules.

…th v2

Generation 2 of the schema depth and cycle check raised the reached depth
for an array but compared only maps with the maximum, so a schema whose
deepest levels are arrays alone, such as a nested `const` or `enum` value,
passed the check past the maximum depth. The array branch now refuses one
level past the maximum with the same DataContractMaxDepthExceedError as the
map branch, carrying the size measured so far for the registration helper
to bill. Both branches build that result through one helper.

Generation 2 is selected only by protocol version 15, which is unreleased
and not active on testnet or mainnet, so it is fixed in place; generations
0 and 1 are unchanged. The v15 note and the CONTRACT_VERSIONS_V7 comment now
state that a schema whose array nesting alone exceeds the maximum depth is
refused at registration and update.

Tests: an array-only `const` tail exactly at the maximum depth is accepted
with its depth and size; one level over is refused with the depth error and
the size measured before it, while protocol version 14 (generation 1) still
accepts it.

Test would have caught this in CI: ✖ before fix
(should_refuse_an_array_only_tail_past_the_depth_limit_from_protocol_version_15
failed: no errors at the latest version), ✔ after.

Addresses the thepastaclaw suggestion on #5871.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shumkov shumkov added this to the v5.1.0 milestone Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The v2 maximum-depth validator now applies the configured limit to arrays as well as maps. It returns the depth consensus error when array nesting exceeds the limit. Tests and platform-version documentation describe the behavior across protocol versions 14 and 15.

Changes: Maximum-depth validation

Layer / File(s) Summary
Enforce the depth limit for arrays
packages/rs-dpp/src/data_contract/document_type/schema/validate_max_depth/v2/mod.rs, packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v7.rs
The validator now checks array nesting against the maximum depth. Map and array over-limit paths use a shared error result that includes the maximum depth, deepest depth reached, and size measured so far.
Verify and document version behavior
packages/rs-dpp/src/data_contract/document_type/schema/validate_max_depth/v2/mod.rs, packages/rs-platform-version/src/version/v15.rs
Tests cover array nesting at and beyond the limit. The beyond-limit case is accepted by protocol version 14 and rejected by version 15. The v15 documentation describes registration and update behavior and notes unchanged parser generation and stored-contract loading behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • dashpay/platform#5871: Adds the v2 maximum-depth validator and establishes its protocol-version configuration and $ref documentation, which this PR extends with array-depth enforcement.

Suggested reviewers: quantumexplorer, thepastaclaw

Merge Risk: Minimal · up to 6e181

The change makes over-deep array nesting fail contract registration and update under the unreleased protocol version 15. Released versions keep their current behavior. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the v2 validate_max_depth now applies the maximum schema depth to arrays, as well as maps. The raw summary and objectives both confirm that array-only nesting over the…
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.
Full details: Title check

Explanation

The title names the main change: the v2 validate_max_depth now applies the maximum schema depth to arrays, as well as maps. The raw summary and objectives both confirm that array-only nesting over the limit is now refused with DataContractMaxDepthExceedError. The title uses the 'fix(dpp)' prefix, which is a conventional commit form and does not affect relevance.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6718211 and 6e18118.

Files selected for processing: 3

  • packages/rs-dpp/src/data_contract/document_type/schema/validate_max_depth/v2/mod.rs
  • packages/rs-platform-version/src/version/dpp_versions/dpp_contract_versions/v7.rs
  • packages/rs-platform-version/src/version/v15.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.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

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

thepastaclaw commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress — actively reviewing now (commit 6e18118) · triage: low
███████░░░░░░░░░░░░░ 36% · about 55 min left · running for 31 min
✅ triage → ⏳ Phase 1 (0/2 lanes) → ▫️ verify 1 → ▫️ gate → ▫️ Phase 2 → ▫️ verify 2 → ▫️ publish
Estimated from recent reviews of this tier · updated 08:18 UTC · live progress

@shumkov
shumkov merged commit 7e35205 into v5.1-dev Nov 12, 2026
29 of 31 checks passed
@shumkov
shumkov deleted the shumkov/v51-max-depth-arrays branch November 12, 2026 08:24
QuantumExplorer added a commit that referenced this pull request Nov 12, 2026
…roposal-contract-1db678

Brings in v5.1-dev at 8b4ca80: the pin of the bytes protocol version 15
stores contracts in (#5880) and the array depth fix of validate_max_depth 2
(#5881). The merge is clean.

The stored contract fixture is regenerated for the one contract this branch
changes: the decision proposals contract, which gains `multipleChoiceProposal`
and `choice` at protocol version 15 (unreleased). No other line of
`stored.jsonl` changes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
QuantumExplorer added a commit that referenced this pull request Nov 12, 2026
…ecision-proposal-description-reference

Brings in v5.1-dev at 8b4ca80 (the pin of the bytes protocol version 15
stores contracts in, #5880, and the array depth fix of validate_max_depth 2,
#5881) and the multiple choice proposals branch's README and protocol guide
wording on when a choice leaves state and how its fund grows.

The stored contract fixture is regenerated for the one contract this branch
changes: the decision proposals contract, whose `multipleChoiceProposal`
names its description through a reference here. No other line of
`stored.jsonl` changes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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