-
Notifications
You must be signed in to change notification settings - Fork 206
Description
Describe the bug
Affected Component
TIP-20 Token Precompile (crates/precompiles/src/tip20/mod.rs)
Description
The TIP-20 token precompile detects overflow/underflow conditions in critical operations (mint, transfer, burn) but does not provide sufficient logging information when these errors occur. This makes debugging overflow scenarios extremely difficult in production environments.
When an overflow is detected, the precompile returns a generic PanicKind::UnderOverflow error without logging:
- Which operation failed (mint/transfer/burn)
- Which account was involved
- Current balance/supply values
- The amount that caused the overflow
- Supply cap constraints
Root Cause
The overflow detection uses ok_or(TempoPrecompileError::under_overflow()) which creates the error inline without context:
// BEFORE (insufficient logging)
let new_supply = total_supply
.checked_add(amount)
.ok_or(TempoPrecompileError::under_overflow())?;This should be replaced with ok_or_else(|| { ... }) to enable logging at the error site:
// AFTER (with detailed logging)
let new_supply = total_supply
.checked_add(amount)
.ok_or_else(|| {
tracing::error!(
total_supply = %total_supply,
amount = %amount,
supply_cap = %self.supply_cap(),
"TIP20 mint: total supply overflow detected"
);
TempoPrecompileError::under_overflow()
})?;Affected Operations
- Mint - Total Supply Overflow: When
total_supply + amountexceeds u128::MAX or supply_cap - Mint - Balance Overflow: When
recipient_balance + amountwould overflow - Transfer - Sender Underflow: When
sender_balance < amount(insufficient balance) - Transfer - Recipient Overflow: When
recipient_balance + amountwould overflow - Burn - Opted-in Supply Underflow: When opted-in supply accounting underflows
- Fee Refund - Opted-in Supply Overflow: When opted-in supply accounting overflows during refund
Steps to reproduce
Scenario 1: Mint Total Supply Overflow
- Deploy a TIP-20 token with a supply cap set to a specific value
- Mint tokens up to the supply cap
- Attempt to mint additional tokens that would exceed the cap
- Observe that the transaction reverts with
PanicKind::UnderOverflow - Check logs - no detailed information about:
- Current total supply
- Amount being minted
- Supply cap value
Expected: Logs showing the exact values that caused overflow
Actual: Generic error with no diagnostic information
Scenario 2: Mint Balance Overflow
- Create a TIP-20 token
- Mint
u128::MAXtokens to an address - Attempt to mint additional tokens to the same address
- Transaction reverts with overflow
- No logs indicate which address or what balance/amount values were involved
Logs
Platform(s)
Linux (x86)
Container Type
Not running in a container
What version/commit are you on?
v1.0.2 - the Presto release
If you've built from source, provide the full command you used
No response
Code of Conduct
- I agree to follow the Code of Conduct