# AutoCompoundingPodLp `_pairedLpTokenToPodLp()` does not correctly handle leftover pTKNs.

AutoCompoundingPodLp ignores existing pTKN balance when computing swap amount, so leftover pTKN snowballs and addLiquidity reverts, DoSing autocompounding and stranding funds.

- Payout: Audit contest
- Severity: high
- Program: Peapods Finance
- Found by: RampageAudit
- Disclosed: 2025-01-08
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/442
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-01-peapods-finance%3AH-4
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos

**Target:** AutoCompoundingPodLp / DecentralizedIndex addLiquidityV2 (Solidity)
**Root cause:** _getSwapAmt computes the pairedLpTKN->pTKN swap from _amountIn only, ignoring the contract's existing pTKN balance, so each epoch swaps ~half of pairedLpTKN again, compounding imbalance. addLiquidityV2 then uses full balances with slippage bounds and reverts when ratio is skewed.
**Steps:**
1. Trigger initial imbalance: addLiquidityV2 fails on slippage leaving pairedLpTKN and pTKN in contract (or attacker donates pTKN to contract).
2. Next epoch: _pairedLpTokenToPodLp calls _getSwapAmt(pairedLpTKN, pod, pairedLpTKN, _amountIn) which ignores existing pTKN balance.
3. Swap ~half of pairedLpTKN to pTKN again, increasing pTKN surplus (e.g. 10000 paired -> 5000/5000 -> 2500/7500).
4. indexUtils.addLPAndStake uses full _podAmountOut and _pairedRemaining; skewed ratio exceeds lpSlippage and reverts.
5. Repeat each epoch: pTKN accumulates stuck, addLiquidity permanently reverts (DoS).
**How found:** Code review of the autocompounding flow: noticed _getSwapAmt only uses _amountIn and not current pTKN balance, then traced how addLiquidityV2 slippage bounds cause reverts on skewed ratios, and that leftover balances persist across epochs.
**Exploitation:** Attacker donates pTKN to the AutoCompoundingPodLp contract to seed an unbalanced pairedLpTKN/pTKN ratio. On each autocompounding epoch the swap logic re-swaps half of pairedLpTKN into pTKN, worsening the imbalance until addLPAndStake reverts on slippage, permanently DoSing autocompounding and stranding pTKN.
**Escalation:** Donation can be repeated to accelerate the snowball; DoS persists across epochs since leftover balances carry over.
**Insight:** When a contract rebalances by swapping a fraction of one token, check whether the swap sizing accounts for the already-held counterparty token; leftover balances from failed LP adds compound across epochs and can be weaponized by donating the counterparty token.

