Skip to content
DoS Audit finding Intermediate

spTKNMinimalOracle `_calculateSpTknPerBase()` does not return 0, which breaks the feature of having a fallback oracle

The spTKNMinimalOracle is meant to fall back to a second price source when one fails, but a require statement in _calculateSpTknPerBase() reverts instead of returning zero. If one oracle source fails, the whole price call reverts, causing a denial of service in Fraxlend.

X77 Follow with pkqs90

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/476

Found by

X77, pkqs90

Summary

spTKNMinimalOracle _calculateSpTknPerBase() does not return 0, which breaks the feature of having a fallback oracle.

Root Cause

The spTKNMinimalOracle is a dual oracle, which fetches price from two different sources. If one of the data source fails, the other one is used as a fallback. This is also the design in original Fraxlend.

However, the _calculateSpTknPerBase() function has a check for require(_basePerSpTkn18 > 0, "V2R");, this means the price will never be zero.

This defeats the meaning of having a fallback oracle, where one is supposed to work if the other one fails. But the current implementation forces both oracle to return the correct value, which is obviously not the original design.

This will lead to Fraxlend DoS when it shouldn't be.

https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/oracle/spTKNMinimalOracle.sol#L1

Solidity
    function getPrices()
        public
        view
        virtual
        override
        returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh)
    {
        uint256 _priceSpTKNBase = _calculateSpTknPerBase(0);
        _isBadData = _priceSpTKNBase == 0;
        uint8 _baseDec = IERC20Metadata(BASE_TOKEN).decimals();
        uint256 _priceOne18 = _priceSpTKNBase * 10 ** (_baseDec > 18 ? _baseDec - 18 : 18 - _baseDec);

        uint256 _priceTwo18 = _priceOne18;
        if (CHAINLINK_BASE_PRICE_FEED != address(0) && CHAINLINK_QUOTE_PRICE_FEED != address(0)) {
            uint256 _clPrice18 = _chainlinkBasePerPaired18();
            uint256 _clPriceBaseSpTKN = _calculateSpTknPerBase(_clPrice18);
            _priceTwo18 = _clPriceBaseSpTKN * 10 ** (_baseDec > 18 ? _baseDec - 18 : 18 - _baseDec);
            _isBadData = _isBadData || _clPrice18 == 0;
        }

@>      require(_priceOne18 != 0 || _priceTwo18 != 0, "BZ");

@>      if (_priceTwo18 == 0) {
            _priceLow = _priceOne18;
            _priceHigh = _priceOne18;
        } else {
            // If the prices are the same it means the CL price was pulled as the UniV3 price
            (_priceLow, _priceHigh) =
                _priceOne18 > _priceTwo18 ? (_priceTwo18, _priceOne18) : (_priceOne18, _priceTwo18);
        }
    }

    function _calculateSpTknPerBase(uint256 _price18) internal view returns (uint256 _spTknBasePrice18) {
        uint256 _priceBasePerPTkn18 = _calculateBasePerPTkn(_price18);
        address _pair = _getPair();

        (uint112 _reserve0, uint112 _reserve1) = V2_RESERVES.getReserves(_pair);
        uint256 _k = uint256(_reserve0) * _reserve1;
        uint256 _kDec = 10 ** IERC20Metadata(IUniswapV2Pair(_pair).token0()).decimals()
            * 10 ** IERC20Metadata(IUniswapV2Pair(_pair).token1()).decimals();
        uint256 _avgBaseAssetInLp18 = _sqrt((_priceBasePerPTkn18 * _k) / _kDec) * 10 ** (18 / 2);
        uint256 _basePerSpTkn18 =
            (2 * _avgBaseAssetInLp18 * 10 ** IERC20Metadata(_pair).decimals()) / IERC20(_pair).totalSupply();

@>      require(_basePerSpTkn18 > 0, "V2R");

        _spTknBasePrice18 = 10 ** (18 * 2) / _basePerSpTkn18;

        // if the base asset is a pod, we will assume that the CL/chainlink pool(s) are
        // pricing the underlying asset of the base asset pod, and therefore we will
        // adjust the output price by CBR and unwrap fee for this pod for more accuracy and
        // better handling accounting for liquidation path
        if (BASE_IS_POD) {
            _spTknBasePrice18 = _checkAndHandleBaseTokenPodConfig(_spTknBasePrice18);
        } else if (BASE_IS_FRAX_PAIR) {
            _spTknBasePrice18 = IFraxlendPair(BASE_TOKEN).convertToAssets(_spTknBasePrice18);
        }
    }

Internal pre-conditions

N/A

External pre-conditions

  • One of the oracle fails, e.g. due to data out of date.

Attack Path

N/A

Impact

Fraxlend is supposed to work when only one oracle fails, but now it doesn't.

PoC

N/A

Mitigation

Allow one of the oracles to return 0. Return 0 directly if _basePerSpTkn18 was 0 in function _calculateSpTknPerBase().

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

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 a require statement enforcing a non-zero intermediate price prevents the function from signalling failure with zero, so the dual-oracle fallback logic can never engage.

Impact

When one oracle source fails, the price call reverts, causing a denial of service in Fraxlend even though the second oracle should have kept it working.

What the attacker needed

One oracle source fails

The fix

The function should return zero instead of reverting when the intermediate value is zero, so the fallback oracle can be used.

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.

An oracle is a service that feeds prices into a smart contract. This contract was designed to use two price sources so that if one breaks, the other still works. But a check inside the code makes the contract stop with an error instead of returning zero, so the backup never gets a chance to be used.

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 X77

View all

6 more disclosed reports, best first.

More from Peapods

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.