Skip to content
DoS Audit finding Advanced

User can’t redeem from RToken based on CurveStableRTokenMetapoolCollateral when any underlying collateral of paired RToken’s price oracle is offline(timeout)

When an underlying collateral's price oracle for a paired RToken times out, the paired RToken's price function returns a huge high price. This causes an arithmetic overflow in the metapool collateral's price check, making the refresh function revert and blocking all redemptions from the RToken.

ronnyx2017 Follow

Originally disclosed on Code4rena

Submitted by ronnyx2017

https://github.com/reserve-protocol/protocol/blob/9ee60f142f9f5c1fe8bc50eef915cf33124a534f/contracts/plugins/assets/curve/CurveStableRTokenMetapoolCollateral.sol#L46-L54 https://github.com/reserve-protocol/protocol/blob/9ee60f142f9f5c1fe8bc50eef915cf33124a534f/contracts/plugins/assets/curve/CurveStableCollateral.sol#L119-L121 https://github.com/reserve-protocol/protocol/blob/9ee60f142f9f5c1fe8bc50eef915cf33124a534f/contracts/plugins/assets/curve/CurveStableMetapoolCollateral.sol#L122-L138

The CurveStableMetapoolCollateral is intended for 2-fiattoken stable metapools that involve RTokens, such as eUSD-fraxBP. The metapoolToken coin0 is pairedToken, which is also a RToken, and the coin1 is lpToken, e.g. 3CRV. And the CurveStableRTokenMetapoolCollateral.tryPairedPrice uses RTokenAsset.price() as the oracle to get the pairedToken price:

function tryPairedPrice()
    ...
    returns (uint192 lowPaired, uint192 highPaired)
{
    return pairedAssetRegistry.toAsset(pairedToken).price();
}

Impact

Users can’t redeem from RToken when any underlying collateral of paired RToken’s price oracle is offline(timeout). It can lead to a serious run/depeg on the RToken.

Proof of Concept

First I submitted another issue named “RTokenAsset price oracle can return a huge but valid high price when any underlying collateral’s price oracle timeout”. It’s the premise for this issue. Because this issue is located in different collateral codes, I split them into two issues.

The conclusion from the pre issue:

If there is any underlying collateral’s price oracle reverts, for example oracle timeout, the RTokenAsset.price will return a valid but untrue (low, high) price range, which can be described as low = true_price * A1 and high = FIX_MAX * A2, A1 is bh.quantity(oracle_revert_coll) / all quantity for a BU and A2 is the BasketRange.top / RToken totalSupply.

Back to the CurveStableRTokenMetapoolCollateral. There are two cases that will revert in the super class CurveStableCollateral.refresh().

The CurveStableRTokenMetapoolCollateral.tryPairedPrice function gets low/high price from paired RTokenAsset.price(). So when any underlying collateral’s price oracle of paired RTokenAsset reverts, the max high price will be FIX_MAX and the low price is non-zero.

  1. If the high price is FIX_MAX, the assert for low price will revert:
    if (high < FIX_MAX) {
        savedLowPrice = low;
        savedHighPrice = high;
        lastSave = uint48(block.timestamp);
    } else {
        // must be unpriced
        // untested:
        //      validated in other plugins, cost to test here is high
        assert(low == 0);
    }
  1. And if high price is There is a little smaller than FIX_MAX, the _anyDepeggedOutsidePool check in the refresh function will revert.
    if (low == 0 || _anyDepeggedInPool() || _anyDepeggedOutsidePool()) {
        markStatus(CollateralStatus.IFFY);
    }

And the CurveStableMetapoolCollateral overrides it:

     function _anyDepeggedOutsidePool() internal view virtual override returns (bool) {
        try this.tryPairedPrice() returns (uint192 low, uint192 high) {
            // {UoA/tok} = {UoA/tok} + {UoA/tok}
            uint192 mid = (low + high) / 2;

            // If the price is below the default-threshold price, default eventually
            // uint192(+/-) is the same as Fix.plus/minus
            if (mid < pairedTokenPegBottom || mid > pairedTokenPegTop) return true;
        }

So the uint192 mid = (low + high) / 2; will revert because of uint192 overflow. The CurveStableRTokenMetapoolCollateral.refresh() will revert without any catch.

Because RToken.redeemTo and redeemCustom need to call assetRegistry.refresh(); at the beginning, it will revert directly.

Recommended Mitigation Steps

The Fix.plus can’t handle the uint192 overflow error. Try to override _anyDepeggedOutsidePool for CurveStableRTokenMetapoolCollateral as:

    unchecked {
        uint192 mid = (high - low) / 2 + low;
    }

The assert assert(low <= high) in the RTokenAsset.tryPrice has already protected everything.

Assessed type

DoS

cccz (judge) decreased severity to Medium and commented:

External requirement with oracle errors.

pmckelvy1 (Reserve) confirmed

Reserve Mitigated:

Unpriced on oracle timeout. PR: https://github.com/reserve-protocol/protocol/pull/917

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 midpoint calculation `(low + high) / 2` overflows uint192 when the high price is near the maximum value returned after an oracle timeout.

Impact

Users could be unable to redeem from the RToken, which could lead to a run or depeg; the judge noted this depends on an external oracle error.

What the attacker needed

An underlying oracle times out; paired RToken uses that oracle

The fix

The project mitigated the issue by treating the asset as unpriced when an oracle times out.

How it was found

  1. An underlying collateral's price oracle for the paired RToken times out.
  2. The paired RToken's price function returns a very large high price.
  3. The metapool collateral's refresh calls the paired price check.
  4. The midpoint calculation overflows and reverts.
  5. RToken redemption calls refresh and therefore also reverts.

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 price oracle is a service that tells a smart contract how much an asset is worth. If that service stops responding, the contract may return a very large placeholder price. Adding two very large numbers in Solidity can overflow and cause the transaction to fail, which here stops users from withdrawing their funds.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

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

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.