Sandwich Attacks in Crypto: Stunning Guide to the Best Defense
News

Sandwich Attacks in Crypto: Stunning Guide to the Best Defense

D
Daniel Thompson
· · 6 min read

Table of Contents Toggle What Are Sandwich Attacks in Crypto? How a Sandwich Attack Works Why Sandwich Attacks Happen Sandwich vs. Other MEV Tactics Where...

What Are Sandwich Attacks in Crypto?

Sandwich attacks are a type of market manipulation on decentralized exchanges (DEXs). They target users who submit large swaps on automated market makers (AMMs) like Uniswap, Sushi, or PancakeSwap. An attacker places one transaction right before yours and one right after. Your trade gets “sandwiched,” the price slips against you, and the attacker pockets the difference.

How a Sandwich Attack Works

On AMM-based DEXs, prices move with each trade. Large orders move the price more. Attackers watch the public mempool for big pending swaps. If they spot one, they submit two transactions with higher fees to get priority in the same block.

  1. Front-run: The attacker buys the token before your trade hits, nudging the price up.
  2. Your swap executes: You pay more per token due to higher slippage.
  3. Back-run: The attacker sells into the inflated price created by your order, realizing a profit.

Example: You try swapping 100 ETH for Token X on an AMM. The attacker detects your order, buys Token X first, pushes the price up, your trade fills at a worse rate, then the attacker sells Token X right after, capturing the price spread. You end up with fewer tokens than expected.

Why Sandwich Attacks Happen

Three features make this possible: public mempools, deterministic pricing curves, and miner/validator ordering control. AMMs use formulas (e.g., x*y=k). The formula ensures liquidity but guarantees price impact depends on trade size. When pending transactions are visible, bots can simulate outcomes and pick profitable targets. Block producers and sophisticated relays can also influence ordering for a fee.

Sandwich vs. Other MEV Tactics

Sandwiching is part of the broader category of maximal extractable value (MEV), the profit from controlling transaction ordering. It differs from other tactics in a few ways.

Common MEV Tactics on DEXs
Tactic Mechanism Impact on User
Front-running Attacker trades before a known large order User gets worse price due to prior slippage
Back-running Attacker trades after a known large order Minimal direct harm; attacker rides price move
Sandwiching Front-run + back-run around the victim’s order Compounded slippage; user receives fewer tokens
Arbitrage Profiting from price gaps across venues Can restore prices; usually neutral to user

In short, sandwiching deliberately worsens your execution. It’s targeted, fast, and highly automated, and it thrives on predictable pricing and transparent order flow.

Where Users See Sandwich Attacks

Any public mempool, AMM-based chain is a candidate. Ethereum mainnet, BNB Chain, Polygon, and other EVM chains have seen waves of sandwich bots. The problem intensifies during volatile markets or memecoin surges when slippage tolerances are set loose and LP depth thins out.

Red Flags and Micro-Scenarios

Here are small, concrete signs you might be exposed. Not all indicate an attack on their own, but they increase risk when combined.

  • Large trade size relative to the pool’s liquidity (e.g., trying to swap 5% of the pool).
  • High slippage tolerance set in your wallet or DEX interface (e.g., 5–15%).
  • Increased gas fees or delays, suggesting mempool congestion.
  • Tokens with thin liquidity or newly launched pairs with shallow pools.
  • Price impact warnings you ignore just to “get it done.”

Micro-scenario: You set slippage to 10% to catch a hype token. Your 20 ETH order hits a pool with only $300k in liquidity. A bot notices, simulates the result, and sandwiches you, skimming thousands of dollars in seconds. The transaction still confirms, but the output shocks you.

How to Reduce Your Risk

Defense is about hiding intent, reducing price impact, and capping slippage. Not every step fits every user; pick those that match your habit and risk tolerance.

  1. Use private or MEV-protected RPCs: Routes transactions through relays that block public mempool visibility and aim to prevent ordering attacks.
  2. Tighten slippage tolerance: Keep it as low as practical. If a trade fails, refine size or timing instead of cranking slippage higher.
  3. Split large trades: Break big orders into smaller chunks across time. This lowers per-trade price impact, making sandwiches less profitable.
  4. Route smartly: Use aggregators with MEV protection or anti-sandwich features. Some split order flow across pools to blunt impact.
  5. Trade during calmer periods: When gas and volatility fall, bots find fewer profitable edges.
  6. Favor deeper pools: More liquidity means smaller price moves for the same size.

None of these eliminate risk across all chains, but together they reduce the attack surface and expected loss per trade.

Slippage, Price Impact, and Execution Math

AMMs move price along a curve as you trade against the pool. If your trade is 1% of pool depth, the price impact might be modest. At 10%, it jumps dramatically. Sandwich bots aim to magnify that impact around your swap, especially if your slippage tolerance allows it. In practice, a user with 3% slippage on a shallow pair is easy prey.

What Protocols Are Doing

Developers have shipped defenses at multiple layers of the stack. While results vary, the trend is toward shrinking the public signal attackers exploit.

  • Private order flow and MEV relays: Prevent mempool visibility and harmful insertion.
  • Intent-based trading: Users specify outcomes; solvers compete to fill orders without leaking timing details.
  • Batch auctions: Aggregate trades in time buckets to reduce ordering games.
  • RFQ models: Off-chain quoting with on-chain settlement lowers exposure to mempool sniping.
  • TWAMM and streaming orders: Split large trades across blocks in a predictable, less exploitable way.

The shared goal: weaken the attacker’s edge by limiting information asymmetry and smoothing price impact.

Practical Checklist Before You Swap

Two short checks can dramatically lower your odds of getting sandwiched or overpaying.

  1. Check pool depth and recent volume for your pair. If your trade is more than 1–2% of TVL or 24h volume, consider smaller clips.
  2. Set slippage to the minimum that still fills. Start at 0.5–1% for liquid pairs; only raise if strictly necessary.

If either check looks rough, pause. Reroute via an aggregator with protection, pick a deeper pool, or wait for calmer conditions.

Key Terms

Clarity helps when comparing wallets and DEX features, so here are the essentials.

  • Mempool: The public queue of pending transactions waiting to be included in a block.
  • MEV: Maximal extractable value from transaction ordering and inclusion.
  • Front-run/Back-run: Trading immediately before/after a known order to profit from its effect.
  • Slippage tolerance: The maximum price deviation you accept before a swap reverts.
  • Price impact: The expected change in price caused by your trade size relative to pool liquidity.

These terms show up across UIs and docs. Knowing them helps you spot protections that actually matter to execution quality.

Bottom Line

Sandwich attacks exploit public order flow and AMM mechanics to extract value from unsuspecting traders. The fix is not one button; it’s a set of habits and tools. Hide your order when possible, keep slippage tight, size down, and favor deeper liquidity. With these in place, you’ll still face market risk, but you’ll stop subsidizing the bots waiting in the mempool.