15,000 USDC
View results
Submission Details
Severity: medium
Valid

Should check return data from Chainlink aggregators

Summary

OracleLib library is designed to check the Chainlink Oracle for stale data, however, the lack of additional validation checks could lead to usage of outdated prices.

Vulnerability Details

In the staleCheckLatestRoundData function, the contract fetches the asset price from a Chainlink aggregator using the latestRoundData function. This function checks if the data is stale by comparing the updatedAt timestamp with the current block.timestamp. If the difference is greater than a predefined TIMEOUT, the function reverts.

This approach is largely sound, but it is susceptible to stale data, especially if the Chainlink Oracle fails to update or maintain its data sources. Furthermore, if the Oracle network encounters an issue, funds locked in the protocol are potentially at risk.

Impact

If the Chainlink Oracle becomes stale or isn't maintained properly, this could lead to outdated or incorrect prices being used by the contracts that depend on this library. This could ultimately lead to financial loss or inaccurate transactions.

Tools Used

Manual Review

Recommendations

To mitigate this issue, consider implementing additional checks on the return data with proper revert messages if the price is stale or the round is incomplete. For instance:

function staleCheckLatestRoundData(AggregatorV3Interface priceFeed)
public
view
returns (uint80, int256, uint256, uint256, uint80)
{
(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) =
priceFeed.latestRoundData();
// Check for an invalid roundId that is 0
require(roundId > 0, "Invalid roundId");
// Check for non-positive price
require(answer > 0, "Non-positive price");
// Check for an outdated price
uint256 secondsSince = block.timestamp - updatedAt;
require(secondsSince <= TIMEOUT, "Price is stale");
// Check for an incomplete round
require(answeredInRound >= roundId, "Incomplete round");
return (roundId, answer, startedAt, updatedAt, answeredInRound);
}

Support

FAQs

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