What is a Sandwich Attack?
A sandwich attack is a type of MEV (Maximal Extractable Value) exploit where a bot “sandwiches” your pending transaction between two of its own trades — buying before you and selling after you — to profit from the price movement your trade causes.
It works like this:
- You submit a large swap on a DEX (e.g., buy 10 ETH worth of TOKEN)
- Attacker bot sees your transaction in the mempool and buys TOKEN first (front-run)
- Your transaction executes at the now-inflated price
- Attacker bot immediately sells TOKEN at the higher price (back-run)
- Attacker profit = the price difference × token amount (comes out of your pocket)
The attacker literally “sandwiches” your trade. You pay more, they pocket the difference.
Real-World Example
Mempool: You submit "Buy 100,000 TOKEN with 5 ETH"
Step 1 — Attacker front-runs: Buys 50,000 TOKEN for 2 ETH
→ TOKEN price goes from $0.10 to $0.12
Step 2 — Your trade executes: Buys 100,000 TOKEN for 5 ETH
→ But at $0.12, you get fewer tokens than expected
→ You pay ~$0.118 avg (price impact)
Step 3 — Attacker back-runs: Sells 50,000 TOKEN
→ Gets 2.4 ETH back (0.4 ETH profit)
You just paid an invisible 8% premium. The attacker made 0.4 ETH in seconds.
How Common Are Sandwich Attacks?
Sandwich attacks extract an estimated $1M+ per day from Ethereum users. They’re especially common for:
- Large swaps on low-liquidity pairs
- New token launches with thin liquidity
- Volatile market conditions
- Ethereum mainnet (much less common on L2s)
Since the introduction of MEV-Boost and Flashbots, sandwich volume has decreased but remains a persistent threat for unprotected traders.
How to Protect Yourself
1. Set Low Slippage Tolerance
| Slippage Setting | Sandwich Risk | Trade Failure Risk |
|---|---|---|
| 0.5% | Very low | Higher (may fail if price moves) |
| 1–2% | Moderate | Low |
| 5%+ | High | Very low |
| 10%+ | Very high | Minimal |
If your slippage tolerance is 0.5%, a sandwich becomes unprofitable for the attacker — they can’t extract enough to cover gas fees. The tradeoff: your transaction might fail if the price naturally moves.
2. Use MEV-Protected Routing
| Service | How It Works | Cost |
|---|---|---|
| Flashbots Protect | Routes your tx privately (invisible to searchers) | Free |
| MEV Blocker | Private mempool | Free |
| CoW Swap | Batch auctions, no individual front-running | Built in |
| 1inch Fusion | Order-based, no on-chain signature until execution | Built in |
3. Split Large Orders
Instead of one 10 ETH swap, do five 2 ETH swaps spread over 10–15 minutes. Smaller trades attract less attention from sandwich bots.
4. Trade on Layer 2s
L2 networks like Arbitrum, Optimism, and Base have significantly less sandwich MEV because of their centralized sequencer model (single sequencer orders transactions, less mempool scanning opportunity).
Sandwich Attack vs Front-Running
| Aspect | Front-Running | Sandwich Attack |
|---|---|---|
| Transactions | 1 (just front-run) | 2 (front-run + back-run) |
| Requires price impact | No | Yes (needs victim’s large trade) |
| Profit source | Information advantage | Victim’s price impact |
| Prevention | Private mempool | Low slippage + private mempool |
A sandwich attack is technically a specific type of front-running that adds a back-run to capture the price impact.
Frequently Asked Questions
Q: How do I check if I was sandwiched? A: Look up your transaction on EigenPhi or libmev.com. If you see a buy right before yours and a sell right after, you were sandwiched.
Q: Are sandwich attacks illegal? A: In traditional finance, equivalent practices (front-running) are illegal. In DeFi, there’s no regulatory framework — it’s technically allowed but widely considered predatory.
Q: Will sandwich attacks go away? A: Proposed solutions like encrypted mempools and frequent batch auctions could largely eliminate them, but adoption is slow.