15,000 USDC
View results
Submission Details
Severity: gas

Gas Optimization for 'staleCheckLatestRoundData' Function

Summary

The goal is to optimize gas usage without compromising functionality. By eliminating unnecessary return values and reducing redundant calculations, we aim to achieve a more efficient and cost-effective implementation.

Vulnerability Details

The original 'staleCheckLatestRoundData' function returns several values, including 'roundId', 'startedAt', and 'answeredInRound', which are not required for the contract implementation. These unused computations lead to increased gas consumption.

Impact

The unnecessary returns and redundant calculations in the 'staleCheckLatestRoundData' function can result in higher gas costs for users interacting with the contract. This can negatively impact the overall user experience and may deter adoption due to higher transaction fees.

Tools Used

Remix IDE

Recommendations

  • Remove Unnecessary Returns: Modify the 'staleCheckLatestRoundData' function to return only the 'int256' price value. The 'roundId', 'startedAt', and 'answeredInRound' values are not required for the contract implementation and can be omitted from the return statement.

function staleCheckLatestRoundData(AggregatorV3Interface priceFeed)
public
view
returns (int256)
{
(, int256 answer, , uint256 updatedAt, ) = priceFeed.latestRoundData();
uint256 secondsSince = block.timestamp - updatedAt;
if (secondsSince > TIMEOUT) revert OracleLib__StalePrice();
return answer;
}
int256 price = priceFeed.staleCheckLatestRoundData();

Support

FAQs

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