> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://www.getfoundry.sh/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

## Reentrancy Events

**Severity**: `Low`
**ID**: `reentrancy-events`

### What it does

Reports events emitted after an external interaction, such as a state-changing contract
call, low-level `call` or `delegatecall`, ETH `send` or `transfer`, or contract creation.
Static calls and `view` or `pure` calls are excluded.

### Why is this bad?

Reentrancy and off-chain ordering both depend on event sequence:

* A reentrant callee can observe (or trigger another contract to observe) events in an order that no longer reflects the final state of the calling contract.
* Indexers, bridges, and monitoring tools that consume logs in emission order may apply state transitions incorrectly when events are not emitted alongside the writes they describe.

Emitting the event **before** the external call ensures the log is anchored to the local state change, regardless of what the callee does.

### Example

```solidity
contract BadCounter {
    uint256 public counter;
    event Counter(uint256 value);

    function count(IExternal d) external {
        counter += 1;
        d.notify();             // external call first ...
        emit Counter(counter);  // ... then the event (may be reordered by reentrancy)
    }
}
```

Use instead:

```solidity
contract GoodCounter {
    uint256 public counter;
    event Counter(uint256 value);

    function count(IExternal d) external {
        counter += 1;
        emit Counter(counter);  // emit event right after the state change
        d.notify();             // then perform the external call
    }
}
```
