MEV is often talked about in a negative context, where bots increase your trade costs to skim profits, but some types of MEV have benefits that blockchains rely on. Learn all about MEV with Matcha!
MEV (maximal extractable value) is a collective name for the many ways inefficient crypto transactions can be turned into profit, most commonly by influencing the order the transactions are executed in. While some types of MEV - like sandwich attacks - can result in higher prices for traders, other forms of MEV can bring benefits like keeping asset prices aligned across exchanges.
In crypto, MEV is a fact of the network because the majority of transactions and market data are public, and because transactions happen fast but not instantly. While your orders wait in a public mempool to be added to a block, they can be analyzed in combination with other data for opportunities to extract value (profit!). MEV protection can save you money, available in Matcha Auto and RFQ.
What is MEV?
MEV is an umbrella term for all the ways an on-chain trade can have value extracted from it. Opportunities can arise whenever a trade impacts the market price of an asset, when there are price discrepancies between two markets, or when a transaction from a discarded block is forced back onto the blockchain.
The most common forms of MEV you might encounter are:
- Sandwich attacks
Blockchain transactions are processed in the same order they are added to a block (first in, first out), so each transaction occupies its own place in a hierarchy. Earlier transactions in any given block have an advantage over those which follow.
Since other network participants can see upcoming public transactions, they can also create new transactions that take advantage of the market impact the original transactions will have when they are executed. This is where MEV is most likely to affect your trades directly.
Most of the time when MEV is discussed it is in a negative context. That’s because MEV usually happens behind the scenes in the form of arbitrage, liquidations and other ways which we’ll cover below, but it is only when a user experiences extreme slippage on a larger trade that they begin to learn that MEV exists. This has led to the misconception that all MEV is bad.
Bad MEV happens when a non-optimized trade submitted to a public mempool for processing is seen and manipulated by other market participants, in order to increase slippage and profit from it. By influencing the order in which your transaction is executed, MEV bots can profit from the difference between your expected price and the price your trade is actually executed at.
Without taking steps to protect yourself from MEV, attacks can happen on virtually any trade, as long as it has some measurable effect on the market. That means that larger trade volumes that have a large price impact are more likely to be targeted, but smaller trades on markets or token pairs with low liquidity can also lead to MEV losses
MEV can be good for blockchains because it incentivizes price normalization and ensures events like liquidations are efficiently executed. Because there is inherent value to capture, MEV bots can exchange assets across pools to maintain the ecosystem without liquidity providers’ or lenders’ involvement. This phenomenon also appears in other DeFi mechanisms where some form of asset rebalancing takes place, and it pays to be first!
To give the most profitable example, there is constant MEV activity in price arbitrage, including maintaining stablecoin pegs and rebalancing liquidity across pools. Here, multiple bots compete to buy assets at a low price from one source and sell it to another as quickly as possible. The profit taken from the price difference alone motivates bot operators to keep AMM (Automated Market Maker) liquidity pools balanced.
There are also other less obvious yet potentially beneficial effects of MEV: incentivizing users to become validators, and good MEV outcompeting bad MEV. Becoming a validator gives vastly more control over the MEV supply chain, which greatly appeals to bot operators who want to optimize their operation, and has a secondary effect of decentralizing the network. In the second case, embracing profitable good-faith MEV also provides an alternative revenue source for validators who would otherwise engage in more harmful MEV, or who fear the risk of slashing.
Maximal Extractable Value or Miner-Extractable Value?
MEV has two meanings depending on the type of blockchain being referenced. In the context of Proof-of-Stake (PoS) blockchains like Ethereum, MEV stands for Maximal Extractable Value, but when speaking about Proof-of-Work (PoW) blockchains, it stands for Miner-Extractable Value.
Maximal Extractable Value is a backronym made to fit the established term, but it is still a good description of what’s happening: you make a trade, which causes movement in the market that can be capitalized on to extract the maximum amount of value.
The distinction between maximal and miner first arose when Ethereum merged to Proof-of-Stake. Before, miners would be the ones who order trades into a block, but now that’s done by staking validators. The old acronym no longer makes sense as miners aren’t involved in validation anymore.
How MEV works
MEV is not a design flaw, but a measure of how efficient a transaction is. In the natural state of a blockchain network, MEV is present to some degree even if there’s no-one capitalizing on it.
Taking advantage of block position is possible because block producers (validators) have the power to choose what transactions to include in a block. They usually choose based on the fee, so a searcher can outbid your transaction to be included first. And in cases where a validator is also the one proposing the transactions, they can simply put their transaction ahead of yours at no expense.
Even though MEV is constant, it is possible to stop MEV attacks. Since MEV bots depend on public mempool data to pick their targets, you can conduct your trades through private channels where no information about your trade is leaked. That’s where Matcha Auto and RFQ orders come in - we cover these in more detail in our MEV Protection article.
Where is MEV most common?
MEV is not limited to one platform, it is a result of how most blockchains operate. That said, looking at the profits made by sandwich attacks alone over the past 30 days shows that Uniswap’s Universal Router accounts for almost 60% of all sandwich bot profits and Uniswap v2 makes up another 20%, meaning 80% of sandwich attacks - 4 out of 5 - happen during Uniswap interactions.
Where does the extracted value in MEV come from?
The value extracted through MEV comes from a combination of knowing what transactions are about to be executed, and controlling the order in which they are processed. Beyond simply searching the mempools for upcoming transactions, there are two key techniques which are deployed to extract value from transactions, often in combination with one another: front-running, and back-running.
Because transactions are typically ordered in a block by gas fee and executed sequentially, if someone knows you are about to trade a large volume of tokens, they can pay a higher fee to skip ahead of you in the block and buy the tokens before your order executes. This is front-running, one common type of MEV strategy generally considered malicious. Front-running is profitable because the attacker receives tokens at the price you wanted to buy, and also benefits from the price impact of your trade.
Similar to front-running, a back-run trade is one where a target transaction is followed immediately by that of a trader hunting for MEV. Back-run trades are commonly seen when new tokens are listed on a DEX, and a back-run transaction will immediately capture a large portion of the liquidity to benefit from the initial price growth, then sell back into the market for profit.
Types of MEV
As a category, the term MEV covers many different techniques. While some of them can be classified as an MEV attack, the majority of MEV profits come from arbitrage, which has little impact on traders and is arguably ‘good MEV’. Now, let’s look at the different types of MEV in more detail, to learn how they can impact you as a trader.
A sandwich attack is a combination of two MEV techniques: front-running, and back-running. The process is simple, using precise transaction ordering to execute a pair of trades both before and after a target, resulting in profits derived from the slippage of the original trade.
First, a user sends a transaction to the public mempool. An sandwich bot can target that transaction by strategically setting their gas fee so their buy executes immediately before it, resulting in a higher price for the original transaction, and then their sell executes immediately after, extracting a portion of the price difference caused by the original transaction as profit.
Learn more about sandwich attack protection in our dedicated article.
As a leveraged position on a DEX approaches its liquidation point, MEV-hunters will race to squeeze the position to liquidation in order to skim a portion of the liquidation fees. Since the leveraged position is indebted to the protocol that lent them the collateral, the borrowed funds will be returned to the protocol, but some of the fees that the liquidated trader has to pay will be sent to the trader who caused the liquidation.
DeFi lending platforms rely on MEV to liquidate any borrower whose collateral ratio falls below a certain threshold. Liquidating these positions is essential for network health, ensuring that lenders get repaid, and MEV provides financial incentive for bot operators to monitor and execute these liquidations quickly. This fast response keeps the protocol solvent, even in volatile market conditions or when the network is congested, as MEV actors are willing ro pay high fees to execute the liquidation as a priority.
Finding exploitable price differences between decentralized exchanges is known as arbitrage. Arbitrage is a common market phenomenon, which helps to keep prices aligned across the ecosystem by trading assets between exchanges. Arbitrage MEV has the lowest impact on your trades, as it profits the exchange’s pricing of an asset rather than targeting your transaction.
In the context of DEXs (decentralized exchanges), arbitrage is essential to keeping prices aligned. That’s because AMMs don’t proactively monitor for price discrepancies, so they depend on arbitrage bots to identify and fix them.
Arbitrage trading is lucrative but that also makes it highly competitive. To be profitable, arbitrage bots pay a premium in gas fees to have their transaction executed first, and tend to submit their trades in a single high-fee transaction containing both the buy and sell order to minimize the risk of another bot’s trade front-running them.
Bonus: Bandit attacks
Watching the mempool for new transactions and taking advantage of transaction ordering within a block is the most common form MEV attacks take. But there are also attacks on Proof-of-Work networks, now left behind by Ethereum since the transition to Proof-of-Stake, that involve modifying the block order itself. These are known as bandit attacks.
A time-bandit attack involves reorganizing the blockchain, which is generally uneconomical but can be profitable in certain situations. Time-bandit attacks take place when a block validator attempts to rewrite a small portion of blockchain history to capture profits initially captured by someone else's confirmed transaction.
First, a validator sees a profitable transaction in a newly added block that can be exploited for profit. Instead of building on top of this new block, the validator goes back a few blocks in time (this is where the name “time-bandit” comes from) and starts validating their own version of the block to exclude the profitable transaction they observed or insert their own transaction to capture the profit.
The validator now has to mine the following blocks faster than the current longest chain to replace it with their own version in which they capture the MEV profit. If they succeed in mining blocks faster and produce a longer chain, the network will recognize this longer chain as the new canonical one. The old blocks, including the original profitable transaction, get "orphaned" and are no longer part of the main chain.
To be profitable, the potential MEV profit has to outweigh the costs of rewriting the blockchain history. The validator also needs to have a large enough stake to produce new blocks quickly, or they won't outpace the current canonical chain, making the attack costly and unprofitable. If the validator is seen as malicious, it may be subject to slashing, and have a portion or all of its stake confiscated.
When two validators produce a block at the same blockheight, the first gets added to the main chain and becomes a canonical block, while the other is left behind as an "uncle". Uncle blocks are not completely discarded; instead, they receive a smaller portion of the block reward, and a reference to the uncled block is included in the main chain. This helps incentivize decentralization, but also opens up an attack vector.
In an Uncle-bandit attack, an unconfirmed transaction from an uncled block might be seen by a validator as exploitable for profit. The validator can decide to take the transaction, which may still be valid, and add it to a new block, reorganized in a way that extracts value. For example, if a sandwich attack ends up in an uncled block, the front-run transaction can be brought into the next block, while the back-run transaction is left behind. The validator then can profit from the price impact of the front-run transaction.
Uncle-bandit attacks are especially interesting because they can’t be mitigated by private-mempool MEV protection solutions, since any private blocks which end up as uncles are free to be exploited like any other.
As demonstrated in this article, MEV is all around us when trading. Some MEV is beneficial, because it provides incentive to keep crypto networks operating smoothly and balance the markets. Manipulating individual trades to create artificial slippage, however, is objectively bad MEV.
Historically validators have beenthe main benefactors of MEV, because they get to choose how transaction are ordered within a block. Since becoming a validator requires a baseline commitment of capital (32 ETH), it has led to a degree of power concentration (oligopoly) in the MEV space. But there are projects and proposals like PBS which are trying to democratize access to MEV.
Proposer/Builder Separation (PBS) and the current state of MEV
Proposer/Builder Separation (PBS) is a protocol design consideration in the Ethereum ecosystem that distinctly defines and divides the roles of block proposers and block builders. This separation streamlines the tasks of transaction submission and ordering, allowing specializations to emerge, while reducing computational overhead for validators and fostering a more diverse pool of participants. In context of MEV, PBS makes large strides in ensuring a permissionless protocol where validators only sign block headers for subsequent blocks, ensuring they don't control transaction order.
Regular users like you can take part in MEV opportunities by creating your own MEV scripts and using products like Flashbots to have them executed with high priority. Flashbots’ tools allow any Ethereum bot operators to bundle MEV transactions and submit them directly to validators for execution.
While MEV is largely perceived as negative, the majority of MEV trades are used to balance markets, which has an overall positive effect. Mitigating the exploitative side of MEV is an area of active research in the Ethereum community. Meanwhile, by making value extraction more widely accessible and educating users about the various types of MEV, more traders can learn to protect themselves from harmful MEV while the network can continue to benefit from other forms such as arbitrage.
Consistently better value with Matcha
Harmful MEV can be a major profit drain on traders and can cost thousands per trade at larger volumes. It’s also a big source of frustration, as many DEXs will end up with huge divergence between the price they quote and the price you get. That’s not the case with Matcha, where you know exactly how much your trade will execute for at the time you submit.
Matcha is more than a DEX, it’s a DEX aggregator, or meta-DEX. It can keep you safe from MEV, and even eliminate slippage altogether! When you turn on Matcha Auto, or manually route trades through RFQ, you connect directly to market makers without being a target of MEV.
Get the price you’re quoted and make the most of your trades. Connect your wallet to Matcha! Built by 0x on top of industry-leading infrastructure, Matcha gives you the deepest liquidity across more than 4 million tokens. Trade on Matcha today!