Time-weighted average price calculation in TimeWeightedAverage.sol
introduces unintended discounts and potential losses for users, deviating from time-accurate oracle pricing.
The calculateTimeWeightedAverage
function in TimeWeightedAverage.sol
calculates a price by averaging prices over a period. This approach, while seemingly smoothing out price volatility, introduces a fundamental flaw: it provides a discounted price compared to a time-accurate oracle reading at the moment of execution. Users interacting with the protocol based on this time-averaged price will receive less value than they would with a spot price from a real-time oracle.
Vulnerable Code Snippet (TimeWeightedAverage.sol
):
Unintended Discounts and Potential User Losses. Using a time-averaged price instead of a spot price leads to:
Discounted Prices for Users: Users interacting with the protocol based on this averaged price will consistently receive a price that is lower than the current market price, effectively receiving less value for their assets.
Arbitrage Opportunities: The price discrepancy between the time-averaged price and the spot price creates arbitrage opportunities for sophisticated actors who can exploit this difference to their advantage, potentially at the expense of regular users.
Inaccurate System Valuation: Relying on a discounted price for core protocol operations can lead to inaccurate valuation of assets within the system, potentially impacting collateral ratios, liquidation thresholds, and overall protocol stability.
Manually review
Immediate Mitigation: Replace the calculateTimeWeightedAverage
function with a direct call to a time-accurate oracle for price feeds. Use Chainlink, Pyth, or another reputable oracle provider to fetch real-time spot prices.
Code Review: Thoroughly review all price-dependent logic in the codebase and replace any instances of calculateTimeWeightedAverage
with calls to the new time-accurate oracle price feed.
Testing: Implement unit tests and integration tests to verify that the protocol now uses time-accurate oracle prices and that price calculations are correct and consistent with market conditions.
In GaugeController.sol._calculateReward
, replace the time-weighted average price calculation with a call to a time-accurate oracle:
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.