Rules › Solidity

State written after an external call (reentrancy)

highSolidityRule sol-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

ToolDetector or reference
Slitherreentrancy-eth, reentrancy-no-eth
Solhintreentrancy
Aderynstate-change-after-external-call
SWC registrySWC-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.

Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.