# Read-Only Reentrancy: Curve & Balancer LP Oracle Exploits

> Dissect read-only reentrancy DeFi hacks ($100M+ Curve/Vyper & Balancer LP lending drains): mid-callback view-function state desynchronization and lock checks.

Canonical: https://nftvenueledger.com/protocols/read-only-reentrancy-balancer-curve-lp-virtual-price-skew
Last updated: 2026-11-14T19:42:39.813Z

**Publication:** NFTVenue Ledger
**Category:** Cross Chain Bridge Validator Exploits
**Published:** 2026-11-13T14:50:25.915Z
**Author:** Dr. Devon Kurosawa, PhD (PhD in Distributed Systems & Cryptographic Protocol Verification)
**Reviewer:** Not recorded

## Answer-first summary

Even when an AMM pool protects its own state with nonReentrant locks, external lending protocols reading get_virtual_price or getRate mid-ETH-callback ingest wildly inflated LP prices.

## Key takeaways

- Read-only reentrancy exploits external protocols that call an AMM view function (get_virtual_price, getRate) during a mid-withdrawal native-ETH or ERC-777 callback when LP supply and reserves are temporarily out of sync.
- Fair LP pricing formulas (2*sqrt(r0*r1*P0*P1)/S) stop spot flash swaps, but STILL fail against read-only reentrancy unless paired with an explicit AMM reentrancy-lock check.
- Lending adapters pricing Balancer/Beethoven X BPT tokens MUST invoke VaultReentrancyLib.ensureNotInVaultContext(vault) before reading pool rates.
- Modern AMMs (Curve StableSwap-NG, Uniswap v4) expose public reentrancy-lock state or guard view getters directly via EIP-1153 transient storage.

## Related financial entities

- **Balancer Liquidity Bootstrapping Pool Standard** (BAL-LBP) — product: Smart contract pool that dynamically changes token weights over a set time window, allowing project teams to raise capital without massive initial liquidity.
- **Checks-Effects-Interactions (CEI) Security Pattern** (CEI-SEC) — product: Foundational programming design pattern in smart contract development preventing reentrancy attacks by executing internal state updates before external calls.
- **Concentrated Liquidity AMM Mathematical Specification** (CL-AMM) — product: Algorithmic market-making protocol allowing liquidity providers to allocate capital within discrete price intervals, maximizing capital efficiency.

## Analysis

Classic Solidity courses teach that `view` functions (`compiled to EVM STATICCALL`) are harmless because they cannot modify storage. **Read-Only Reentrancy** shattered that myth across more than **`$120M` in DeFi exploits** (`Sentiment, Midas Capital, Jarvis, Sturdy Finance, Era Lend`)! Notice the diabolical twist: **the AMM pool itself (`Curve ETH/stETH or Balancer Weighted/ComposableStable Pool`) was NOT drained and its own `nonReentrant` lock worked as intended for mutating calls**—instead, an external **Lending Market (`VictimVault`)** called the AMM's unguarded `view` function `get_virtual_price` or `getRate` **right in the middle of the AMM's native-ETH withdrawal `receive` callback**, while the AMM's internal accounting was temporarily half-updated!

Anchored in our [cross-chain bridge, oracle & exploit RCA master guide](/protocols/cross-chain-bridge-verification-oracle-exploit-rca-guide-2026), auditing LP collateral adapters across ecosystems in our [marketplaces directory](/marketplaces)—such as Balancer-powered [Beethoven X](/marketplaces/beethoven-x) (`built on the Balancer LBP & Vault standard` [Balancer standard](/tokens/balancer-lbp-standard)), [Acala Swap](/marketplaces/acala-swap), and [Astroport](/marketplaces/astroport)—requires **Cross-Contract Reentrancy Lock Inspection**!

## Step-by-Step Execution Trace of a `3.8x` LP `virtual_price` Inflation Attack!

Watch how an attacker flash-borrows `100,000 ETH`, inflates a Curve/Balancer `ETH/wstETH` LP token price by `+280%` **with zero net price impact**, and drains `VictimLendingMarket`:

