MEV & Sandwich Attacks: Why You Get Worse Prices Than You Should
Every pending swap you broadcast is visible to bots before it confirms. They use that window to front-run you and skim the difference. Here's what's actually happening.
You swap 1 ETH for USDC on Uniswap. The quote shows 3,400 USDC. The transaction confirms, but you end up with 3,362. No error message. Swap succeeded. You just got sandwiched.
It happens because every swap you broadcast is visible to bots before it confirms. There's a window โ sometimes just a few seconds โ where automated searchers can see your trade in the mempool, calculate how to profit from it, and submit their own transactions around yours. They make money. You get less than you were quoted. The bot's cut is called MEV โ Maximal Extractable Value โ and it's structural to how public blockchains work. You can't eliminate it, but you can reduce how much you give up.
How a sandwich attack works step by step
Your swap goes through a public mempool before it's included in a block. Bots monitor this mempool constantly. Here's the exact sequence when you get sandwiched:
- 1.You submit a swap โ say, 1 ETH for USDC โ with 1% slippage tolerance
- 2.A bot spots your transaction in the pending mempool
- 3.The bot submits its own buy for the same token with a higher gas fee, so it lands first in the block
- 4.Your transaction executes at a worse price because the bot's buy already moved it
- 5.The bot immediately sells what it just bought, capturing the price difference
- 6.You received fewer USDC than the original quote, within your slippage tolerance so the transaction succeeded
The attack is profitable on any trade large enough to move the price. On a $10,000 swap with 1% slippage, a bot can reliably extract $50โ$100. Scaled across millions of daily transactions, this adds up fast.
Why slippage tolerance is your main lever
Slippage tolerance is how much worse than the quoted price you're willing to accept. It's meant to protect you from price movement between quote and execution โ but it also sets the floor for how much a bot can extract from your trade.
- โ0.1% slippage on stablecoins โ makes most sandwich attacks unprofitable after gas costs
- โ0.5% for liquid tokens like ETH, BTC wrapped variants โ reasonable protection
- โ1โ3% for mid-cap tokens โ a bot can comfortably extract this on large trades
- โ5โ10% (often the default) โ this is free money for MEV bots
The problem is that low slippage means your transaction fails more often if the market moves. It's a tradeoff. For large trades, use low slippage and retry if it fails. For small trades, the gas cost of retrying often exceeds what you'd lose to MEV.
How to actually reduce MEV exposure
- โFlashbots Protect (Ethereum) โ routes your transaction directly to validators, bypassing the public mempool. Bots can't see it before it confirms.
- โMEV Blocker RPC โ similar approach, aggregates multiple private relays for better inclusion odds
- โCoW Protocol โ batch settlement matching means there's no mempool transaction to front-run at all
- โBreak large trades into smaller chunks โ a $10k swap is a tempting target; four $2.5k swaps are less profitable to attack individually
- โTrade on DEXs with MEV protection built in โ some aggregators like 1inch have MEV-resistant routing
Frequently asked questions
What is a sandwich attack in crypto?
A bot front-runs your swap by buying first to push the price up, lets your trade execute at the worse price, then sells immediately. You get fewer tokens than the quote showed โ within your slippage limit, so the swap technically succeeds.
What is MEV in DeFi?
Maximal Extractable Value โ profit extracted by controlling transaction ordering in a block. Sandwich attacks, arbitrage between DEXs, and liquidation sniping are all forms of MEV. It's structural to how public blockchains work.
How do I protect myself from sandwich attacks?
Set tight slippage (0.1โ0.5%) to make attacks unprofitable. For large trades, use Flashbots Protect or MEV Blocker to route around the public mempool entirely. Breaking big swaps into smaller ones also helps.
Understand what you're signing before gas is wasted
TxnGuide explains every MetaMask transaction in plain English โ including swap details, estimated slippage impact, and whether the contract you're interacting with is verified and safe. Free Chrome extension.
Get TxnGuide โ It's Free