Reproduced Exploit

Derby: the vault quotes its own slippage inside the swap

swapTokensMulti sets amountOutMinimum from quoteExactInput and then swaps. The quote reads the pool after any earlier trade in the same transaction. A searcher sells 333 TOKEN_IN first. The vault's 500 TOKEN_IN sale clears that quote and receives 204.6 TOKEN_OUT. The untouched pool would have paid…

Jan 2023•Ethereum•defi•3 min read

Loss

Vault receives 204.6 TOKEN_OUT instead of 333.3. Searcher gains 242.7 TOKEN_IN

Chain

Ethereum

Category

defi

Date

Jan 2023

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: 12295-h-13-vault-executes-swaps-without-slippage-protection-sherlo. Standalone Foundry PoC and full write-up: 12295-h-13-vault-executes-swaps-without-slippage-protection-sherlo_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/defi/slippage · vuln/defi/sandwich-attack

Key info#

FieldValue
LossVault receives 204.6 TOKEN_OUT instead of 333.3. Searcher gains 242.7 TOKEN_IN
Vulnerable contractSwapVault.swapTokensMulti
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2023-01
Compilersolc 0.8.27, cancun, via IR
Bug classmin-out is a same-transaction spot quote

TL;DR#

swapTokensMulti sets amountOutMinimum from quoteExactInput and then swaps. The quote reads the pool after any earlier trade in the same transaction. A searcher sells 333 TOKEN_IN first. The vault's 500 TOKEN_IN sale clears that quote and receives 204.6 TOKEN_OUT. The untouched pool would have paid 333.3. The searcher sells the output token back and finishes 242.7 TOKEN_IN ahead.

The vulnerable code#

SOLIDITY
uint256 amountOutMinimum = IQuoter(address(router)).quoteExactInput(path, amount);
// @> VULN: min-out is the in-transaction spot quote
ISwapRouter(address(router)).exactInput(params);

The Sherlock recommendation is to take the minimum from calldata, computed before the transaction.

Root cause#

A minimum computed from the pool you are about to trade is equal to the fill you are about to receive. It rejects nothing that the pool itself would return. Sandwich protection has to be fixed before the searcher's trade.

Preconditions#

  • A constant-product pool holds 1000 TOKEN_IN and 1000 TOKEN_OUT.
  • The vault holds 500 TOKEN_IN and will swap all of it.
  • The searcher can trade the same pool in the same transaction.

Attack walkthrough#

  1. Record the fair output of 500 into the untouched pool: 333.3 TOKEN_OUT.
  2. Searcher sells 333 TOKEN_IN and takes TOKEN_OUT out of the pool.
  3. Vault calls swapTokensMulti. The quote is now the bad price, and that number is the minimum.
  4. The swap succeeds. The vault's TOKEN_OUT balance is 204.6.
  5. Searcher sells the TOKEN_OUT back. TOKEN_IN balance is 242.7 above the pre-trade capital.

Diagrams#

flowchart TD A["Pool is 1000 TOKEN_IN and 1000 TOKEN_OUT"] --> B["Searcher sells 333 TOKEN_IN"] B --> C["Vault calls swapTokensMulti with 500"] C --> D["VULN quoteExactInput of the moved pool becomes amountOutMinimum"] D --> E["Vault receives 204.6 instead of 333.3"] E --> F["Searcher sells TOKEN_OUT back and keeps 242.7 TOKEN_IN"]

Impact#

Reward and claim swaps pay the searcher the difference. Here that difference is 242.7 TOKEN_IN taken from the vault's 500 TOKEN_IN sale. A swap that quotes before the pool is touched fills the vault for the full 333.3 and leaves the searcher's 333 TOKEN_IN untouched.

Remediation#

Pass amountOutMinimum in from the caller. Do not call the quoter in the same transaction as the swap.

How to reproduce#

BASH
cd 12295-h-13-vault-executes-swaps-without-slippage-protection-sherlo_exp
forge test -vv

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.