Token-0x

First Flight #54
Beginner FriendlyDeFi
100 EXP
Submission Details
Impact: high
Likelihood: high

Unchecked Yul Arithmetic Enables Overflow/Underflow in Token Accounting

Author Revealed upon completion

Root + Impact

Description

  • The ERC20 implementation uses custom Yul-based internals for balance and allowance updates.
    These operations may bypass Solidity 0.8’s built-in safety checks, allowing arithmetic overflow or underflow.

  • This can corrupt balances, break total supply, or enable mint-like behavior by wrapping values around uint256.


// ERC20Internals.sol (example structure)
function _update(address from, address to, uint256 value) internal {
assembly {
// @> raw sload/sstore + add/sub without checked arithmetic
// @> missing overflow / underflow protections
let fromBal := sload(from)
sstore(from, sub(fromBal, value)) // underflow if fromBal < value
let toBal := sload(to)
sstore(to, add(toBal, value)) // overflow wraps silently
}
}

Risk

Likelihood:

  • Custom Yul arithmetic executes without 0.8 overflow checks.

  • Any wallet or attacker transferring near boundary values can trigger wrap-around.

Impact:

  • Balance corruption.

Possible infinite mint through overflowed balances.

  • Permanent state damage leading to stuck or invalid supply.

Proof of Concept

function testOverflow() external {
address attacker = address(0xBEEF);
// Attacker manually sets balance near uint256 max (via compromised transfer / bridge / airdrop)
vm.store(token, token.balanceSlot(attacker), bytes32(uint256(type(uint256).max - 10)));
// Transfer should revert — but with unchecked Yul, it wraps
token.transfer(victim, 50);
// Attacker receives effectively infinite tokens due to wrap-around
}

Recommended Mitigation

- remove this code
+ add this code
- sstore(from, sub(fromBal, value))
- sstore(to, add(toBal, value))
+ if (fromBal < value) revert InsufficientBalance();
+ sstore(from, fromBal - value);
+ sstore(to, toBal + value);

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!