What is a sandwich attack?
The most common MEV attack on traders: a buy before your swap, a sell after it, and your slippage tolerance as the budget. Here is how it works and what actually removes it.
Last updated:
The short version: a sandwich attack needs two things: a visible pending swap, and a slippage tolerance that pre-authorizes a worse price. The attacker buys before you, lets your trade move the price, and sells after you, pocketing up to your tolerance. Remove the visibility, and harden the tolerance into a contract-enforced floor cleared at a uniform batch price, and the attack has nothing to work with, which is what batch-auction settlement does structurally.
What is a sandwich attack?
A sandwich attack brackets your swap between two attacker trades: a buy placed just before yours pushes the price up, your swap executes at that worse price, and a sell placed just after captures the difference. You still receive tokens, just fewer of them, which is why many victims never notice. The attacker's profit comes out of your execution price.
How does the attacker see my trade before it executes?
Through the public mempool. A normal swap is a transaction that sits visible and pending before it is mined, carrying the pool it will trade against and the worst price it will accept. Bots scan pending transactions for exactly this and can pay for the ordering they need around yours.
How much can a sandwich cost me?
Up to your slippage tolerance. The tolerance is the worst price you pre-authorized, so it is precisely the budget an attacker can harvest: a 1% tolerance on a large swap hands over up to 1% of it. Tightening the tolerance shrinks the budget but starts failing your trades in volatile markets, which is the uncomfortable trade-off tolerance-based execution forces.
How do batch auctions prevent sandwich attacks?
By removing both preconditions. Orders are signed off-chain and submitted to an orderbook, so there is no pending swap in the public mempool to spot. Settlement happens in batches where every trade of a pair clears at one uniform price, so ordering inside the batch carries no advantage to sell. Batch-auction settlement mitigates MEV by design; it is not an absolute guarantee against all adversarial conditions.
Does a tight slippage setting protect me on a regular DEX?
Only partially. A tighter tolerance shrinks the attacker's budget but does not remove the visible pending transaction that invites the attack, and it raises the chance your trade reverts and you pay gas for nothing. Hiding the transaction (a private RPC) or hardening the tolerance into a contract-enforced floor on an off-chain order (a signed limit settled in a batch auction) addresses the cause rather than the budget: with no pending swap to bracket and no fill possible below the floor, the band is not harvestable.
Go deeper
The full protection picture, including exactly what is and is not guaranteed, is in MEV-protected swaps, explained. How orders work without a tolerance at all: what is an intent-based DEX aggregator. The role of the parties who settle your trade: what is a solver.