Don't Get Rekt

Smart contract bugs / Is the math and the design right?

Integer overflow, underflow and unsafe casts

A number wraps around: a balance under zero becomes huge, or a large value cut to fewer bits becomes small. Solidity 0.8 checks most math, but not unchecked blocks, casts or assembly.

OWASP SC09:2026 · 13 real exploits · $1.3B lost

How the attack works

  1. Before Solidity 0.8, +, - and * wrapped silently. Many old contracts and forks still use 0.6 or 0.7.
  2. In 0.8, math inside unchecked { } and in inline assembly still wraps.
  3. A cast such as uint128(x) cuts the high bits with no error.
  4. The attacker gives a value that wraps, so a check passes or a balance becomes very large.

Vulnerable and fixed code

Vulnerable
// Solidity 0.7: no checks on math
function transfer(address to, uint256 amt) external {
    require(balance[msg.sender] - amt >= 0); // always true: uint underflows
    balance[msg.sender] -= amt;
    balance[to] += amt;
}

// Solidity 0.8: a cast cuts the high bits with no error
uint128 stored = uint128(amount);
Fixed
// Solidity ^0.8.20: checked math by default
function transfer(address to, uint256 amt) external {
    require(balance[msg.sender] >= amt, "balance");
    balance[msg.sender] -= amt;
    balance[to] += amt;
}

import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
uint128 stored = SafeCast.toUint128(amount); // reverts if too large

Review checklist

  • Use Solidity 0.8 or later. If you must use an older version, use SafeMath on every operation.
  • Use unchecked only where you can prove that the value cannot wrap. Write the proof in a comment.
  • Use SafeCast for every downcast.
  • Review all inline assembly math by hand.