1. **`Step 1` — Flash Deposit**: Attacker flash-borrows `100,000 ETH` + `100,000 wstETH` and calls `CurvePool.add_liquidity([100k, 100k])`, minting `~200,000 LP` tokens (`depositing a small slice—say 5,000 LP—into VictimLendingMarket as collateral`).
2. **`Step 2` — Trigger `remove_liquidity` Callback**: Attacker calls `CurvePool.remove_liquidity(195,000 LP)`:
 - `CurvePool` **first burns `195,000 LP`** (`totalSupply drops immediately from 210,000 down to 15,000 LP!`)!
 - `CurvePool` next sends `97,500 native ETH` to the Attacker via `attacker.call{value: 97,500e18}("")`—**BEFORE updating `CurvePool.balances[0]` and `balances[1]` (`or BEFORE transferring Token #1 wstETH!`)**!
3. **`Step 3` — Reenter `VictimLendingMarket.borrow` Inside `receive`!**:
 - Inside `Attacker.receive`, `CurvePool`'s invariant `D` still reflects the **old un-decremented `105,000 wstETH`** (`and/or un-decremented internal balances`), while `LP.totalSupply` has **already shrunk by `-93%`**!
 - Attacker calls `VictimLendingMarket.borrow(MAX)` -> `VictimOracle` calls `CurvePool.get_virtual_price = D / totalSupply` -> **`get_virtual_price` reads `3.80 ETH` per LP instead of `1.02 ETH`**!
4. **`Step 4` — Clean Exit**: `Attacker.receive` returns cleanly; `CurvePool` finishes updating `balances`, Attacker repays the flash loan, and walks away with `VictimLendingMarket`'s entire USDC/WBTC treasury!

![Read-only reentrancy exploit call graph from AMM remove_liquidity ETH callback into Lending Oracle getRate](/api/figure?type=flow&title=Read-Only%20Reentrancy%20Call-Stack%20Desynchronization&subtitle=How%20half-updated%20AMM%20LP%20supply%20vs%20reserve%20invariants%20poison%20external%20view-function%20price%20adapters&steps=1.%20Burn%20LP%20First%3A%3APool%20burns%2093%25%20of%20LP%20totalSupply%20BEFORE%20external%20ETH%20transfer%7C2.%20ETH%20Callback%3A%3APool%20sends%20ETH%20-%3E%20triggers%20Attacker%20receive%28%29%20while%20balances%5B%5D%20stale!%7C3.%20Cross-Call%20Borrow%3A%3AAttacker%20calls%20Lending.borrow%28%29%20-%3E%20Oracle%20STATICCALLs%20pool.getRate%28%29%7C4.%20Lock%20Check%20Fix!%3A%3AHardened%20Oracle%20touches%20Balancer%20Vault%20nonReentrant%20lock%20-%3E%20REVERTS!&metrics=STALE%20NUMERATOR%3A%3AD%28old%20balances%29%3A%3AToken%20%231%20not%20yet%20transferred%2Fupdated%7CSHRUNK%20DENOM%3A%3ALP%20Supply%20-%2093%25%3A%3ABurned%20prior%20to%20native%20ETH%20send%7CPRICE%20INFLATION%3A%3A2.0x%20-%204.5x%20Skew%3A%3AZero%20AMM%20swap%20fee%20paid%20by%20attacker!%7CVYPER%20COMPILER%20BUG%3A%3A0.2.15%20-%200.3.0%3A%3ABroken%20%40nonreentrant%20per-fn%20storage%20slots)

## How to Harden Oracle Adapters Against Read-Only Reentrancy!

If you are building a lending market or structured vault accepting LP tokens (`Curve, Balancer, Beethoven X, Velodrome`), **you cannot modify the already-deployed AMM pool bytecode**—so your **Oracle Adapter itself** must detect whether the AMM's reentrancy lock is currently entered!

- **Balancer V2 / Beethoven X Vault Lock Check (`ensureNotInVaultContext`)**:
 Balancer V2's `Vault` stores its global reentrancy semaphore on `manageUserBalance`. Calling `VaultReentrancyLib.ensureNotInVaultContext(IVault(balancerVault))` (`which executes a zero-op staticcall/view check reading the Vault reentrancy flag via manageUserBalance or EIP-1153 lock`) **reverts immediately if the call stack is currently inside ANY Balancer join/exit/swap callback**!
