# Position's owed fees should allow underflow but it reverts instead, resulting in locked funds

Superposition's position.update uses checked_sub on fee growth, reverting when Uniswap-style negative fees occur, permanently locking position funds.

- Payout: Audit contest
- Severity: high
- Program: Superposition
- Found by: DadeKuma
- Disclosed: 2024-10-18
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-08-superposition-findings/issues/143
- Library page: https://bugbountylibrary.com/r/c4%3A2024-08-superposition%3AH-04
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:rust tech:solidity technique:regression technique:source-review vuln:accounting-error vuln:dos

**Target:** Seawater position accounting (position.rs)
**Root cause:** fee_growth_inside - fee_growth_inside_last can legitimately be negative per Uniswap fee math, but the Rust port uses checked_sub and errors on underflow instead of wrapping.
**Steps:**
1. Open pkg/seawater/src/position.rs update()
2. Observe `fee_growth_inside_0.checked_sub(info.fee_growth_inside_0.get()).ok_or(Error::FeeGrowthSubPos)?`
3. Trigger a state where fee_growth_inside decreases below stored value (negative owed fees, per Uniswap v3-core issue #573)
4. Call position update (add/remove liquidity) -> reverts with FeeGrowthSubPos
5. Funds in position become permanently inaccessible
**How found:** Compared the Rust port against Uniswap v3-core Position.sol, noting Solidity allows uint underflow in fee subtraction while the port used checked_sub; referenced Uniswap issue #573 explaining negative fees are expected.
**Insight:** When porting Solidity to Rust, audit every arithmetic op for intentional wrapping/underflow semantics—Uniswap fee-growth subtraction is designed to underflow, so checked_sub introduces a DoS/lock.

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

**Rust position.update checked_sub underflow revert**

```
pub fn update(
        &mut self,
        id: U256,
        delta: i128,
        fee_growth_inside_0: U256,
        fee_growth_inside_1: U256,
    ) -> Result<(), Error> {
        let mut info = self.positions.setter(id);

        let owed_fees_0 = full_math::mul_div(
            fee_growth_inside_0
->              .checked_sub(info.fee_growth_inside_0.get())
                .ok_or(Error::FeeGrowthSubPos)?,
            U256::from(info.liquidity.get()),
            full_math::Q128,
        )?;

        let owed_fees_1 = full_math::mul_div(
            fee_growth_inside_1
->              .checked_sub(info.fee_growth_inside_1.get())
                .ok_or(Error::FeeGrowthSubPos)?,
            U256::from(info.liquidity.get()),
            full_math::Q128,
        )?;

        let liquidity_next = liquidity_math::add_delta(info.liquidity.get().sys(), delta)?;

        if delta != 0 { 
            info.liquidity.set(U128::lib(&liquidity_next));
        }

        info.fee_growth_inside_0.set(fee_growth_inside_0);
        info.fee_growth_inside_1.set(fee_growth_inside_1);
        if !owed_fees_0.is_zero() {
            // overflow is the user's problem, they should withdraw earlier
            let new_fees_0 = info
                .token_owed_0
                .get()
                .wrapping_add(U128::wrapping_from(owed_fees_0));
            info.token_owed_0.set(new_fees_0);
        }
        if !owed_fees_1.is_zero() {
            let new_fees_1 = info
                .token_owed_1
                .get()
                .wrapping_add(U128::wrapping_from(owed_fees_1));
            info.token_owed_1.set(new_fees_1);
        }

        Ok(())
```

**Uniswap Solidity reference allowing underflow**

```
uint128 tokensOwed0 =
        uint128(
            FullMath.mulDiv(
                feeGrowthInside0X128 - _self.feeGrowthInside0LastX128,
                _self.liquidity,
                FixedPoint128.Q128
            )
        );
```

