Don't Get Rekt

Smart contract bugs / In what order does it run?

Denial of service and locked funds

One user, one failed transfer or one long loop can block a function for everyone. Funds stay locked in the contract.

1 real exploit · $34.0M lost

How the attack works

  1. A function loops over all users or all positions. When the list grows, the loop needs more gas than a block allows.
  2. A function sends ETH to many receivers in a loop. One receiver is a contract that always reverts, so the whole call reverts.
  3. Variants: an attacker sends ETH with selfdestruct to break a balance == x check; a griefing call fills a queue.

Vulnerable and fixed code

Vulnerable
function distribute() external {
    for (uint256 i; i < users.length; i++) {       // unbounded loop
        payable(users[i]).transfer(share);          // one revert blocks all
    }
}
Fixed
mapping(address => uint256) public owed;

function claim() external {                         // pull, not push
    uint256 amt = owed[msg.sender];
    owed[msg.sender] = 0;
    (bool ok,) = msg.sender.call{value: amt}("");
    require(ok, "send failed");
}

Review checklist

  • Use pull payments: each user claims their own funds.
  • Do not loop over arrays that users can make longer. If you must loop, process in batches.
  • Do not use exact balance checks (address(this).balance == x).
  • Make sure an admin pause cannot lock user funds forever: give users a way to exit.

How to test for it

  • Test the loop with a large number of entries and check the gas.
  • Add a receiver that always reverts, and check that other users can still claim.

Real exploits (1)

  • Apr 23, 2022Ethereum$34.0M

    Akutar NFT: Akutar NFT had about $34M locked forever because a contract bidder could make processRefunds() revert and a wrong require in claimProjectFunds() blocked the project's withdrawal.

    Root cause and fix

    Vulnerable code: AkutarNFT · processRefunds()

    processRefunds() sends ETH to each bidder in a loop and does not check whether the bidder is a contract or handle a failed send. A malicious contract bidder reverts in its fallback, so the whole refund loop fails and later honest bidders never get their refunds. A second bug is an incorrect require check in claimProjectFunds(). It makes that call revert, so the project funds (more than $34M) stay locked.

    What would have stopped it: Use a pull-payment refund pattern, where each user withdraws their own refund, or skip failed sends instead of reverting the whole loop. Test the end-of-auction flow, including claimProjectFunds(), against contract bidders that revert and against edge-case counters.

    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 ↗