Wiki/Reentrancy Attacks in DeFi: The Classic DAO Hack Explained
Reentrancy Attacks in DeFi: The Classic DAO Hack Explained - Biturai Wiki Knowledge
ADVANCED | BITURAI KNOWLEDGE

Reentrancy Attacks in DeFi: The Classic DAO Hack Explained

Reentrancy attacks are a critical vulnerability in smart contracts where an attacker repeatedly calls a function before its state is updated, leading to unauthorized fund withdrawals or state manipulation. The infamous DAO hack in 2016

Biturai Knowledge
Biturai Knowledge
Research library
Updated: 6/27/2026
Technically checked

Structure, readability, internal linking, and SEO metadata were automatically checked. This article is continuously updated and is educational content, not financial advice.

Definition

A reentrancy attack is a severe vulnerability in smart contracts, particularly prevalent in the decentralized finance (DeFi) ecosystem, where a malicious actor can repeatedly call a function within a target contract before the initial execution of that function has fully completed and its internal state has been updated. This allows the attacker to drain funds, manipulate balances, or alter the contract's logic in unintended ways, often leading to significant financial losses. The core issue arises when a contract makes an external call to an untrusted address before updating its own internal state variables that are affected by that call.

A reentrancy attack occurs when a malicious smart contract repeatedly calls a vulnerable function in another contract before the initial execution of that function is completed and its internal state is updated. This allows the attacker to drain funds or manipulate the contract's logic in unintended ways.

Key Takeaway

The fundamental principle behind a reentrancy attack is the improper ordering of operations: specifically, performing an external call to another contract before updating the internal state variables that the external call might influence. If a smart contract sends Ether or tokens to an external address and then, after that transfer, attempts to update the sender's balance or other relevant state, it creates a window of opportunity. During this window, the recipient, if it's a malicious contract, can re-enter the original function, exploiting the outdated state to perform additional unauthorized actions.

Mechanics

