HomeKnowledge BaseWhat is MEV? — Maximal Extractable Value Explained

What is MEV? — Maximal Extractable Value Explained

15 min read

MEV or “maximal extractable value” is a hidden tax on all types of Ethereum transactions. Any time you make a DeFi trade, buy or sell an NFT, or lend tokens to a liquidity pool, opportunistic users known as “searchers” may manipulate your trades, resulting in unfavorable prices, failed transactions, and missed opportunities.

To date, MEV has been responsible for more than $1.3 billion in lost value for Ethereum users.

1-what-is-mev.png

MEV is a complex phenomenon with multiple different causes. In this article we’ll take a deeper look at what causes MEV, how it affects traders, and how you can protect yourself.

How Does MEV Work?

MEV is possible because validators are free to order blockchain transactions as they see fit in order to maximize their profits. Proof-of-stake (PoS) blockchains such as Ethereum use parties known as “validators” in order to ensure that the consensus rules of the blockchain are followed by all participants. Validators get randomly selected to add the next block to the blockchain. In this process, they determine what transactions are included in the block, and in what order.

2-what-is-mev.png

When you submit a transaction on Ethereum, it does not immediately get added to the next block. Instead, it first goes into the “mempool” which is the collection of all pending transactions. Validators then pull transactions from the mempool and add them to the next block when it’s time for it to be built.

Here is where the opportunity to extract value through MEV comes in.

Validators are not required to add transactions to the block in the same order that they were submitted by users, so searchers can pay validators a fee to order transactions in a specific way. For example, they can pay to have their transactions come first if they want to frontrun someone else, or they can pay to have their transactions come right after a specific transaction if they want to perform a backrun — both are types of MEV.

Understanding MEV Terms

In order to get a solid grasp of how the different types of MEV work, we must first familiarize ourselves with the function of on-chain trading through decentralized exchanges (DEXs) along with some terms.

Automated Market Makers (AMM): Automated Market Makers are trading mechanisms that allow traders to buy and sell assets in real time. Unlike traditional “orderbook” trading, which relies on counterparties for every transaction (you need a seller in order to buy and a buyer in order to sell), AMMs work by maintaining a constant ratio between the prices of two assets. For example, ETH and COW. AMMs use the formula “x*y = k” to determine a fair price based on the ratio between two assets (x and y) in the liquidity pool.

Any time a trade alters this ratio by depleting the supply of one asset and increasing the other, the prices of the assets adjust in order to preserve the established ratio. For instance, if a trader buys COW and sells ETH, the COW price rises, and the ETH price falls. The opposite happens when traders sell COW and buy ETH.

Slippage Tolerance: When placing a trade, traders set a “slippage tolerance” for their transactions, which represents the maximum price difference they’re willing to accept for their trade. For example, if ETH is trading at $2,000 and you place an order to buy ETH with a 5% slippage tolerance, you’re willing to buy ETH at up to $2,100. If ETH goes above $2,100, however, your trade will fail, as it’s outside your slippage tolerance.

Some slippage tolerance is always necessary because the prices of crypto assets are constantly fluctuating, so by the time your trade executes, the price may have moved. Setting your slippage tolerance too high, however, leaves room for searchers to exploit your trades.

Price Impact: Crypto markets, like all markets, are based on supply and demand. AMMs maintain “liquidity pools” of assets that they use to fill trades. Each trade drains some amount of this liquidity, moving the price of the asset. This price movement is known as “price impact.” The larger the trade, the bigger the price impact.

A trade of $100 ETH will not move the price of ETH very noticeably, since it makes up a tiny fraction of the available liquidity. A trade of $1,000,000 ETH however, will noticeably move the price of ETH.

Transaction Reordering: Blockchain transactions do not always enter the block in the order that they were submitted. Searchers can “bribe” the validators responsible for creating the block to get them to arrange transactions in a specific sequence. This transaction reordering is what makes all of MEV possible.

