Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cergyk - HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators #72

Closed
sherlock-admin3 opened this issue Jun 4, 2024 · 0 comments
Labels
Excluded Excluded by the judge without consulting the protocol or the senior Non-Reward This issue will not receive a payout

Comments

@sherlock-admin3
Copy link
Contributor

sherlock-admin3 commented Jun 4, 2024

cergyk

medium

HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators

Summary

HOTOracle::getSqrtOraclePriceX96 is relying on latestRoundData() but the returned data isn’t properly checked potentially returning stale or incorrect result.

Vulnerability Detail

HOTOracle::getSqrtOraclePriceX96 is relying on Chainlink latestRoundData() function to get the price in USD: HOTOracle.sol#L142.

However, according to Chainlink documentation, the returned data should be checked to ensure no stale or incorrect result:

function latestRoundData() external view
    returns (
        uint80 roundId,
        int256 answer,
        uint256 startedAt,
        uint256 updatedAt,
        uint80 answeredInRound
    )

In the current implementation, only updatedAt is checked, which could lead to stale or incorrect result: HOTOracle.sol#L144-L146.

Here’s an example of a previous report related to this issue: sherlock-audit/2023-02-blueberry-judging#94.

Impact

HOTOracle::_getOraclePriceUSD could return stale or incorrect data, thus wrongly calculating sqrt oracle price.

Code Snippet

Tool used

Manual Review, Solodit

Recommendation

Add the below checks for returned data: HOTOracle.sol#L138-L149

    function _getOraclePriceUSD(
        AggregatorV3Interface feed,
        uint32 maxOracleUpdateDuration
    ) internal view returns (uint256 oraclePriceUSD) {
-       (, int256 oraclePriceUSDInt, , uint256 updatedAt, ) = feed.latestRoundData();
+       (uint80 roundID, int256 answer, uint256 timestamp, uint256 updatedAt, ) = feed.latestRoundData();
        
+		    require(updatedAt >= roundID, "Stale price");
+		    require(timestamp != 0, "Round not complete");
+		    require(answer > 0, "Chainlink answer reporting 0");
        
        if (block.timestamp - updatedAt > maxOracleUpdateDuration) {
            revert HOTOracle___getOraclePriceUSD_stalePrice();
        }

        oraclePriceUSD = oraclePriceUSDInt.toUint256();
    }
@github-actions github-actions bot closed this as completed Jun 6, 2024
@github-actions github-actions bot added the Excluded Excluded by the judge without consulting the protocol or the senior label Jun 6, 2024
@sherlock-admin2 sherlock-admin2 changed the title Merry Yellow Osprey - HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators cergyk - HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators Jun 12, 2024
@sherlock-admin2 sherlock-admin2 added the Non-Reward This issue will not receive a payout label Jun 12, 2024
@github-actions github-actions bot changed the title cergyk - HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators Merry Yellow Osprey - HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators Jun 13, 2024
@sherlock-admin sherlock-admin changed the title Merry Yellow Osprey - HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators cergyk - HOTOracle::getSqrtOraclePriceX96 Missing checks on values returned by Chainlink aggregators Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Excluded Excluded by the judge without consulting the protocol or the senior Non-Reward This issue will not receive a payout
Projects
None yet
Development

No branches or pull requests

2 participants