MEV Explained: Front-Running, Sandwich Attacks, and How to Defend
Understand Maximal Extractable Value (MEV): front-running, sandwich attacks, backrunning, Flashbots Protect private mempools, and slippage defense.

On this page
- 1. What is Maximal Extractable Value (MEV)?
- 2. The Four Primary Profitable MEV Strategies
- 3. Example of a Sandwich Attack
- 4. Technical Defenses: How to Protect Your Trades
- MEV Strategy Comparison Matrix
- 5. Conclusion: Protecting Your Trades in an MEV World
- Frequently Asked Questions
- Sources and further reading
Quick read
Maximal Extractable Value (MEV) refers to profit extracted by blockchain block builders and automated searcher bots by reordering, inserting, or censoring pending transactions. This deep dive explains how sandwich attacks and front-running work on DEXs, provides a worked numerical example, and details how to defend your trades using private RPC endpoints and slippage settings.
What to remember
- MEV (Maximal Extractable Value) is profit captured by searchers and validators through strategic transaction positioning in a block.
- Sandwich attacks are the most common form of retail MEV loss—bots buy immediately before your trade and sell immediately after.
- High slippage tolerance (e.g., >1.0%) invites automated MEV bots to exploit your order for profit.
- Using private mempools (like Flashbots Protect or MEV Blocker) hides your transaction from public searcher bots entirely.
- MEV is an inherent structural property of public blockchains, making user-level RPC defenses essential for on-chain traders.
When you trade on a centralized exchange, order execution is hidden inside the exchange's private matching engine. But when you trade on a public blockchain like Ethereum, your transaction is broadcast to a public waiting room called the .
While your transaction waits to be confirmed, specialized algorithms called inspect the mempool, calculate profitable ordering strategies, and bribe block builders to execute their transactions ahead of yours.
1. What is Maximal Extractable Value (MEV)?
Originally termed Miner Extractable Value, Maximal Extractable Value (MEV) is the total maximum profit that can be extracted from a blockchain block by adding, removing, or reordering transactions.
Because block producers (validators) have ultimate control over which transactions enter a block and in what exact sequence, they can prioritize transactions that pay higher priority tips or yield arbitrage profits.
2. The Four Primary Profitable MEV Strategies
Extracting MEV is not just about buying ahead of someone else. Front-running alone is unprofitable because buying a token ahead of a victim trade leaves the searcher holding price risk without a guaranteed sell price. To lock in profit, searcher bots execute one of four complete, multi-step MEV strategies:
1. Sandwich Attacks (Front-Running + Back-Running Combination)
A sandwich attack is the most predatory form of MEV. It surrounds a victim's pending DEX swap with two automated transactions inside the exact same block:
- Front-Leg: The bot detects your pending buy order in the mempool and buys the token first, driving the market price up to your maximum slippage limit.
- Victim Fill: Your trade executes next, filling at the worst possible price allowed by your slippage setting and pushing the price up further.
- Back-Leg: The bot immediately sells its tokens after your trade in the same block, pocketing a risk-free profit from the artificially inflated price.
2. DEX Back-Running Arbitrage
When a large swap on a DEX shifts a token's price out of line with secondary exchanges (e.g., Uniswap vs. Sushiswap), searcher bots submit an arbitrage trade immediately after the price-shifting swap to buy low on one pool and sell high on another, restoring market price balance.
3. Liquidation Preemption
When a borrower's collateral ratio drops below health thresholds on Aave or Compound following an oracle price update, searcher bots race to execute a liquidation transaction immediately after the oracle update block to collect the liquidation bonus.
4. Priority Gas Auctions (PGA) & Opportunity Sniping
In high-demand scenarios (such as limited-edition NFT mints, new token launches, or highly contested liquidations), searchers engage in Priority Gas Auctions (PGA):
- Searcher bots submit high priority gas tips to guarantee their transaction lands at position #0 in a block.
- By bidding a fraction of the expected profit as a tip to the block builder, searchers secure first access to scarce, high-value opportunities.
3. Example of a Sandwich Attack
Here is how a sandwich bot extracts profit from a $10,000 swap for a low-liquidity token:
- Pending Victim Order: Alice submits a trade to swap 10,000 USDC for a low-liquidity altcoin with a 5% slippage tolerance.
- Bot Front-Run: A searcher bot detects Alice's pending order in the public mempool. Paying a higher priority gas fee, the bot buys $5,000 worth of the altcoin first. Because pool liquidity is thin, this front-run buy spikes the token price on the DEX by 4.8%.
- Victim Fill: Alice's transaction executes next. Because her slippage tolerance was set to 5%, her trade fills at the artificially inflated price, driving the token price up by another 4.5%.
- Bot Back-Run: The bot immediately sells its altcoins back to the pool in the same block, pocketing ~$450 in net profit directly out of Alice's trade value.
4. Technical Defenses: How to Protect Your Trades
Traders can protect their on-chain orders from MEV bots by taking three practical steps:
Steps
Use a Private RPC Endpoint
Configure your Web3 wallet (MetaMask, Rabby) to route transactions through a private mempool endpoint (such as Flashbots Protect or MEV Blocker). Private RPCs send transactions directly to reputable block builders, bypassing the public mempool where sandwich bots operate.
Set Tight Slippage Tolerance (0.1% – 0.5%)
Never leave default DEX slippage set to high percentages. On liquid pairs like ETH/USDC, set slippage between 0.1% and 0.5%. If a sandwich bot tries to push your price up, your tight slippage causes the trade to revert safely.
Use DEX Aggregators with MEV Protection
DEX aggregators (like 1inch or CoW Protocol) use batch auctions or off-chain solvers that guarantee protection against front-running and sandwich attacks.
MEV Strategy Comparison Matrix
| MEV Strategy | Execution Mechanism | Trader Financial Impact | Primary Protection |
|---|---|---|---|
| Sandwich Attack | Front-run buy + Back-run sell around victim order | High Direct Loss (Executes trade at max allowed slippage) | Private RPC (Flashbots) / Tight Slippage |
| DEX Back-Running Arbitrage | Executed immediately after price-shifting trades | Low Direct Loss (Restores cross-market price balance) | Not applicable (Healthy market arbitrage) |
| Liquidation Preemption | Executed immediately after oracle price update | High for Borrower (Triggers liquidation bonus penalty) | Maintain Health Factor > 1.50 |
| Priority Mint Sniping | Bribe block builder via priority gas fee for block position #0 | Indirect (Front-runs retail access to limited mints) | Use anti-bot commit-reveal mint contracts |
5. Conclusion: Protecting Your Trades in an MEV World
Maximal Extractable Value is an inevitable economic reality of open, transparent blockchains. Because block builders control transaction sequencing and mempools are public by default, un-protected DEX trades will always be targeted by automated searcher bots.
Fortunately, protecting your crypto trades requires only two simple habit changes:
- Route through a Private RPC: Use Flashbots Protect or MEV Blocker to hide your transactions from public searcher bots entirely.
- Tighten Your Slippage: Never accept default 3% to 5% DEX slippage on liquid token pairs. Keep slippage between 0.1% and 0.5% so sandwich bots have no room to exploit your order.
By combining private transaction routing with strict slippage limits, you can trade on DEXs with complete confidence, ensuring your funds go toward your trade rather than MEV bot profits.
Frequently Asked Questions
No. MEV is an inherent technical feature of open, permissionless blockchains. Because block space is auctioned off via gas fees and validators control block ordering, MEV extraction is a fundamental economic reality of decentralized networks.
No. Flashbots Protect is a free private RPC endpoint. It routes your transactions directly to trusted block builders, and if a transaction fails, you don't even pay a gas fee.
Yes. While Layer 2s and fast chains like Solana use different sequencer and priority fee mechanisms, MEV searcher bots operate across all public smart contract chains where DEX trading volume exists.
Front-running alone simply buys a token before a victim's order. Without a back-run sell transaction in the same block, the searcher holds open market exposure and has no guaranteed way to lock in profit, exposing the bot to price risk.
A mempool (memory pool) is the waiting area for unconfirmed transactions before they are included in a block. MEV searchers run high-speed nodes that scan the public mempool in real time to spot large pending trades or slippage vulnerabilities.
Proposer-Builder Separation is an Ethereum architecture that splits the role of creating blocks (block builders) from proposing blocks (validators). It prevents validators from extracting MEV directly and creates a competitive, transparent auction for block space.
No. CoW Protocol uses off-chain batch auctions and peer-to-peer coincidence of wants (CoW) matching. Transactions are executed in batches at a uniform price, completely eliminating sandwich attacks.
Sources and further reading
Developer specifications and RPC defense guides:
- Flashbots Documentation — Flashbots Protect & Private RPC
- Ethereum Foundation — Maximal Extractable Value (MEV) Developer Guide
This article is educational. It is not financial advice. MEV extraction dynamics vary by network, RPC provider, and DEX aggregator settings.