The Different Types of MEV

Now that we’re familiar with the core concepts at play in MEV attacks, let’s take a look at the different types of MEV.

Frontrunning

Frontrunning is a particular type of MEV that affects all forms of Ethereum transactions including trades, NFT mints, and more. Users can sometimes receive messages like “your transaction may be frontrun” on decentralized exchanges and it’s important to understand what this means.

3-what-is-mev.png

Frontrunning occurs when a user makes a transaction but gets “front run” by an MEV bot who makes the same transactions ahead of them.

  1. Monitoring Pending Transactions: The first step involves monitoring the blockchain network’s mempool, a holding area for pending transactions. Here, frontrunners, who are often sophisticated bots, scan the mempool to identify transactions that can carry significant value that they want to snatch away or that could influence the price of a particular asset.
  2. Selecting Profitable Transactions: The frontrunner will analyze the potential market impact once such a transaction is identified. For instance, if a large buy order for a specific token is detected, the frontrunner knows that this transaction could increase the asset’s price once processed.
  3. Placing a New Transaction: The frontrunner will initiate their buy order for the same asset, intending to get their transaction processed before the initially detected transaction. They typically give the validators a higher “tip” to execute their transaction first in the block in comparison to the target transaction.

Frontrunning disrupts the fair operation of blockchain transactions, leading to distorted prices, value drain, and missed opportunities for everyday traders.

Read more about frontrunning in our article: “What is Frontrunning

Backrunning

Backrunning is another form of MEV that affects various Ethereum transactions, including trades, NFT mints, and more. Unlike frontrunning, backrunning takes advantage of transactions after they have been executed.

4-what-is-mev.png

Backrunning occurs when a user makes a transaction that gets followed by an MEV bot executing a strategic transaction right after theirs in order to capture a price movement.

  1. Monitoring Pending Transactions: Like frontrunning, backrunning attacks begin with searchers monitoring the mempool for profitable opportunities. In particular, they are looking for transactions that cause a large price impact, as the backrunning attack involves capturing the arbitrage opportunity left behind after a large trade.
  2. Finding a Transaction with a Large Price Impact: Once a valuable transaction is identified, the searcher analyzes its impact. For instance, if a large sell order for a specific token is detected, the backrunner knows that this transaction could decrease the asset’s price once processed.
  3. Capturing the Price Impact: By placing a transaction directly after a previous, large transaction, the MEV bot can capture the price movement that the transaction causes on the AMM. The backrunner makes a transaction correcting this price impact and collecting the arbitrage in the process.

Backrunning is considered the least harmful type of MEV. While it still captures value, it does not do it at the expense of the trader. When done in isolation, it only captures leftover arbitrage after a large transaction moves an asset’s price.

Read more about backrunning in our article: “What is Backrunning

Sandwich Attacks

Sandwich attacks are considered the most dangerous type of MEV as they extract the most value from users. A sandwich attack is a combination of frontrunning and backrunning for maximum profit on the part of the searcher.

5-what-is-mev.png

Sandwich attacks occur when a user’s transaction gets trapped, or “sandwiched,” between two hostile transactions — one before and one after. As a result, the original transaction executes at a much higher price than necessary, leading to an inflated price for the original trader and a profit for the searcher placing the two extra trades.

  1. Monitor Pending Transactions: Like all other types of MEV, sandwich attacks begin with searchers monitoring the mempool for profitable opportunities. In this case, they’re looking for trades that will create a large price impact which they can frontrun, capturing the value of the asset before the large transaction, and then backrun after the victim transaction, capitalizing on the price impact.
  2. Perform a Frontrunning Transaction: When a large trade is identified, the searcher will duplicate it and place their own transaction right before the victim’s — in essence frontrunning. The searcher gauges the size of their transaction to cause just enough price impact to push the asset’s price up to the precise slippage tolerance the victim has set.
  3. Execute the Victim Transaction: Since a sandwich attack is a 2-part process, the searcher orders transactions so that the victim’s transaction executes right after the seracher’s frontrunning transaction, but just before their backrunning transaction.
  4. Execute a Backrunning Transaction: After the victim transaction executes, its price impact pushes the price of the asset even further (remember it was already raised as a result of the searcher’s frontrunning transaction). Once this takes place, the searcher executes a backrunning transaction, selling the asset and profiting from the arbitrage.

