Deep diveLearn the foundationsLeaves: Go deeper

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.

CoinBeaver TeamPublished Jul 21, 2026Updated Jul 21, 2026
A mascot beaver guide using a protective shield to defend DEX transactions against sandwich searcher bots in a mempool
On this page

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:

  1. Pending Victim Order: Alice submits a trade to swap 10,000 USDC for a low-liquidity altcoin with a 5% slippage tolerance.
  2. 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%.
  3. 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%.
  4. 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

  1. 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.

  2. 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.

  3. 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

Comparison of primary MEV extraction strategies and trader protection
MEV StrategyExecution MechanismTrader Financial ImpactPrimary Protection
Sandwich AttackFront-run buy + Back-run sell around victim orderHigh Direct Loss (Executes trade at max allowed slippage)Private RPC (Flashbots) / Tight Slippage
DEX Back-Running ArbitrageExecuted immediately after price-shifting tradesLow Direct Loss (Restores cross-market price balance)Not applicable (Healthy market arbitrage)
Liquidation PreemptionExecuted immediately after oracle price updateHigh for Borrower (Triggers liquidation bonus penalty)Maintain Health Factor > 1.50
Priority Mint SnipingBribe block builder via priority gas fee for block position #0Indirect (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:

  1. Route through a Private RPC: Use Flashbots Protect or MEV Blocker to hide your transactions from public searcher bots entirely.
  2. 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


Sources and further reading

Developer specifications and RPC defense guides:

This article is educational. It is not financial advice. MEV extraction dynamics vary by network, RPC provider, and DEX aggregator settings.