Repository navigation
fix(drive-abci)!: refuse a token mint or direct purchase past the i64::MAX supply ceiling (PV14) - #5000
Conversation
…::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]>
|
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 configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughToken mint and direct-purchase validation now use version 1 checks that cap total supply at ChangesToken Supply Ceiling
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
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
Merge Risk: ⚪ Minimal · up to 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 ReviewSecurity architecture risk: 🔵 Low · up to 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 Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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 — 3rd in line, estimated start in ~25 min (commit b9f1978)
|
…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]>
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 configuredmaxSupply. With no max supply, or one abovei64::MAX(creation accepts anyu64), a mint or purchase that takes the supply pasti64::MAXpassed validation. It then failed in execution on Drive's overflow guard (add_to_token_total_supplyv0,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::MAXas a ceiling. The other claim kinds saturate at the ceiling, so they never fail.What was done?
state_v1forTokenMintTransitionActionandTokenDirectPurchaseTransitionAction, copied fromstate_v0. The only change is the supply check: the ceiling ismax_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 paidTokenMintPastMaxSupplyError, withi64::MAXreported as the max supply.DRIVE_ABCI_VALIDATION_VERSIONS_V10(protocol version 14 only) selects v1 fortoken_mint_transition_state_validationandtoken_direct_purchase_transition_state_validation. Earlier protocol versions keep v0.PLATFORM_V14doc 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 nomaxSupply, then a mint of 1:The same happens with
maxSupply: 18446744073709551615(u64::MAX), sincei64::MAX + 1is under it. A direct purchase of 1 token gives the same result.After (protocol version 14):
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_v0modules are unchanged. The new behaviour is in newstate_v1modules, selected only byDRIVE_ABCI_VALIDATION_VERSIONS_V10, which only protocol version 14 uses.How Has This Been Tested?
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_errortest_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.batch/tests/token/direct_selling): the same three tests.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_13and_protocol_version_11twins 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_txpasses.Breaking Changes
Consensus, protocol version 14: a token mint or direct purchase that would take the total supply past
i64::MAXis refused with a paidTokenMintPastMaxSupplyError. 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:
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