Read-Only Reentrancy Explained | Solidity Security (0.8)

Added:

Oracle-First Architecture vs. Spot-Price View Hardening

While read-only reentrancy is a recognized vulnerability, many smart contract architects argue that hardening individual pool view functions is the wrong layer to address the issue. Implementing reentrancy guards on view functions (making them state-modifying or gas-heavy) introduces significant gas overhead and degrades composability. The counter-perspective emphasizes an 'Oracle-First' design. It argues that integrating protocols should never rely on raw spot prices or instantaneous pool states for critical financial calculations. Instead, developers should use Time-Weighted Average Prices (TWAPs) or decentralized oracle networks (like Chainlink). From this viewpoint, focusing heavily on patching read-only reentrancy at the AMM level is a band-aid; the fundamental security flaw is the architectural decision to use spot reserves as a price oracle in the first place.

Understanding of classic (state-changing) reentrancy vulnerabilities and standard mitigations like the Checks-Effects-Interactions pattern and ReentrancyGuards.
Basic mechanics of Automated Market Makers (AMMs) and how decentralized finance (DeFi) protocols utilize them as on-chain price oracles.
Proficiency in Solidity 0.8 development, specifically around contract-to-contract interactions, external calls, and state management.
Familiarity with the Foundry development and testing framework, including writing unit tests and executing mainnet fork simulations.
Implementation of advanced mitigation strategies for read-only reentrancy, such as utilizing lock-aware external checks or integrating resilient Chainlink TWAP oracles.
Analysis of prominent real-world read-only reentrancy exploits, such as the Euler Finance, Sentiment, or Balancer pool vulnerabilities.
Exploration of complex cross-contract and cross-protocol reentrancy vectors where execution flow spans multiple distinct DeFi projects.
Using automated vulnerability detection tools (like Slither) and writing property-based fuzz tests in Foundry to identify price manipulation risks.
14K views377likes19:55@smartcontractprogrammerOriginal Release: 2022-10-30

A read-only reentrancy attack exploits the fact that when a contract calls another contract (like Curve's remove_liquidity), the receiving contract's receive() function executes before the original call finishes, allowing an attacker to read inflated or stale state values (such as virtual price) during the intermediate execution phase, which can be leveraged to manipulate reward calculations or other dependent logic in target contracts.