DeFiHardhatOracleProxyUpdates
100,000 USDC
View results
Submission Details
Severity: low
Invalid

'loopback' can be less than 900

Summary

Use a lookback of 900 seconds for an instantaneous price query for manipulation resistance. we are not using 900 in our code.

Vulnerability Details

function getEthUsdPrice(uint256 lookback) internal view returns (uint256) {
    uint256 chainlinkPrice = lookback > 0 ?
        LibChainlinkOracle.getEthUsdTwap(lookback) :
        LibChainlinkOracle.getEthUsdPrice();

    // Check if the chainlink price is broken or frozen.
    if (chainlinkPrice == 0) return 0;

    // Use a lookback of 900 seconds for an instantaneous price query for manipulation resistance.
    if (lookback == 0) lookback = INSTANT_LOOKBACK;
    if (lookback > type(uint32).max) return 0;

@>>    uint256 usdcPrice = LibUniswapOracle.getEthUsdcPrice(uint32(lookback));
    uint256 usdcChainlinkPercentDiff = getPercentDifference(usdcPrice, chainlinkPrice);

    // Check if the USDC price and the Chainlink Price are sufficiently close enough
    // to warrant using the greedy approach.
    if (usdcChainlinkPercentDiff < MAX_GREEDY_DIFFERENCE) {
        return chainlinkPrice.add(usdcPrice).div(2);
    }

    uint256 usdtPrice = LibUniswapOracle.getEthUsdtPrice(uint32(lookback));
    uint256 usdtChainlinkPercentDiff = getPercentDifference(usdtPrice, chainlinkPrice);

    // Check whether the USDT or USDC price is closer to the Chainlink price.
    if (usdtChainlinkPercentDiff < usdcChainlinkPercentDiff) {
        // Check whether the USDT price is too far from the Chainlink price.
        if (usdtChainlinkPercentDiff < MAX_DIFFERENCE) {
            return chainlinkPrice.add(usdtPrice).div(2);
        }
        return chainlinkPrice;
    } else {
        // Check whether the USDC price is too far from the Chainlink price.
        if (usdcChainlinkPercentDiff < MAX_DIFFERENCE) {
            return chainlinkPrice.add(usdcPrice).div(2);
        }
        return chainlinkPrice;
    }
}

Impact

Use a lookback of 900 seconds for an instantaneous price query for manipulation resistance.

Tools Used

Recommendations

    if (lookback == 0 ||lookback<900) lookback = INSTANT_LOOKBACK;
Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

Oracle lookback

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.