Token-0x

First Flight #54
Beginner FriendlyDeFi
100 EXP
View results
Submission Details
Severity: high
Valid

Burn Underflow-_burn() has no balance check causing underflow and unlimited token creation

Root + Impact

Description

  • In a standard ERC20, burning more tokens than the account balance should revert.

  • In Token-0x, _burn() does not verify the balance before subtracting, causing an underflow in Yul (which has no automatic overflow checks).

// src/helpers/ERC20Internals.sol#L158-L180
function _burn(address account, uint256 value) internal {
assembly ("memory-safe") {
// ... address(0) check only
let accountBalanceSlot := keccak256(ptr, 0x40)
let accountBalance := sload(accountBalanceSlot)
@> // No check: if value > accountBalance, underflow occurs!
@> sstore(accountBalanceSlot, sub(accountBalance, value))
}
}

Risk

Likelihood:

  • Any contract inheriting Token-0x that exposes _burn() is vulnerable

  • A simple call with value > balance triggers the bug

Impact:

  • User balance wraps to type(uint256).max - difference

  • Attacker gains mass balance of tokens

  • Token supply accounting completely broken

Proof of Concept

function test_BUG_BurnUnderflowDemonstration() public {
token.mint(alice, 100e18);
uint256 balanceBefore = token.balanceOf(alice);
console.log("Balance before burn:", balanceBefore); // 100e18
token.burn(alice, 101e18); // Burn more than balance
uint256 balanceAfter = token.balanceOf(alice);
console.log("Balance after burn:", balanceAfter);
// Output: 115792089237316195423570985008687907853269984665640564039456584007913129639936
}

Recommended Mitigation

function _burn(address account, uint256 value) internal {
assembly ("memory-safe") {
// ...
let accountBalance := sload(accountBalanceSlot)
+ // Check balance before burning
+ if lt(accountBalance, value) {
+ mstore(0x00, shl(224, 0xe450d38c)) // ERC20InsufficientBalance
+ mstore(add(0x00, 4), account)
+ mstore(add(0x00, 0x24), accountBalance)
+ mstore(add(0x00, 0x44), value)
+ revert(0x00, 0x64)
+ }
sstore(accountBalanceSlot, sub(accountBalance, value))
}
}
---
Updates

Lead Judging Commences

gaurangbrdv Lead Judge 19 days ago
Submission Judgement Published
Validated
Assigned finding tags:

overflow & underflow

missing checks for overflow and underflow.

Support

FAQs

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

Give us feedback!