Wiki/Read-Only Reentrancy: The Underestimated Vulnerability
Read-Only Reentrancy: The Underestimated Vulnerability - Biturai Wiki Knowledge
ADVANCED | BITURAI KNOWLEDGE

Read-Only Reentrancy: The Underestimated Vulnerability

Read-only reentrancy is a subtle smart contract vulnerability where an attacker exploits a temporary, inconsistent state by calling a view function from an external contract. This allows the attacker to read an outdated or manipulated

Biturai Knowledge
Biturai Knowledge
Research library
Updated: 7/2/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

Read-only reentrancy is a specific type of smart contract vulnerability that leverages a temporary, inconsistent state within a contract. Unlike traditional reentrancy, which focuses on repeatedly executing state-modifying functions, read-only reentrancy exploits the ability to call a "view" or "pure" function from an external contract during an intermediate phase of a transaction, before the original operation has fully completed and all relevant state variables are updated. This allows an attacker to read an outdated or manipulated value, which can then be used to influence subsequent operations or the logic of a dependent contract. The danger lies in the fact that these "read" operations, typically considered harmless, can become vectors for exploitation when the underlying data they access is momentarily out of sync with the contract's true state.

Read-only reentrancy is a smart contract vulnerability where an attacker calls a view function during an inconsistent intermediate state of a transaction, obtaining manipulated or outdated data to influence subsequent contract logic.

This vulnerability often arises when a contract makes an external call to another contract, and that external contract (potentially controlled by an attacker) then re-enters the original contract to query a view function. If the original contract's state variables, which the view function depends on, have not yet been fully updated to reflect the ongoing transaction, the view function will return an incorrect value. This incorrect value can then be used by the attacker's contract to make decisions that are detrimental to the victim contract or its users. It highlights a critical aspect of smart contract design: the order of operations, especially state updates relative to external calls, is paramount for security.

Key Takeaway

The core danger of read-only reentrancy lies in its ability to manipulate decision-making processes in smart contracts by providing false or outdated information, even without directly altering the contract's state during the reentrant call itself. This vulnerability underscores that even seemingly harmless "read" operations can be weaponized if not properly secured against intermediate state inconsistencies. Developers often focus on protecting against state-changing reentrancy with checks-effects-interactions patterns, but read-only reentrancy demonstrates that the timing of external calls and subsequent data reads is equally critical.

This subtle form of attack can lead to significant financial losses by causing contracts to miscalculate prices, collateral values, or other critical metrics. It forces a re-evaluation of security assumptions, particularly regarding the immutability of data during complex multi-step transactions involving external calls. The key takeaway is that any external call, regardless of its apparent purpose, introduces a potential reentrancy vector, and developers must consider not only state modifications but also the integrity of data read by view functions during such calls.

Mechanics

The mechanics of a read-only reentrancy attack typically involve a specific sequence of events. First, a victim smart contract initiates an external call to another contract. This external call could be a token transfer (e.g., sending ETH or an ERC-20 token), a call to another DeFi protocol, or any interaction that triggers code execution in the recipient contract. If the recipient contract is an attacker-controlled contract, its fallback or receive function will be triggered.

Within this triggered fallback function, the attacker's contract then makes a reentrant call back to the original victim contract. Crucially, this reentrant call targets a view function (or a pure function) on the victim contract. The vulnerability arises if, at the moment of this reentrant call, the victim contract's internal state variables, which the view function relies upon, have not yet been fully updated to reflect the initial external call. For instance, if a withdrawal function first sends funds and then updates the user's balance, an attacker could re-enter after receiving funds but before the balance is decremented. The view function, when called during this window, would return a value based on the outdated balance, effectively showing more funds than are actually available or a different price than intended.

Consider a scenario where a vault contract calculates a user's share of total tokens based on totalTokens and userBalance. A withdrawal function might first send tokens to the user, then update userBalance and totalTokens. If the user's contract is malicious, its fallback function could be triggered upon receiving tokens. Within this fallback, the malicious contract could call a view function on the vault that calculates the "current price" or "share value" based on totalTokens. If totalTokens has not yet been updated to reflect the outgoing withdrawal, the view function would return an inflated value. This inflated value could then be used by the attacker's contract to manipulate subsequent actions, such as borrowing against an artificially high collateral value or exploiting a price oracle. The critical element is the temporary inconsistency of state variables that view functions rely on, which are exposed during the execution flow of an external call.

