Skip to main content

MEV & Frontrunning Protection

Complete MEV taxonomy, mempool mechanics, Flashbots (Protect, Builder, Relay, MEV-Share), private mempools, and how to protect yourself as a trader.

The Complete MEV Taxonomy

MEV is not a single phenomenon. It is an entire ecosystem of value extraction strategies that operate in the space between when you submit a transaction and when it is included in a block. Understanding each category is essential for protecting yourself as a trader and for understanding why DeFi transactions sometimes behave unexpectedly.

DEX arbitrageThe most benign form. A bot detects a price discrepancy between Uniswap and SushiSwap, buys on the cheaper exchange and sells on the more expensive one in the same block. This actually improves market efficiency by aligning prices across venues. ~$2-5M daily on Ethereum.
Sandwich attacksA bot sees your pending swap in the mempool, places a buy order before yours (frontrun) to push the price up, then your trade executes at the inflated price, and the bot sells immediately after (backrun) to capture the difference. You get worse execution; the bot profits from your slippage.
Liquidation MEVLending protocols like Aave and Compound offer liquidation bonuses (5-10%) when positions become undercollateralized. MEV bots compete to execute these liquidations first, often paying substantial gas to block builders for priority inclusion.
JIT liquidityA bot deposits concentrated liquidity into a Uniswap v3 pool in the same block as a large swap, captures most of the swap fee, and removes liquidity in the next block. The bot earns fees with near-zero IL exposure.
NFT snipingBots monitor NFT marketplace listings and instantly buy underpriced NFTs the moment they appear. Some bots front-run pending listing transactions to acquire the NFT before other buyers see it.

How the Mempool Works

When you submit a transaction, it enters the mempool (memory pool): a holding area of unconfirmed transactions that validators and block builders can see. The mempool is public by default. Any node operator can observe every pending transaction, decode the calldata, simulate the outcome, and decide whether to extract value from it before including it in a block.

Searchers are specialized actors who scan the mempool for profitable MEV opportunities. They run simulations against the current blockchain state to calculate the exact profit from a sandwich, liquidation, or arbitrage. When they find a profitable opportunity, they bundle their transactions and submit them to block builders with a bid (priority fee) that represents a portion of the expected profit. Higher bids win inclusion. This is the MEV auction.

Flashbots: Protect, Builder, Relay, MEV-Share

Flashbots is an organization that has built the core infrastructure for MEV on Ethereum. Their products form a stack that ranges from user protection to block building.

Flashbots Protect

