Deviation is calculated incorrectly allowing more than permitted manipulations of pool spot prices
Vulnerability Detail
When computing the deviations of prices from TWAP in Bunni and UniV3 Deviation.isDeviatingWithBpsCheck() always uses the highest of the two values as the denominator
hash
medium
Incorrect deviation check
Summary
Deviation is calculated incorrectly allowing more than permitted manipulations of pool spot prices
Vulnerability Detail
When computing the deviations of prices from TWAP in Bunni and UniV3
Deviation.isDeviatingWithBpsCheck()
always uses the highest of the two values as the denominatorThis allows for underreporting of the deviation causing the pool to be manipulated outside of acceptable limits
Example
TWAP = 100 Spot Price = 200 maxDeviationBps = 51%
Actual deviation = (200 - 100) / 100 == 100% Calculated deviation = (200 - 100) / 200 == 50%
Impact
Pools can be manipulated outside of expected limits
Code Snippet
deviation lib https://github.com/sherlock-audit/2023-11-olympus/blob/main/bophades/src/libraries/Deviation.sol#L69
bunni deviation check https://github.com/sherlock-audit/2023-11-olympus/blob/main/bophades/src/modules/PRICE/submodules/feeds/BunniPrice.sol#L255-L265
uniV3 deviation check https://github.com/sherlock-audit/2023-11-olympus/blob/main/bophades/src/modules/PRICE/submodules/feeds/UniswapV3Price.sol#L227-L235
Tool used
Manual Review
Recommendation
Keep TWAP in the denominator
Duplicate of #193