What Is a Re-Entrancy Attack?

A re-entrancy attack exploits the gap between a smart contract's external call and its state update, allowing an attacker to drain funds by recursively re-entering the function before balances are zeroed.
Lewis Jackson
CEO and Founder

The DAO hack is the obvious entry point. In June 2016, an attacker drained roughly $60 million from an Ethereum-based fund using a technique that, in retrospect, is almost embarrassingly simple — and one that's reappeared in DeFi protocols ever since.

Re-entrancy is a class of smart contract vulnerability where an external contract exploits the timing between a function call and a state update. It's not a bug in the Ethereum language. It's a structural consequence of how the EVM handles external calls, and understanding it means understanding one of the most consequential design constraints in smart contract development.

How Re-Entrancy Works

The mechanism unfolds in three steps.

Step one: a vulnerable contract sends ETH (or tokens) to an external address before updating its own records. In a simple withdrawal function, the order looks like this: check the user's balance, send the funds, then set the balance to zero.

Step two: the recipient is a malicious contract — one that has a receive() or fallback() function that automatically executes when it receives ETH. That function immediately calls back into the original contract's withdrawal function before the first execution has finished.

Step three: the original contract processes this new call. From its perspective, nothing has changed. The balance still shows the original amount — because it hasn't been set to zero yet. So it sends funds again. And again. The loop continues until the contract's ETH is drained or the gas runs out.

This is re-entrancy: the attacker's contract "re-enters" the vulnerable function during its execution, before the state is updated. The contract is mid-execution and doesn't know it.

The DAO hack followed this pattern exactly. The DAO contract sent ETH before updating the attacker's internal balance record. The attacker's contract had a fallback function that looped back into the split function before the balance could be zeroed, draining approximately one-third of the fund's holdings.

Variants Beyond the Classic

The single-function version is now well understood. But re-entrancy has evolved.

Cross-function re-entrancy is subtler. Here, the malicious callback doesn't re-enter the same function — it enters a different function in the same contract that reads the same shared state. The original function hasn't updated state yet, so the second function sees stale data and behaves accordingly. Auditors who only check for single-function re-entrancy miss this entirely.

Read-only re-entrancy (a more recently characterized variant) doesn't steal funds directly. Instead, the callback re-enters to read state that's temporarily inconsistent — say, a price oracle querying pool balances during a token transfer. If another protocol uses that oracle in the same transaction, it may receive a manipulated price and make decisions based on it. Several major DeFi exploits in 2022 and 2023 followed this pattern. The attack surface isn't the contract being entered; it's anything downstream that trusts its state.

The underlying constraint is consistent across all variants: Ethereum's execution model allows external contracts to run arbitrary code when they receive ETH or tokens, and that code runs synchronously, inside the original transaction, before control returns to the caller.

Why It Keeps Happening

There are two standard defenses, both now considered mandatory in professional Solidity development.

The first is the Checks-Effects-Interactions (CEI) pattern: always update state before making external calls. Check conditions, update internal state (balance = 0), then transfer funds. If an attacker re-enters, the balance is already zero — the withdrawal fails.

The second is a re-entrancy guard: a boolean flag that flips to "locked" when the function is executing, rejecting any re-entrant call before it can proceed. OpenZeppelin's ReentrancyGuard and nonReentrant modifier have been standard across professional codebases for years.

Neither defense is complicated. Both have been well-documented since 2016. The persistence of re-entrancy vulnerabilities in deployed protocols isn't a knowledge problem — it's an execution problem. Teams under time pressure, code that evolves after an audit, newer developers unfamiliar with EVM semantics, or assumptions about how an inherited contract behaves can all introduce re-entrancy in unexpected places. The attack surface has also grown: composable DeFi means more external calls, which means more re-entry surface.

The structural constraint doesn't go away. Ethereum's composability — the property that lets protocols build on each other — is the same mechanism that makes re-entrancy possible. You can't eliminate external calls without eliminating DeFi.

What's Changing

The classic single-function re-entrancy pattern is now reliably caught. OpenZeppelin's implementations are widely used, automated static analysis tools (Slither, Mythril) flag common variants before deployment, and major audit firms include explicit re-entrancy testing as standard scope.

The active risk has shifted. Post-exploit analysis of recent re-entrancy incidents consistently finds one of three conditions: the vulnerability was introduced after the audit, it existed in code paths the audit didn't cover, or it was a cross-function or read-only variant that required semantic reasoning rather than pattern matching.

