Skip to main content
DFR Publication
Donate
← DeFi glossary

Glossary · S

Sandwich Attack

Key takeaway

An MEV attack where a bot detects a large pending DEX swap, places a buy order immediately before it (frontrun — pushing the price up), lets the victim's trade execute at the worse price, then immediately sells (backrun — pocketing the price impact). The victim receives fewer tokens than expected; the bot profits from the spread. Protection: use MEV-resistant RPCs (Flashbots Protect), tight slippage tolerance, or intent-based protocols like CoW Protocol.

Last updated

How Sandwich Attack works in practice

A sandwich attack brackets a victim's trade with two of the attacker's own. Seeing a pending buy, the attacker buys first to push the price up, lets the victim fill at the worse price, then sells into the recovery. It is the most common form of MEV that ordinary users encounter.

Worked example

You submit a 50,000 USDC buy with 3% slippage tolerance. A searcher buys ahead of you, moving the price up nearly 3%. Your order fills at that worse price. They sell immediately after, pocketing most of the 1,500 difference.

Figures are illustrative and chosen to be checkable, not live market data.

The mistake that costs people money

Slippage tolerance is a ceiling on how much can be taken from you. Setting it generously to avoid failed transactions is an invitation. Use tight tolerances and route through a private mempool for large trades.

Sandwich Attack: common questions

What is Sandwich Attack?
An MEV attack where a bot detects a large pending DEX swap, places a buy order immediately before it (frontrun — pushing the price up), lets the victim's trade execute at the worse price, then immediately sells (backrun — pocketing the price impact). The victim receives fewer tokens than expected; the bot profits from the spread. Protection: use MEV-resistant RPCs (Flashbots Protect), tight slippage tolerance, or intent-based protocols like CoW Protocol.
Which DeFi concepts are most closely linked to Sandwich Attack?
Sandwich Attack is closely connected to Front-Running, Price Impact, DEX (Decentralised Exchange). Understanding how these concepts interact helps evaluate real yield, execution costs and smart-contract risk in decentralised finance.
What is the main risk or misconception around Sandwich Attack?
Slippage tolerance is a ceiling on how much can be taken from you.
Which guide covers Sandwich Attack in practice?
Read "What is MEV (Maximal Extractable Value)?" for full context on how Sandwich Attack affects real DeFi workflows, costs and risk management.

Related DeFi glossary terms

  • Front-Running In DeFi, front-running occurs when a bot detects a profitable pending transaction in the mempool and submits an identical or similar transaction with a higher gas fee to execute first and capture the profit. Classic front-running copies an arbitrage opportunity discovered by another trader. Sandwich attacks are a related form of front-running specific to large DEX swaps. MEV-protected RPCs (Flashbots Protect) help prevent front-running.
  • Price Impact The change in token price caused by your own trade on an AMM. Large trades deplete one side of the pool reserve, driving the price up for buyers and down for sellers. Price impact is deterministic and calculable before executing — DEX interfaces show estimated price impact as a percentage. Price impact is distinct from slippage (which also includes price movement from other traders). Larger trades in shallower pools have higher price impact.
  • DEX (Decentralised Exchange) A cryptocurrency exchange that operates through smart contracts without a central authority holding user funds. Users trade directly from their self-custodial wallets. Uniswap, Curve, and Balancer are leading DEXs. Unlike centralised exchanges (CEXs), DEXs require no account registration or identity verification.
  • Intent-Based Trading A trading model where users sign a desired outcome (an intent) — e.g. “swap X for at least Y” — and solvers compete to fill it optimally. Also searched as intent trading or intent settlement. Protocols such as CoW Protocol use intents to reduce MEV versus sending a raw swap straight to the public mempool.
  • Cold Wallet A cryptocurrency wallet that stores private keys offline, disconnected from the internet. Hardware wallets (Ledger, Trezor) are the most common form. Cold wallets are significantly more secure against remote hacking than software (hot) wallets.
  • Liquidity The ease with which an asset can be bought or sold without significantly affecting its price. High liquidity means large orders can be filled with minimal slippage. In DeFi, liquidity is provided by users who deposit assets into AMM pools, lending pools, or order books.