Documentation Index
Fetch the complete documentation index at: https://docs.webacy.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
A reentrancy attack is a serious vulnerability where a function calls an external contract, allowing that contract to make repeated calls back before execution completes.How It Works
The basic mechanism: Contract A calls Contract B. The exploit allows B to call back into A before A finishes execution.Attack Sequence
Step-by-Step Example
- User initiates withdrawal from bank contract holding 10 ETH
- Bank verifies balance equals 10 ETH
- Bank begins transferring 10 ETH to user
- Attacker’s contract receives funds and immediately triggers another withdrawal
- Balance hasn’t been updated yet, so contract allows another 10 ETH withdrawal
- Cycle repeats until bank is drained
Vulnerable Code
Attacker Contract
Safe Patterns
Checks-Effects-Interactions
Reentrancy Guard
Reentrancy Variants
| Variant | Description |
|---|---|
| Single-function | Re-entering the same function |
| Cross-function | Re-entering a different function that shares state |
| Cross-contract | Re-entering via another contract in the same protocol |
| Read-only | Exploiting view functions during reentrancy |
API Detection
Prevention Checklist
- Follow Checks-Effects-Interactions pattern
- Update all state before making external calls
- Use reentrancy guards (e.g., OpenZeppelin
ReentrancyGuard) on sensitive functions - Use
.call{value: ...}("")for ETH transfers (nottransfer()/send()) - Always check the boolean return value from
.calland handle failures explicitly