Sandwich attacks are the most common types of swap-related MEV, taking advantage of a user’s slippage tolerance to cause maximum pain for the trader and maximum profit for the searcher.

Read more about sandwich attacks in our article: “What is a Sandwich Attack

Loss-Versus-Rebalancing (LVR)

Loss-versus-rebalancing (LVR) is a type of MEV that affects liquidity providers (LPs) and accounts for more value loss than all other types of MEV combined.

LVR is different from the swap-based versions of MEV we’ve covered so far. It occurs when liquidity providers lose out on potential profits due to stale prices. Many liquidity providers haven’t even heard of LVR, but it costs them 5–7% of their liquidity, resulting in hundreds of millions lost each year. In fact, when accounting for LVR, many of the largest liquidity pools are not profitable for LPs at all.

6-what-is-mev.png

(Source: Delphi Digital)

LVR is a form of arbitrage that occurs whenever an AMM has an outdated (stale) price in comparison to some other trading venue. Arbitrageurs exploit this price difference by trading from the AMM to the more liquid exchange (usually a centralized exchange like Binance), correcting the arbitrage and extracting value from LPs in the process.

Learn more about LVR in our article: “What is Loss-Versus-Rebalancing (LVR)?

Other MEV

Since the definition of MEV is broad enough to encompass all validator activities that maximize the profits of a given block, there are many other types of MEV that we haven’t covered here as well.

One such example is “Oracle Extractable Value” (OEV) which occurs whenever data from an oracle (such as pricing information) is outdated and searchers can capitalize on this arbitrage at the expense of regular users.

An Example of an MEV Attack

Let’s take a look at a sample MEV attack through the example of the most common type of MEV — the sandwich attack. In this example, we’re going to be trading ETH and COW.

7-what-is-mev.png

Step 1: Bessie wants to buy COW using her ETH. She goes to a decentralized exchange (DEX) like Uniswap, and places an order for 4,000 COW. This should cost her around 1 ETH, but due to significant market volatility, Bessie decides to set a 10% slippage tolerance. This means she’s willing to pay up to 1.1 ETH for 4,000 COW.

Step 2: Bessie’s trade enters the Ethereum mempool (the pending order queue), and a lurking searcher spots an opportunity. Springing into action, the searcher places a trade just before Bessie’s trade that is large enough to push the COW price up to her slippage tolerance. In this case, the searcher buys 4,000 COW for exactly 1 ETH. As a result of this first trade’s price impact, Bessie’s 4,000 COW purchase now costs 1.1 ETH — the maximum she’s willing to pay.

Step 3: Once the searcher’s transaction clears, Bessie’s transaction also goes through and she receives her 4,000 COW in exchange for 1.1 ETH. The searcher takes advantage of this price impact and sells his original COW at this new rate — 4,000 COW for 1.1 ETH.

In the end, the searcher buys 4,000 COW for 1 ETH and sells it for 1.1 ETH, earning a profit of 0.1 ETH (before gas and fees) for not much effort.

It’s easy to see how lucrative sandwich attacks are!

Bessie, on the other hand, ends up with a bad deal. She could have purchased 4,000 COW for just 1 ETH, but her slippage tolerance left room for a sandwich attack that forced her to pay an extra 10% for her trade.

Why is MEV Bad?

MEV is a complex and often controversial topic in the Ethereum community.

Some say that MEV is a natural part of the Ethereum market mechanism and it helps to find the most efficient prices. Others believe that MEV can be harmful, but only if it’s concentrated in the hands of a few validators — therefore they work to “democratize” MEV and allow anyone to extract value from on-chain transactions.

However, MEV makes money for searchers, block builders, and Ethereum validators at the expense of regular users… especially beginners who don’t know how to protect themselves. As of the time of writing, sandwich attacks on AMMs and aggregators alike generate almost $1 million in profit for searchers each week.

8-what-is-mev.png

Over time, persistent MEV erodes market confidence as traders realize they are at a constant disadvantage to more sophisticated actors. Ultimately, MEV may pose an existential threat to blockchain ecosystems like Ethereum so it’s imperative for solutions to emerge that protect everyday traders from price exploitation.

How to Protect Yourself from MEV

There are multiple ways to avoid MEV as a trader. The most comprehensive solutions take place at the dApp level, but not all dApps provide MEV protection so there are more all-encompassing protection methods including RPC endpoints.

Reduce Slippage

The most basic defense against MEV is setting a low slippage tolerance.

Since MEV relies on slippage for price manipulation, transactions with a lower slippage tolerance give searchers less room to exploit trades.

For users who aren’t utilizing any other MEV protection tools, setting a lower slippage tolerance can be a good first line of defense, however it’s by no means a complete solution. Setting the slippage tolerance too low often results in failed transactions. Even with optimal slippage, MEV bots may still be able to extract value from your trades.

Use a Custom RPC Endpoint

9-what-is-mev.png

A better protection method is to install an MEV protection RPC endpoint.

A Remote Procedure Call (RPC) endpoint is an intermediate layer that routes transactions from a user’s wallet to the blockchain itself. Transactions pass through RPC endpoints before getting to the mempool, so RPCs can provide additional functionality across any blockchain application or protocol.

Normally, RPCs are a boring piece of blockchain infrastructure. Recently, however, specialized RPCs have begun incorporating extra security guarantees for transactions before they reach the blockchain.

One of the most popular specialized RPC endpoints is MEV Blocker. As the name suggests, MEV Blocker provides protection against MEV across all of Ethereum. The RPC works by managing a permissionless network of searchers and hiding transactions from the public mempool. These searchers cannot frontrun or sandwich user transactions. Instead, they capture value through backrunning. Anytime a searcher backruns a user’s transaction, the searcher keeps up to 10% of the value and sends the other 90% back to the user as a rebate.

Install MEV Blocker here: https://cow.fi/mev-blocker

Use an MEV-Protected DEX

10-what-is-mev.png

As MEV has become more prevalent, decentralized applications (especially decentralized exchanges) have begun offering creative protection solutions to users. For example, many DEXs offer an “auto-slippage” feature which determines the optimal slippage for user trades, reducing the chances of price exploitation.

CoW Swap is a meta DEX aggregator that finds the best prices for trades and provides comprehensive MEV protection. The protocol uses a unique trading mechanism that relies on batch auctions and intents to achieve the best outcomes for users. Thanks to a powerful combination of delegated trade execution, batch auctions, and protected transaction flow through MEV Blocker, CoW Swap users benefit from thorough MEV protection on all trades.

Try CoW Swap here: https://swap.cow.fi/#/

Maximal Extractable Value — Ethereum’s Existential Battle

MEV is a critical problem for the Ethereum ecosystem because it undermines the fundamental principles of fairness and transparency that blockchain technology aims to uphold. The ability of sophisticated actors to extract value from everyday traders pushes users away and discourages the broad adoption of decentralized technologies.

Addressing — and eventually solving — MEV is essential to keeping Ethereum a robust, innovative, and user-friendly platform for all participants. To this end, CoW DAO is working hard to secure a decentralized future by creating products that ensure a fair and protective decentralized financial system.

Learn more about CoW DAO, its mission, and its various products here: https://cow.fi/.