Killua
← All parts Bug Hunting Field Guide · Part 5 of 8

Unguarded fund movers: public sweeps and balance drains

Killua · 6 min read

If a contract exposes a function that sends out the tokens it holds, and nothing ties the caller to those tokens, someone will eventually take all of them.

This is the simplest bug in the series and one of the most common. It hides in helpers, routers, unwrappers and payroll contracts, written for convenience and forgotten.

The bug in one sentence

A contract that holds other people’s value has an external function that moves those funds out, and nothing checks who the caller is or limits the payout to what the caller is owed.

Protecting pooled funds takes two separate barriers:

When both are missing, the contract is a faucet.

Two real cases

Unwarp (Base, May 2025, about $9K)

An unverified logic contract behind a standard OpenZeppelin TransparentUpgradeableProxy held a small idle WETH balance. It exposed a convenience unwrap helper. Reconstructed from the on-chain trace, it looked like this:

// selector 0xe16d9ce5: unwrapWETH(uint256,address)
function unwrapWETH(uint256 amount, address recipient) external { // no auth check
    IWETH(weth).withdraw(amount);                       // unwraps the contract's own WETH
    (bool success, ) = recipient.call{value: amount}(""); // caller picks the destination
    require(success, "ETH transfer failed");
}

There was no onlyOwner, no allowance check and no check that the caller had deposited that WETH. The function took the contract’s own WETH, unwrapped it and sent it wherever the caller asked.

INK Finance (Polygon, May 2026, about $140K)

INK Finance ran an on-chain payroll and treasury protocol. Its Payroll proxy exposed claimPayroll(uint256 employeeId). Instead of checking that msg.sender was that employee and paying an accrued salary, the implementation read the treasury’s entire live balance and transferred all of it, about 140,180 USDT0.

The accounting, and why attackers still use flash loans

In its purest form:

profit = token.balanceOf(victim) − gas

Both attackers still used flash loans, even though the borrowed money earns nothing. In Unwarp:

  1. Flash-borrow WETH from Balancer at zero fee.
  2. Send it to the victim contract, which raises its balance.
  3. Call unwrapWETH(fullBalance, attackerContract).
  4. Repay the loan.
  5. Keep the difference, which is the contract’s original idle balance.

The loan is mechanical, not a source of profit. It satisfies whatever amount or threshold the function expects, so the whole real balance comes out in one atomic call. INK Finance worked the same way: a flash loan topped up the treasury balance, the attacker claimed it all and repaid the loan.

The attack, step by step (Unwarp)

  1. Recon. Find a proxy holding tokens whose implementation has an external function, such as unwrapWETH, sweep or claimPayroll, with no role check.
  2. Borrow. Flash-borrow WETH.
  3. Inflate. Transfer it into the victim, raising its balance.
  4. Drain. Call the unguarded function with the full balance and your own address.
  5. Settle. Re-wrap and repay the loan. Keep the victim’s original balance.

Why it worked: three facts

  1. Custodied assets. The contract holds value that isn’t the caller’s.
  2. Public fund mover. An external function sends assets out with no access control.
  3. Unbound entitlement. The payout size and recipient don’t depend on the caller’s deposits.

Remove any one and it’s safe. Helpers can hold no idle funds, the function can sit behind onlyOwner or a keeper role, or payouts can be tied to an internal ledger.

How to hunt for it

Lookalikes that are safe, and why

Fixes that work

The same bug in other clothes

Test yourself

  1. An external sweep(token, to) has no auth but currently holds nothing. Finding? Yes, usually High. The moment fees accrue or someone sends tokens by mistake, a bot will take them. Show the ungated call in a proof of concept, and scale severity with how much value is expected to pass through.
  2. rescueERC20() is onlyOwner, but the owner is address(0). Finding? It’s not theft, because nobody can call it. But stuck funds can never be rescued. Report it as a locked-funds issue.
  3. An open claim() pays rewardPerToken * stake[msg.sender]. Vulnerable? No. The payout is bound to the caller’s recorded stake.
  4. Why use a flash loan if it earns nothing? It satisfies amount or threshold conditions, so the whole real balance comes out in one atomic transaction.
  5. What’s the strongest structural fix for the whole class? Zero-custody periphery: helpers and routers should end every transaction holding nothing.

Recap