Token-0x

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

Unchecked Overflow in `_mint`

Author Revealed upon completion

Description

  • The _mint function is expected to increase the total supply and user balance by a specific amount.

  • The implementation uses unchecked Yul add instructions; this allows the total supply or balance to wrap around from type(uint256).max to 0 without reverting.

/// File: src/helpers/ERC20Internals.sol:L147
@> sstore(supplySlot, add(supply, value)) // No overflow check

Risk

Likelihood:

  • A malicious admin or open mint function allows minting enough tokens to exceed 2^256 - 1.

Impact:

  • Total supply accounting becomes corrupt, potentially showing 0 supply despite massive holder balances.

  • This breaks the totalSupply == sum(balances) invariant which is critical for many DeFi protocols.

Proof of Concept

function test_MintOverflow() public {
// 1. Setup
uint256 initialAmount = type(uint256).max - 10;
token.mint(alice, initialAmount);
// 2. Exploit steps
// Mint 20 tokens. Should overflow.
// (max - 10) + 20 = 9 (wrapped)
token.mint(alice, 20);
// 3. Assertions (impact)
uint256 expectedBalance = 9;
console.log("Alice Balance:", token.balanceOf(alice));
assertEq(token.balanceOf(alice), expectedBalance, "Balance did not overflow as expected");
}

Recommended Mitigation

+ if gt(value, sub(not(0), supply)) { revert(0,0) }
sstore(supplySlot, add(supply, value))

Support

FAQs

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

Give us feedback!