# Wrong liquidity formula used

Superposition's adjust_position derives sqrt price from the floored current tick instead of stored sqrtPriceX96, breaking Uniswap V3 liquidity math and causing reverts or miscomputed deltas.

- Payout: Audit contest
- Severity: medium
- Program: Superposition
- Found by: prapandey031
- Disclosed: 2024-10-18
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-08-superposition-findings/issues/77
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-superposition%3AM-03
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:rust tech:solidity technique:source-review vuln:accounting-error

**Target:** SeawaterAMM Solidity/Rust pool contract (adjust_position / incrPositionC3AC7CAA)
**Root cause:** adjust_position computes sqrt_ratio_x_96 via tick_math::get_sqrt_ratio_at_tick(get_cur_tick()) rather than reading self.sqrt_price.get(); the current tick is the floor of the true tick, so the derived price deviates from the actual pool price and the wrong get_liquidity_for_amounts branch is taken.
**Steps:**
1. Deploy pool with token0=X, token1=FUSDC, position tick range [0,5], current price 1.00005 between ticks 0 and 1.
2. Owner calls `incrPositionC3AC7CAA(pool, id, amount0Min, amount1Min, amount0Desired, amount1Desired)` with amount0Min = 95% of amount0Desired = 1000.
3. Trace to pool.rs adjust_position: `sqrt_ratio_x_96 = tick_math::get_sqrt_ratio_at_tick(self.get_cur_tick())` yields 2^96 (tick 0), not the true sqrt price.
4. get_liquidity_for_amounts sees sqrt_ratio_x_96 <= sqrt_ratio_a_x_96 and takes the amount_0-only branch, computing delta ~900 instead of ~1000.
5. update_position applies wrong delta; resulting amount0 ~899.98 < amount0Min, so the tx reverts.
**How found:** Code review of adjust_position against Uniswap V3 periphery addLiquidity, noticing the protocol passes the tick-derived sqrt ratio instead of slot0's sqrtPriceX96; confirmed via Uniswap V3 whitepaper equation 6.8 and blog showing current_tick is the floor of the true tick.
**Exploitation:** No direct theft demonstrated; impact is that incrementing liquidity reverts when amountMin is close to amountDesired, making the function effectively unusable for tight-slippage users and miscomputing position deltas.
**Insight:** When porting Uniswap V3 math, verify every sqrtPriceX96 input comes from stored slot0 price, not from getSqrtRatioAtTick(currentTick) — the tick is floored, so the two diverge within a tick and flip the getLiquidityForAmounts branch selection.

## Proof of concept (copied exactly from the original report)

**Wrong sqrt price line in adjust_position**

```
let sqrt_ratio_x_96 = tick_math::get_sqrt_ratio_at_tick(self.get_cur_tick().as_i32())?;
        let sqrt_ratio_a_x_96 = tick_math::get_sqrt_ratio_at_tick(position.lower.get().as_i32())?;
        let sqrt_ratio_b_x_96 = tick_math::get_sqrt_ratio_at_tick(position.upper.get().as_i32())?;
```

