Don't Get Rekt

Smart contract bugs / What does it trust?

Unchecked return values and non-standard tokens

The contract ignores a failed transfer, or assumes every ERC-20 behaves the same. A token that returns false, takes a fee or rebases breaks the accounting.

OWASP SC06:2026 · 4 real exploits · $748K lost

How the attack works

  1. The contract calls token.transfer() or a low-level call and does not check the result.
  2. Some tokens return false on failure instead of a revert, and some (USDT) return nothing.
  3. The transfer fails, but the contract records it as done. The attacker gets credit for a deposit that never arrived.
  4. Variants: fee-on-transfer tokens deliver less than the amount, rebasing tokens change balances, ERC-777 hooks call back.

Vulnerable and fixed code

Vulnerable
function deposit(uint256 amt) external {
    token.transferFrom(msg.sender, address(this), amt); // result ignored
    balance[msg.sender] += amt;                          // credited anyway
}

function pay(address to, uint256 amt) external onlyOwner {
    to.call{value: amt}("");                             // failure ignored
}
Fixed
using SafeERC20 for IERC20;

function deposit(uint256 amt) external {
    uint256 before = token.balanceOf(address(this));
    token.safeTransferFrom(msg.sender, address(this), amt);  // reverts on false
    balance[msg.sender] += token.balanceOf(address(this)) - before;
}

function pay(address to, uint256 amt) external onlyOwner {
    (bool ok,) = to.call{value: amt}("");
    require(ok, "ETH transfer failed");
}

Review checklist

  • Use OpenZeppelin SafeERC20 for every token call.
  • Check the bool of every low-level call, send and delegatecall.
  • Write down which tokens you support. If you accept any token, test fee-on-transfer, rebasing, no-return and 6-decimal tokens.
  • Credit the measured balance change, not the amount in the call.

How to test for it

  • Use the Weird ERC20 mocks (github.com/d-xo/weird-erc20) in your test suite.
  • Slither detectors unchecked-transfer, unchecked-lowlevel and unchecked-send.

Real exploits (4)

  • Jun 28, 2020Ethereum$500KFlash loan

    Balancer: Balancer pool lost about $500K (figure from general knowledge, not this write-up) because it did not handle the deflationary STA token, which burns a fee on every transfer, so its recorded balances were wrong.

    Root cause and fix

    Vulnerable code: BPool · swapExactAmountIn()

    The Balancer pool assumed that the amount it asked an ERC-20 to transfer is the amount it received. STA is a deflationary token that burns part of every transfer. The pool's internal STA balance therefore drifted from its real balance. The attacker took a dYdX flash loan of WETH and made many swapExactAmountIn calls to push the pool's STA balance down to about 1 wei, which made STA very expensive in WETH. They called gulp() to reset the recorded balance to the real one and kept the price high. They then swapped STA for WETH repeatedly, repaid the loan and kept the profit.

    What would have stopped it: Measure the balance before and after each token transfer and use the actual amount received for accounting. Alternatively, whitelist tokens and reject fee-on-transfer or deflationary ones. Also limit how far a pool's token balance can be drained by swaps.

    Run the exploit (Foundry PoC) ↗

  • Jun 28, 2021Polygon$248KFlash loan

    SafeDollar: SafeDollar on Polygon lost about $248k when a fee-on-transfer token (PLX) broke its farm reward accounting, inflating accSdoPerShare and allowing an infinite SDO mint.

    Root cause and fix

    Vulnerable code: Safe Farms (reward pool) · deposit()/withdraw()

    The farm incentivised PLX, a token that charges a fee on every transfer. On withdrawal the fee was taken from the pool's balance instead of the user, so the pool's accounting no longer matched its real PLX balance. The attacker made a small deposit, then ran a deposit/withdraw loop over 101 transactions. This drained the pool's PLX balance and inflated accSdoPerShare to about 1.14e18 SDO per PLX. They then claimed rewards on the initial deposit (about 8.3e17 SDO) and sold it at once. That crashed SDO to $0 and drained 202k USDC and 46k USDT of liquidity.

    What would have stopped it: Do not list fee-on-transfer tokens as farm tokens, or measure the actual balance change on deposit and withdraw instead of trusting the amount argument. Compute accSdoPerShare from the real token balance, guard against a near-zero pool supply, and fuzz-test the farm with fee-charging tokens.

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

  • Apr 4, 2021Ethereum

    Force DAO: Force DAO's xFORCE vault let a white hat mint 347M xFORCE for free because it ignored the false return of transferFrom on the MiniMeToken-based FORCE token; the FORCE price fell about 90% and the funds were later returned.

    Root cause and fix

    Vulnerable code: xFORCE vault

    The xFORCE vault did not check the return value of transferFrom when taking deposits. FORCE uses the old MiniMeToken contract, which returns false instead of reverting when there is no approval or not enough balance. The attacker called the deposit with no FORCE and no approval, and the vault still minted 347,432,986 xFORCE. They then withdrew 4,112 FORCE with the minted xFORCE and sold it via 1inch. The price fell about 90%, and 14,833 FORCE was later returned.

    What would have stopped it: Wrap token transfers in a safeTransferFrom helper that reverts on a false return value. Also test deposits with no approval and with an insufficient balance, and check that they revert.

    rekt.news article ↗

  • Sep 12, 2021AvalancheFlash loan

    ZABU Finance: ZABU Finance's farm on Avalanche was drained of ZABU rewards because it did not handle the deflationary SPORE token, which burns a fee on each transfer.

    Root cause and fix

    Vulnerable code: ZABUFarm (0xf61b4f980A1F34B55BBF3b2Ef28213Efcc6248C4) · deposit()

    The farm credited deposits and withdrawals at the nominal amount instead of the amount actually received. SPORE is a deflationary token that takes a fee on transfer, so the farm's real balance and the recorded accounting drifted apart. The attacker made a normal SPORE deposit. They then used flash swaps on two Pangolin pairs to borrow most of the SPORE supply. They looped deposit/withdraw in the farm to shrink its SPORE balance and distort per-share rewards. After that they advanced blocks and withdrew, collecting a large ZABU reward, and sold it for WAVAX.

    What would have stopped it: Measure the balance before and after transferFrom and credit only the difference. Do not accept fee-on-transfer or deflationary tokens as farm staking tokens unless that is handled, or whitelist the pool tokens. Add tests with deflationary tokens.

    Run the exploit (Foundry PoC) ↗

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 ↗