sherlock-audit / 2023-05-perennial-judging

12 stars 9 forks source link

MohammedRizwan - Chainlink's latestRoundData might return stale or incorrect results #235

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

MohammedRizwan

medium

Chainlink's latestRoundData might return stale or incorrect results

Summary

Chainlink's latestRoundData might return stale or incorrect results

Vulnerability Detail

Impact

The getLatestRound() function in the contract ChainlinkAggregator.sol fetches the asset price from a Chainlink aggregator using the latestRoundData function. However, there are no checks on roundID, resulting in stale prices. The oracle wrapper calls out to a chainlink oracle receiving the latestRoundData().

Stale prices could put funds at risk. According to Chainlink's documentation, This function does not error if no answer has been reached but returns 0, causing an incorrect price fed to the PriceOracle. The external Chainlink oracle, which provides index price information to the system, introduces risk inherent to any dependency on third-party data sources. For example, the oracle could fall behind or otherwise fail to be maintained, resulting in outdated data being fed to the index price calculations. Oracle reliance has historically resulted in crippled on-chain systems, and complications that lead to these outcomes can arise from things as simple as network congestion.

Code Snippet

https://github.com/equilibria-xyz/perennial-mono/blob/b06d5145db62a312dd88dfcafef0f8e2166c5e32/packages/perennial-oracle/contracts/types/ChainlinkAggregator.sol#L32-L36

Tool used

Manual Review

Recommendation

Consider adding missing checks for stale data.

For example:


(uint80 roundID, int256 feedPrice, , uint256 timestamp, uint80 answeredInRound) = feed.latestRoundData();
require(feedPrice > 0, "Chainlink price <= 0"); 
require(answeredInRound >= roundID, "Stale price");
require(timestamp != 0, "Round not complete");