Skip to content

fix(drive-abci)!: refuse a token mint or direct purchase past the i64::MAX supply ceiling (PV14) - #5000

Merged
QuantumExplorer merged 2 commits into
v4.2-devfrom
claude/token-supply-overflow-fix-0479a7
Sep 25, 2026
Merged

QuantumExplorer merged 2 commits into
v4.2-devfrom
claude/token-supply-overflow-fix-0479a7

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

A token's total supply is stored in a GroveDB sum item, so it can never be more than i64::MAX. Token mint and token direct purchase state validation checked the supply only against a configured maxSupply. With no max supply, or one above i64::MAX (creation accepts any u64), a mint or purchase that takes the supply past i64::MAX passed validation. It then failed in execution on Drive's overflow guard (add_to_token_total_supply v0, CorruptedCodeExecution) as an internal error. An internal error charges nothing and bumps no nonce, so the same transition could be sent again and again.

A contract can start with a base supply of i64::MAX, so one mint of 1 reaches the case. Without that, a single mint is capped at 2^48 - 1, so it takes about 32,768 paid mints to reach it.

Once-per-identity claims (#4827) already treat i64::MAX as a ceiling. The other claim kinds saturate at the ceiling, so they never fail.

What was done?

  • New state_v1 for TokenMintTransitionAction and TokenDirectPurchaseTransitionAction, copied from state_v0. The only change is the supply check: the ceiling is max_supply.map_or(i64::MAX, |m| m.min(i64::MAX)), and it is checked on every mint and purchase. A transition past it gets the existing paid TokenMintPastMaxSupplyError, with i64::MAX reported as the max supply.
  • DRIVE_ABCI_VALIDATION_VERSIONS_V10 (protocol version 14 only) selects v1 for token_mint_transition_state_validation and token_direct_purchase_transition_state_validation. Earlier protocol versions keep v0.
  • Documented as item 43 in the PLATFORM_V14 doc comment.

Fee: v0 read the total supply only when a max supply was set. v1 always reads it, so at protocol version 14 a mint or purchase of a token without a max supply pays for one more read.

Before, a token created with baseSupply: 9223372036854775807 (i64::MAX) and no maxSupply, then a mint of 1:

InternalError("... trying to add an amount that would overflow total supply")
not charged, nonce not bumped, supply unchanged

The same happens with maxSupply: 18446744073709551615 (u64::MAX), since i64::MAX + 1 is under it. A direct purchase of 1 token gives the same result.

After (protocol version 14):

PaidConsensusError(StateError::TokenMintPastMaxSupplyError {
    amount: 1,
    current_supply: 9223372036854775807,
    max_supply: 9223372036854775807,
})
charged, nonce bumped, supply unchanged

Mints and purchases that stay under the ceiling behave as before, apart from the extra read.

In-place changes to shipped generations

None. Both state_v0 modules are unchanged. The new behaviour is in new state_v1 modules, selected only by DRIVE_ABCI_VALIDATION_VERSIONS_V10, which only protocol version 14 uses.

How Has This Been Tested?

  • Mint (batch/tests/token/mint): the characterization test that pinned the internal error at the latest version is replaced by:
    • test_token_mint_past_i64_max_supply_without_max_supply_is_paid_consensus_error
    • test_token_mint_past_i64_max_supply_with_a_higher_max_supply_is_paid_consensus_error (maxSupply: u64::MAX)
    • test_token_mint_past_i64_max_supply_is_internal_error_protocol_version_13: both cases at protocol version 13 still give the uncharged internal error.
  • Direct purchase (batch/tests/token/direct_selling): the same three tests.
  • Each test also checks that the total supply is unchanged, and whether the sender was charged.
  • Fee re-pin: test_successful_direct_purchase_single_price (protocol version 14) pays 8,420 credits more for the supply read, 699_868_045_440 -> 699_868_037_020. Its _protocol_version_13 and _protocol_version_11 twins pass unchanged.
  • cargo test -p drive-abci --lib -- batch::tests::token: 230 passed after the re-pin (7 ignored, as before). token_mint_confirmation_check_tx passes.

Breaking Changes

Consensus, protocol version 14: a token mint or direct purchase that would take the total supply past i64::MAX is refused with a paid TokenMintPastMaxSupplyError. Before, it was an uncharged internal error. Every mint and direct purchase now reads the total supply and pays for that read.

Not changed here: data contract creation still accepts a base supply above the max supply (see the ignored test test_data_contract_creation_with_base_supply_over_max_supply_should_cause_error). That token can never mint, but it cannot pass the ceiling either.

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

…::MAX supply ceiling (PV14)

A token's total supply is stored in a sum item, so it can never pass
i64::MAX. Mint and direct purchase state validation v0 checked only a
configured max supply. With none configured, or one above i64::MAX, a
mint or purchase past the ceiling passed validation and failed in
execution on Drive's overflow guard as an internal error, which charges
nothing.

State validation v1 of both treats i64::MAX as the max supply when none
is configured and caps a configured one there, refusing with the paid
TokenMintPastMaxSupplyError, as once-per-identity claims already do.
Selected at protocol version 14 only; v13 keeps v0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

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: 7dc576c3-472b-414c-bba1-e801dcef5498

📥 Commits

Reviewing files that changed from the base of the PR and between 2498727 and ece954e.

📒 Files selected for processing (8)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_direct_purchase_transition_action/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_direct_purchase_transition_action/state_v1/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_mint_transition_action/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_mint_transition_action/state_v1/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/direct_selling/mod.rs
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/mint/mod.rs
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v10.rs
  • packages/rs-platform-version/src/version/v14.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Token mint and direct-purchase validation now use version 1 checks that cap total supply at i64::MAX, including when no maximum is configured. Tests cover rejection at the latest protocol version and the prior overflow behavior at protocol version 13.

Changes

Token Supply Ceiling

Layer / File(s) Summary
V1 validation dispatch and protocol activation
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_direct_purchase_transition_action/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_mint_transition_action/mod.rs, packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v10.rs, packages/rs-platform-version/src/version/v14.rs
Both action validators dispatch version 1 to their V1 implementations. The validation-version fields change to 1, and the v14 change description records the total-supply ceiling.
Mint and purchase supply checks
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_direct_purchase_transition_action/state_v1/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_mint_transition_action/state_v1/mod.rs
The V1 validators reject supply addition overflow or resulting supply above the configured maximum capped at i64::MAX. Mint validation also checks authorization, existing mint actions, recipient identity, and frozen accounts.
Supply-ceiling protocol tests
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/direct_selling/mod.rs, packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/tests/token/mint/mod.rs
Tests check paid max-supply errors and unchanged balances at the latest protocol version. Protocol-version-13 tests check uncharged internal overflow errors.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Dispatcher as Token transition dispatcher
  participant Validator as TokenDirectPurchaseTransitionActionStateValidationV1
  participant Drive as Drive state
  Dispatcher->>Validator: Dispatch validation version 1
  Validator->>Drive: Fetch token configuration and total supply
  Drive-->>Validator: Return configuration and current supply
  Validator-->>Dispatcher: Return validation result
Loading
sequenceDiagram
  participant Dispatcher as Token transition dispatcher
  participant Validator as TokenMintTransitionActionStateValidationV1
  participant Drive as Drive state
  Dispatcher->>Validator: Dispatch validation version 1
  Validator->>Drive: Fetch total supply and recipient state
  Drive-->>Validator: Return supply and recipient data
  Validator-->>Dispatcher: Return validation result
Loading

Merge Risk: ⚪ Minimal · up to ece95

At protocol version 14, token mints and direct purchases that would push total supply past i64::MAX are rejected with a paid max-supply error instead of failing as an uncharged internal error. Earlier protocol versions keep their previous behavior. The only cost is one additional supply read. No blocking issues were identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ece95

The change closes a path where an over-ceiling mint or purchase failed without a charge. The reviewed paths show no new authorization bypass, but simultaneous-transaction behavior was not fully established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed validation applies to protocol-selected token mint and direct-purchase transitions, with the affected supply state identified by token ID; no new service or credential authority is shown.

Security Findings and Attack Paths

  • inferred — An over-ceiling transition that reached v13’s execution overflow could be retried without a charge; V1 instead refuses that input as a paid consensus error. The reviewed paths establish no new authorization bypass.

Trust Boundaries and Controls

  • observed — Both V1 paths return an invalid shared base-validation result before reading supply; mint additionally checks group authority and preserves existing group-action parameters.

Resilience and Maintainability Implications

  • inferred — The supply writer’s independent overflow guard limits the consequence of a validation/write mismatch. The reviewed sequential batch path does not establish how conflicting concurrent transaction commits are resolved.

Hardening Proposals

  • proposed — Exercise multiple same-token actions and conflicting transaction contexts at the ceiling to establish fee, nonce, supply, and recovery outcomes beyond the single-transition tests.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing token mints and direct purchases from exceeding the i64::MAX supply ceiling in protocol version 14.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

@thepastaclaw

thepastaclaw commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 3rd in line, estimated start in ~25 min (commit b9f1978)
Estimated review time once started: ~35 min (two-phase automated review; median of recent runs).

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

…upply read

Direct purchase state validation v1 reads the total supply on every
purchase, so the buyer pays 8,420 credits more at protocol version 14.
The protocol version 13 and 11 twins are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 25, 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

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