# ReLPContract wrongfully assumes protocol owns all of the liquidity in the UniswapV2 pool

ReLPContract computes LP tokens to remove from total pool reserves instead of the AMO's own LP balance, causing underflow revert and DoS of bond() when protocol is minority LP.

- Payout: Contest reward
- Severity: high
- Program: Dopex
- Credited: deadrxsezzz
- Disclosed: 2023-12-29
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2023-08-dopex-findings/issues/143
- Library page: https://bugbountylibrary.com/r/c4%3A2023-08-dopex%3AH-09
- Tags: domain:web3 impact:dos kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:business-logic vuln:dos

**Target:** ReLPContract#reLP / RdpxV2Core bond flow
**Root cause:** reLP derives tokenAToRemove and lpToRemove from the pool's total reserves rather than UniV2LiquidityAmo's actual LP balance, so lpToRemove can exceed the AMO's holdings.
**Steps:**
1. Deploy Dopex periphery, set ReLP addresses, grant RDPXV2CORE_ROLE, setreLpFactor(9e4)
2. uniV2LiquidityAMO.addLiquidity(5e18,1e18,0,0) and approve ReLPContract to spend pair tokens
3. rdpxV2Core.setIsreLP(true)
4. Mint 10x reserves to address(2) and router.addLiquidity to make external LP the majority holder
5. Call `rdpxV2Core.bond(1e18,0,address(this))`; observe lpToRemove (17832559500122488916) > AMO LP balance (2235173550604750304)
6. Transaction reverts with `ds-math-sub-underflow`
**How found:** Code reading of reLP: noticed getReserves() total pool reserves used as tokenALpReserve and assumed protocol-owned, then reasoned that if AMO holds minority LP the computed lpToRemove exceeds its balance; confirmed with a Foundry PoC adding external liquidity.
**Exploitation:** Any external LP can dilute the protocol's share of the UniswapV2 pool; subsequent bond() calls with isReLPActive trigger reLP, which computes lpToRemove above the AMO balance and reverts, blocking bonding.
**Insight:** When a contract converts a desired token amount into LP shares, check whether it divides by total pool reserves or by the contract's own LP balance; diluting the protocol's pool share is a cheap way to force underflow reverts in share math.
