Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

volodya - Chainlink's latestRoundData return stale or incorrect result for ChainlinkExpandAdaptor #15

Closed
sherlock-admin opened this issue May 10, 2023 · 0 comments
Labels
Non-Reward This issue will not receive a payout

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented May 10, 2023

volodya

medium

Chainlink's latestRoundData return stale or incorrect result for ChainlinkExpandAdaptor

Summary

Chainlink's latestRoundData returns stale or incorrect result

Vulnerability Detail

    function getMarkPrice() external view returns (uint256 price) {
        int256 rawPrice;
        uint256 updatedAt;
        (, rawPrice, , updatedAt, ) = IChainlink(chainlink).latestRoundData();
        (, int256 USDCPrice,, uint256 USDCUpdatedAt,) = IChainlink(USDCSource).latestRoundData();
        require(
            block.timestamp - updatedAt <= heartbeatInterval,
            "ORACLE_HEARTBEAT_FAILED"
        );
        require(block.timestamp - USDCUpdatedAt <= heartbeatInterval, "USDC_ORACLE_HEARTBEAT_FAILED");
        uint256 tokenPrice = (SafeCast.toUint256(rawPrice) * 1e8) / SafeCast.toUint256(USDCPrice);
        return tokenPrice * 1e18 / decimalsCorrection;
    }

contracts/adaptor/chainlinkAdaptor.sol#L43

Impact

Code Snippet

Tool used

Related report: sherlock-audit/2023-02-blueberry-judging#94
Manual Review

Recommendation

Add the below check for returned data

    function getMarkPrice() external view returns (uint256 price) {
        int256 rawPrice;
        uint256 updatedAt;
        (uint80 roundId, int256 price,uint256 startedAt, uint256 updatedAt,) = IChainLinkAggregator(chainlink).latestRoundData();
        (uint80 USDCroundId, int256 USDCPrice,uint256 USDCstartedAt, uint256 USDCUpdatedAt,) = IChainLinkAggregator(USDCSource).latestRoundData();

        //Solution
        require(updatedAt >= roundID, "Stale price");
        require(USDCUpdatedAt >= USDCroundId, "Stale price");
        require(startedAt != 0,"Round not complete");
        require(USDCstartedAt != 0,"Round not complete");
        require(price > 0,"Chainlink answer reporting 0");
        require(USDCPrice > 0,"Chainlink answer reporting 0");

        require(
            block.timestamp - updatedAt <= heartbeatInterval,
            "ORACLE_HEARTBEAT_FAILED"
        );
        require(block.timestamp - USDCUpdatedAt <= heartbeatInterval, "USDC_ORACLE_HEARTBEAT_FAILED");
        uint256 tokenPrice = (SafeCast.toUint256(price) * 1e8) / SafeCast.toUint256(USDCPrice);
        return tokenPrice * 1e18 / decimalsCorrection;
    }

Duplicate of #173

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels May 17, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label May 30, 2023
@sherlock-admin sherlock-admin added Non-Reward This issue will not receive a payout and removed Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Reward A payout will be made for this issue labels Jun 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Non-Reward This issue will not receive a payout
Projects
None yet
Development

No branches or pull requests

1 participant