What is Maximal Extractable Value (MEV)?
With the transition to proof-of-stake, validators now take on the roles formerly held by miners, including the inclusion, exclusion, and ordering of transactions in blocks.
The maximal extractable value, or MEV, is the maximum value extracted from block production in addition to the standard gas fees and associated block rewards. Following The Merge, mining isn’t part of the Ethereum protocol any longer, and validators are responsible for the roles formerly held by miners: transaction inclusion, exclusion, and changing the order of transactions in a block on the Ethereum chain.
MEV originally stood for “miner extractable value” when miners providing proof-of-work on the Ethereum protocol controlled the inclusion, exclusion, and ordering of Ethereum blocks. As the value extraction methods still work with proof-of-stake, as Ethereum functions now, the acronym was modified to accommodate the change in block proofing.
How Does MEV Work?
MEV opportunities are achieved through trading techniques that essentially equate to buying assets at a low price on a decentralized exchange (DEX) and selling them for a profit on another DEX, known as arbitrage, or on the same exchange after a price increase occurs. MEV opportunities usually occur after a large market movement that causes the price of tokens on one exchange to drop relative to the general market, giving quick traders a chance to capitalize on this difference in price and exploit it for pure profits.
While theoretically, only validators can accrue profits through MEV opportunities, “searchers” running algorithms with bots can detect potentially profitable transactions and automatically submit those transactions for inclusion in a block.
Because a validator still needs to validate a trade, searchers typically pay high gas fees to the validator —as much as 90% or more. Since so many users want to run the same arbitrage trade, the only way to guarantee that the trade goes through is to submit the transaction with the highest gas price to the validator.
Before a transaction can be executed, it must go through the public mempool, where traders risk a couple of things happening that can negatively impact their chances of profiting from the MEV.
1. The Block Producer Can Refuse the Transaction or Capture It
Traders can run into issues if the block producer refuses to process their transaction, preventing the trader from profiting from the opportunity, or they can capture the MEV opportunity for themselves.
If the block producer decides to capture the MEV opportunity for themselves, all they have to do is copy the transaction details, refuse to process the trader’s transaction, and instead include their own transaction in a block, capturing the profits and preventing traders from profiting.
2. A Bidding War Starts With Another Trader or Trading Bot
Another potential downfall is that a trader or trading bot watching the mempool copies your transaction and submits a similar transaction to the mempool with a higher gas price. This results in the block producer executing their trade first. This may lead to a bidding war, with the original trader increasing their gas fee in an attempt to secure the MEV transaction before their competitor and have their transaction added first by the block producer.
Techniques for MEV Traders
Because of the dynamics created between traders, searchers, and the block producer, several techniques have become popular for optimizing the possibility of successful, profitable MEV transactions.
Searchers that are good at programming transactions to use the least amount of gas have a competitive advantage over traders unfamiliar with the concept. They can set a higher gas price and be prioritized by the block producer over other transactions in the mempool while keeping their total gas fees constant and retaining their profit margin.
Some of the better-known gas golfing techniques are:
- Addresses that start with a long string of zeroes don’t use as much gas or space to store. (Security note: these addresses may be more susceptible to brute force attacks.)
- Traders can leave a small ERC-20 token balance in contracts, which uses less gas to update than initializing a new storage slot.
Some searchers use bots known as “Frontrunners,” or generalized frontrunners tasked with watching the mempool to locate potentially profitable transactions. The frontrunner bot copies the original searcher’s MEV transaction code, replaces it with its own address, then runs the transaction locally to ensure it’s profitable.
If it will result in a profitable transaction, the frontrunner bot submits the modified transaction with a higher gas price and “frontruns” the original transaction, hijacking the original transaction’s MEV.
Flashbots prevent generalized frontrunners from taking advantage of MEV transactions by allowing searchers to submit MEV transactions to validators without showing them to the public mempool.
Add Flashbots Protect to your build for free in QuickNode Marketplace.
Traders and searchers are always looking for new MEV opportunities, which are ever-evolving, just like the blockchain. The following are examples of the most popular methods for targeting and achieving successful MEV transactions.
The most common and simplistic method for traders to take advantage of MEV opportunities, DEX arbitrage is unsurprisingly the most competitive and accessible to traders without complex algorithms, bots, and other tools.
When two decentralized exchanges offer a token at different prices, quick-moving traders can buy tokens or coins on the lower-priced DEX and sell it on the exchange with a higher token price in a single atomic transaction. While this is a riskless arbitrage, the competition is high, as mentioned above.
Searchers watch the mempool for large trades on DEXs. Large trades, such as 5,000 or more UNI with DAI on Uniswap, can impact the price of these tokens. A searcher calculating the price effect can execute a buy order immediately before the large trade, buying UNI at a lower price, followed by a sell order following the large trade, cashing in on the price increase.
Decentralized lending protocols like Maker and Aave require users to deposit collateral in the form of Ethereum or another supported token, which is then used to lend out to other users on the protocols.
After depositing collateral tokens, users can borrow tokens and assets up to a percentage of their collateral. The value of a user’s collateral fluctuates, as does their borrowing power. The collateral can be liquidated if the value of borrowed assets exceeds a certain percentage, as determined by the protocol.
Similarly to margin calls in traditional finance, once liquidated, the borrower must pay a liquidation fee, which is usually quite steep. Some of this fee goes to the liquidator. Searchers compete to parse blockchain data to determine which borrowers can be liquidated, and the first to submit the liquidation transaction collects the fee.
Positives of MEV
Without searchers finding and fixing inefficiencies with decentralized exchanges’ economic systems and taking advantage of economic incentives, DeFi protocols and dApps would unlikely be as advanced as they are.
Another benefit is to lending protocols, which rely on fast liquidations that MEV opportunity searchers provide.
Negatives and Risks of MEV
While savvy traders can cash in on MEV opportunities, provided they understand the intricacies of decentralized finance, there are risks to consider.
Similarly to a sandwich trade, a sandwich attack places an order before and after another user’s trade. While in theory, similar to sandwich trades, attacks are made by malicious traders who artificially inflate the price of a token by frontrunning and backrunning a trade simultaneously.
Their attack affects how much of a token the original trader receives, and the attacker can collect the profit they’ve made by artificially inflating the token price.
Another downside of MEV traders is the gas-price auctions they engage in, which result in network congestion and higher gas fees for regular traders not engaged in MEV competitions.
In the case of Bitcoin, when block rewards halved, transaction fees became a more significant portion of the block reward. When this happens, it often becomes more economically viable for miners to re-mine past blocks with higher transaction fees, resulting in instability of the blockchain.
Even with the growing popularity and increased opportunity associated with MEV, the integrity of the Ethereum blockchain is currently not at risk — and it is likely to remain safe in the future.
QuickNode is building infrastructure to support the future of Web3. Since 2017, we've worked with hundreds of developers and companies, helping scale dApps and providing high-performance access to 16+ blockchains. Subscribe to our newsletter for more content like this and stay in the loop with what's happening in Web3!