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:
- Caller authentication: who may call the payout function?
- Entitlement binding: how much is this caller actually owed?
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:
- Flash-borrow WETH from Balancer at zero fee.
- Send it to the victim contract, which raises its balance.
- Call
unwrapWETH(fullBalance, attackerContract). - Repay the loan.
- 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)
- Recon. Find a proxy holding tokens whose implementation has an external function, such as
unwrapWETH,sweeporclaimPayroll, with no role check. - Borrow. Flash-borrow WETH.
- Inflate. Transfer it into the victim, raising its balance.
- Drain. Call the unguarded function with the full balance and your own address.
- Settle. Re-wrap and repay the loan. Keep the victim’s original balance.
Why it worked: three facts
- Custodied assets. The contract holds value that isn’t the caller’s.
- Public fund mover. An external function sends assets out with no access control.
- 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
- Find the money. Check which deployed contracts and proxies actually hold tokens or ETH, and which ones custody pooled or idle capital.
- List every function that moves it. For each value holder, find every external function that does
transfer,transferFrom,call{value: ...}or unwraps the contract’s own holdings.bash grep -rnE "\.transfer\(|safeTransfer\(|transferFrom\(|call\{value" src/ - Check the guards. Does a caller check protect every path? Flag any fund mover without
onlyOwner,onlyRole, a keeper check or a pause guard. - Check the amount. Is the payout capped by the caller’s own recorded balance, or does it read
balanceOf(address(this))? - Check the recipient. Can the caller pass any
recipient, or is it fixed tomsg.senderor a hard-coded treasury?
Lookalikes that are safe, and why
- Permissionless reward claims (MasterChef, StakingRewards). Anyone can call
getReward(), but the payout is computed from the caller’s own stake. The entitlement is bound. - Owner-gated rescue functions.
rescueTokens(token, to, amount)behindonlyOwneror a multisig timelock isn’t public. - Fee harvesters with a fixed destination. A public
collectFees()that always pays a hard-coded, immutable treasury can’t be redirected to the caller, so calling it is harmless.
Fixes that work
- Strict access control. Gate every fund-moving function with
onlyOwner,onlyRoleor keeper authentication. It fails when the modifier sits on an outer wrapper but the implementation function is still reachable some other way. - Internal ledger accounting. Never pay out from
token.balanceOf(address(this)). Track each user’s entitlement in storage and cap payouts atbalances[msg.sender]. - Pay
msg.sender, not a freerecipient. This removes the “send it anywhere” part, but it only protects funds when combined with ledger accounting. On its own, an unauthenticated function that paysmsg.senderfrom the pooled balance still pays the attacker. - Zero-custody periphery. Routers, helpers and aggregators shouldn’t hold idle tokens between transactions. Refund anything left over before the transaction ends.
The same bug in other clothes
- Unwarp (Base). A flash-amplified WETH unwrap, covered above.
- INK Finance (Polygon). A payroll claim that paid the whole live treasury balance, covered above.
- StrongBlock (Ethereum, about $72K). An inventory proxy holding STRONG and STRNGR tokens exposed a public
run()function with hard-coded recipients. The attacker called it straight from a wallet and moved the full pooled supply. - BitCrown (BNB Chain, about $7.9K). A distributor exposed an ungated
batchTransfermeant for faucet drops. With no limit on recipients or calls, the attacker sent the whole inventory to themselves.
Test yourself
- 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. rescueERC20()isonlyOwner, but the owner isaddress(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.- An open
claim()paysrewardPerToken * stake[msg.sender]. Vulnerable? No. The payout is bound to the caller’s recorded stake. - 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.
- What’s the strongest structural fix for the whole class? Zero-custody periphery: helpers and routers should end every transaction holding nothing.
Recap
- Any external function that moves custodied assets with no caller check and no entitlement bound turns custody into a race.
- The three ingredients are a value holder, a public fund mover and no link between the payout and the caller.
- Flash loans here are catalysts, not profit. They let the attacker take the real balance in one go.
- The fix: gate fund movers with roles, bind payouts to a ledger, and keep periphery contracts empty.