What is read-only reentrancy?
Read-only reentrancy is when a contract reads a view function on another protocol while that protocol is in the middle of an update, and acts on a value computed from half-written state. The view changes nothing, so the other protocol's reentrancy guard doesn't stop the call, but the reader prices collateral or shares from a wrong number. Check the other protocol's lock before you read its views, and make your own views refuse to answer while your contract is mid-update.
How does read-only reentrancy work?
Classic reentrancy re-enters a function that changes state. Read-only reentrancy needs no state change in the victim at all. It needs three things:
- A protocol that hands control to someone else before its accounting is finished, usually by sending ETH or calling a token hook in the middle of a withdrawal.
- A view on that protocol, such as a share price or an LP token price, computed from the half-updated state.
- A second protocol that reads that view and lends, mints or liquidates on the answer.
The attacker starts the withdrawal and, inside the callback, calls the second protocol, which reads the view while the first one is mid-update. A nonReentrant modifier on the first protocol doesn't help, because nobody re-enters its state-changing functions. A guard on the second protocol doesn't help either, because it is entered only once.
What does vulnerable code look like?
This pool burns shares before it sends ETH and lowers totalAssets only after the call. Its own functions are guarded. The lender next to it prices pool shares with sharePrice().
Vulnerable: a pool that calls out mid-update, and a lender that trusts its view (illustrative, not audited code) MidUpdatePricing.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
contract SharePool {
uint256 public totalShares;
uint256 public totalAssets; // ETH the pool counts as its own
mapping(address => uint256) public shares;
uint256 private locked = 1;
modifier nonReentrant() {
require(locked == 1, "reentrant call");
locked = 2;
_;
locked = 1;
}
function deposit() external payable nonReentrant {
uint256 minted = totalShares == 0 ? msg.value : msg.value * totalShares / totalAssets;
shares[msg.sender] += minted;
totalShares += minted;
totalAssets += msg.value;
}
function withdraw(uint256 amount) external nonReentrant {
uint256 assets = amount * totalAssets / totalShares;
shares[msg.sender] -= amount;
totalShares -= amount;
// The caller's code runs here, while totalAssets still counts the ETH being sent.
(bool ok, ) = msg.sender.call{value: assets}("");
require(ok, "send failed");
totalAssets -= assets;
}
// The guard can't help here: a view never takes the lock.
function sharePrice() external view returns (uint256) {
return totalAssets * 1e18 / totalShares;
}
}
interface ISharePool {
function sharePrice() external view returns (uint256);
}
contract ShareLender {
ISharePool public immutable pool;
mapping(address => uint256) public posted; // pool shares posted as collateral
mapping(address => uint256) public debt; // ETH borrowed
constructor(ISharePool pool_) {
pool = pool_;
}
function post(uint256 amount) external {
posted[msg.sender] += amount;
// ... take `amount` pool shares from msg.sender
}
function borrow(uint256 amount) external {
// Read during a withdrawal from the pool, this price is too high.
uint256 value = posted[msg.sender] * pool.sharePrice() / 1e18;
require((debt[msg.sender] + amount) * 100 <= value * 80, "undercollateralized");
debt[msg.sender] += amount;
// ... send `amount` ETH to msg.sender
}
}
Say the pool holds 100 ETH against 100 shares, so a share is worth 1 ETH. An attacker owns 95 shares and has posted 5 of them to the lender. When the attacker withdraws the other 90, the pool has already cut totalShares to 10 but still counts 100 ETH, so inside the ETH callback sharePrice() returns 10 ETH. The lender values the 5 posted shares at 50 ETH and lends 40 against them. After the callback the price is back to 1 ETH, and the lender holds 5 ETH of collateral against a 40 ETH loan. We ran these numbers as a Foundry test against the code above.
How do you fix it?
Fixed: the pool finishes its updates first, its view refuses to answer mid-update, and the lender checks the lock (illustrative, not audited code) LockAwarePricing.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
contract SafeSharePool {
uint256 public totalShares;
uint256 public totalAssets;
mapping(address => uint256) public shares;
uint256 private locked = 1;
modifier nonReentrant() {
require(locked == 1, "reentrant call");
locked = 2;
_;
locked = 1;
}
function deposit() external payable nonReentrant {
uint256 minted = totalShares == 0 ? msg.value : msg.value * totalShares / totalAssets;
shares[msg.sender] += minted;
totalShares += minted;
totalAssets += msg.value;
}
function withdraw(uint256 amount) external nonReentrant {
uint256 assets = amount * totalAssets / totalShares;
shares[msg.sender] -= amount;
totalShares -= amount;
totalAssets -= assets; // every update happens before the call
(bool ok, ) = msg.sender.call{value: assets}("");
require(ok, "send failed");
}
function isLocked() external view returns (bool) {
return locked != 1;
}
// Refuses to answer while a call into the pool is still running.
function sharePrice() external view returns (uint256) {
require(locked == 1, "pool is mid-update");
return totalAssets * 1e18 / totalShares;
}
}
interface ILockablePool {
function isLocked() external view returns (bool);
function sharePrice() external view returns (uint256);
}
contract LockCheckingLender {
ILockablePool public immutable pool;
mapping(address => uint256) public posted;
mapping(address => uint256) public debt;
constructor(ILockablePool pool_) {
pool = pool_;
}
function post(uint256 amount) external {
posted[msg.sender] += amount;
// ... take `amount` pool shares from msg.sender
}
function borrow(uint256 amount) external {
// A pool you don't control may not guard its views, so check its lock first.
require(!pool.isLocked(), "pool is mid-update");
uint256 value = posted[msg.sender] * pool.sharePrice() / 1e18;
require((debt[msg.sender] + amount) * 100 <= value * 80, "undercollateralized");
debt[msg.sender] += amount;
// ... send `amount` ETH to msg.sender
}
}
- Finish every update before the call. The fixed pool lowers
totalAssetsbefore it sends ETH, so a view read during the callback is already consistent. This is checks, effects, interactions applied to the numbers your views expose as well as to balances. - Make views refuse to answer mid-update. A view can't take a lock, but it can read one. The fixed
sharePrice()reverts while the pool's lock is held, andisLocked()lets integrators check. - Check the lock of pools you don't control. Before the fixed lender reads
sharePrice(), it asks the pool whether it is locked. If a pool has no lock getter, some integrations call a cheap function on it that takes the same lock and reverts mid-update. Make sure such a call has no other effect. - Don't price collateral from a view you haven't traced. For each external view you read, find out whether the protocol behind it ever calls out before its accounting is final.
How has read-only reentrancy been exploited?
| Protocol | Conic Finance ETH Omnipool |
|---|---|
| Date | 21 July 2023 |
| Chain | Ethereum |
| Loss | about $3.3M |
| What happened | Conic priced Curve LP tokens through its oracle contract, CurveLPOracleV2, and had reentrancy protection for the Curve pools it read. According to rekt.news, that protection never triggered, because Conic assumed Curve represents ETH with the 0xeee... placeholder address, while Curve's V2 pools use WETH. The attacker re-entered through the read-only reentrancy, manipulated the prices the oracle returned and withdrew more from the ETH Omnipool than it had deposited, about $3.3M. A second attack the same day took about $934,000 from Conic's crvUSD Omnipool through a different flaw, price bounds that were too loose. |
| Sources | rekt.news, rekt.news |
Conic had a guard and still lost, because the guard rested on a wrong assumption about which pools hold ETH. Test the lock check itself: read the price from inside a real withdrawal callback, on a fork, for every pool type you support, and make sure the check fires.
How is it different from other kinds of reentrancy?
| Variant | What the callback does | Does the called contract's guard stop it? |
|---|---|---|
| Single-function | Calls the same function again | Yes |
| Cross-function | Calls another function of the same contract that shares state | Yes, if that function carries the guard too |
| Cross-contract | Calls another contract of the same protocol that shares state | No, unless that contract checks the same lock |
| Read-only | Reads a view, or calls another protocol that reads one | No. The view has to check the lock, or the reader has to |
GMX V1's July 2025 loss is a cross-contract case rather than a read-only one: BlockSec's analysis traces a callback from GMX's OrderBook into its Vault, which the OrderBook's guard did not cover. The reentrancy page covers the classic variants with code.
What should a reviewer check?
- List every external view your contracts read for a price, a share value, an exchange rate or a balance.
- For each one, can the protocol behind it send ETH, call a token hook or call any external address before its accounting is final?
- Does that protocol expose its lock state, and does your code check it before trusting the view?
- In your own contracts, is every value that a view exposes updated before each external call?
- Do your views revert while your reentrancy lock is held, and is the lock state public so integrators can check it?
- Is there a test where an attacker contract calls your protocol from inside another protocol's callback and reads the price there?
How does QuillShield check for read-only reentrancy?
This class lives in the gap between two codebases, the one that calls out and the one that reads its view, so put your price adapters in scope together with every function that acts on their answers. QuillShield runs a full audit of a Solidity codebase in a Foundry project. It builds a security graph of the code and lists the invariants the code must keep.
A separate reviewer agent tries to disprove every finding before you see it, and each finding that holds up comes with the exact lines, the impact, a recommended fix and, on full audits, a proof of concept. For a callback bug, the useful proof of concept reads the price inside the callback and compares it with the price before and after.
It then checks every pull request on GitHub or GitLab.com against that graph. Integrations with another protocol's views usually arrive as small pull requests, one new collateral type at a time. QuillShield does not replace a manual audit, and you can request a manual audit from QuillAudits.
Start free. New accounts get $50 in credit, good for up to half of an order.
FAQ
Does nonReentrant protect view functions?
No. A view can't set the lock, and the usual modifier only checks it in functions that change state. A view has to read the lock and revert while it is held, as the fixed sharePrice() does.
Who should fix read-only reentrancy, the pool or the protocol that reads it?
Both can. The pool can finish its updates before any external call and make its views revert mid-update. A protocol that reads a pool it doesn't control has to check that the pool isn't locked before trusting the value.
Is read-only reentrancy only a problem for pools that hold ETH?
No. Any contract that hands control to someone else before its accounting is final can expose a wrong value through its views. ETH transfers, ERC-777 hooks, ERC-721 and ERC-1155 safe transfer callbacks and flash loan callbacks all hand over control.
How do I test for read-only reentrancy in Foundry?
Write an attacker contract whose receive function, or token hook, calls your protocol while another protocol is mid-withdrawal. Assert that every price your protocol reads inside the callback equals the price before and after, or that your call reverts.
Sources
- Conic Finance REKT, rekt.news checked 3 December 2026
- Leaderboard, rekt.news checked 3 December 2026
- Smart Contract Weakness Classification Registry, SWC Registry checked 3 December 2026
- GMX incident: cross-contract reentrancy bypasses a four-year-old guard, BlockSec checked 3 December 2026
- OWASP Smart Contract Top 10: 2026, OWASP checked 3 December 2026