How to test for it

  • Fuzz with values near type(uint256).max and near zero.
  • Search the code for unchecked, assembly and uint128(, uint64(, int256( casts.

Real exploits (13)

  • Apr 22, 2018Ethereum$900.0M

    Beauty Chain (BEC): Beauty Chain's BEC token lost a reported $900 million of token value when an integer overflow in batchTransfer() let the attacker mint huge balances.

    Root cause and fix

    Vulnerable code: BecToken · batchTransfer()

    In batchTransfer(), the total amount is computed as receivers.length * _value with no overflow check. The attacker passed two receivers and a _value of 2^255. The product wrapped to 0, so the balance check passed. Each receiver was then credited the huge _value, which created a massive token balance from nothing. The attacker then sold the tokens, and exchanges halted BEC trading.

    What would have stopped it: Use checked arithmetic, such as SafeMath or Solidity 0.8 or later, for every multiplication and addition on token amounts. Also bound _value and the receivers array length, and add a test with extreme values.

    Run the exploit (Foundry PoC) ↗

  • May 22, 2025SuiMove$223.0MFlash loanAudited, bug out of scope

    Cetus: Cetus, a Sui DEX, lost about $223M (of which $162M was frozen by validators) because a flawed overflow check in the shared integer-mate math library let 1 token mint huge liquidity.

    Root cause and fix

    Vulnerable code: integer-mate library · checked_shlw

    The liquidity math (get_liquidity_from_a) relied on the integer-mate library's checked_shlw method. Its overflow check did not cover this path, so with a very narrow tick range (300,000 to 300,200) a deposit of 1 SCA token produced about 10^34 units of liquidity. The attacker took a flash loan of 56,700 SUI, opened the position, then withdrew real SUI and USDC against the inflated liquidity, repaying the loan and keeping the rest. They repeated this across every Cetus pool.

    What would have stopped it: Test the shared math library's overflow and shift checks with edge cases, such as tiny tick ranges and extreme values, using fuzzing and invariant tests. Include third-party math libraries in the audit scope, and require that a deposit's liquidity can never be worth more than the tokens deposited.

    rekt.news article ↗

  • Apr 24, 2018Ethereum$140.0M

    SmartMesh: SmartMesh's SMT token lost about $140M (reported) because transferProxy() did unchecked arithmetic on _value + _feeSmt, which overflowed and let the attacker mint a huge balance.

    Root cause and fix

    Vulnerable code: SmartMesh (SMT token) 0x55f93985431fc9304077687a35a1ba103dc1e081 · transferProxy()

    transferProxy() added the user-supplied _value and _feeSmt without overflow protection (the contract used Solidity before 0.8). The attacker chose _value = 0x8fff...ff and _feeSmt = 0x7000...01. Their sum wraps to 0, so the balance check passed. The attacker passed the same address as _from and _to, with a signature that matched, and the wrapped arithmetic credited the account with a huge amount of tokens.

    What would have stopped it: Use checked arithmetic (Solidity 0.8+ or SafeMath) for every addition and subtraction on balances and amounts. Fuzz test transfer functions with extreme values, and reject _from == _to.

    Run the exploit (Foundry PoC) ↗

  • Jan 8, 2026Ethereum$26.2M

    Truebit: Truebit lost about $26.2M (8,535 ETH) when an unchecked addition in getPurchasePrice() of a 5-year-old Solidity 0.5.3 bonding-curve contract overflowed, letting the attacker mint TRU for almost nothing and burn it for ETH.

    Root cause and fix

    Vulnerable code: Truebit Purchase contract (0x764C64b2A09b09Acb100B80d8c505Aa6a0302EF2) · getPurchasePrice(uint256 amount)

    The contract was compiled with Solidity 0.5.3, which has no built-in overflow checks. SafeMath guarded multiplication and division in getPurchasePrice(), but one addition was left unguarded. With a huge mint amount, that addition wrapped around to near zero, so the quoted ETH cost was about zero. The attacker minted hundreds of millions of TRU for free, sold them back to the contract at the 12.5% buyback rate for real ETH, and repeated this five times in one transaction.

    What would have stopped it: Use Solidity 0.8+ or apply SafeMath to every arithmetic operation, including additions. Add upper bounds on mint amounts and fuzz or invariant-test the pricing function with extreme inputs. Re-audit or sunset legacy contracts that still hold funds.

    rekt.news article ↗Run the exploit (Foundry PoC) ↗

  • Nov 30, 2025Ethereum$9.0M

    Yearn (yETH stableswap pool): Yearn's legacy yETH stableswap pool lost about $9M when an unchecked arithmetic underflow in its Newton-Raphson supply solver let an attacker mint a huge amount of yETH from a dust deposit.

    Root cause and fix

    Vulnerable code: yETH pool (0x69accb968b19a53790f43e57558f5e443a91af22) · calc_supply()

    The pool's calc_supply() Newton-Raphson solver computed s' = (A*Σ - s*r) / (A - PREC) with unchecked arithmetic. It did not check that the invariant state was sane. The attacker first made many remove_liquidity(0) and update_rates() calls. Together with the rounding asymmetry between pow_up and pow_down and OETH's rebasing, these drove the pool to Σ = 0, Π = 0, supply = 0. They then deposited a few wei of several LSTs. With A·Σ < s·r the numerator underflowed and wrapped to about 2^256, so the solver converged on a huge value and minted about 2.35×10^56 yETH. The attacker used those tokens to drain the pool through single-asset withdrawals, all in one transaction.

    What would have stopped it: Use checked arithmetic (Solidity 0.8 defaults) in the solver and revert when the numerator would be negative. Add invariant checks and bounds on minted supply, for example rejecting states where Σ or Π is zero while supply is non-zero. Fuzz and invariant-test the pool math, and retire or monitor legacy pools.

    rekt.news article ↗

  • Mar 5, 2025Ethereum$5.0MAudited, bug out of scope

    1inch (Fusion v1 resolvers / TrustedVolumes): 1inch's deprecated Fusion v1 settlement code let an attacker drain about $5M from resolver TrustedVolumes by setting interactionLength to -512, causing an integer underflow and calldata corruption in Yul code.

    Root cause and fix

    Vulnerable code: 1inch Settlement V1 · _settleOrder

    The old _settleOrder function, rewritten in Yul in November 2022, did not bound-check the user-supplied interactionLength. The attacker set it to 0xff...fe00 (-512), which underflowed memory pointer arithmetic. With a padded order and a fake suffix structure placed in the interaction, the suffix data was redirected and the resolver address was overwritten. This made the settlement contract call resolveOrders (0x1944799f) on TrustedVolumes as if it were a legitimate settlement, and the resolver's checks passed. The function was marked out of scope in audits, and Decurity's March 2023 finding was lost when the code was refactored. The legacy contract was never retired.

    What would have stopped it: Validate lengths and offsets in hand-written Yul or assembly, and revert if a length is larger than the calldata size. Fuzz test the calldata parsing with extreme values. Retire or disable deprecated contracts, and make sure audit scope covers every code path that is still deployed.

    rekt.news article ↗

  • Sep 3, 2026Ethereum$1.7M

    Notional Finance (V1): Notional Finance V1 lost about $1.73M (DAI and USDC) because an ERC-1155 fCash transfer minted unbacked claims and a uint128 cash ladder overflowed.

    Root cause and fix

    Vulnerable code: ERC1155Trade · safeTransferFrom

    Notional V1 treats an ERC-1155 fCash transfer as a minted pair: a payer (short) leg on from and a receiver (long) leg on to, even when from never held the token. Each account's fCash is netted in uint128 cash ladders. The attacker minted a short of about 2^128 so the ladder wrapped, which left the counterparty with an unbacked long and no offsetting debt. After maturity (about 73s later), the attacker called settleMaturedAssets and then Escrow.withdraw. This turned the fake claims into real DAI and USDC, sized to the escrow's whole balance.

    What would have stopped it: Require from to actually hold at least value of the fCash token in safeTransferFrom, so no unbacked pair can be minted. Use checked or bounded arithmetic (SafeCast, explicit bounds) on uint128 ladder netting. Add an invariant test that total claims never exceed total debts and escrow balances.

    Run the exploit (Foundry PoC) ↗

  • Mar 20, 2022Ethereum$700K

    Umbrella Network: Umbrella Network lost about $700k because StakingRewards._withdraw() subtracted balances without overflow checks, so an attacker with no stake could withdraw LP tokens.

    Root cause and fix

    Vulnerable code: StakingRewards · _withdraw()

    In StakingRewards._withdraw(), the code did _totalSupply = _totalSupply - amount and _balances[user] = _balances[user] - amount without SafeMath. A comment says no safe math was needed, which assumed Solidity's checks or token supply would prevent overflow. The contract was compiled with an older Solidity version that has no built-in checks, so the subtraction wrapped around. The attacker called withdraw() with an amount while holding zero stake. The balance underflowed to a huge number and the contract sent out the staked Uniswap LP tokens.

    What would have stopped it: Use Solidity 0.8+ checked arithmetic or SafeMath for all balance subtractions. Add an explicit require(_balances[user] >= amount) check, and test withdrawals by accounts with no stake.

    Run the exploit (Foundry PoC) ↗

  • Mar 15, 2023BNB Chain$390KFlash loan

    Poolz: Poolz lost about $390K on BNB Chain because CreateMassPools in the LockedDeal contract summed token amounts with an overflow, so the attacker could create a huge pool and withdraw the contract's whole token balance.

    Root cause and fix

    Vulnerable code: LockedDeal · CreateMassPools()

    CreateMassPools adds up the per-pool amounts to work out how many tokens to pull from the caller. This sum wraps around, because the contract was built for Solidity before 0.8 with no SafeMath, as the PoC's overflow arithmetic implies. The attacker passed two amounts: (2^256 − poolBalance + 2) and poolBalance. The sum wrapped to a tiny number, so the deposit check passed with almost no tokens. The second pool was recorded with the full balance of the contract's tokens. The attacker called WithdrawToken on that pool and took the MNZ, SIP, WOD and ECIO held by the contract. They sold the tokens on PancakeSwap, using a small flash loan for the starting funds.

    What would have stopped it: Use Solidity 0.8+ checked arithmetic or SafeMath for the sum of amounts in CreateMassPools. Also check that each recorded amount is bounded, and that the contract's token balance rose by exactly the total of the recorded pool amounts.

    Run the exploit (Foundry PoC) ↗

  • Mar 28, 2025Ethereum$96KFlash loan

    Alkimiya (SilicaPools): Alkimiya SilicaPools lost about $95.5K (1.14 WBTC) because an unsafe uint256-to-uint128 cast of shares in collateralizedMint let the attacker mint huge positions with almost no collateral.

    Root cause and fix

    Vulnerable code: SilicaPools · collateralizedMint()

    collateralizedMint() takes a uint256 shares amount and casts it to uint128 without a bounds check. The attacker passed type(uint128).max + 2, so the cast wrapped and the collateral charged was tiny, while the share amount used elsewhere stayed huge. The pool's index was an attacker-controlled contract with fake decimals(), shares() and transferFrom(), and the pool did not validate it. The attacker took a Morpho flash loan, minted, moved the ERC1155 tokens, then ran startPool, endPool and redeemShort to withdraw WBTC collateral that belonged to other users.

    What would have stopped it: Use SafeCast (or an explicit check that the value is at most type(uint128).max) for every downcast of user-supplied amounts. Whitelist the index and payout-token addresses, or do not call into untrusted index contracts. Fuzz tests with extreme share values would catch this.

    Run the exploit (Foundry PoC) ↗

3 more examples in the full guide.

References

Send a new scam

Describe what happened, or paste a link to the post. Do not include seed phrases, keys or passwords.

Open the post ↗