# The value of LP token can be manipulated by the first minister, which allows the attacker to dilute future liquidity providers' shares

First LP minter of ElasticSwap pool can inflate share value via donation and singleAssetEntry, causing later depositors to receive zero or fewer LP tokens.

- Payout: Audit contest
- Severity: medium
- Program: ElasticSwap
- Found by: WatchPug
- Disclosed: 2022-03-02
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2022-01-elasticswap-findings/issues/145
- Library page: https://bugbountylibrary.com/r/c4%3A2022-01-elasticswap%3AM-01
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:precision-loss vuln:share-inflation

**Target:** AMM Exchange pool LP token accounting (MathLib)
**Root cause:** LP token supply can be reduced to 1 wei while reserves are inflated by direct token transfer; integer division in calculateLiquidityTokenQtyForDoubleAssetEntry then rounds new depositors' minted shares down, potentially to zero.
**Steps:**
1. `addLiquidity()` with `2 wei baseToken` and `100e18 quoteToken`, receive `14142135623` LP tokens
2. `removeLiquidity()` with `14142135622` LP tokens leaving totalSupply=1 wei, baseReserve=1 wei, quoteReserve=7071067813 wei
3. `baseToken.transfer()` `7071067812` wei to pool to rebase reserves up
4. `addLiquidity()` with 0 baseToken and `50e18 quoteToken` (singleAssetEntry)
5. `swapBaseTokenForQuoteToken()` with `600000000000000` baseToken
6. `baseToken.transfer()` `999399992928932200` wei to pool
7. `addLiquidity()` with 0 baseToken and `1e18 quoteToken`; totalSupply stays 1 wei
8. Subsequent `addLiquidity()` below ~`1e18` mints 0 LP tokens due to precision loss
**How found:** Code review of MathLib initial-mint branch and calculateLiquidityTokenQtyForDoubleAssetEntry; recognized classic X-shares/Y-totalSupply rounding attack, amplified by singleAssetEntry rebasing design.
**Exploitation:** Attacker mints then burns nearly all LP tokens to leave 1 wei supply, donates baseToken to inflate reserves, uses singleAssetEntry addLiquidity and a swap to rapidly inflate the per-share value, then future LPs' deposits are rounded down to fewer or zero LP tokens, diluting their share in favor of the attacker's 1 wei position.
**Escalation:** Amounts can be scaled higher so most future liquidity providers receive fewer LP tokens than expected, letting attacker capture a larger pool share.
**Insight:** In AMMs with single-asset entry and rebasing reserves, the first-minter share-inflation attack is amplified: check whether totalSupply can be driven to 1 wei while reserves are inflated by direct transfer, and whether integer division in share math can round new deposits to zero.
