Skip to content
Audit finding Intermediate

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.

ronnyx2017 Follow

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:

  1. Assumption: There is a CurveVolatileCollateral bases on a TriCrypto ETH/WBTC/USDT, and the value of them should be 1:1:1, and the _defaultThreshold of the CurveVolatileCollateral is 5%. And at first, there are 1000 USDT in the pool and the pool is balanced.

  2. The attacker uses flash loan to deposit 500 USDT to the pool. Now, the USDT distribution is 1500/(1500+1000+1000) = 42.86%.

  3. Attacker refresh the CurveVolatileCollateral. Because the USDT distribution - expected = 42.86% - 33.33% = 9.53% > 5% _defaultThreshold. So CurveVolatileCollateral will be marked as IFFY.

  4. The attacker withdraw from the pool and repay the USDT.

  5. Just wait delayUntilDefault, the collateral will be marked as defaulted by the alreadyDefaulted function.

    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

tbrent (Reserve) confirmed

Reserve Mitigated:

Removes CurveVolatileCollateral. PR: https://github.com/reserve-protocol/protocol/pull/896

Status: Mitigation confirmed. Full details in reports from ronnyx2017, RaymondFam and bin2chen.


The original report as published on Code4rena, by ronnyx2017. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Assume a CurveVolatileCollateral pool with three tokens at equal value and a 5% threshold, initially balanced with 1000 USDT.
  2. The attacker uses a flash loan to deposit 500 USDT into the pool, making USDT's share 42.86%.
  3. The attacker calls refresh on the CurveVolatileCollateral, which marks it as IFFY because the USDT share exceeds the threshold.
  4. The attacker withdraws the USDT from the pool and repays the flash loan.
  5. 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.

More by ronnyx2017

View all

24 more disclosed reports, best first.

More from Reserve Core

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.