Skip to content

ERC-777 / Token Hook Reentrancy

SAFE-0004 Reentrancy Checked automatically by the scanner
1

What goes wrong

ERC-777 (and ERC-1363/ERC-721 safe transfers) invoke a hook on the sender/recipient. A token transfer that looks atomic actually hands control to attacker code via tokensReceived/onERC721Received, enabling reentrancy even without raw ETH calls.

2

How to fix it

the pattern that is safe
function deposit(uint256 amt) external nonReentrant {
    shares[msg.sender] += amt;                           // effects first
    token.transferFrom(msg.sender, address(this), amt);
}
imBTC/Uniswap-V1 ERC-777 incident. Guard token-moving paths.
Check your own contract for this

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