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

bin2chen - getLatestPrice() possible use stale price #171

Closed
sherlock-admin opened this issue Mar 27, 2023 · 0 comments
Closed

bin2chen - getLatestPrice() possible use stale price #171

sherlock-admin opened this issue Mar 27, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Mar 27, 2023

bin2chen

medium

getLatestPrice() possible use stale price

Summary

not check updatedAt, still possible to use stale price

Vulnerability Detail

getLatestPrice:

    function getLatestPrice(address _token) public view returns (int256) {
...
        AggregatorV3Interface priceFeed = AggregatorV3Interface(
            vaultFactory.tokenToOracle(_token)
        );
        (uint80 roundID, int256 price, , , uint80 answeredInRound) = priceFeed
            .latestRoundData();
        uint256 decimals = priceFeed.decimals();

        if (decimals < 18) {
            decimals = 10**(18 - (decimals));
            price = price * int256(decimals);
        } else if (decimals == 18) {
            price = price;
        } else {
            decimals = 10**((decimals - 18));
            price = price / int256(decimals);
        }

        if (price <= 0) revert OraclePriceZero();

        if (answeredInRound < roundID) revert RoundIDOutdated();
        //<-------only check roundID, not check updatedAt
        return price;

Currently, only the answeredInRound is checked and not check updatedAt, still possible to use stale price

Impact

getLatestPrice() may return stale data

Code Snippet

https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Controllers/ControllerPeggedAssetV2.sol#L273

Tool used

Manual Review

Recommendation

    function getLatestPrice(address _token) public view returns (int256) {
        (
...
-        (uint80 roundID, int256 price, , , uint80 answeredInRound) = priceFeed
            .latestRoundData();
+        (uint80 roundID, int256 price, , updatedAt, uint80 answeredInRound) = priceFeed
            .latestRoundData();


        if (price <= 0) revert OraclePriceZero();

        if (answeredInRound < roundID) revert RoundIDOutdated();

+       if (updatedAt < block.timestamp - MAX_DELAY) {
+           revert();
+       }
        return price;

Duplicate of #70

@github-actions github-actions bot closed this as completed Apr 3, 2023
@github-actions github-actions bot added the Excluded Excluded by the judge without consulting the protocol or the senior label Apr 3, 2023
@dmitriia dmitriia added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label and removed Excluded Excluded by the judge without consulting the protocol or the senior labels Apr 10, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

2 participants