Reproduced Exploit

GammaSwap: processWithdrawals always swaps along path1

When the asset token is token1, the base balance is token0. On Ethereum, WETH is token1 and USDC is token0, so the sell path for the base token is path0. processWithdrawals still passes path1. The router sells 100 WETH into USDC. The vault's WETH balance is then 0, and the withdraw vault receives n…

Dec 2024•Ethereum•logic•3 min read

Loss

Router takes 100 WETH. The withdraw vault receives 0 WETH instead of 200

Chain

Ethereum

Category

logic

Date

Dec 2024

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: 45530-h-01-incorrect-swapping-path-in-processwithdrawals-pashov-au. Standalone Foundry PoC and full write-up: 45530-h-01-incorrect-swapping-path-in-processwithdrawals-pashov-au_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/wrong-condition

Key info#

FieldValue
LossRouter takes 100 WETH. The withdraw vault receives 0 WETH instead of 200
Vulnerable contractGammaVault.processWithdrawals
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-12
Compilersolc 0.8.27, cancun
Bug classbase-token swap is hardcoded to path1

TL;DR#

When the asset token is token1, the base balance is token0. On Ethereum, WETH is token1 and USDC is token0, so the sell path for the base token is path0. processWithdrawals still passes path1. The router sells 100 WETH into USDC. The vault's WETH balance is then 0, and the withdraw vault receives nothing.

The vulnerable code#

SOLIDITY
router.swapExactTokensForTokens(
    baseBalance,
    0,
    path1, // @> VULN: path1 even when the asset token is token1
    address(this),
    type(uint256).max
);
DIFF
- path1,
+ isAssetToken0 ? path1 : path0,

Root cause#

baseBalance already switches on isAssetToken0, but the path argument does not. path1 is the token1 path. Using it while the base token is token0 sells the asset instead of the base.

Preconditions#

  • Asset token is WETH, isAssetToken0 is false, so the base token is USDC.
  • The vault holds 100 USDC and 100 WETH and has approved the router for both.
  • path0 is USDC to WETH. path1 is WETH to USDC.

Attack walkthrough#

  1. processWithdrawals reads a base balance of 100 USDC.
  2. The router is called with path1 and that amount.
  3. The router pulls 100 WETH from the vault and returns 100 USDC.
  4. The vault's WETH balance is 0, so the transfer to the withdraw vault sends 0.
  5. The router holds 300 WETH, up 100.
  6. The control passes path0 and the withdraw vault receives 200 WETH.

Diagrams#

flowchart TD A["Vault holds 100 USDC and 100 WETH"] --> B["Base balance is the USDC"] B --> C["VULN swap uses path1"] C --> D["Router pulls 100 WETH"] D --> E["Withdraw vault receives 0 WETH"] B --> F["Control uses path0"] F --> G["Withdraw vault receives 200 WETH"]

Impact#

Withdrawers are paid in the asset token. This run pays them 0 WETH instead of 200. The 100 WETH that should have stayed, plus the 100 WETH the correct swap would have bought, never reaches the withdraw vault. The router keeps the 100 WETH it pulled.

How to reproduce#

BASH
cd 45530-h-01-incorrect-swapping-path-in-processwithdrawals-pashov-au_exp
forge test -vv

output.txt is the captured passing run. The control test checks the recommended fix.

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.