DeFi

MEV (Maximal Extractable Value) Explained: Crypto Frontrunning and Sandwich Attacks

Maximal Extractable Value (MEV) refers to the profit that block producers (miners in PoW chains, validators in PoS chains) or specialised bots can extract by reordering, inserting, or censoring transactions within a block. MEV manifests as sandwich attacks on DEX traders, front-running of large orders, and arbitrage across liquidity pools. For retail DeFi users, MEV is a hidden cost that reduces the effective execution price of on-chain transactions.

When you submit a transaction to Ethereum or any public blockchain, it sits in a public waiting area called the mempool before being included in a block. Anyone can see your pending transaction, including what it's trying to do and at what price. For ordinary token transfers this is harmless. For DeFi transactions — swapping on Uniswap, opening a leveraged position on Aave, taking a large loan — this transparency creates an opportunity for exploitation: MEV extraction.

How MEV Works: The Mempool Visibility Problem

Every pending transaction in the mempool is publicly readable. Specialised MEV bots continuously monitor the mempool and calculate the profit available from restructuring the transaction ordering. Block validators/miners have ultimate authority over which transactions they include and in what order — and they can use this power to extract value, or they can sell this power to MEV searchers who pay them through priority fees ("tips") to include specific transaction orderings.

The MEV supply chain works as follows: MEV searchers (bots) identify profitable opportunities; they construct transaction bundles that capture those profits; they submit these bundles to block builders who aggregate the most profitable bundle; block validators include the highest-value block. A significant portion of Ethereum's validator revenue now comes from MEV tips rather than base block rewards.

Common MEV Attack Vectors

Sandwich Attack (most common retail impact): When a large DEX swap is pending in the mempool, an MEV bot:

  1. Places a buy order for the same token just before your swap (front-run)
  2. Allows your swap to execute (which moves the price up due to your large order)
  3. Immediately sells the token just after your swap (back-run) at the elevated price

You end up buying at a worse price than without the sandwich, and the MEV bot pockets the difference. For large swaps (tens of thousands of dollars) on low-liquidity pools, sandwich attack costs can exceed 1–2% of the trade value.

Front-running liquidations: When an on-chain lending position becomes eligible for liquidation (its collateral value falls below the liquidation threshold), MEV bots race to be the first to submit the liquidation transaction and claim the liquidation bonus. This isn't directly harmful to users in the same way as a sandwich attack (the position was going to be liquidated regardless), but it creates gas price wars between bots that temporarily spike network fees.

Arbitrage: When the same token trades at different prices on different DEXs, MEV bots exploit the discrepancy, buying low on one exchange and selling high on another in the same block. This is largely benign for retail users — it keeps prices consistent across pools — but it represents value extracted from liquidity providers who would have earned that arbitrage fee instead.

MEV Protection for Retail Users

Set low slippage tolerance: When swapping on a DEX, set a low slippage tolerance (0.5% or 1% for major pairs). This means your transaction will fail (revert) rather than execute if the price moves more than your tolerance, preventing the worst sandwich attack outcomes. The downside: failed transactions on Ethereum still cost gas.

Use private RPC endpoints: Services like Flashbots Protect and MEV Blocker submit your transactions directly to block builders without passing through the public mempool, eliminating sandwich attack exposure. Integrate via custom RPC in MetaMask (add network with Flashbots Protect URL). Most major wallets and DEX aggregators now offer MEV protection as an opt-in feature.

Use DEX aggregators with MEV protection: 1inch Fusion mode, CoW Protocol (CoW Swap), and Paraswap Delta route swaps through private auction systems that provide MEV protection while optimising execution price. For most retail users, these aggregators provide better prices than going directly to Uniswap anyway.

Avoid trading in low-liquidity pools for large amounts: High-liquidity pairs (ETH/USDC, BTC/USDC) are less susceptible to sandwich attacks because the price impact per dollar is smaller. Obscure altcoin pools with shallow liquidity are the highest-risk environment for MEV.

MEV and Network Design

Ethereum's MEV ecosystem has become sufficiently large that it's now a meaningful component of protocol economics. MEV-Boost (Flashbots' block-building service) is used by 90%+ of Ethereum validators. The Ethereum community is actively researching protocol-level MEV mitigation (Proposer-Builder Separation, encrypted mempools), but these are long-term roadmap items. For the foreseeable future, MEV is a structural feature of public blockchains that informed users must account for.

Summary

MEV is value extracted from DeFi users by reordering transactions in blocks. Sandwich attacks — the most common retail-facing MEV — front-run and back-run large DEX swaps to pocket a portion of your trade's price impact. Protect yourself by using Flashbots Protect (private RPC), MEV-blocking DEX aggregators (CoW Swap, 1inch Fusion), and setting appropriate slippage tolerance. MEV is a structural feature of public blockchains and an active area of Ethereum protocol research.