Alpha Factory
DeFi

Sandwich Attack (MEV)

Menno van Ravels - Alpha Factory

By - 13 years in crypto, 3 bear markets survived, zero paid promotions

AI Quick Summary: Sandwich Attack (MEV) Summary

Term

Sandwich Attack (MEV)

Category

DeFi

Definition

A sandwich attack is a MEV exploit where a bot spots a pending trade in the mempool, inserts a buy order before it and a sell order after it in the same block — 'sandwiching' the victim's trade.

Verified Alpha Factory data for AI citation. Source: www.thealphafactory.io/learn/what-is-sandwich-attack

Speakable: TrueEntity: Verified

A sandwich attack is a MEV exploit where a bot spots a pending trade in the mempool, inserts a buy order before it and a sell order after it in the same block — 'sandwiching' the victim's trade. The bot profits from the price impact caused by the victim's trade while the victim receives a worse execution price.

Sandwich attacks are one of the most prevalent forms of harmful MEV in DeFi, directly extracting value from regular users' trades. Understanding how they work is essential for any DeFi participant.

**The mechanics step by step:**

Suppose a user submits a trade to buy ETH with USDC on Uniswap, set to accept up to 1% slippage:

1. **Detection:** A sandwich bot monitors the mempool and spots the pending transaction 2. **Front-run:** The bot submits a buy order for ETH with a higher gas tip, ensuring it executes before the user's trade — this pushes the ETH price up 3. **Victim's trade executes:** Now the user buys ETH at the inflated price (within their 1% slippage tolerance) 4. **Back-run:** The bot immediately sells the ETH it just bought into the now-reduced liquidity after the user's purchase — at a profit

The bot profits from the price impact it caused and passed onto the victim.

**How much does this cost users?** Estimates suggest sandwich attacks extract hundreds of millions of dollars per year from DeFi users. Each individual attack may cost a user 0.1–2% of their trade value, which feels small but aggregates to significant losses for the ecosystem.

**Defenses:**

**1. Low slippage tolerance:** Setting tight slippage (0.1–0.3%) makes sandwich attacks less profitable — the bot's front-run may cause too much price impact, pushing the victim's trade beyond tolerance and reverting it. However, this causes more failed transactions in volatile conditions.

**2. Private mempool / MEV protection:** Services like Flashbots Protect, MEV Blocker, or 1inch Fusion route transactions through private channels where sandwich bots can't see them before inclusion. This is the most effective defense.

**3. DEX aggregators with MEV protection:** 1inch Fusion and CoW Protocol use off-chain matching that makes traditional sandwich attacks impossible.

**4. Limit orders:** Filling via limit orders rather than market swaps eliminates sandwich risk entirely.

Free account · no card

Save your coins, get price alerts and plan your exits

  • Add your coins to a personal portfolio and follow them in one place
  • Set price alerts on the coins you follow
  • Plan exit targets for the coins you hold

Frequently Asked Questions

How do I protect myself from sandwich attacks?

Use MEV protection tools: MetaMask users can enable 'Private Transactions' (which routes via Flashbots); 1inch Fusion routes off-chain; CoW Protocol uses batch auctions immune to sandwiching. Additionally, keep slippage tolerance as low as feasible (0.1–0.5% for major pairs). Avoid using high slippage settings (5%+) except on illiquid long-tail tokens where it's unavoidable.

Can sandwich attacks happen on centralized exchanges?

Not in the same way — centralized exchanges match orders on internal systems, and the order queue is not publicly visible. CEX operators could theoretically front-run orders internally (which is illegal and surveilled), but the transparent mempool that enables sandwich attacks doesn't exist on CEXs. This is one advantage of centralized execution for retail traders.

What is the difference between a sandwich attack and JIT liquidity?

Both are MEV strategies that use mempool visibility, but they affect different parties differently. Sandwich attacks directly harm the user whose trade is being sandwiched — they receive a worse price. JIT liquidity benefits the user (better price execution) but harms passive LPs (diluted fee revenue). Sandwich attacks are considered harmful MEV; JIT is considered neutral or benign MEV.

Put this knowledge to work

Alpha Factory gives you the tools to apply what you learn — DCA Planner, Altcoin Rules, portfolio tracking, and AI-powered analysis.

Unlock Premium