# First liquidity provider of a newly created stable pair can cause DOS and loss of funds

Stable pair _k() rounds to 0 for tiny reserves, letting first LP drain pool and inflate totalSupply to block future mints.

- Payout: Audit contest
- Severity: medium
- Program: Velocimeter
- Found by: 0xNazgul
- Disclosed: 2024-06-27
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/27
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-velocimeter%3AM-1
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos vuln:share-inflation

**Target:** Solidity AMM Pair contract (stable curve)
**Root cause:** _k() computes _a = (_x*_y)/1e18 which rounds to 0 when _x*_y < 1e18, so the stable-curve invariant check in swap() passes trivially for tiny reserves.
**Steps:**
1. Create stable pair via factory.createPair(DAI, FRAX, true)
2. Transfer small amounts of tokenA/tokenB so product < 1e18, call pair.mint() to receive LP
3. Transfer 1 token to pair to satisfy `amountIn > 0` (IIA) check
4. Call pair.swap() to extract nearly all reserves; _k returns 0 for both reserve and balance so `require(_k(bal) >= _k(res), 'K')` passes
5. Repeat mint/swap loop to inflate totalSupply toward overflow
6. Subsequent mint() reverts on overflow, DOSing the pair
**How found:** Code review of _k() stable curve: noticed integer division by 1e18 in _a can round to zero for small _x*_y, then reasoned the swap invariant check would trivially pass and built a Foundry PoC.
**Exploitation:** Attacker is first LP of a fresh stable pair; deposits dust amounts whose product is below 1e18, mints LP, then swaps out reserves since invariant check is bypassed. Repeating inflates totalSupply near uint max, permanently blocking new deposits; only cost is gas.
**Escalation:** Looping mint/swap repeatedly grows totalSupply until future mint() overflows, and factory getPair mapping prevents redeployment of the pair.
**Insight:** For AMM forks, check whether invariant functions with fixed-point scaling can round to zero at small reserves; a zero k makes the swap check vacuous and lets the first LP drain the pool and grief totalSupply.

