Advanced Topics
What Are Flash Loans in DeFi?
Learn what flash loans are, how they work within a single transaction, their legitimate use cases like arbitrage and collateral swaps, and the risks of flash loan attacks in DeFi.
Understand Maximal Extractable Value (MEV): how block producers and searchers extract value through transaction ordering, front-running, sandwich attacks, and what it means for DeFi users.
Maximal Extractable Value, commonly known as MEV, is the profit that can be extracted by block producers and specialized actors by manipulating the order, inclusion, or exclusion of transactions within a block. Originally called "Miner Extractable Value" when Ethereum used proof-of-work, the concept was renamed after the merge to proof-of-stake, since validators now fill the role that miners once held.
MEV is sometimes called the "invisible tax" on DeFi users. Every swap, every loan, every liquidation is potentially subject to value extraction by parties who can see and reorder pending transactions before they are confirmed.
When you submit a transaction on Ethereum or another blockchain, it enters the mempool — a waiting area for unconfirmed transactions. Traditionally, block producers ordered transactions by gas price: higher gas, higher priority. This created an auction where anyone willing to pay more could get their transaction included first.
MEV arises because the order in which transactions execute within a block matters enormously. If a searcher knows a large swap is about to move the price on a DEX, they can position their own transactions before and after that swap to extract profit.
Modern MEV extraction (particularly on Ethereum post-merge) involves a specialized supply chain:
This architecture — formalized by Flashbots through MEV-Boost — separates the roles of finding MEV, assembling blocks, and proposing blocks. It reduces centralization risks but does not eliminate MEV itself.
Front-running is the most widely known form of MEV. A searcher observes a pending transaction — say, a large buy order on Uniswap — and places their own buy transaction ahead of it with a higher gas fee. The original transaction then executes at a worse price, and the front-runner profits from the price movement they anticipated.
In traditional finance, front-running is illegal. In the permissionless world of DeFi, there is no regulatory framework preventing it — though protocol-level and infrastructure-level solutions are emerging.
A sandwich attack combines front-running and back-running into a single strategy:
The attacker "sandwiches" the victim's transaction between their own. The victim receives fewer tokens and experiences worse execution quality. Sandwich attacks are one of the most common and most extractive forms of MEV, estimated to cost DeFi users hundreds of millions of dollars annually.
In DeFi lending protocols — including those aggregated by Borrow — positions that fall below their required collateral ratio become eligible for liquidation. Liquidators repay a portion of the borrower's debt and receive collateral at a discount (the liquidation bonus).
Searchers compete intensely to execute these liquidations, as the liquidation bonus represents a guaranteed profit. This competition plays out through gas price auctions or through the builder/searcher pipeline. While liquidation MEV can be extractive (searchers capture value that could go to borrowers or protocols), it serves a critical function: keeping lending protocols solvent.
Arbitrage MEV involves profiting from price discrepancies across DEXs. If ETH is trading at $3,000 on Uniswap and $3,005 on Curve, a searcher can buy on Uniswap and sell on Curve simultaneously. This is often funded using flash loans, making it capital-efficient.
Unlike front-running and sandwich attacks, arbitrage MEV is generally considered beneficial because it equalizes prices across venues, improving market efficiency for all participants.
A more sophisticated MEV strategy where a searcher observes a large pending swap and provides concentrated liquidity to the AMM pool just for that transaction's execution range, earning swap fees. The liquidity is added in the same block, just before the swap, and removed just after. This improves execution for the swapper but captures fee revenue that would otherwise go to passive LPs.
MEV is not a theoretical concern — it is a multi-billion dollar phenomenon:
These figures likely underestimate the true scope, as sophisticated MEV strategies are increasingly difficult to detect on-chain.
If you are trading on a DEX, MEV searchers may front-run or sandwich your transaction, causing you to receive fewer tokens than the quoted amount. Slippage settings provide some protection, but a tight slippage tolerance can cause transactions to fail, while a loose tolerance invites more extraction.
When using collateralized borrowing platforms — like those integrated with Borrow — MEV searchers compete to liquidate your position the moment it becomes eligible. The speed and aggression of MEV searchers means you have very little time to add collateral or repay debt once your position approaches the liquidation threshold.
MEV competition historically drove up gas fees for all users, as searchers bid aggressively for transaction priority. The Flashbots ecosystem and MEV-Boost have reduced this externality by moving the auction off-chain, but gas costs remain elevated during high-MEV periods.
Users sometimes pay gas for transactions that fail because a searcher front-ran them or because the on-chain state changed before their transaction was included. This is particularly frustrating during high-volatility periods when MEV activity spikes.
The most effective protection for regular users is routing transactions through MEV-protected RPC endpoints rather than the public mempool:
Setting appropriate slippage tolerances on swaps limits the amount of value a sandwich attacker can extract. Using limit orders instead of market swaps eliminates front-running risk entirely, as the order only executes at your specified price.
Some DeFi protocols implement MEV protection directly:
Ethereum's current MEV architecture relies on Proposer-Builder Separation (PBS) implemented through MEV-Boost:
Over 90% of Ethereum blocks are now produced through MEV-Boost, making it a de facto part of Ethereum's block production pipeline.
Ethereum's roadmap includes enshrined PBS — building proposer-builder separation into the protocol itself rather than relying on external infrastructure like MEV-Boost. This would reduce trust assumptions and centralization risks in the current relay system.
Layer 2 scaling solutions have their own MEV dynamics. Currently, most L2 sequencers are centralized, meaning the sequencer operator could theoretically extract MEV. As L2s decentralize their sequencers, MEV competition will emerge on these networks as well, likely with different dynamics than on L1.
For users of lending platforms like Borrow, MEV manifests primarily through liquidation dynamics. Understanding these dynamics helps you manage risk:
When using Borrow to manage your collateralized positions, maintaining a healthy buffer above the liquidation threshold is the best defense against MEV-driven liquidation. The platform helps you monitor positions across multiple protocols, giving you visibility into your risk exposure.
MEV raises fundamental questions about fairness in decentralized systems:
MEV is a fundamental feature of public blockchains — not a bug, but an emergent property of systems where transaction ordering carries economic value. As a DeFi user, understanding MEV helps you protect yourself through MEV-resistant tools, appropriate slippage settings, and awareness of how front-running and sandwich attacks operate.
For borrowers using platforms like Borrow, MEV primarily impacts liquidation dynamics. Keeping your collateral ratio healthy and monitoring positions across protocols is the most practical defense. The broader DeFi ecosystem continues to evolve solutions — from Flashbots Protect to enshrined PBS — that aim to reduce the extractive impact of MEV while preserving its market-efficiency benefits.
Common Questions
MEV stands for Maximal Extractable Value (originally Miner Extractable Value before Ethereum moved to proof-of-stake). It refers to the profit that block producers — validators or miners — and specialized searchers can extract by including, excluding, or reordering transactions within a block beyond the standard block reward and gas fees.
Related Questions
Advanced Topics
Learn what flash loans are, how they work within a single transaction, their legitimate use cases like arbitrage and collateral swaps, and the risks of flash loan attacks in DeFi.
DeFi Basics
Learn what gas fees are in cryptocurrency, how they work on Ethereum and other blockchains, why gas fees fluctuate, and practical strategies for reducing transaction costs in DeFi.
DeFi Basics
Learn about the key risks of decentralized finance (DeFi), including smart contract vulnerabilities, protocol risk, systemic risk, and how to protect your assets.
Advanced Topics
Learn what rehypothecation means in DeFi, how it differs from traditional finance, and the risks and benefits of collateral reuse in crypto lending protocols.