To understand the mechanics of a reentrancy attack, consider a simplified smart contract acting as a digital bank where users can deposit and withdraw Ether. A common vulnerability arises when the contract first sends the Ether to the user and then updates the user's balance to reflect the withdrawal. Here's a step-by-step breakdown of how an attacker exploits this:

  1. Initial Deposit: An attacker deposits a small amount of Ether into the vulnerable contract, establishing a balance.
  2. Withdrawal Request: The attacker calls the withdraw() function in the vulnerable contract, requesting to withdraw their deposited Ether.
  3. External Call: Inside the withdraw() function, the vulnerable contract initiates an external call to send the requested Ether to the attacker's address. Crucially, this transfer happens before the contract updates its internal record of the attacker's balance (e.g., setting it to zero or subtracting the withdrawn amount).
  4. Malicious Fallback Function: If the attacker's address belongs to another smart contract, this external Ether transfer automatically triggers the attacker contract's fallback function (or receive function in Solidity). This fallback function is designed to execute when Ether is sent to a contract without specifying a particular function to call.
  5. Re-entry: Within its fallback function, the malicious attacker contract immediately calls the vulnerable contract's withdraw() function again. Because the vulnerable contract's internal state (the attacker's balance) has not yet been updated from the first withdrawal, it still shows the original balance. The vulnerable contract, unaware it's being re-entered, processes this second withdrawal request, sending more Ether to the attacker.
  6. Loop and Drain: This process repeats. Each time the vulnerable contract sends Ether to the attacker, the attacker's fallback function is triggered, which then re-enters the withdraw() function. This loop continues until the vulnerable contract's Ether reserves are depleted or the transaction's gas limit is reached. Only after the attacker's contract stops re-entering does the vulnerable contract finally update its state, but by then, it's too late.

This mechanism was famously exploited in the DAO hack, where the call.value() method was used for the Ether transfer. While send() and transfer() methods provide a limited gas stipend (2300 gas) which can mitigate some reentrancy scenarios by preventing complex re-entry logic, call.value() forwards all available gas, making it highly susceptible if not handled with the Checks-Effects-Interactions pattern. This pattern dictates that all checks (e.g., require statements), then all state changes (effects), and finally all external interactions should occur in that specific order to prevent reentrancy.

Reentrancy can also manifest in two main forms: single-function reentrancy, where the same vulnerable function is called repeatedly, and cross-function reentrancy, where a vulnerable function shares state with another function that the attacker can exploit to re-enter and drain funds. For instance, an attacker might call withdrawA() which updates a shared balance, and then re-enter via withdrawB() before the state from withdrawA() is finalized.

Trading Relevance

While reentrancy attacks are not directly related to trading strategies or market analysis, their impact on the DeFi ecosystem has profound implications for traders and investors. The security of the underlying smart contracts directly affects the safety of digital assets. A successful reentrancy attack can lead to the sudden and massive draining of funds from a DeFi protocol, causing immediate and severe market instability for the affected tokens and potentially the broader market.

For traders, understanding reentrancy is crucial for risk management. Investing in or interacting with DeFi protocols requires a thorough assessment of their smart contract security. Protocols that have undergone rigorous audits and adhere to best practices like the Checks-Effects-Interactions pattern are generally safer. A reentrancy exploit can lead to a rapid devaluation of a protocol's native token, liquidity pools being emptied, and a complete loss of trust, making any associated assets highly volatile and risky. Traders must be aware that even seemingly robust projects can harbor vulnerabilities, and a hack can wipe out investments overnight, irrespective of market trends or fundamental analysis.

Risks

The risks associated with reentrancy attacks are multifaceted and can have catastrophic consequences for individuals, projects, and the entire DeFi ecosystem.

Firstly, the most immediate and devastating risk is financial loss. Attackers can drain vast amounts of Ether, tokens, or other digital assets from vulnerable contracts, leading to irreversible losses for users and liquidity providers. The scale of these losses can range from thousands to hundreds of millions of dollars, as demonstrated by historical events.

Secondly, reentrancy attacks severely damage the reputation and trust in affected projects. A successful exploit signals a fundamental flaw in the project's security architecture, leading to a loss of user confidence, a decline in adoption, and a potential death spiral for the protocol. This reputational damage can extend beyond the immediate project, fostering skepticism about the security of DeFi as a whole.

Thirdly, these attacks introduce systemic risk to the broader blockchain and DeFi landscape. Major hacks can trigger cascading effects, impacting interconnected protocols, stablecoin pegs, and overall market sentiment. The response to such attacks, as seen with the DAO, can even necessitate controversial measures like hard forks, which have long-term implications for the blockchain's integrity and community cohesion. Furthermore, the legal and regulatory implications of such large-scale thefts are still evolving, adding another layer of uncertainty for projects and investors.

History and Examples

The most infamous and historically significant reentrancy attack is The DAO Hack of June 2016. The DAO (Decentralized Autonomous Organization) was an early, ambitious project on the Ethereum blockchain, designed as a decentralized venture capital fund. It raised over 150 million USD worth of Ether, representing about 14% of all Ether in circulation at the time.

The DAO's smart contract included a splitDAO function that allowed investors to withdraw their Ether and create a

OKX · Official Biturai Partner

OKX

Explore the current OKX offering through the official Biturai partner link. Products and availability may vary by country.

Explore OKX

Partner link · Biturai may receive compensation when it is used · not investment advice

OKX

Disclaimer

This article is for informational purposes only. The content does not constitute financial advice, investment recommendation, or solicitation to buy or sell securities or cryptocurrencies. Biturai assumes no liability for the accuracy, completeness, or timeliness of the information. Investment decisions should always be made based on your own research and considering your personal financial situation.

Transparency

Biturai may use AI-assisted tools to research, structure, or update Wiki articles. Editorially reviewed articles are marked separately; all content remains educational and does not replace your own review.