Trading Relevance

Read-only reentrancy, while not directly a trading strategy, has profound implications for the security and integrity of decentralized finance (DeFi) protocols, which are the backbone of on-chain trading. Its relevance to trading stems from its potential to manipulate critical data points that directly influence asset prices, collateral valuations, and arbitrage opportunities. For instance, many DeFi protocols, such as lending platforms, decentralized exchanges (DEXs), and synthetic asset platforms, rely heavily on external calls to price oracles or other contracts to determine asset values, interest rates, or liquidation thresholds.

If a price oracle contract is susceptible to read-only reentrancy, an attacker could exploit it to temporarily report an incorrect asset price. This manipulated price could then be used to execute profitable trades, such as borrowing more assets than justified by collateral, liquidating positions unfairly, or exploiting arbitrage opportunities on DEXs that rely on the compromised oracle. Imagine a scenario where a DEX's liquidity pool calculates the price of a token based on its current reserves. If a large withdrawal is initiated, and an attacker can re-enter to query the price before the reserves are fully updated, they could get an artificially low or high price, allowing them to buy or sell at a manipulated rate. This directly impacts the fairness and efficiency of trading, leading to significant financial losses for legitimate traders and liquidity providers.

Furthermore, the integrity of collateral calculations in lending protocols is paramount for trading. If an attacker can manipulate the reported value of their collateral through a read-only reentrancy attack on a dependent contract, they could borrow excessive amounts, leading to undercollateralized loans and potential bad debt for the protocol. This not only affects the stability of the lending market but also creates systemic risks for other protocols that integrate with it. Understanding and mitigating read-only reentrancy is therefore essential for anyone involved in on-chain trading, as it directly impacts the reliability of the data and mechanisms that govern asset valuation and exchange.

Risks

The risks associated with read-only reentrancy are substantial and multifaceted, extending beyond immediate financial losses to broader systemic concerns within the blockchain ecosystem. The most immediate risk is financial loss for users and the protocol itself. Attackers can exploit manipulated data to drain funds, acquire assets at unfair prices, or borrow against non-existent collateral, leading to direct monetary damages. For example, if a lending protocol's collateral valuation is compromised, users could lose their deposited funds, and the protocol could incur significant bad debt.

Beyond direct financial impact, read-only reentrancy poses significant reputational damage to affected projects and the broader DeFi space. A successful exploit erodes user trust, making it harder for projects to attract liquidity and users. This loss of trust can have long-term consequences, hindering innovation and adoption. Furthermore, the subtlety of this vulnerability makes it particularly dangerous during security audits. Traditional reentrancy checks often focus on state-modifying functions and reentrancy guards, potentially overlooking the risks associated with view functions reading inconsistent states. This makes detection more challenging and increases the likelihood of such vulnerabilities slipping into production code.

Another significant risk is the potential for systemic risk across interconnected DeFi protocols. Many protocols rely on external contracts for critical data, suchs as price feeds, governance decisions, or liquidity provision. If a foundational contract is vulnerable to read-only reentrancy, it can create a cascading effect, compromising the integrity of all dependent protocols. This interconnectedness means that a single, subtle vulnerability can have far-reaching consequences, impacting the stability of the entire ecosystem. Ultimately, the presence of such vulnerabilities undermines the core promise of decentralized finance: secure, transparent, and trustless operations.

History and Examples

While traditional reentrancy attacks, famously exemplified by the DAO hack in 2016, are well-documented, read-only reentrancy is a more recently recognized and often underestimated variant. Its subtle nature means that specific, named exploits are less frequently publicized in the same dramatic fashion as direct fund drains. However, security research teams and auditors have increasingly highlighted this class of vulnerability, with reports indicating that it has been responsible for putting "100m+ funds at risk" across various protocols. This suggests that while not always leading to a single, massive, named hack, the cumulative impact of such vulnerabilities has been substantial.

