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.
See the following code:
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.
Manual Review
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.