CurveVolatileCollateral Collateral status can be manipulated by flashloan attack
The CurveVolatileCollateral contract checks whether the pool's token distribution is balanced to decide if it is depegged. An attacker can use a flash loan to temporarily skew the distribution, causing the collateral to be marked as IFFY and later defaulted, which triggers the basket to sell off all that collateral.
Originally disclosed on Code4rena
Submitted by ronnyx2017
Attacker can make the CurveVolatileCollateral enter the status of IFFY/DISABLED. It will cause the basket to rebalance and sell off all the CurveVolatileCollateral.
Proof of Concept
The CurveVolatileCollateral overrides the _anyDepeggedInPool function to check if the distribution of capital is balanced. If the any part of underlying token exceeds the expected more than _defaultThreshold, return true, which means the volatile pool has been depeg:
uint192 expected = FIX_ONE.divu(nTokens); // {1}
for (uint8 i = 0; i < nTokens; i++) {
uint192 observed = divuu(vals[i], valSum); // {1}
if (observed > expected) {
if (observed - expected > _defaultThreshold) return true;
}
}
And the coll status will be updated in the super class CurveStableCollateral.refresh():
if (low == 0 || _anyDepeggedInPool() || _anyDepeggedOutsidePool()) {
markStatus(CollateralStatus.IFFY);
}
The attack process is as follows:
-
Assumption: There is a CurveVolatileCollateral bases on a TriCrypto ETH/WBTC/USDT, and the value of them should be 1:1:1, and the
_defaultThresholdof the CurveVolatileCollateral is 5%. And at first, there are 1000 USDT in the pool and the pool is balanced. -
The attacker uses flash loan to deposit 500 USDT to the pool. Now, the USDT distribution is
1500/(1500+1000+1000) = 42.86%. -
Attacker refresh the CurveVolatileCollateral. Because the USDT distribution - expected = 42.86% - 33.33% = 9.53% > 5% _defaultThreshold. So CurveVolatileCollateral will be marked as IFFY.
-
The attacker withdraw from the pool and repay the USDT.
-
Just wait
delayUntilDefault, the collateral will be marked as defaulted by thealreadyDefaultedfunction.function alreadyDefaulted() internal view returns (bool) { return _whenDefault <= block.timestamp; }
Recommended Mitigation Steps
I think the de-pegged status in the volatile pool may be unimportant. It will be temporary and have little impact on the price of outside lp tokens. After all, override the _anyDepeggedOutsidePool to check the lp price might be a good idea.
Assessed type
Context
Removes
CurveVolatileCollateral. PR: https://github.com/reserve-protocol/protocol/pull/896
Status: Mitigation confirmed. Full details in reports from ronnyx2017, RaymondFam 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
Likely the depeg check relies on the current pool balances, which can be manipulated within a single transaction using a flash loan.
Impact
The basket could rebalance and sell off all the CurveVolatileCollateral, potentially at a loss.
What the attacker needed
Flash loan available; ability to call refresh; wait for delayUntilDefault
The fix
The CurveVolatileCollateral was removed as a mitigation.
How it was found
- Assume a CurveVolatileCollateral pool with three tokens at equal value and a 5% threshold, initially balanced with 1000 USDT.
- The attacker uses a flash loan to deposit 500 USDT into the pool, making USDT's share 42.86%.
- The attacker calls refresh on the CurveVolatileCollateral, which marks it as IFFY because the USDT share exceeds the threshold.
- The attacker withdraws the USDT from the pool and repays the flash loan.
- After the delayUntilDefault period, the collateral is marked as defaulted by the alreadyDefaulted function.
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 flash loan is a loan that must be borrowed and repaid within the same transaction. The contract decides if a pool is 'depegged' by checking if one token's share is too high. The attacker borrows a lot of one token, briefly makes its share too high, triggers the check, then repays the loan, leaving the contract wrongly marked as unsafe.