Sandwich Attack

Security Updated Apr 2026

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:

  1. You submit a large swap on a DEX (e.g., buy 10 ETH worth of TOKEN)
  2. Attacker bot sees your transaction in the mempool and buys TOKEN first (front-run)
  3. Your transaction executes at the now-inflated price
  4. Attacker bot immediately sells TOKEN at the higher price (back-run)
  5. 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 SettingSandwich RiskTrade Failure Risk
0.5%Very lowHigher (may fail if price moves)
1–2%ModerateLow
5%+HighVery low
10%+Very highMinimal

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

ServiceHow It WorksCost
Flashbots ProtectRoutes your tx privately (invisible to searchers)Free
MEV BlockerPrivate mempoolFree
CoW SwapBatch auctions, no individual front-runningBuilt in
1inch FusionOrder-based, no on-chain signature until executionBuilt 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

AspectFront-RunningSandwich Attack
Transactions1 (just front-run)2 (front-run + back-run)
Requires price impactNoYes (needs victim’s large trade)
Profit sourceInformation advantageVictim’s price impact
PreventionPrivate mempoolLow 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.