- **Curve Pool Lock Check (`withdraw_admin_fees` / `claim_admin_fees` or Pool `nonReentrant` View)**:
 Curve StableSwap-NG and Tricrypto-NG now apply `@nonreentrant` **directly onto `get_virtual_price`**! For legacy Curve pools whose `get_virtual_price` lacks `@nonreentrant`, the oracle adapter either invokes a lightweight state-noop gated by the pool's `@nonreentrant` lock (`prior to STATICCALL boundary`) or **computes Fair LP Valuation mathematically from Chainlink/Pyth prices without trusting pool reserves at all**!

## LP Token Valuation Methods: Vulnerable vs Fair-Reserve Math

| LP Oracle Strategy | Vulnerable to Read-Only Reentrancy? | Vulnerable to Spot Flash-Swap Skew? | Gas Cost | Institutional Audit Verdict |
| :--- | :--- | :--- | :--- | :--- |
| Raw `pool.get_virtual_price * P_ETH` (Legacy Pool) | **YES (CRITICAL DRAIN!)** | Partially (Amplification `A` bounds) | `~6,500g` | **BANNED in Lending Markets!** |
| Raw `balancerPool.getRate` (No Context Check) | **YES (CRITICAL DRAIN!)** | Partially | `~9,000g` | **BANNED without `VaultReentrancyLib`!** |
| **`VaultReentrancyLib` +NG Guarded `getRate`** | **NO (Reverts on Active Lock)** | Bounded by `A` & fees | `~13,500g` | Safe when paired with Fair LP cap |
| **Alpha Homora / Fair LP Pricing Formula** | ** Check `totalSupply` Sync!** (`Still check lock!`) | **100% Immune to Reserve Skew!** | `~18,000g` | **Gold Standard (`Lock Check + Fair Math`)** |

![Vulnerability of LP collateral valuation formulas to reserve flash swaps and mid-withdrawal callback skews](/api/figure?type=bars&title=LP%20Token%20Oracle%20Hardening%3A%20Lock%20Check%20%2B%20Fair%20Reserve%20Math&subtitle=Why%20BOTH%20AMM%20reentrancy-lock%20inspection%20AND%20Alpha-Homora%20fair-reserve%20math%20are%20required%20together&steps=Sum%28r_i%20*%20P_i%29%20%2F%20Supply%3A%3ABROKEN%20ON%20BOTH%3A%20Drained%20by%20flash%20swaps%20AND%20callback%20totalSupply%20skew!%7CFair%20Math%20%282*sqrt%28k*P1*P2%29%2FS%29%3A%3ATRAP!%20Stops%20flash%20swaps%2C%20BUT%20STILL%20reads%20desynced%20k%20%2F%20Supply%20in%20callback!%7CLock-Guard%20%2B%20Raw%20Reserves%3A%3AStops%20callback%20reentrancy%2C%20but%20weighted%20pools%20still%20need%20manipulation%20check%7CLock-Guard%20%2B%20Fair%20LP%20Math%3A%3A100%25%20IMMUNE%20to%20both%20callback%20desynchronization%20AND%20spot%20reserve%20skews!&metrics=BALANCER%20GUARD%3A%3AVaultReentrancyLib%3A%3A1-line%20check%20in%20Balancer%20oracle%20adapter%7CCURVE%20NG%20FIX%3A%3AView%20%40nonreentrant%3A%3ACurve%20NG%20locks%20get_virtual_price%28%29%7CERC-777%20%2F%20HOOKS%3A%3AtokensToSend%28%29%3A%3AAlso%20triggers%20before%20ERC-20%20state!%7CNATIVE%20ETH%20RULE%3A%3ASend%20ETH%20dead%20LAST%3A%3AEnforce%20strict%20CEI%20across%20multi-token)

## Fair LP Valuation Formula (`Constant-Product & Weighted Pools`) + Lock Invariant

Look closely at Bar #2 in our diagram above—a subtlety that caught even senior DeFi teams off guard: **Alpha Homora's Fair LP Formula (`2 * sqrt(r_0 * r_1 * P_0 * P_1) / totalSupply`) stops spot flash swaps, YET STILL FAILS under read-only reentrancy if you skip the AMM lock check**, because during the mid-withdrawal callback `k = r_0 * r_1` has NOT shrunk yet while `totalSupply` HAS shrunk! You MUST combine **both**:

