Reproduced Exploit

Peapods: removeLeverage with a slippage floor leaves 75 borrowed tokens in the manager

Removing leverage holds 100 borrowed tokens and needs 120 to repay the flash loan. The user sets _podSwapAmtOutMin to 95 so the exact-out swap cannot be pushed to the full pod balance. The swap delivers 95, the repay takes 120, and 75 borrowed tokens are left in the manager. _borrowAmtRemaining is…

Jan 2025•Ethereum•dos•3 min read

Loss

75 borrowed tokens stuck in LeverageManager

Chain

Ethereum

Category

dos

Date

Jan 2025

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 52751-h-6-leveragemanager-remove-leverage-will-lead-to-stuck-token. Standalone Foundry PoC and full write-up: 52751-h-6-leveragemanager-remove-leverage-will-lead-to-stuck-token_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/dos/frozen-funds · vuln/defi/slippage

Key info#

FieldValue
Loss75 borrowed tokens stuck in LeverageManager
Vulnerable contractLeverageManager.removeLeverage
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2025-01
Compilersolc 0.8.27, cancun, via IR
Bug classPost-swap surplus ignored when podSwapAmtOutMin is set

TL;DR#

Removing leverage holds 100 borrowed tokens and needs 120 to repay the flash loan. The user sets _podSwapAmtOutMin to 95 so the exact-out swap cannot be pushed to the full pod balance. The swap delivers 95, the repay takes 120, and 75 borrowed tokens are left in the manager. _borrowAmtRemaining is computed from the pre-swap 100, so it is 0 and the user is paid nothing. The control sends the post-repay balance and the user receives 75.

Background#

Sherlock contest 2025-01-peapods-finance, issue H-6, found by pkqs90, X77, ZoA, and elolpuer. _swapPodForBorrowToken calls swapV2SingleExactOut with _podSwapAmtOutMin when that argument is non-zero, instead of the exact shortfall. _removeLeveragePostCallback then sets the refund to zero whenever the pre-swap paired balance is below the repay.

The vulnerable code#

SOLIDITY
_dexAdapter.swapV2SingleExactOut(
    _pod, _targetToken, _podAmt, _podSwapAmtOutMin == 0 ? _targetNeededAmt : _podSwapAmtOutMin, address(this)
);
require(borrowToken.transfer(flashSource, repayAmount), "repay");
// @> VULN: surplus borrowed tokens from the slippage swap are not included, so they stay in the manager
borrowAmtRemaining = pairedAmtReceived > repayAmount ? pairedAmtReceived - repayAmount : 0;

Root cause#

The refund uses _pairedAmtReceived, the balance from before the swap. The slippage swap's extra output is invisible to that subtraction, and nothing else transfers balanceOf(address(this)) after the repay.

Preconditions#

  • The position redeem leaves 100 pTKN and 100 borrowed tokens in the manager.
  • The flash repay is 120, so a swap is required.
  • The user sets _podSwapAmtOutMin to 95. The pool can fill an exact output of 95 at one-to-one.

Attack walkthrough#

  1. 100 borrowed tokens and 100 pTKN are approved to the manager. The DEX holds 95 borrowed tokens.
  2. removeLeverage pulls both balances.
  3. The swap requests 95, not the 20 token shortfall.
  4. The DEX sends 95. The manager holds 195 borrowed tokens.
  5. 120 is repaid. 75 remains.
  6. borrowAmtRemaining is 0. The user receives none of the 75.

Diagrams#

flowchart TD A["Manager holds 100 borrowed tokens and needs 120"] --> B["User sets minOut to 95"] B --> C["Exact-out swap delivers 95"] C --> D["Repay takes 120 and 75 is left"] D --> E["VULN sets borrowAmtRemaining to 0"] E --> F["75 borrowed tokens stay in the manager"] D --> G["Control transfers the post-repay balance"] G --> H["User receives 75"]

Impact#

The position owner is short 75 borrowed tokens that the swap produced above the 20 token need. They sit in LeverageManager with no refund. The flash source did receive its 120. The control returns the 75 to the user and leaves the manager empty.

Remediation#

After the repay, transfer borrowToken.balanceOf(address(this)) to the position owner. Do not derive the refund only from the pre-swap paired amount.

How to reproduce#

BASH
cd 52751-h-6-leveragemanager-remove-leverage-will-lead-to-stuck-token_exp
forge test -vv

test_exploit_75_borrow_tokens_stuck asserts 75 in the manager, 0 returned to the user, and 120 repaid. test_control_returns_the_slippage_surplus asserts the user receives 75. Captured output is output.txt.

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.