Curve Read-only Reentrancy can increase the price of some CurveStableCollateral
The price of a CurveStableCollateral LP token can be manipulated during a Curve pool's remove_liquidity call because the pool burns LP tokens before transferring out the underlying assets, and the collateral's price calculation uses the reduced LP supply while other assets remain in the pool. An attacker could exploit this to make the collateral appear more valuable than it is.
ronnyx2017 Follow with bin2chen
Originally disclosed on Code4rena
Submitted by ronnyx2017, also found by bin2chen
If the curve pool of a CurveStableCollateral is a Plain Pool with a native gas token, just like eth/stETH pool: https://etherscan.io/address/0xdc24316b9ae028f1497c275eb9192a3ea0f67022#code The price can be manipulated by Curve Read-only Reentrancy.
A example is eth/stETH pool, in its remove_liquidity function:
# snippet from remove_liquidity
CurveToken(lp_token).burnFrom(msg.sender, _amount)
for i in range(N_COINS):
value: uint256 = amounts[i] * _amount / total_supply
if i == 0:
raw_call(msg.sender, b"", value=value)
else:
assert ERC20(self.coins[1]).transfer(msg.sender, value)
First, LP tokens are burned. Next, each token is transferred out to the msg.sender. Given that ETH will be the first coin transferred out, token balances and total LP token supply will be inconsistent during the execution of the fallback function.
The CurveStableCollateral uses total underlying token balance value / lp supply to calculate the lp token price:
(uint192 aumLow, uint192 aumHigh) = totalBalancesValue();
// {tok}
uint192 supply = shiftl_toFix(lpToken.totalSupply(), -int8(lpToken.decimals()));
// We can always assume that the total supply is non-zero
// {UoA/tok} = {UoA} / {tok}
low = aumLow.div(supply, FLOOR);
high = aumHigh.div(supply, CEIL);
So the price will be higher than the actual value because the other assets(except eth) are still in the pool but the lp supply has been cut down during the remove_liquidity fallback.
tbrent (Reserve) commented via duplicate issue #14:
We have considered this very issue before and have decided as a solution to avoid raw ETH and ERC777’s entirely, and not try to detect reentrancy in the way described in the article. This is for a few reasons:
- It cannot be implemented uniformly.
withdraw_admin_feesis not on all Curve pools, and in particular not on Tricrypto. https://etherscan.io/address/0xd51a44d3fae010294c616388b506acda1bfaae46- Raw ETH presents other challenges. Even if we detect reentrancy in the way suggested, the assetRegistry making multiple asset
refresh()calls means an attacker could gain execution under a different asset’s refresh() and use that to manipulate refPerTok().Also related: Our target unit system does not work well with volatile pools. Each pool would need its own target unit and therefore could not be backed up with any other collateral except identically/distributed pools. We plan to remove
CurveVolatileCollateralentirely.
tbrent (Reserve) commented via duplicate issue #14:
There is documentation on the website indicating to avoid ERC777 tokens, but this should probably be updated to include forbidding LP tokens that contain raw ETH. Though, it is a bit more complicated than that since some LP tokens offer withdrawal functions that automate the unwrapping of WETH into ETH.
https://reserve.org/protocol/rtokens/#non-compatible-erc20-assets
pmckelvy1 (Reserve) confirmed via duplicate issue #14
Removes
CurveVolatileCollateral. PR: https://github.com/reserve-protocol/protocol/pull/896
Status: Mitigation confirmed. Full details in reports from RaymondFam, ronnyx2017 and bin2chen.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The Curve pool burns LP tokens before transferring out all underlying assets, and the collateral's price calculation reads the LP total supply during this inconsistent state without any reentrancy protection.
Impact
The collateral price could be temporarily inflated, potentially allowing an attacker to mint or borrow more than they should, though the project mitigated by removing the affected collateral type.
What the attacker needed
Collateral uses a Curve Plain Pool with raw ETH; Attacker can call remove_liquidity on that pool
The fix
The project mitigated by removing CurveVolatileCollateral and avoiding raw ETH and ERC777 tokens in collateral pools.
How it was found
- Identify a Curve Plain Pool with a native gas token (e.g., ETH/stETH) used as collateral.
- Call remove_liquidity on the pool, which burns LP tokens first.
- During the ETH transfer, a fallback function executes while other assets remain in the pool and LP supply is reduced.
- The collateral's price calculation reads the reduced LP supply and inflated asset value, yielding a higher price.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A liquidity pool lets people deposit tokens and get LP tokens representing their share. The pool's value per LP token is total assets divided by total LP tokens. If someone can withdraw assets in a way that temporarily reduces the LP token count before all assets are removed, the calculated price per LP token goes up. This report shows that a specific pool type allows such a temporary inconsistency, and the collateral contract reads the price during that window.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.