Ambitious Cedar Monkey - getTWAPPriceInEth ()
will return incorrect price for negative ticks cause it doesn't round up for negative ticks.
#241
Labels
Sponsor Disputed
The sponsor disputed this issue's validity
Won't Fix
The sponsor confirmed this issue will not be fixed
Ambitious Cedar Monkey
High
getTWAPPriceInEth ()
will return incorrect price for negative ticks cause it doesn't round up for negative ticks.Summary
Negative ticks when fetching the price from the Uniswap pool are not rounded towards 0, which will give a higher price for pools using TWAP.
For reference here is the Uniswap implementation which uses the correct approach.
As result, in case if int24(tickCumulatives[1] - tickCumulatives[0]) is negative and (tickCumulatives[1] - tickCumulatives[0]) % secondsAgo != 0, then returned tick will be bigger then it should be, which opens possibility for some price manipulations and arbitrage opportunities.
Root Cause
The problem is that due to the implementation of
getV3SqrtPriceAvg()
function, wrong prices are prone to be returned leading to the use of wrong pricing protocol wide.Moreso, the
getTWAPPriceInEth()
function is used extensively for TWAP pricing in the protocolhttps://github.com/sherlock-audit/2024-12-numa-audit/blob/main/Numa/contracts/NumaProtocol/NumaOracle.sol#L226-L247
Internal pre-conditions
No response
External pre-conditions
No response
Attack Path
No response
Impact
If
tickCumulatives[1] - tickCumulatives[0]
is negative and(tickCumulatives[1] - tickCumulatives[0]) % int56(int32(_interval) != 0
, then returned tick will be bigger than it should be this returning a wrong price.This pricing is used for evaluations and state update extensively throughout the protocol
PoC
No response
Mitigation
Consider modifying the function as shown below
The text was updated successfully, but these errors were encountered: