Skip to content

Rescue/Sweep Function Can Take User Funds

SAFE-0225 Access Control Checked automatically by the scanner
1

What goes wrong

An owner rescue/sweep function can withdraw the protocol's core token or user deposits, not just accidentally-sent stray tokens. This is a rug-pull primitive: the admin can drain everything under the guise of 'recovering' tokens.

2

The vulnerable pattern

proof of concept — how it is exploited
// function sweep(address t) external onlyOwner { IERC20(t).transfer(owner, bal); }
// owner: sweep(stakingToken) -> every staker's deposit sent to owner.
3

How to fix it

the pattern that is safe
function rescue(IERC20 t) external onlyOwner {
  require(t != stakingToken && t != rewardToken, "protected");
  t.safeTransfer(owner(), t.balanceOf(address(this)));
}
Exclude protocol/user tokens from any rescue function.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0225 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs