The explosion in Ethereum-based DeFi protocols provides a glimpse of what the DeFi ecosystem breakthrough can bring in the future. As DeFi grows in the blockchain ecosystem, MEV is becoming a trending topic for developers and miners community. Miners frequently utilize MEV to make more income on a block by reordering transactions in each block in ways that benefit them.
Maximum Extractable Value (aka Miner Extractable Value) refers to the value that a miner or validator can earn by reordering transactions inside the blocks they produce, in addition to the block reward and transaction fees they typically receive.
Table of content
- Working of MEV
- How does MEV affect Key Players?
- What is Front-Running?
- What is Back-Running?
- FrontRunner Bot Vs BackRunner Bot
- Possible Mitigation Solutions
- What is DEX Arbitrage?
- MEV Attacks
- Prominent Solutions
- Where are we today?
- MEV Post Merge
- Reddit User Pmcgoohan initially discovered the MEV problem in Ethereum's pre-Genesis draft documents in 2014, a year before Ethereum was launched.
- After being horrified by what happened in the 2008 global financial crisis , Pmcgoohan became fascinated with Ethereum and the idea of using a programmable blockchain in place of traditional financial markets.
- At that time, Vitalik Buterin proposed a solution to solve the MEV problem. Follow the Reddit post here .
- Philip Daian , Steven Goldfeder , Tyler Kell, Yunqi Li, Xueyuan Zhao, Iddo Bentov, Lorenz Breidenbach and Ari Juels highlighted the problem by releasing a research paper called Flash Boys 2.0 : Frontrunning, Transaction Reordering, and Consensus Instability in Decentralized Exchanges .
- Here, the word MEV was first used to explain the problem.
- Georgios Konstantopoulos and Dan Robinson published Ethereum is a Dark Forest on August 8, 2020, and Samczsun published Escaping the Dark Forest on September 24, 2020, to explain the MEV problem in detail.
- They introduced MEV as a core term in crypto-economics and emphasized its significance as one of the most difficult challenges Ethereum is facing today.
- MEV extraction is now a $1 billion-plus industry that has expanded beyond the boundaries of Ethereum. Here is MEV in 2021: A Year In Review by the Flashbots Team.
Working of MEV
MEV is most commonly linked with miners, but it is not a Proof-of-Work nor an Ethereum-specific problem. Today, the majority of MEV extraction comes from searchers.
Searchers are Arbitrage Traders and Bot Operators who are actively seeking and discovering MEV chances on-chain and capturing them in various ways, whereas miners only earn from these traders' transaction fees.
Image Source: MEV-Explore v1
MEV is present on all blockchains that support smart contracts. Miners and validators tend to choose and arrange transactions based on the highest gas price or transaction fees as they search for profit. They are in-charge of choosing and grouping transactions into blocks. They have complete control over which transactions from the mempool they will include in the blocks.
Mempool: It keeps track of all crypto transactions that have yet to be confirmed by a miner. It acts as a buffer zone or waiting area for pending crypto transactions. Lower-priority transactions, such as ones with a low fee, will frequently have to wait more than one block before being processed and verified.
Example If there is a $1,000 arbitrage opportunity on Uniswap due to a price slippage caused by a huge trade, A miner is offered a $10 transaction fee by a bot who spots the opportunity and sends a transaction to seize it. In order to seize the opportunity, a miner will clone and censor the bot's transactions. Other bots will notice and bid a larger transaction fee, resulting in a bidding war for the arbitrage. This is how a typical MEV occurs.
How does MEV affect Key Players?
In case of a blockchain transaction key players:
- an end user who initiates a transaction and
- a miner who includes the transaction in a block to add to the blockchain.
An end user pays for inclusion in a block through their transaction’s gas price, and therefore through the transaction fee they indicate they are willing to pay miners.
Miners on the other hand may choose to pick the transactions with the highest gas price and order them by gas spent in the block they are producing. This sequencing of transactions helps miners earn profit from the MEV.
There are many different opportunities, the two popular ways increasing competition are:
- Front Running: By selling block space to non-miner MEV extractors in return for transaction fees through Priority Gas Auctions.
- Back Running: By directly extracting MEV by reordering, including, or censoring transactions in order to profit from on-chain liquidation or arbitrage opportunities.
What is Front-Running?
It is often called Priority Gas Auctions (PGAs) is getting a transaction ahead of a pending transaction in the execution queue by bidding higher gas prices. Searchers use customized front-running bots to monitor the network for large orders on DEXes and submit competing transactions with higher gas fees to be mined before the pending transaction. Miners can easily front-run as they know all the transaction details.
Priority Gas Auctions
Priority Gas Auctions (PGAs) or competitive bidding is observed among bots to engage in an arbitrage opportunity. For high revenue, bots compete against each other by bidding on transaction fees (gas), to obtain priority ordering, i.e., early block position and execution, for their transactions, which drives up fees for other users.
For example, transaction A is broadcasted with a higher gas price than an already pending transaction B, so that A gets mined before B.
Like high-frequency traders on Wall Street, these bots exploit inefficiencies in DEXes, paying high transaction fees and optimizing network latency to frontrun, i.e., anticipate and exploit ordinary users’ DEX trades.
These are the bots that watch the mempool for profitable transactions, which are then used by searchers to find profitable MEV chances. They will duplicate the code of the potentially profitable transaction, substitute addresses with the frontrunner's address, and perform the transaction locally to ensure that the updated transaction results in a profit for the frontrunner's address. If the transaction is profitable, the frontrunner will submit a modified transaction with a new address and a higher gas price, thereby frontrunning the original transaction.
It is programming transactions so that they use the least amount of gas. It is used by searchers to extract MEV. It enables searchers to set a higher gas price while maintaining a constant total gas fee, i.e., gas fees = gas price * gas used
For Example: If a large trade is detected, a front-running bot can copy the user's trade and pay a larger transaction fee to get their transaction executed first. This shifts the market price of the item being traded, resulting in more slippage for the user's trade. After a user's trade is finalized, the market price of the sold item changes even further in favour of the frontrunner.
What is Back-Running?
It is a technique of getting a transaction ordered second in line or immediately after an unconfirmed target transaction. Common examples of target transactions
can be price oracle updates that allow liquidation transactions to be triggered immediately afterwards, or trades on AMM (automated market maker) exchanges such as Uniswap where one trade affects the price offered to subsequent trades.
For Example:A back-running bot monitors the Ethereum mempool for new pairs created on Uniswap. If it finds a new token pair, the bot places a buy order immediately. The bot tries to buy as many tokens as possible, but not all of them, as there needs to be an opportunity for others to buy tokens as well. The bot then waits for the price to go up so that other traders can buy the token from Uniswap, and then the bot proceeds to sell back the tokens at a higher price.
In order to maximize their chances of being mined immediately after their target, a typical backrunner will send many identical transactions, with gas price identical to that of the target transaction, sometimes from different accounts, in order to increase the chances that one of their transactions is ordered after the target but before any competitor.
FrontRunner Bot Vs BackRunner Bot
|Factors||FrontRunner Bot||BackRunner Bot|
|Gas Fees||Bots are competing for a profitable transaction and end up paying a portion of MEV (miner extractable value) to miners in gas fees by using a high gas price.||Bots transfer MEV to miners by spending more gas, without increasing the gas price.|
|Block Gas Utilization||Bots do not have a disproportionate effect on block gas utilization.||Bots are likely to imposes a larger negative externality on the network by consuming the gas limit (i.e. using up network throughput with useless transactions)|
|Block Space Utilization||Do not spam||Spam the network with useless transaction|
Therefore, it would likely benefit the network if backrunning was converted into frontrunning when possible, as a "less harmful outlet" for MEV extraction.
Possible Mitigation Solutions
Backrunning seems largely to be made possible due to go-ethereum's method of randomly ordering identically-priced transactions. If transactions were deterministically ordered, or ordered by some other quantity like arrival time, back-running in its current form would not be possible.
If ordering by arrival time, low latency transaction propagation will be incentivised instead in similar scenarios (whether or not this has any harmful side-effects is unclear).
If deterministically ordering (e.g. by transaction hash), then participants will be incentivised to mine txhashes (or similar), which would add a PoW-style game to transaction priority but at least would not use Ethereum network resources.
There could also be other approaches to ordering transactions that do not incentivise spam.
At Client Level
It is also possible for smart contracts to be designed in a way that removes the incentives for backrunning. However, it is not always clear that a backrunning scenario might be incentivised, or how to prevent it, so it may be preferable for this to be addressed at the client level.
Smart contract authors may wish to mitigate this on the smart contract level for the time being (backrunning typically deteriorates the QoS for users of a smart contract, since it can have the effect of delaying user transactions or delaying oracle updates, etc.).
What is DEX Arbitrage?
If two DEXes are offering a token at two different prices, someone can buy the token on the lower-priced DEX and sell it on the higher-priced DEX. This creates an arbitrage opportunity.
This is used by third-party bots looking to make profits from arbitrage trading on DEXes. These bots can analyze the market to realize these price differences and make a profit by buying and selling until the value of the assets on both exchanges reaches a similar price. These price differences, however, never stay for long. This means the bots must ensure faster transactions if they want to earn a profit.
These bots compete by bidding on transactions, which causes them to raise the transaction fees they are willing to pay miners in order to have their transaction processed first. As miners prioritize transactions based on the highest gas price, this raises the transaction fees for everyone else on the network. These transaction fees are sent straight to the miners. This implies that even if miners do not take advantage of the arbitrage opportunity, they still gain from this type of MEV since they get greater transaction fees.
Image Source: MEV-Explore v1
It is a technique in which the miner places the transaction in the middle of other transactions instead of placing it at the front.
- In Case of Searcher: A searcher can identify a token that a user is going to buy and then execute a transaction to raise the price, then sell the token immediately after the user's buy order, so that the price increases even more.
- For Example: If a user wants to buy 10,000 ETH on Uniswap with DAI, this will have a great impact on the ETH/DAI pair, boosting the price of ETH compared to DAI dramatically. A searcher can estimate the price impact of this huge trade on the ETH/DAI pair and can place a buy order just before this trade to acquire ETH, then place an ideal sell order just after the large trade to sell it for the higher price.
- In Case of Miner: In the above example, a miner can figure out a method to add their transaction in between the buy and sell orders. The gas fees will rise as a result, resulting in greater revenue for miners.
In this type of attack, Miners rewrite blockchain history to steal funds by reorganizing blocks to capture MEV opportunities in previously mined blocks. Miners try to destabilize consensus if block rewards are minimal enough in comparison to MEV.
- For Example: If a miner A with sufficient mining power discovers a $10,000 arbitrage opportunity three blocks deep at block 100, Instead of mining the most recent block for a much lower block reward, they try to re-mine blocks 100, 101, and 102 to take advantage of the arbitrage opportunity and have a longer chain than the miner who first mined the block.
In this type of attack, Attacker notices something in an uncle and brings it up. This also shows that attacks go beyond the mempool to uncled blocks.
- For Example: In Ethereum, two blocks are mined roughly at the same time, and only one block can be added to the chain at a time. The other becomes orphaned or uncled. As part of the uncled block, these transactions are now public. An uncled block can contain a Sandwicher's bundle. Bundles are groups of transactions that Flashbots users submit. When an attacker noticed this, he took only the Buy portion of the Sandwich, and then added an arbitrage. After that, the attacker sent it as a bundle, which was mined.
NFT transactions take place on the same Ethereum blockchain as all other Ethereum transactions, so searchers can use the same strategies to find MEV opportunities.
- For Example: If a searcher wants a certain NFT or group of NFTs during a popular NFT drop, they can design a transaction to be the first in line to buy the NFT. Also, if an NFT is accidentally posted at a low price, a searcher can outbid other buyers and get it at a bargain.
Liquidators are Searchers who specialize in extracting MEV from Decentralized On-Chain Protocols like Compound, Maker, Aave, and dYdX by liquidating Over-Collateralized Loans.
- Lending protocols work by requiring users to deposit some sort of collateral. Users can then borrow various assets and tokens from others, up to a specific amount of their deposited collateral.
- If the value of borrowed assets exceeds the value of the collateral due to market movements, the protocol allows anybody to liquidate the collateral, quickly repaying the lenders.
- If a loan is liquidated, the borrower is often required to pay a large liquidation fee, a portion of which goes to the liquidator, which is where the MEV opportunity comes in.
- Searchers compete to see which borrowers can be liquidated first, then submit a liquidation transaction and get the liquidation fee.
Image Source: MEV-Explore v1
In this section, we will see the effects of MEV.
On DeFi and Lending Protocols
MEV increases the efficiency of DeFi and Lending protocols. DeFi protocols cannot be as robust as they are now without searchers discovering and resolving economic inefficiencies and making use of the protocols' economic incentives. DEX arbitrage ensures that users receive the best and most accurate pricing for their tokens, while lending protocols rely on quick liquidations to ensure that lenders are paid back when borrowers fall below collateralization ratios.
Image Source: MEV-Explore v1
On Normal Users
MEVs result in a worse experience for users. Users have to pay high amounts of gas fees due to increased slippage, which is caused by sandwich trading and frontrunning.
Due to Generalized Frontrunners and Priority Gas Auctions, MEV causes congestion and high gas prices on the network.
If the MEV available in a block exceeds the standard block reward, miners can remine blocks and capture the MEV for themselves, causing blockchain re-organization and consensus instability. In MEV situations, it is economically rational for miners to give up the next block's reward and instead remine past blocks for more profits.
In this section, we will look at some prominent solutions to solve the MEV issue.
It is a research and development organization that aims to reduce the negative externalities and existential threats that MEV poses to smart-contract blockchains. Its goal is to create a permissionless, transparent, and fair ecosystem for MEV extraction.
To resolve the MEV crisis, their strategy can be broken down into three steps.
Step 1: Using MEV-Inspect , it scans Ethereum blocks and visualizes MEV metrics over time. This helps with a better understanding of the MEV ecosystem, and normal users can get a better idea of what MEV is and how it affects them.
Step 2: Using MEV-Geth , it is a Go-Ethereum client upgrade that adds a sealed-bid block space auction mechanism for communicating transaction order preference. It establishes a more efficient communication route for miners and traders bidding for transaction inclusion. It helps in relieving most of the network congestion caused by frontrunning and backrunning bots.
Step 3: Distribution of Profits, MEV involves the entire ecosystem, from miners, traders, DeFi developers, and users. MEV extraction currently benefits traders and miners. As MEV extraction continues to grow in scale, so Flashbots will redistribute this MEV extraction towards users and system stability.
Chainlink's Fair Sequencing Services
It is an MEV solution that employs a decentralized oracle network to order transactions sent to an on-chain smart contract in a fair manner.
FSS decentralizes transaction ordering, guaranteeing that smart contracts process transactions in an efficient manner. This solution avoids making modifications to the base layer blockchain on which smart contracts function.
FSS not only eliminates unfair transaction ordering, but it also has the ability to reduce network gas costs by eliminating gas price bidding wars. The amount of fees a user pays has no influence on the ordering of their transaction compared to other transactions.
FSS involves sending transactions off-chain to the Oracle network and users to send transactions directly to the mempool. This implies that FSS can be easily compatible with existing user wallets and infrastructure.
FSS enables smart contract developers to verify that their dapps treat users fairly. This increases the user experience while engaging with dapps.
Optimism's MEV Auction
Karl Floersch was the first person to suggest the MEV Auction in early 2020. He is also the CTO of Optimism.
The MEV auction is designed in such a way that the auction winner has the power to reorder submitted transactions and insert their own, as long as they do not delay any single transaction by more than N blocks.
Image Source: EthResearch
The auction can collect MEV from miners by distributing the process between two functions, i.e., transaction inclusion and transaction ordering. Transaction Inclusion is determined by Block producers, whereas Transaction Ordering is determined by Sequencers.
Block Producers are similar to regular blockchain miners. In this case, instead of proposing blocks in a certain sequence, they propose a set of transactions that will eventually be included before N blocks. The MEVA contract, which is handled by the block producers, is used to choose Sequencers. This auction determines who gets the right to sequence the last N transactions. If the sequencer has not submitted an order that is included by block producers within a timeout, a new sequencer is elected.
Instant Transaction Inclusion: MEVA also allows the current sequencer to give instant cryptoeconomic guarantees on transaction inclusion. They do this by signing off on an order as soon as they receive a transaction from a user, even before it is transmitted to a block producer. If the sequencer fails to put the transaction in the index as promised, the user may submit a fraud proof to the MEVA contract, which will result in the sequencer being slashed.
Layer-2 Implementation: The MEVA contract can be implemented directly on layer 1 (L1) of the blockchain. But it is more feasible to implement this in layer 2 (L2) and use it to manage Optimistic Rollup transaction ordering. L1 miners are simply repurposed and used as block proposers in layer 2. A MEVA contract is then implemented, and a single sequencer is designated at a time. In Layer 2, it allows us to freely experiment with different auction parameters while also realigning Ethereum incentives to return back into the ecosystem.
BackRunMe by bloXroute is a service that allows users to submit private transactions for protection against frontrunning and sandwich attacks while also allowing searchers to backrun the transaction via MEV if it provides an arbitrage profit opportunity. It returns a share of the additional profit to the user.
In the image given below, we can see the profit sharing structure of this service.
Image Source: bloXroute
Searchers only receive metadata about the private transaction and do not have access to the signed raw transaction . As a result, they are unable to submit a regular MEV bundle. bloXroute will only create a MEV bundle if the proposed transaction by the searcher is a backrun transaction that pays the user 40% of the profit.
Also, users can directly use MetaMask with backrunme to trade on Uniswap or Sushiswap.
In the image given below, we can see how the BackRunMe service works.
If a transaction does not provide an arbitrage profit opportunity, it will be executed as a regular private transaction, i.e., it will be sent to miners via private communication.
Where are we today?
The introduction of Flashbots' MEV relay has lowered gas prices for regular users by reducing the impact of Generalized Frontrunners and taking gas price auctions off-chain. Many searchers are still profiting from MEVs, as opportunities become more well-known and more searchers compete for the same chance. The next era will come when miners begin actively exploiting MEV. Various techniques are now being explored by developer communities to reduce the threat of MEV in the future.
Image Source: MEV-Explore v1
MEV Post Merge
The Flashbots team, EF Research team, Client Implementation teams, and Staking Service Providers have created MEV-Boost, i.e., Merge Ready Flashbots Architecture.
Validators can outsource the process of block creation to a network of third-party block builders. While validators can add any payload into the chain, network neutrality and validator revenue are maximized when the validator's role is limited to picking the payload that pays the most ETH. On the validator side, this design employs MEV-Boost, an independent middleware that resides between the consensus client and the execution client. This middleware supports relay communication, profit switching logic for selecting the most valuable payload, and a fallback mechanism for a local execution client if relays fail.
Image Source: EthResearch
We should note that relays should only be used for payloads during block creation. If relays are unavailable, validators should always resort to local payload creation. This model allows solo stakers to participate in MEV, thus reducing the incentive for economic centralization. This approach, however, necessitates validators' trust in the relay to filter invalid payloads, accurately report payload value, and reveal transaction content once the header is signed. Escrows increase data availability by replicating transaction content across multiple providers.
The goal of transaction fees was to encourage miners to validate transactions and secure blockchain networks. MEV is a greater concern for ordinary users than the present excessive gas prices. A high-value AMM transaction will draw the attention of MEV predators. MEV will soon outnumber the regular Ethereum block reward. Some regard this as an existential threat to Ethereum.
Q1) Why was MEV formerly known as Miner Extractable Value?
- This is because, in a Proof-of-Work scenario, miners control transaction inclusion, exclusion, and ordering.
Q2) What are the views of Vitalik Buterin on MEV?
- Vitalik Buterin has explained his opinion regarding MEV in Lex Fridman's podcast . Here is a short clip for those who only want to know about his view on MEV.
Q3) How Developers create MEV opportunities?
- Developers create MEV opportunities through their design flaws, such as giving block producers more power to sequence transactions, in turn making MEV possible.
We would like to thank Moloch DAO for support.
- An overview of Decentralized Finance (DeFi)
- Ethereum Layer 2 projects: An Overview
- Deriswap, an all-in-one DeFi protocol
- DeFi pushing Ethereum towards trillion dollars transactions
Disclaimer: The information contained on this web page is for education purpose only. Readers are suggested to conduct their own research, review, analyze and verify the content before relying on them.
To publish press releases, project updates and guest posts with us, please email at email@example.com.
Subscribe to EtherWorld YouTube channel for easy digestable content.
Support us at Gitcoin
You've something to share with the blockchain community, join us on Discord!