code-423n4 / 2024-04-revert-mitigation-findings

1 stars 1 forks source link

M-19 MitigationConfirmed #94

Open c4-bot-2 opened 6 months ago

c4-bot-2 commented 6 months ago

Lines of code

Vulnerability details

C4 issue

M-19: V3Oracle susceptible to price manipulation

Comments

V3Oracle relies on calculating the price of a NFT position tokens from the Uniswap V3 Pool. This calculation comes from the following logic in V3Oracle:

// _initializeState()
// AUDIT: pulls sqrtPriceX96 from slot0 which is manipulatible
(state.sqrtPriceX96, state.tick,,,,,) = state.pool.slot0();

// _getAmounts()
(amount0, amount1) = LiquidityAmounts.getAmountsForLiquidity(
    state.sqrtPriceX96, state.sqrtPriceX96Lower, state.sqrtPriceX96Upper, state.liquidity
);

// getValue()
value = (price0X96 * (amount0 + fees0) / Q96 + price1X96 * (amount1 + fees1) / Q96) * Q96 / priceTokenX96;
feeValue = (price0X96 * fees0 / Q96 + price1X96 * fees1 / Q96) * Q96 / priceTokenX96;
price0X96 = price0X96 * Q96 / priceTokenX96;
price1X96 = price1X96 * Q96 / priceTokenX96;

The core of the issue is that V3Oracle relies on the pool's sqrtPriceX96 to retrieve the value of the NFT's position. The sqrtPriceX96 is manipulatable and therefore the position value is manipulatable.

Mitigation

PR #26

Major changes include:

Minor changes include:

Based on these changes, specifically square rooting the pool price, the Oracle is safe from slot0 price manipulation. All other changes are minor refactorings to improve organization and code quality of the codebase.

Anything Else We Should Know

AutoRange.execute() and AutoExit.execute() also calls slot0 and utilizes the sqrtPriceX96 value but does not square root the price. Although the report discussion suggests that the slot0 bug only impacts the Oracle, the raw slot0() price in both AutoRange.execute() and AutoExit.execute() may be impacted by fluctuations in market prices. This in turn creates potential inaccurate slippage amounts at any given time during turbulent markets. There is little to no harm in square rooting this change.

Conclusion

LGTM

c4-judge commented 6 months ago

jhsagd76 marked the issue as satisfactory

c4-judge commented 6 months ago

jhsagd76 marked the issue as confirmed for report