Technical Definition

Sandwich Attack

A sandwich attack places one trade before and another after a user's DEX trade to profit from the price movement caused by that user's transaction.

By Crypto University Editorial
MEVSlippageLiquidity Pool

✦ Key Insight

Sandwiching can directly worsen execution for DEX users. Larger trades, thin liquidity, and wide slippage settings can make a transaction more attractive to sandwich searchers.

✕ Common Misconceptions

Setting extremely tight slippage can reduce sandwich room but may also make legitimate transactions fail. Use reputable routing, reasonable slippage settings, and protective transaction-routing features where available.

Detailed Explanation

Plain-English explanation: The attacker or searcher first trades in the same direction as the user's pending swap, moving the price against the user. The user's trade then executes at a worse price within its slippage tolerance. The searcher trades back afterward and attempts to keep the difference as profit.

Analogy: It is like someone buying an item just before you, pushing up the price you pay, then immediately selling it after your purchase at the new higher price.

How it works: A searcher detects a suitable pending swap, estimates its price impact and slippage limit, then tries to order a buy before the victim and a sell after it. Profit must exceed gas, builder payments, price risk, and other execution costs.

FAQs

Q: Why are large swaps more exposed?

A: Large swaps can move pool prices more, creating more value from ordering trades around them.

Q: Does a sandwich attack steal tokens from my wallet?

A: Typically it harms execution price rather than directly taking wallet custody, though the economic loss can still be meaningful.

Q: Can sandwich attacks happen on every DEX?

A: Exposure depends on the trading design, order flow, liquidity, chain, and protections used by the venue or wallet.

Sources

• Ethereum.org - MEV and sandwich trading

• EIP-8099 - MEV attack motivation

In Practice

“A user submits a large token swap with 3% slippage. A searcher buys first, the user's swap pushes the price higher, and the searcher sells immediately afterward at the higher price.”

Dig Deeper