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.
✦ 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
In Practice
Dig Deeper
Slippage
Slippage is the difference between the price a trader expects when submitting an order and the actual price at which the trade executes. Slippage is common in crypto markets and is usually more noticeable during high volatility or when trading low-liquidity tokens.
Liquidity Pool
A liquidity pool is a collection of crypto assets locked in a smart contract that allows users to trade tokens on decentralized exchanges without relying on a traditional order book.
