code-423n4 / 2021-09-wildcredit-findings

0 stars 0 forks source link

UniswapV3Helper: Avoid recomputation of sqrtRatio from pool tick #58

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

hickuphh3

Vulnerability details

Impact

In getUserTokenAmount(), TickMath.getSqrtRatioAtTick(_tick) is called twice when the position is active (tickLower ≤_tick < tickUpper).

Its value should be saved to avoid a repeat calculation.

Recommended Mitigation Steps

_uint160 oracleTickPrice = TickMath.getSqrtRatioAtTick(_tick);
amount0 = uint(SqrtPriceMath.getAmount0Delta(
  oracleTickPrice,
  TickMath.getSqrtRatioAtTick(tickUpper),
  (int128)(liquidity)
));
amount1 = uint(SqrtPriceMath.getAmount1Delta(
  TickMath.getSqrtRatioAtTick(tickLower),
  oracleTickPrice,
  (int128)(liquidity)
));