Intent-based protocols and cross-chain architectures introduce new trust boundaries where re-entrancy semantics aren't always clear. When execution spans multiple contracts across multiple hops, the question of "what state is consistent" becomes harder to answer.

EIP-1153 (transient storage, live on Ethereum mainnet as of the Cancun upgrade) may reduce some re-entrancy attack surfaces by enabling cheaper, atomic state locks. The long-term effect on re-entrancy tooling and patterns is still being characterized.

Confirmation Signals

Re-entrancy defenses are holding where: audit reports include explicit re-entrancy testing; major multi-year protocols with significant TVL remain uncompromised on this vector; static analysis tooling catches classic variants in pre-deployment review. The declining frequency of single-function re-entrancy exploits relative to more novel variants suggests the basic pattern is contained.

Invalidation: the thesis that standard defenses are sufficient breaks if read-only re-entrancy in composable protocols causes continued losses at scale; if cross-chain re-entrancy patterns emerge that standard guards don't address; or if formal verification adoption stays low while protocol complexity increases.

Timing

Now: active risk for unaudited contracts, complex DeFi integrations with multiple external call paths, and protocols using non-standard ERC token implementations that may trigger unexpected callbacks. Any contract moving value without explicit re-entrancy guards is exposed.

Next: improved tooling for cross-function and read-only re-entrancy detection; wider adoption of transient storage for cheaper mutex implementations.

Later: formal verification becoming a standard pre-deployment requirement for high-TVL protocols would meaningfully reduce re-entrancy as an ongoing risk category, but the tooling and cost barriers remain high.

Boundary

This explains the mechanism and structural conditions — not a comprehensive smart contract security guide. Re-entrancy is one of many EVM vulnerability classes. If you're evaluating a specific protocol's security posture, read the audit reports directly; the depth of re-entrancy testing varies significantly between firms. This doesn't constitute advice on any protocol's safety or suitability.

Related Posts

See All
Crypto Research
New XRP-Focused Research Defining the “Velocity Threshold” for Global Settlement and Liquidity
A lot of people looking at my recent research have asked the same question: “Surely Ripple already understands all of this. So what does that mean for XRP?” That question is completely valid — and it turns out it’s the right question to ask. This research breaks down why XRP is unlikely to be the internal settlement asset of CBDC shared ledgers or unified bank platforms, and why that doesn’t mean XRP is irrelevant. Instead, it explains where XRP realistically fits in the system banks are actually building: at the seams, where different rulebooks, platforms, and networks still need to connect. Using liquidity math, system design, and real-world settlement mechanics, this piece explains: why most value settles inside venues, not through bridges why XRP’s role is narrower but more precise than most narratives suggest how velocity (refresh interval) determines whether XRP creates scarcity or just throughput and why Ripple’s strategy makes more sense once you stop assuming XRP must be “the core of everything” This isn’t a bullish or bearish take — it’s a structural one. If you want to understand XRP beyond hype and price targets, this is the question you need to grapple with.
Read Now
Crypto Research
The Jackson Liquidity Framework - Announcement
Lewis Jackson Ventures announces the release of the Jackson Liquidity Framework — the first quantitative, regulator-aligned model for liquidity sizing in AMM-based settlement systems, CBDC corridors, and tokenised financial infrastructures. Developed using advanced stochastic simulations and grounded in Basel III and PFMI principles, the framework provides a missing methodology for determining how much liquidity prefunded AMM pools actually require under real-world flow conditions.
Read Now
Crypto Research
Banks, Stablecoins, and Tokenized Assets
In Episode 011 of The Macro, crypto analyst Lewis Jackson unpacks a pivotal week in global finance — one marked by record growth in tokenized assets, expanding stablecoin adoption across emerging markets, and major institutions deepening their blockchain commitments. This research brief summarises Jackson’s key findings, from tokenized deposits to institutional RWA chains and AI-driven compliance, and explains how these developments signal a maturing, multi-rail settlement architecture spanning Ethereum, XRPL, stablecoin networks, and new interoperability layers.Taken together, this episode marks a structural shift toward programmable finance, instant settlement, and tokenized real-world assets at global scale.
Read Now

Related Posts

See All
No items found.
Lewsletter

Weekly notes on what I’m seeing

A personal letter I send straight to your inbox —reflections on crypto, wealth, time and life.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.