Rules › Solidity
State written after an external call (reentrancy)
A function sends ETH or calls another contract before updating its own state, so the callee can re-enter and act on stale state.
Why it matters
When a contract sends ETH or calls another contract, the callee runs code before the call returns, and can call back in. If the caller hasn't updated its own state yet (a balance, a claimed flag), the re-entrant call sees the old state and can withdraw again. This is how The DAO lost 3.6 million ETH, and variants (cross-function, read-only reentrancy through view functions used as oracles) keep appearing.
Vulnerable
function withdraw() external {
uint256 amount = balances[msg.sender];
(bool ok, ) = msg.sender.call{value: amount}("");
require(ok);
balances[msg.sender] = 0; // too late
}
Fixed
function withdraw() external nonReentrant {
uint256 amount = balances[msg.sender];
balances[msg.sender] = 0; // effects first
(bool ok, ) = msg.sender.call{value: amount}("");
if (!ok) revert TransferFailed();
}
What other tools call it
| Tool | Detector or reference |
|---|---|
| Slither | reentrancy-eth, reentrancy-no-eth |
| Solhint | reentrancy |
| Aderyn | state-change-after-external-call |
| SWC registry | SWC-107 |
Check your code
Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.
Related rules
- tx.origin used for authorization
- Return value of a low-level call is ignored
- delegatecall to an address the caller controls
- Initializer anyone can call
- Privileged function without access control
- selfdestruct in contract code