MEV and Sandwich Attacks: Why Your Swap Filled Worse Than the Quote
Sandwich attacks and MEV in plain terms: why a successful swap can fill worse than quoted, how bots read your slippage setting, and what reduces your exposure.
How swaps getpicked off
Here's a swap that goes wrong without ever looking wrong. The quote says 10 ETH for 34,120 USDC. You accept it, you sign, the transaction confirms with a green check — and 33,880 USDC lands in your wallet. Nothing failed. There's no error to read, no support ticket to file. You're just a couple hundred dollars short of the number you agreed to, and there's no obvious villain.
Sometimes that's the market doing what markets do in the twelve seconds between signing and inclusion. Sometimes a bot read your pending transaction and took the difference on purpose, and the only thing that made it possible was that you announced your intentions in public first.
MEV is the value of deciding what goes first
A block is an ordered list. Whoever assembles it decides which transactions land, and in what sequence — and in a market where prices move with every trade, that ordering is worth money. That's MEV: the value extractable purely from choosing what goes before and after what.
Most MEV isn't aimed at you. Arbitrage that pulls two pools back into line is how prices stay coherent across venues. Liquidations keep lending markets solvent. Those are load-bearing parts of the system, and they'd exist in any market with an order book and fast participants. The subset worth learning about is the part where the profit comes directly out of your fill.
Your pending transaction is a public broadcast
When your wallet submits a swap on a chain with a public mempool, that transaction sits in the open where anyone can read it before it's included. Not just that you're trading — the exact tokens, the exact size, the exact route, and the minimum output you'll accept, all encoded in the calldata.
That last field is the one people underestimate. Slippage tolerance feels like a private setting in an interface. It isn't. It's compiled into your transaction as a hard number, and it tells every observer precisely how much worse than quoted you have already agreed to accept.
Your slippage tolerance isn't a preference. It's a public statement of the most you're willing to lose, signed by you, broadcast before anyone has to earn it.
Anatomy of a sandwich
A sandwich attack is three transactions in one block, and it only works because the middle one is yours.
- 1The front-run. A bot sees your pending buy and places its own buy into the same pool immediately before yours, pushing the price up.
- 2Your trade. It executes against the pool the bot just moved. You get a worse price than you were quoted — but still inside your slippage tolerance, so it succeeds rather than reverting.
- 3The back-run. The bot sells straight back into the pool your trade just pushed further, capturing the difference. Net: it started and ended with roughly the same inventory, plus your loss, minus gas.
The profit is bounded by the gap between your quoted price and your minimum received. That's the whole economics of it. Set 5% tolerance on a thin pair and you've drawn a 5%-wide box; the bot's job is to fill as much of that box as possible while leaving you just enough that the transaction doesn't revert. Set 0.3% and the same attack has to work in a box a sixteenth the size — which very often means it isn't worth the gas to try.
Loosening slippage to make a stubborn trade go through is therefore exactly backwards. It's the one variable you control that directly sets the attacker's budget.
Not every bad fill is an attack
"I got sandwiched" has become the default explanation for any disappointing fill, and it's often wrong. Before assuming, rule out the boring causes:
- Ordinary volatility. The price genuinely moved between quote and inclusion. On a fast-moving pair this is the most likely answer by a wide margin.
- Price impact you already accepted. If your size was large relative to the pool, the quote told you so. That's the cost of the trade, not theft.
- A stale quote. You opened the app, got distracted, and signed four minutes later against numbers that had expired.
The signature of a real sandwich is specific and checkable: two trades bracketing yours in the same block, from the same address, in the opposite direction to your own. A block explorer will show you the block's contents if you want to settle the question rather than guess at it.
What actually reduces your exposure
In rough order of how much they matter:
- 1Stop broadcasting. Protected RPC endpoints send your transaction straight to block builders instead of the public mempool. It's a one-time wallet setting and it's the single biggest improvement available on Ethereum mainnet — a bot can't front-run what it can't see.
- 2Match slippage to the pair, not to your patience. Stablecoin-to-stablecoin can run very tight. A volatile long-tail token genuinely needs room. The 0.5% default is a sane starting point, not a universal answer, and raising it to 3% to stop reverts fixes the symptom by feeding the disease.
- 3Size against the liquidity that exists. A large order into a shallow pool suffers high price impact and makes an unusually attractive target. Splitting across pools, or across time, reduces both at once.
- 4Prefer routes that don't take their price from a public curve. Fills quoted by professional market makers commit to a price rather than reading it off a pool, so there's no curve for a bot to push in front of you.
- 5Know your chain's mempool. Base, Arbitrum, and Optimism currently run a single sequencer with no public mempool, which removes the classic sandwich vector almost entirely. Treat that as a property of today's centralized sequencer, not a permanent guarantee — decentralized sequencing is on the roadmap for all of them, and it changes this calculus.
Where routing helps, and where it doesn't
No aggregator can reorder a block on your behalf. Anyone claiming to make you immune is selling something. What routing genuinely does is change the economics: splitting a trade across several pools means no single pool moves far enough to be worth attacking, and comparing every available route means you aren't stuck executing against the one shallow venue that happens to be easiest to exploit.
SwapRoute queries multiple aggregators in parallel and ranks by best net output, shows the alternates so you can see what you're choosing between, and puts slippage in front of you rather than burying it three menus deep. The floor you sign against — minimum received — is the number that caps your downside, whatever a bot decides to attempt.
MEV isn't going away; it's a structural feature of public, ordered blockchains. But the version that costs you money is unusually responsive to a few defensive habits. Most people who get sandwiched repeatedly are being sandwiched by their own settings.
Compare routes across multiple aggregators, set slippage per trade, and see the minimum received before you sign.
Open the swap app