What is a sandwich attack, and how does it differ from ordinary front-running?
A sandwich attack is a specific form of MEV (Miner/Maximal Extractable Value) extraction: the attacker spots a large decentralized exchange (DEX) transaction sitting in the mempool awaiting confirmation, predicts it will push the price in a particular direction, and front-runs it by submitting a same-direction transaction first (pushing the price up ahead of time). Once the victim's transaction executes at a worse price, the attacker immediately submits a reverse transaction to close the position and lock in profit. The victim's transaction ends up sandwiched between the attacker's two transactions — hence the name.
Ordinary front-running just means the attacker completes a same-direction trade ahead of the victim. A sandwich attack combines front-running with a follow-up close, requiring the attacker to execute two transactions within the same block (or an extremely short window) — a more well-defined technique with a more explicit profit mechanism.
Why does the sandwich attack exist, and what mechanism makes it profitable?
The fundamental reason a sandwich attack is possible is that transactions on chains like Ethereum sit briefly in a public mempool before being packed into a block — anyone can see the contents of these unconfirmed transactions. This transparency (originally meant to let network nodes verify transactions) inadvertently lets attackers "see in advance" what someone is about to execute, and exploit the fact that block builders (miners or validators) prioritize transactions offering higher gas fees, cutting in line before and after the victim's transaction.
AMM (automated market maker) style DEX pricing also amplifies the problem — the larger the trade, the greater its slippage impact on price, meaning larger trades offer attackers more "juice" to extract. This is exactly why sandwich attacks tend to concentrate on large swap transactions.
How is a sandwich attack actually carried out, and what does an attacker need?
Attackers typically run an automated agent system that continuously monitors pending transactions in the mempool, using algorithms to determine in real time which transactions are worth attacking based on size and slippage tolerance (the more loosely a transaction's slippage tolerance is set, the more room there is to exploit). Once a suitable target is identified, the agent assembles two transactions simultaneously — the front-run and the back-run — and pays a higher gas fee than the victim's transaction to ensure its front-run gets prioritized by the block builder.
In recent years, as pure gas-fee-bidding front-running has become more expensive and easily outcompeted by other MEV bots, many attackers have shifted to using private transaction pool services (such as Flashbots-style infrastructure), negotiating transaction ordering directly with block builders instead of competing in the public mempool — making the attack stealthier and more reliably successful.
What's the practical impact for everyday users, and how can they reduce their chances of being attacked?
If you get hit by a sandwich attack while executing a swap on a DEX, the practical impact is that your execution price ends up worse than expected — that difference becomes the attacker's profit directly, and the trading interface usually gives no indication that "this loss happened because of an attack," so it's easily mistaken for ordinary market slippage.
Practical ways to lower attack risk include: setting slippage tolerance as close to a reasonable range as possible (not setting it too wide just to avoid failed transactions), using a trading route with built-in MEV protection (such as routing through a private transaction pool to avoid exposure in the public mempool), and avoiding large swaps on thinly liquid trading pairs (the larger the slippage room, the easier it is to target). Most mainstream wallets and DEX front-ends now have some built-in MEV protection options — worth checking whether they're enabled before trading.
In 2023, a well-known sandwich-attack MEV bot was traced by on-chain analysts to a single-day exploit in which it sandwiched a whale user's large swap transaction, netting over $200,000 in profit from that one trade. The incident sparked extensive community discussion around mempool transparency and the need for wider adoption of private transaction pools.
From the attacker's perspective, the advantage is being able to profit consistently from transaction information asymmetry without needing large capital; from an ordinary user's perspective, the drawback is that the actual execution price can be significantly worse than expected, and the loss is often mistaken for plain market slippage and goes unnoticed unless additional precautions (tighter slippage, private transaction pools) are taken.