What Is Sandwich Attack?
A sandwich attack is a form of MEV extraction where a bot detects a pending DEX swap in the mempool, front-runs it with a buy order (pushing the price up), lets the victim's transaction execute at the now-worse price, and then back-runs it with a sell order (capturing the price difference as profit). The victim gets a worse execution price, and the attacker profits.
How Sandwich Attack Works
The attack works because DEX swaps have a slippage tolerance — the maximum price deviation the user is willing to accept. The attacker calculates exactly how much to buy to push the price to the edge of the victim's slippage tolerance, maximizing extraction. With high slippage settings (common when swapping volatile tokens), the profit per sandwich can be hundreds to thousands of dollars.
Why It Matters for Traders
To protect against sandwich attacks: use low slippage tolerance (0.5-1% where possible), use private transaction relays (like Flashbots Protect) that bypass the public mempool, break large swaps into smaller pieces, or use DEXs with built-in MEV protection. Understanding sandwich attacks explains why large DEX swaps often execute at worse prices than expected.