Reentrancy is one of the oldest smart contract bugs and it still drains protocols, because every external call hands control to code the caller does not own. The classic withdraw-before-update mistake is now well known, so modern losses come from the harder variants: a callback that enters a different function, a path through several contracts, or a view function that reports stale numbers to another protocol mid-transaction. This guide covers where reentrancy sits in the OWASP Smart Contract Top 10:2026, how each variant works, the checks-effects-interactions pattern, reentrancy guards including the transient storage versions, read-only reentrancy, and how to test and audit for it. It is written for Solidity and Vyper developers, auditors and protocol security leads, and describes safe patterns only. For the full list, see the OWASP Smart Contract Top 10 Guide.
Key takeaways
- Reentrancy is SC08:2026. OWASP lists it as Reentrancy Attacks, eighth in the 2026 edition (fifth in 2025), and treats ERC-777, ERC-721 and ERC-1155 receiver hooks, ERC-4626 vaults and flash loan callbacks as reentrancy vectors.
- Checks-effects-interactions is the first defence. The Solidity documentation says interaction with other contracts should be the very last step in any function, after all planned state changes are written to storage.
- Guards cover what ordering misses. A lock such as OpenZeppelin's nonReentrant modifier blocks re-entry across every function that shares the lock, which matters when one function's external call can be used to enter another.
- View functions can be re-entered too. Read-only reentrancy makes a getter or price feed return inconsistent state during a callback, harming any protocol that trusts it. OpenZeppelin's nonReentrantView exists for this case.
- Guards themselves need testing. The July 2023 Curve pool losses came from a Vyper compiler bug that gave each function its own lock, so a cross-function reentrancy test, not the source code, was the missing control.
Where reentrancy sits in the OWASP list
The OWASP Smart Contract Top 10:2026 places SC08:2026 Reentrancy Attacks eighth. In the 2025 edition the same risk was SC05. Its fall in rank reflects OWASP's ordering by recent incident data rather than lower severity: well-understood defences have reduced the simple cases, while the risk persists in composable systems. The closest neighbour is SC06:2026 Unchecked External Calls, which OWASP describes as covering failures or callbacks from external calls that leave inconsistent state or enable reentrancy. In practice an audit finding often belongs to both.
OWASP describes reentrancy as a callee calling back into the original contract before the first invocation finishes and state is updated, so the callback reads stale state. It names the risk across DeFi, NFTs, DAOs, bridges and composable protocols, and notes that similar patterns exist on non-EVM chains. The impacts it lists are withdrawing more than a balance, double-counting rewards and manipulating accounting across multi-step flows.
| Related list or registry | Entry | Status and use |
|---|---|---|
| OWASP Smart Contract Top 10:2026 | SC08:2026 Reentrancy Attacks | Current edition; use for risk ranking and audit scoping |
| OWASP Smart Contract Top 10:2026 | SC06:2026 Unchecked External Calls | Overlaps where unhandled callbacks cause re-entry |
| SWC Registry | SWC-107 Reentrancy | The site states it is no longer actively maintained and has not been thoroughly updated since 2020; it points to EthTrust and SCSVS |
| Slither static analyser | reentrancy-eth, reentrancy-no-eth, reentrancy-balance, reentrancy-benign, reentrancy-events, reentrancy-unlimited-gas | Detector names to require in CI output |
For the maintained verification standards that replaced the SWC Registry, see the Smart Contract Security Standards Guide.
How reentrancy works
On the EVM a call to another contract transfers execution to that contract. The Solidity documentation is direct: any transfer of Ether hands over control to the recipient, and the same applies to any function call on another contract, not only payments. If the caller has not finished updating its own records, the callee can call back in and act on the old values. The variants differ in where the callback lands and what stale state it reads.
| Variant (OWASP) | Where the callback lands | Typical stale state | Primary control |
|---|---|---|---|
| Single-function | The same function, recursively | A balance not yet reduced | Checks-effects-interactions; nonReentrant |
| Cross-function | A different function in the same contract | Shared accounting written by the first function | One lock shared by every state-changing entry point |
| Cross-contract | Another contract in the system, for example vault to strategy to exchange | Totals split across contracts mid-update | System-wide lock or ordering across contracts; invariant tests |
| Read-only | A view function or price getter, read by a third party | Share price, reserves or total assets mid-update | nonReentrantView on getters; consumers check the lock |
| Token and callback hooks | Receiver hooks (ERC-777, ERC-721, ERC-1155), ERC-4626 flows, flash loan callbacks | Any state the hook can reach | Treat every hook as an external call |
Why gas stipends are not a defence
Older advice relied on transfer and send, which forward a 2,300 gas stipend that is too small to modify storage. The Solidity documentation warns that the stipend could change in future hard forks, and a low-level call with value forwards all remaining gas, subject to the 63/64 rule. Slither flags stipend-based patterns under reentrancy-unlimited-gas as informational for this reason. Design as if the recipient has unlimited gas.
Lessons from incidents
- Unaudited patches: OWASP's SC08 entry cites GMX V1 in July 2025, about 42 million US dollars, where a function accepted a caller-supplied contract address, a refund passed control to it, and re-entry manipulated average short prices and pool valuations. OWASP attributes it to state updated after an external call, missing guards, and a 2022 patch that had not been audited.
- Compiler-level guard failure: on 30 July 2023 several Curve liquidity pools were exploited. The Vyper post-mortem explains that versions 0.2.15, 0.2.16 and 0.3.0 gave each
@nonreentrantdecorator its own storage slot regardless of key, so functions that shared a key did not share a lock. The fix in 0.3.1 added the cross-function reentrancy test the repository had lacked (advisory GHSA-5824-cm3x-3c38, CVE-2023-39363).
Checks-effects-interactions
The Solidity security considerations define the ordering that removes most single-function reentrancy:
- Checks: validate caller, inputs, balances and other preconditions, and revert early.
- Effects: write every planned change to the contract's own state, such as zeroing or reducing the caller's balance and updating totals.
- Interactions: only then call other contracts or send value, and check the result. The documentation's corrected withdraw example zeroes the share before the call and then requires success.
The documentation advises applying the pattern always, because a call to a known contract may itself call an unknown one. It also warns that a called contract can change the state of another contract you depend on, which is the root of cross-contract and read-only reentrancy.
- Pull over push: record what each party is owed and let them withdraw in a separate transaction, rather than paying several recipients inside one function. Each withdrawal then has one external call at the end.
- Events before calls: Slither's
reentrancy-eventsdetector exists because re-entry can reorder or change emitted events and mislead off-chain systems. Emit events in the effects phase where the logic allows. - Balance checks:
reentrancy-balanceflags a balance read before an external call and checked again after it, which re-entry can make stale. Compute expected values from your own accounting, not from a live balance read either side of a call. - Check token return values: OWASP's remediation list includes checking return values from token transfers and reverting on failure.
Ordering alone has limits. Some flows need an external call in the middle, for example a swap whose output decides the next step, and cross-function paths are easy to miss in review. That is where guards come in.
Reentrancy guards
A reentrancy guard is a lock flag set on entry and cleared on exit; a second entry while the flag is set reverts. OWASP recommends a lock on functions that change balances or accounting, or that make external calls that could re-enter.
| Mechanism | How it works | Points to know |
|---|---|---|
| OpenZeppelin ReentrancyGuard | nonReentrant modifier using a storage slot; reverts with ReentrancyGuardReentrantCall | Marked deprecated in the 5.x docs, to be removed in v6.0 in favour of the transient version |
| OpenZeppelin ReentrancyGuardTransient (since v5.1) | Same modifiers backed by transient storage (EIP-1153) | Only works on networks where EIP-1153 is available |
| nonReentrantView | Makes a view function revert while a nonReentrant function is on the call stack | View functions only; does not change the guard state |
| _reentrancyGuardEntered() | Returns true when the lock is set | Lets integrating code or internal checks detect mid-execution state |
| Vyper @nonreentrant | Compiler-generated lock | Versions 0.2.15 to 0.3.0 mis-allocated keyed locks; use 0.3.1 or later and test cross-function paths |
Transient storage locks
EIP-1153 (status Final) adds TSTORE and TLOAD, storage that is discarded at the end of each transaction, costing 100 gas each at the time of writing. The EIP lists reentrancy locks first among its use cases. Its security considerations matter for guards: transient values persist for the whole transaction and are not cleared when a call returns or reverts, so a lock left set by mistake blocks later calls in the same transaction. Always clear the lock on every exit path, which the library modifiers do for you.
Design rules for guards
- One lock across the contract: OpenZeppelin notes that because there is a single guard, functions marked nonReentrant may not call one another. Move shared logic into private functions and expose separate external nonReentrant entry points.
- Cover every state-changing entry point: a guard on
withdrawdoes not help iftransferorclaimreads the same balances unguarded. - Guards do not cross contracts: a lock in one contract does not stop re-entry into a sibling contract. Systems with vaults, strategies and routers need either a shared lock contract or strict ordering plus invariant tests.
- Keep CEI as well: the guard is a backstop for ordering mistakes, not a replacement, and OWASP lists both.
Read-only and cross-contract reentrancy
Read-only reentrancy is the variant that hurts integrators rather than the contract with the bug. OWASP describes it as view functions or oracles returning inconsistent state during a callback. A typical setting is a pool or vault whose share price is computed from reserves and supply: mid-way through a withdrawal, one has been updated and the other has not. A lending protocol that reads that price during the callback values collateral wrongly, even though the pool itself loses nothing.
- If you publish getters others rely on: guard price and accounting getters with nonReentrantView or an equivalent check, and document that they revert mid-execution.
- If you consume another protocol's price: check the source's lock state where it exposes one, prefer time-weighted or independent oracles over spot getters, and treat any value read during your own external calls as suspect. See the Oracle Manipulation and Flash Loan Attacks Guide.
- Map the call graph: for cross-contract reentrancy, list every external call in the system, what it can reach, and which totals are split across contracts. Proxies add a further layer: a guard's storage slot must survive upgrades. See the Smart Contract Upgradeability and Proxy Security Guide.
- Hooks are calls: ERC-721 and ERC-1155 safe transfers call the receiver, ERC-777 calls registered hooks, and flash loan providers call back the borrower. Apply CEI and guards around each.
Testing and audits
OWASP's SC08 entry recommends reentrancy-focused fuzzing and unit tests wherever external calls are involved. A layered test plan catches different classes.
| Technique | What it finds | How to use it |
|---|---|---|
| Static analysis (Slither) | Calls before state writes, stale balance checks, event reordering | Run in CI; treat reentrancy-eth and reentrancy-balance (High) and reentrancy-no-eth (Medium) as blocking until triaged |
| Unit tests with a malicious receiver | Re-entry into the same or another function | Write a test contract that calls back on receipt and assert the second call reverts; cover every state-changing function, not only withdraw |
| Property and invariant fuzzing (Echidna, Foundry invariant tests) | Accounting that breaks across sequences, such as total shares no longer matching assets | Express invariants (sum of balances equals total supply; assets cover liabilities) and fuzz with callback-capable actors |
| Read-only checks | Getters returning mid-update values | Call each public getter from inside a callback and assert it reverts or returns consistent values |
| Compiler and library review | Lock implementation faults | Pin compiler versions, check advisories for the exact version, keep a cross-function reentrancy regression test |
| Manual audit | Business-logic paths tools miss, multi-contract flows | Give auditors the call graph and invariants; re-audit every patch that touches external calls |
The GMX and Vyper cases share one lesson: the gap was a change that was not tested or audited for reentrancy. Gate every change that adds or moves an external call on re-review. See the Smart Contract Audit Readiness and Choosing an Auditor Guide.
Monitoring and response after deployment
- On-chain alerts: watch for repeated calls into the same contract within one transaction, unusual withdrawals relative to deposits, and share price moves inside a block. See the Blockchain Analytics and On-Chain Monitoring Guide.
- Pause path: a tested emergency pause limits loss while a fix is prepared. See the Smart Contract Emergency Pause Guide.
- Metrics: track reentrancy findings open at release, percentage of external-call functions with a malicious-receiver test, invariant suite run on every merge, and time from compiler or library advisory to rebuilt and verified deployment.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev. 5 | SA-11 Developer Testing and Evaluation; SA-11(1) Static Code Analysis; SA-11(8) Dynamic Code Analysis | Static analysis, fuzzing and unit tests for reentrancy |
| NIST SP 800-53 Rev. 5 | SA-8 Security and Privacy Engineering Principles; SA-15 Development Process, Standards, and Tools | CEI as a coding standard; pinned compilers and libraries |
| NIST SP 800-53 Rev. 5 | CM-3(2) Testing, Validation, and Documentation of Changes | Re-test and re-audit patches that touch external calls |
| NIST CSF 2.0 | ID.RA-01 Vulnerabilities in assets are identified, validated, and recorded | Audit findings and tool output tracked to closure |
Practitioner checklist
- Apply checks-effects-interactions in every function that makes an external call or sends value, including token hooks and flash loan callbacks.
- Put one reentrancy guard on every state-changing external entry point, using ReentrancyGuardTransient where EIP-1153 is available.
- Guard public price and accounting getters with nonReentrantView or an equivalent, and document the behaviour for integrators.
- Prefer pull payments over pushing value to several recipients in one function.
- Never rely on the 2,300 gas stipend of transfer or send as a reentrancy defence.
- Run Slither reentrancy detectors in CI and triage High and Medium findings before release.
- Keep malicious-receiver unit tests and invariant fuzzing for single, cross-function, cross-contract and read-only paths.
- Pin compiler and library versions, check their advisories, and keep a cross-function reentrancy regression test.
- Re-audit any patch that adds or moves an external call before deployment.
Standards and references
- OWASP: Smart Contract Top 10:2026, SC08 Reentrancy Attacks
- OWASP: Smart Contract Top 10
- Solidity: Security Considerations
- OpenZeppelin: Contracts 5.x Utilities (ReentrancyGuard, ReentrancyGuardTransient)
- Ethereum: EIP-1153 Transient Storage Opcodes
- Vyper: Incorrectly allocated named re-entrancy locks (GHSA-5824-cm3x-3c38)
- Slither: Detector Documentation
- SWC Registry: SWC-107 Reentrancy
Related NHI Mgmt Group resources: OWASP Smart Contract Top 10 Guide · Smart Contract Security Guide · Smart Contract Access Control Guide · DeFi Risk Guide