# LeverageManager remove leverage will lead to stuck tokens if slippage `_podSwapAmtOutMin` is set.

LeverageManager's removeLeverage leaves leftover borrowed tokens stuck in the contract when a nonzero _podSwapAmtOutMin slippage is set, because _borrowAmtRemaining is computed as zero.

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

**Target:** LeverageManager.sol removeLeverage / _swapPodForBorrowToken
**Root cause:** _swapPodForBorrowToken uses swapV2SingleExactOut with _podSwapAmtOutMin as the exact output target, so the swap returns more borrowedTKN than _targetNeededAmt; _borrowAmtRemaining is computed only from _pairedAmtReceived vs _repayAmount and ignores the surplus, leaving it in the contract.
**Steps:**
1. Call removeLeverage with a nonzero _podSwapAmtOutMin (e.g. 95) while needing 120 borrowedTKN and holding 100 pTKN + 100 borrowedTKN.
2. _swapPodForBorrowToken executes swapV2SingleExactOut with exactOutput=_podSwapAmtOutMin=95 instead of _targetNeededAmt=20.
3. Swap returns 95 borrowedTKN; only 20 needed for repay, 75 surplus remains in contract.
4. _borrowAmtRemaining = _pairedAmtReceived > _repayAmount ? diff : 0 evaluates to 0, so surplus is never transferred to owner.
**How found:** Code review of removeLeverage flow: noticed _podSwapAmtOutMin is passed as the exactOutput amount to swapV2SingleExactOut, then traced that _borrowAmtRemaining only accounts for _pairedAmtReceived minus _repayAmount, missing the swap surplus.
**Insight:** When a slippage parameter is reused as an exact-output target in a swap, check whether the surplus output is reconciled against the repayment amount; exact-output swaps with a min-out floor can over-deliver and the leftover must be explicitly returned.

