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…
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
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.
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-registrymirror.
Vulnerability classes:
vuln/defi/slippage·vuln/defi/sandwich-attack
Key info#
| Field | Value |
|---|---|
| Loss | Vault receives 204.6 TOKEN_OUT instead of 333.3. Searcher gains 242.7 TOKEN_IN |
| Vulnerable contract | SwapVault.swapTokensMulti |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2023-01 |
| Compiler | solc 0.8.27, cancun, via IR |
| Bug class | min-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#
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#
- Record the fair output of 500 into the untouched pool: 333.3 TOKEN_OUT.
- Searcher sells 333 TOKEN_IN and takes TOKEN_OUT out of the pool.
- Vault calls
swapTokensMulti. The quote is now the bad price, and that number is the minimum. - The swap succeeds. The vault's TOKEN_OUT balance is 204.6.
- Searcher sells the TOKEN_OUT back. TOKEN_IN balance is 242.7 above the pre-trade capital.
Diagrams#
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#
cd 12295-h-13-vault-executes-swaps-without-slippage-protection-sherlo_exp
forge test -vv
Sources#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/12295-h-13-vault-executes-swaps-without-slippage-protection-sherlo.md
- Sherlock issue 64: https://github.com/sherlock-audit/2023-01-derby-judging/issues/64
- Swap library: https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/libraries/Swap.sol#L60-L97
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 12295-h-13-vault-executes-swaps-without-slippage-protection-sherlo_exp (evm-hack-registry mirror).
- AuditVault finding: 12295-h-13-vault-executes-swaps-without-slippage-protection-sherlo.
Alerts & third-party analyses
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.