Skip to content

Reentrancy via Forced Callback Abuse

SAFE-0005 Reentrancy Checked automatically by the scanner
1

What goes wrong

A contract passes execution to a user-supplied callback or arbitrary target inside a sensitive flow (flash loans, hooks, plugins). The callback re-enters protocol functions that assume the outer call has completed.

2

How to fix it

the pattern that is safe
function flashLoan(address receiver, uint256 amt) external nonReentrant {
    uint256 before = token.balanceOf(address(this));
    token.transfer(receiver, amt);
    IReceiver(receiver).execute();
    require(token.balanceOf(address(this)) >= before, "not repaid");
}
Guard the entry and validate balances against a pre-call snapshot.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0005 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