A common hypothetical, yet highly realistic, example involves a lending protocol interacting with a custom price oracle. Imagine a lending contract that allows users to deposit collateral and borrow stablecoins. The amount a user can borrow is determined by calling a getCurrentPrice() view function on an external price oracle contract. Now, consider the oracle's internal logic: it might update its totalValueLocked variable after an external withdraw call has been made to a user, but before the transaction fully completes. An attacker could craft a malicious contract that, upon receiving funds from the oracle's withdraw function, immediately re-enters the oracle to call getCurrentPrice(). During this brief window, totalValueLocked might still reflect the state before the withdrawal, leading getCurrentPrice() to return an artificially inflated price. The attacker could then use this inflated price to borrow more stablecoins from the lending protocol than their actual collateral justifies, leading to an undercollateralized loan.

Another scenario could involve a decentralized exchange (DEX) liquidity pool. If a large swap or withdrawal occurs, the internal reserves of the pool are updated. If an attacker can re-enter a view function that calculates the current exchange rate before these reserves are fully adjusted, they could obtain a temporarily skewed price. This skewed price could then be used to execute a subsequent trade at an advantageous rate, effectively front-running or manipulating the market. These examples illustrate that the vulnerability often arises from a mismatch in the timing of state updates and external calls, allowing an attacker to exploit an intermediate, inconsistent state.

Common Misunderstandings

One of the most prevalent misunderstandings regarding read-only reentrancy is the belief that "view functions are inherently safe". Many developers assume that because view functions do not modify the contract's state, they cannot be exploited in a reentrancy attack. This is a dangerous oversimplification. While view functions themselves do not change state, they read state. If the state they read is temporarily inconsistent due to an ongoing external call, the returned value can be manipulated, leading to severe consequences for dependent logic. The safety of a view function is contingent on the integrity and consistency of the data it accesses, especially during complex transaction flows.

Another common misconception is that "reentrancy guards protect against all reentrancy attacks." While patterns like the "checks-effects-interactions" pattern and reentrancy guards (e.g., nonReentrant modifiers) are highly effective against traditional reentrancy attacks that aim to repeatedly execute state-modifying functions, they often do not directly address read-only reentrancy. A nonReentrant guard typically prevents a function from being called again while it's already executing. However, a read-only reentrancy attack might target a different view function that doesn't have such a guard, or it might exploit a window between the "effects" and "interactions" phases where state is temporarily inconsistent but no explicit reentrancy is detected on the guarded function itself. The problem isn't the re-execution of the same function, but the reading of an intermediate state.

Finally, some might dismiss read-only reentrancy as a "theoretical or niche vulnerability." This perspective underestimates its real-world impact. As highlighted by security reports, this class of vulnerability has put substantial funds at risk. The increasing complexity and interconnectedness of DeFi protocols mean that subtle timing-dependent bugs, like read-only reentrancy, become more probable and more impactful. It's not a theoretical edge case but a practical concern that demands rigorous attention during design and auditing phases, especially for protocols that rely on external calls and inter-contract-communication for critical data.

Summary

Read-only reentrancy represents a sophisticated and often underestimated smart contract vulnerability that exploits temporary inconsistencies in a contract's state during external calls. Unlike its traditional counterpart, which focuses on repeated state modifications, this variant leverages view functions to read manipulated or outdated data, influencing critical decision-making processes in dependent contracts. The attack vector typically involves an external call triggering an attacker's contract, which then re-enters the victim contract to query a view function before the victim's state variables are fully updated.

The implications for decentralized finance are significant, potentially leading to price manipulation, incorrect collateral valuations, and substantial financial losses for users and protocols. Its subtlety makes it challenging to detect during standard security audits, and common reentrancy mitigation techniques may not fully address it. Understanding read-only reentrancy is paramount for developers and auditors to build resilient smart contracts and for users to comprehend the underlying risks in the DeFi ecosystem. Robust security practices, including careful ordering of operations, thorough state consistency checks, and comprehensive auditing, are essential to guard against this insidious threat.

OKX · Official Biturai Partner

Trade smarter with OKX.

Access spot and derivatives markets, automate strategies with trading bots, use advanced order tools, and verify 1:1 reserves every month.

  • Spot and derivatives markets
  • Trading bots and advanced orders
  • 1:1 reserves with monthly Proof of Reserves
  • Account protection and 24/7 monitoring
Open your OKX account

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.