DeFiHardhat
35,000 USDC
View results
Submission Details
Severity: low
Invalid

No check when `lookback` is greater than 0 in Oracle Price Calculation

Summary

The getUsdPrice function in the provided code is responsible for fetching the price of a given token in USD. It also includes an optional parameter lookback, which determines the time window for calculating the Time-Weighted Average Price (TWAP). If lookback is set to 0, the function returns the instantaneous price. However, if lookback is greater than 0, it calculates the TWAP over the specified time window. The function includes a comment advising that if a non-zero lookback is used, it should be substantially large (> 900 seconds) to protect against manipulation.

Vulnerability Details

See the following code:

/**
* @dev Returns the price of a given token in in USD with the option of using a lookback. (Usd:token Price)
* `lookback` should be 0 if the instantaneous price is desired. Otherwise, it should be the
* TWAP lookback in seconds.
* If using a non-zero lookback, it is recommended to use a substantially large `lookback`
* (> 900 seconds) to protect against manipulation.
*/
function getUsdPrice(address token, uint256 lookback) internal view returns (uint256) {
if (token == C.WETH) {
uint256 ethUsdPrice = LibEthUsdOracle.getEthUsdPrice(lookback);
if (ethUsdPrice == 0) return 0;
return uint256(1e24).div(ethUsdPrice);
}
if (token == C.WSTETH) {
uint256 wstethUsdPrice = LibWstethUsdOracle.getWstethUsdPrice(lookback);
if (wstethUsdPrice == 0) return 0;
return uint256(1e24).div(wstethUsdPrice);
}
revert("Oracle: Token not supported.");
}

Impact

The impact of using a lookback value greater than zero and less than 900 seconds could introduce susceptibility to price manipulation. A shorter time window allows potential manipulators to influence the price within that period, leading to inaccurate or manipulated price data. This manipulation could adversely affect the reliability of the oracle and, consequently, any smart contracts relying on it for price information. Contracts depending on accurate price data may make incorrect decisions or expose themselves to vulnerabilities due to inaccurate price information.

Tools Used

Manual Review

Recommendations

To mitigate this risk, it's crucial to adhere to the recommendation of using a substantially large lookback value, preferably greater than 900 seconds. By employing a longer time window for TWAP calculations, the oracle becomes more resistant to manipulation attempts within that timeframe.

Updates

Lead Judging Commences

giovannidisiena Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

Informational/Invalid

Support

FAQs

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