Open sherlock-admin opened 11 months ago
1 comment(s) were left on this issue during the judging contest.
nirohgo commented:
True observation but the effect on deviation is miniscule and no viable scenario has been shown that leads to a loss of material amounts.
Accurate that uncollected fees are excluded from the TWAP check but included in the reserves check, which could lead to inconsistencies. This has been made consistent now.
this approach of directly computing the price of LP tokens via spot reserves is well-known to be vulnerable to manipulation
We are aware, hence the reserves & TWAP check, plus re-entrancy check.
Fix looks good. Fees are now included in determining bunni token price. Fees are now not considered in BunniHelper#getFullRangeBunniKey
lil.eth
high
Inconsistency in BunniToken Price Calculation
Summary
The deviation check (
_validateReserves()
) from BunniPrice.sol considers both position reserves and uncollected fees when validating the deviation with TWAP, while the final price calculation (_getTotalValue()
) only accounts for position reserves, excluding uncollected fees.The same is applied to BunniSupply.sol where
getProtocolOwnedLiquidityOhm()
validates reserves + fee deviation from TWAP and then returns only Ohm reserves usinglens_.getReserves(key_)
Note that
BunniSupply.sol#getProtocolOwnedLiquidityReserves()
validates deviation using reserves+fees with TWAP and then return reserves+fees in a good way without discrepancy.But this could lead to a misalignment between the deviation check and actual price computation.
Vulnerability Detail
Deviation Check :
_validateReserves
Function:BunniHelper.sol :
UniswapV3OracleHelper.sol :
You can see that this function (
_getTotalValue()
) excludes uncollected fees in the final valuation, potentially overestimating the total value within deviation check process, meaning the check could pass in certain conditions whereas it could have not pass if fees where not accounted on the deviation check. Moreover the below formula used :$$ price_{LP} = {reserve_0 \times price_0 + reserve_1 \times price_1} $$
where $reserve_i$ is token $i$ reserve amount, $price_i$ is the price of token $i$
In short, it is calculated by getting all underlying balances, multiplying those by their market prices
However, this approach of directly computing the price of LP tokens via spot reserves is well-known to be vulnerable to manipulation, even if TWAP Deviation is checked, the above summary proved that this method is not 100% bullet proof as there are discrepancy on what is mesured. Taken into the fact that the process to check deviation is not that good plus the fact that methodology used to compute price is bad, the impact of this is high
The same can be found in BunnySupply.sol
getProtocolOwnedLiquidityReserves()
:Where returned value does not account for uncollected fees whereas deviation check was accounting for it
Impact
_getTotalValue()
from BunniPrice.sol andgetProtocolOwnedLiquidityReserves()
from BunniSupply.sol have both ratio computation that includes uncollected fees to compare with TWAP ratio, potentially overestimating the total value compared to what these functions are aim to, which is returning only the reserves or LP Prices by only taking into account the reserves of the pool. Meaning the check could pass in certain conditions where fees are included in the ratio computation and the deviation check process whereas the deviation check should not have pass without the fees accounted.Code Snippet
https://github.com/sherlock-audit/2023-11-olympus/blob/main/bophades/src/modules/SPPLY/submodules/BunniSupply.sol#L212-L260 https://github.com/sherlock-audit/2023-11-olympus/blob/main/bophades/src/modules/PRICE/submodules/feeds/BunniPrice.sol#L110
Tool used
Manual Review
Recommendation
Align the methodology used in both the deviation check and the final price computation. This could involve either including the uncollected fees in both calculations or excluding them in both.
It's ok for BunniSupply as there are 2 functions handling both reserves and reserves+fees but change deviation check process on the second one to include only reserves when checking deviation twap ratio