```formula
1) Step 1 — Mandatory Counterparty AMM Reentrancy-Semaphore Assertion:
 require(!CounterpartyPool.isReentrancyLocked, "ReadOnlyReentrancyDetected!");
 // Balancer V2: VaultReentrancyLib.ensureNotInVaultContext(vault)

2) Step 2 — Manipulation-Resistant Fair LP Token Price (Weighted Pool w_1 + w_2 = 1, Oracle Prices P_1, P_2):
 Given verified post-lock invariant K = (r_1 ^ w_1) * (r_2 ^ w_2) and LP totalSupply S:
 P_LP_fair = ( K / S ) * ( (P_1 / w_1) ^ w_1 ) * ( (P_2 / w_2) ^ w_2 )
 Special Case (50/50 Constant Product x * y = k, w_1 = w_2 = 0.5):
 P_LP_fair = ( 2 * sqrt(r_1 * r_2) * sqrt(P_1 * P_2) ) / S

Worked Audit Check:
 Flash attacker swaps $50M into 50/50 ETH/USDC pool -> spot ratio skews 10x, YET invariant k = r_1 * r_2 only grows slightly by fees!
 AND because Step 1 verified !isReentrancyLocked, k and S are 100% synchronized -> P_LP_fair shifts 0.00%!
```

## Enforcing Universal Checks-Effects-Interactions & Transient Locks Next

How should AMM and lending-protocol authors write their *own* contracts so neither mutating nor `view` functions ever expose an inconsistent intermediate state? Examine compiler-safe patterns next in [CEI & ReentrancyGuardTransient engineering](/protocols/cei-checks-effects-interactions-reentrancyguard-transient) and [cross-contract flash-swap drains](/protocols/cross-contract-flash-swap-price-oracle-collateral-drain) inside our [Cross-Chain Bridge & Oracle Security hub](/topics/cross-chain-bridge-validator-exploits).

## Frequently asked questions

### How can a read-only view function be exploited by reentrancy if STATICCALL forbids state changes?

The attacker does NOT mutate the AMM during the reentrant call; instead, while the AMM is paused mid-withdrawal (having burned LP tokens before deducting reserves), the attacker calls a separate Lending Market whose oracle reads the temporarily inflated view price.

### What caused the July 2023 $70M Curve Vyper compiler reentrancy exploit?

Vyper versions 0.2.15, 0.2.16, and 0.3.0 contained a compiler bug generating separate @nonreentrant storage slots per function instead of sharing one lock key—allowing add_liquidity to be called inside remove_liquidity native-ETH callbacks.

### How does Balancer VaultReentrancyLib.ensureNotInVaultContext work inside a view oracle?

In Balancer V2 hardened libraries, an oracle adapter executes a low-gas call probing the Vault reentrancy semaphore; if the Vault is currently mid-join/exit/swap, the probe reverts the entire transaction.

### Why is Alpha Homora Fair LP math alone insufficient against read-only reentrancy?

Fair LP math replaces manipulable reserve ratios r1/r2 with invariant sqrt(r1*r2)/totalSupply; however, during a mid-withdrawal callback, totalSupply has already decreased while r1*r2 has not, so sqrt(r1*r2)/totalSupply still inflates wildly!


## Source URLs

- https://docs.balancer.fi/concepts/vault/reentrancy.html
- https://blog.openzeppelin.com/reentrancy-after-istanbul
- https://cmichel.io/pricing-lp-tokens/

## Citation

- APA: Dr. Devon Kurosawa, PhD. (2026). Read-Only Reentrancy Exploits: Curve get_virtual_price & Balancer getRate View Skews. NFTVenue Ledger. https://nftvenueledger.com/protocols/read-only-reentrancy-balancer-curve-lp-virtual-price-skew
- Canonical article: [Read-Only Reentrancy Exploits: Curve get_virtual_price & Balancer getRate View Skews](https://nftvenueledger.com/protocols/read-only-reentrancy-balancer-curve-lp-virtual-price-skew)
- Site research index: [NFTVenue Ledger](https://nftvenueledger.com/llms-full.txt)
