Join our Newsletter — 33% off our NHI Course
Home› Guides› OWASP Smart Contract Reentrancy: Checks-Effects-Interactions, Guards and Read-Only…
Guide Application Security

OWASP Smart Contract Reentrancy: Checks-Effects-Interactions, Guards and Read-Only Reentrancy

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 13 min read
On this page

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 registryEntryStatus and use
OWASP Smart Contract Top 10:2026SC08:2026 Reentrancy AttacksCurrent edition; use for risk ranking and audit scoping
OWASP Smart Contract Top 10:2026SC06:2026 Unchecked External CallsOverlaps where unhandled callbacks cause re-entry
SWC RegistrySWC-107 ReentrancyThe site states it is no longer actively maintained and has not been thoroughly updated since 2020; it points to EthTrust and SCSVS
Slither static analyserreentrancy-eth, reentrancy-no-eth, reentrancy-balance, reentrancy-benign, reentrancy-events, reentrancy-unlimited-gasDetector 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 landsTypical stale statePrimary control
Single-functionThe same function, recursivelyA balance not yet reducedChecks-effects-interactions; nonReentrant
Cross-functionA different function in the same contractShared accounting written by the first functionOne lock shared by every state-changing entry point
Cross-contractAnother contract in the system, for example vault to strategy to exchangeTotals split across contracts mid-updateSystem-wide lock or ordering across contracts; invariant tests
Read-onlyA view function or price getter, read by a third partyShare price, reserves or total assets mid-updatenonReentrantView on getters; consumers check the lock
Token and callback hooksReceiver hooks (ERC-777, ERC-721, ERC-1155), ERC-4626 flows, flash loan callbacksAny state the hook can reachTreat 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 @nonreentrant decorator 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:

  1. Checks: validate caller, inputs, balances and other preconditions, and revert early.
  2. Effects: write every planned change to the contract's own state, such as zeroing or reducing the caller's balance and updating totals.
  3. 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-events detector 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-balance flags 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.

MechanismHow it worksPoints to know
OpenZeppelin ReentrancyGuardnonReentrant modifier using a storage slot; reverts with ReentrancyGuardReentrantCallMarked 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
nonReentrantViewMakes a view function revert while a nonReentrant function is on the call stackView functions only; does not change the guard state
_reentrancyGuardEntered()Returns true when the lock is setLets integrating code or internal checks detect mid-execution state
Vyper @nonreentrantCompiler-generated lockVersions 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 withdraw does not help if transfer or claim reads 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.

TechniqueWhat it findsHow to use it
Static analysis (Slither)Calls before state writes, stale balance checks, event reorderingRun in CI; treat reentrancy-eth and reentrancy-balance (High) and reentrancy-no-eth (Medium) as blocking until triaged
Unit tests with a malicious receiverRe-entry into the same or another functionWrite 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 assetsExpress invariants (sum of balances equals total supply; assets cover liabilities) and fuzz with callback-capable actors
Read-only checksGetters returning mid-update valuesCall each public getter from inside a callback and assert it reverts or returns consistent values
Compiler and library reviewLock implementation faultsPin compiler versions, check advisories for the exact version, keep a cross-function reentrancy regression test
Manual auditBusiness-logic paths tools miss, multi-contract flowsGive 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

FrameworkReferenceRelevance
NIST SP 800-53 Rev. 5SA-11 Developer Testing and Evaluation; SA-11(1) Static Code Analysis; SA-11(8) Dynamic Code AnalysisStatic analysis, fuzzing and unit tests for reentrancy
NIST SP 800-53 Rev. 5SA-8 Security and Privacy Engineering Principles; SA-15 Development Process, Standards, and ToolsCEI as a coding standard; pinned compilers and libraries
NIST SP 800-53 Rev. 5CM-3(2) Testing, Validation, and Documentation of ChangesRe-test and re-audit patches that touch external calls
NIST CSF 2.0ID.RA-01 Vulnerabilities in assets are identified, validated, and recordedAudit 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

Related NHI Mgmt Group resources: OWASP Smart Contract Top 10 Guide · Smart Contract Security Guide · Smart Contract Access Control Guide · DeFi Risk Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.