A private RPC endpoint that bypasses the public mempool entirely. Your transactions go directly to the Flashbots builder, invisible to sandwich bots. Free to use: add the RPC to your wallet (https://rpc.flashbots.net). Transactions that fail are never included on-chain, so you do not pay gas for reverts.

Flashbots Builder (mev-boost)

A block builder that constructs optimally ordered blocks by including bundles from searchers. Searchers bid for transaction inclusion, and the builder selects the most profitable combination. The winning block is proposed to the network through a relay.

Flashbots Relay

A trusted intermediary between builders and validators. The relay verifies block validity and profitability before passing it to the proposer. This prevents builders from submitting invalid blocks and protects validators from slashing.

MEV-Share

A protocol that returns a portion of MEV profits back to the user whose transaction generated the opportunity. Instead of losing 100% of the value to a searcher, MEV-Share ensures users receive 50-90% of the backrun value. Integrated into Flashbots Protect by default.

Proposer-Builder Separation (PBS)

PBS separates the roles of building blocks (selecting and ordering transactions) from proposing blocks (adding them to the chain). Before PBS, validators both built and proposed blocks: concentrating MEV extraction power in the hands of large staking pools. With PBS, specialized builders compete to construct the most valuable block, and validators simply choose the highest-bidding block to propose. This levels the playing field: solo validators earn the same MEV revenue as large pools because both receive the same auction-winning block.

Currently, PBS is implemented through mev-boost: a sidecar software that validators run alongside their consensus client. Over 90% of Ethereum blocks are built through mev-boost. Enshrined PBS (ePBS) is a proposed protocol-level change that would bake builder-proposer separation directly into Ethereum's consensus layer, eliminating the trust assumption on external relays.

Private Mempools and Order Flow Protection

Beyond Flashbots, several protocols offer private transaction routing with different trade-offs.

MEV Blocker (by CoW Protocol)Sends transactions to a network of searchers who compete to provide the best execution. Searchers can only backrun your transaction (beneficial arbitrage after your swap), not frontrun or sandwich it. Returns 90%+ of backrun profits to users. Supported by multiple wallets.
CowSwap (batch auctions)Does not use a traditional AMM. Collects orders into batches and finds the optimal execution across on-chain liquidity sources. Batching eliminates sandwich attacks by design. There is no single transaction to frontrun. Solvers compete to find the best price, often achieving execution better than the best DEX quote.
Private RPC providersServices like Alchemy, Infura, and BloxRoute offer private transaction submission. Your transaction goes directly to builders without entering the public mempool. Effectiveness varies: some providers have better builder relationships than others.

Cross-Domain MEV

Cross-domain MEV exploits price differences or state changes across multiple chains or L2s simultaneously. A searcher might observe a large swap on Arbitrum that will move the price of ETH on that L2, then immediately buy ETH on Optimism (where the price has not updated yet) and sell on Arbitrum after the price impact. As more value flows through L2s and bridges, cross-domain MEV is growing rapidly and is significantly harder to protect against because no single private mempool covers all domains.

Cross-domain MEV also operates between L1 and L2. A sequencer on an L2 can observe pending deposits from the bridge and front-run them. Since L2 sequencers are currently centralized (Arbitrum, Optimism, Base all run single sequencers), the sequencer operator has privileged access to order flow. Shared sequencers and decentralized sequencer networks are active areas of research aimed at mitigating this centralization risk, but they are not yet deployed at scale.

The MEV Supply Chain

MEV flows through a structured pipeline: users submit transactions → searchers identify profitable orderings → builders construct optimally ordered blocks → relays validate and forward blocks → proposers (validators) select the highest-value block. Each layer takes a cut. Searchers typically pass 90%+ of extracted MEV to builders as bids, builders pass most of that to proposers, and proposers keep the final payment. Understanding this pipeline reveals who captures value and where intervention points exist for user protection.

Protecting Yourself as a Trader

Sandwich attacks cost DeFi users hundreds of millions annually. You cannot eliminate MEV exposure entirely, but you can reduce it dramatically with practical measures.

Use a private RPC

Add Flashbots Protect (rpc.flashbots.net) or MEV Blocker to your wallet. This single step eliminates most sandwich attacks by keeping your transactions out of the public mempool. Takes 30 seconds to configure.

Set tight slippage

Default slippage tolerance of 0.5-1% is fine for most trades. Never set slippage above 3% unless you are trading extremely illiquid tokens. High slippage tolerances are an open invitation for sandwich bots.

Use CowSwap or aggregators

Batch auction protocols like CowSwap eliminate sandwiching by design. Aggregators like 1inch find the best route across multiple DEXs, reducing price impact. Both are strictly better than swapping directly on Uniswap for most trade sizes.

Time your transactions

Gas prices and mempool activity are lower during off-peak hours (weekend nights UTC). Lower congestion means less competition among searchers and lower gas costs for your transactions.

Split large trades

A $500K swap in a single transaction creates massive price impact that attracts MEV. Splitting into 5 × $100K trades across multiple blocks reduces the per-trade profit for a sandwich bot below the gas cost threshold, making the attack unprofitable.

The 30-second MEV protection checklist

Before any DeFi swap: (1) Check that your wallet is connected through a private RPC, not the default public endpoint. (2) Verify slippage is set to 0.5% or lower for liquid pairs. (3) Use an aggregator or CowSwap instead of a direct DEX swap. (4) Check the gas fee: if gas is abnormally high, wait. These four steps protect you from 95%+ of retail MEV extraction.
Module Quiz

1.What is the difference between a sandwich attack and DEX arbitrage in terms of their effect on users?

2.How does Flashbots Protect prevent sandwich attacks?

3.Why does CowSwap's batch auction model inherently prevent sandwich attacks?

4.What is Proposer-Builder Separation (PBS) and why does it matter for MEV distribution?

5.A trader sets 10% slippage tolerance on a $50,000 Uniswap swap. What is the likely outcome?

0/5 answered

Put this lesson to work

Free on Thrive, no account needed.