What is a Sandwich Attack?
A sandwich attack is a form of MEV extraction where an attacker places transactions immediately before and after a victim's swap, profiting from the predictable price impact. The attacker front-runs to move the price against the victim (buying what they want to buy), lets the victim's trade execute at a worse price, then back-runs to take profit (selling at the elevated price). The victim receives fewer tokens than expected. The attacker extracts this difference.
How Sandwich Attacks Work
When a large swap appears in the public mempool, MEV bots analyze its expected price impact. They construct a sandwich bundle:
- Front-run: Attacker buys the target token, pushing price up
- Victim trade: Executes at the now-higher price, pushing it further
- Back-run: Attacker immediately sells at the elevated price
The victim experiences worse execution than if no attack occurred. Their slippage tolerance setting determines maximum extraction. Attackers typically extract up to this limit.
Example
Alice wants to swap 100 ETH for USDC on Uniswap. An attacker sees this pending transaction, buys USDC first (reducing USDC in pool, raising its price), Alice's swap executes getting fewer USDC per ETH, then the attacker sells their USDC at the now-elevated rate.
Protection Strategies
Setting lower slippage tolerance limits sandwich profitability but risks transaction failure on volatile pairs. Private transaction submission (Flashbots Protect, MEV Blocker) hides transactions from public mempool, preventing attackers from seeing them.
Some DEXs implement sandwich protection: CoW Swap batches trades to minimize MEV extraction, using batch auctions where orders are matched at uniform prices. MEV-aware DEX aggregators route through private channels.
Impact on Users
Regular DeFi users frequently experience sandwich attacks without realizing it. Tools like Zeromev and EigenPhi help identify past attacks on your transactions. Sandwich attacks represent a significant MEV category, extracting hundreds of millions annually from DeFi users. Understanding this risk helps protect yourself through appropriate slippage settings and private transaction channels.