• Pricing
  • Enterprise
  • Customers
  • Blog

What is MEV and how does Solana solve its MEV issues

Introduction

MEV, or “maximal extractable value”, “miner’s extractable value”, and “maximum extractable value”, is a unique word in the blockchain space. Despite several variants of the term, nowadays MEV usually refers to extracting the value from transaction ordering on the chain.

In this article, we will take a look into MEV: how people do it; the scale of this problem, and how blockchains like Solana deal with it. Below is a brief outline of this article:

  • The evolution of MEV
  • The impact of MEV on Ethereum
  • The differences between Solana and Ethereum
  • The common types of MEV activities

From MEV (miner extractable value) to MEV (maximal extractable value), the evolution of blockchain

You may come across MEV many times, but most likely in different forms:

  • Maximal extractable value
  • Maximum extractable value
  • Miner extractable value

And you are wondering if they mean different things.

Well, the short answer is no. They are referring to the same thing.

Let us start with Ethereum because that is where it all began.

When Ethereum was proof-of-work, miners packed transactions into a block, and they were able to decide to include or exclude certain transactions or rearrange the order of these transactions. This gave the miners an advantage over regular users.

For example, this is Derp and Derp wants to buy an NFT:

Figure 1: MEV frontrunning an NFT purchase

That was an oversimplified illustration of NFT frontrunning, which is one type of MEV. When a miner decides to play around with the system, there is no effective mechanism to protect regular users from the attack.

And the worst part is, that Derp even must pay the miner gas fee for validating his transaction.

And that is why MEV was called “miner extractable value” initially. Because in theory, only the miner can decide the ordering of transactions in a block.

In practice, however, a large portion of MEV is extracted by independent network participants, who were referred to as “searchers”. This is because:

  1. On Ethereum, pending transaction information is transparent to all users through a node’s mempool.
  2. The order of transactions depends mostly on the amount of gas fee included in each transaction.

Taking Derp as an example. Derp wants to buy another NFT. This time, he makes sure that his miner is not a malintent miner. Derp sends his transaction request paying a 0.1 ETH gas fee.

Derpina sees Derp’s transaction and decides to front-run this transaction. So, she sends a duplicate transaction, but with a higher gas fee.

The miner packages Derpina’s transaction first because the gas fee is higher. As a result, Derp’s transaction fails, and Derpina gets the NFT. Poor Derp lost his gas fee too.

This was also an oversimplified example. In the real world, MEV activities are far more complicated and diversified. Searchers run complex algorithms on blockchain data to detect profitable MEV opportunities and have bots to automatically submit those profitable transactions to the network.

Since MEV is no longer limited to miners, MEV eventually becomes the common abbreviation of “maximal extractable value” instead of “miner extractable value”. But people still use them interchangeably.

The endless debate around MEV

Some people see MEV as a threat to the ecosystem for example Vitalik Buterin.

Figure 2: Vitalik Buterin’s tweet on frontrunning back in 2020

But there are also many people who believe that banning MEV will eventually lead to corruption of the “decentralization” aspect of a blockchain.

Initially, on Ethereum, MEV was brought to people’s attention as early as 2018. Since then, millions of dollars have been spent to battle against MEV activities. However, there has not been one concrete solution to it yet.

According to a BIS report, the amount of MEV has increased exponentially since 2019. in 2022, the total MEV on Ethereum has amounted to an estimated USD 550–650 millions, which is 5 times the amount two years ago.

Figure 3: Measures of miner extractable value are accumulating over time; Source: BIS(https://www.bis.org/publ/bisbull58.pdf)

Being a completely different type of blockchain, Solana has MEV issues just as Ethereum. In this article, we will take a closer look into MEV on Solana.

Differences between Solana and Ethereum

Solana is a very different blockchain. Some characteristics of Solana make it not suitable for certain MEV activities.

First, let us look at how Solana and Ethereum are different.

  1. Solana is a proof-of-stake (PoS) chain. In a PoS chain, instead of miners, validators finalize transactions. Each validator node is staked with a large number of tokens, which serves as a security deposit to ensure the performance and reliability of a validator.
    On Ethereum as of proof-of-work, there was no effective mechanism to penalize a faulty miner. However, this is not hold true after the merge.
  2. Solana validators are grouped into clusters. to finalize a transaction, all validators in a cluster vote to decide if the transaction is valid.
    At each point in time, one cluster has one leader. The leader decides only the order of transactions to be voted, but not the finality of the transaction. Each validator takes turns acting as the leader validator.
    This ensures its safety will not be compromised by a single bad actor.
  3. Unlike Ethereum, Solana nodes do not have a mempool, which means searchers can’t target individual transactions unless they are a validator.
  4. Solana has a standardized gas fee, which means searchers can’t front-run or back-run any transaction. (We will talk about front-running and back-running later).
  5. Non-leader validator nodes vote for transactions in FIFO (first in first out) order, which limits the possibility that any malintent validator holds certain transactions indefinitely.

All these make some MEV techniques from Ethereum not viable on Solana. However, Solana nurtures its own MEV issue, which will be discussed below.

Technical requirement

Nowadays many MEV strategies are around DeFi platforms. To analyze the current MEV situation on Solana, we choose Raydium for our research. Raydium is one of the biggest Automated Market Maker (AMM) exchanges on Solana. According to DefiLlama, it has $218M TVL (total value locked) at the time of writing (August 2022).

Figure 4. Total value locked in Raydium from DefiLlama

Here is an online Python script to extract and analyze data from Raydium. It is hosted on Google Colab. It is a notebook script—you can either run it in your browser or download the file and run it with a local Jupyter notebook.

The detail of this Python script can be found in this article.

In order to run the script, you will need a Solana endpoint.

The sample code is developed and tested with a Chainstack Solana node endpoint—it is highly recommended for the following reasons:

  • No limits on the request rate.
  • Free Solana node endpoint with 3 million free requests.
  • Fast node deployment.

MEV on Solana

Types of MEV techniques – DEX arbitrage

How does it work?

Decentralized exchange (DEX) arbitrage is likely to be the most common MEV activity.

Imagine two DEX on Solana, Raydium, and Orca, each has its own liquidity pool. At one point in time, they are offering SOL and USDC swap pairs at different exchange rates.

Arbitrage traders seek opportunities like this. They will make two swap transactions to Raydium and Orca, earning profit from counter swapping SOL -> USDC -> Sol. Simple as that.

Figure 5. Counterswapping SOL/USDC

Case study

Below is an example of a profitable arbitrage transaction where a searcher turned 8.2452 USDC into 8.2682 USDC by taking advantage of different pricing on Raydium and Orca.

Arbitrage on Solana

In a stable market, arbitrage trading is usually profit guaranteed and relatively simple to set up. So there are many arbitrage bots running on Solana. Arbitrage trading is very competitive. Of all transactions on Raydium, about 80% are failed or invalid arbitrage transactions.

In the Solana community, the opinion on arbitrage is diversified. Some people think arbitrage is bad because it congests the network and is wasting computation resources.

Others treat arbitrage as a market corrector. It ensures the DEXes have a uniform exchange rate across platforms, even across chains.

Analysis

The profitability of arbitrage is co-related to the volatility of the crypto market. It is because the only time arbitrage works are when there is a significant exchange rate mismatch between two liquidity pools. In a volatile market, for example (an extreme one though) during Terra’s collapse, when every holder of Luna tries to escape at any cost, the exchange rate of Luna and USDC falls almost 100%. That is when an arbitrage opportunity arises.

Types of MEV techniques—sandwich trading, front-running, and back-running

Sandwich trading is another type of MEV extraction technique. Sandwich trading is sometimes referred to as a sandwich attack because it happens around a target transaction, and a successful sandwich trading will result in an increase

How does 🥪 trading work?

To sandwich, a searcher will watch the mempool for large DEX trades. For instance, suppose Derp wants to exchange 10k SOL for USDC on Sushi swap.

Figure 6. Exchange rate before a large swap

A trade of this magnitude will significantly reduce the amount of SOL in the liquidity pool. Resulting in a significant increase in the price of USDC.

Figure 7. Exchange rate after a large swap

This is an ideal target for sandwich trading. A searcher can measure the approximate price change, and decide to front-run, back-run, or sandwich attack Derp’s transaction.

Sandwich trading in a nutshell:

  1. Searcher buys 40000 USDC before Derp’s transaction with 1000 SOL (front-run).
  2. Derp’s transaction makes USDC cheaper, the exchange rate is now 1:38.
  3. Searcher sells the 40000 USDC for 1052.6 SOL. Making a 5% profit.

Finding sandwich trading on Solana

After carefully examining 600K transactions in Raydium, no evidence of a sandwich attack was found.

A typical sandwich trading has 3 parts: A “victim” transaction; a front-run and a back-run transaction that contains the same trading pair as the victim transaction. A successful sandwich attack should have the following characteristics:

  • The attacker exchange X amount of tokens in the front-run transaction and immediately swap back the same amount in the back-run transaction.
  • There is a potential “victim” transaction that contains the same token pair between the front-run transaction and the back-run transaction.
  • The front-run transaction and the back-run transaction are executed relatively close, usually within a few seconds.

After examining all the transactions from Raydium, there is no transaction that matches the above characteristics.

So, why is the Solana sandwich attack free?

On Ethereum, there are several features that are necessary for sandwich trading.

One of the primary features is its mempool design. On Ethereum, everyone has access to the mempool and anyone can examine the transactions before they get finalized.

In contradiction, Solana is a mempool-less chain. Theoretically only validators, in fact, only the leader validator has access to the transactions. But in a PoS chain like Solana, the suspicious activity may cause the validator to lose its deposit/stake, which ensures the reliability of the network.

Types of MEV techniques—NFT bot

MEV in the NFT space is an emerging phenomenon, especially on Solana.

For example, if there’s a popular NFT launch and a searcher sees that as a profitable opportunity.

Figure 8. MEV NFT opportunity

NFT bots will swarm the NFT minting program with mint requests, trying to get as many tokens as possible in a short period of time and resell them immediately.

Figure 9. NFT bots spamming mint requests during NFT launch

NFT bot wasn’t considered a threat until people realized that it not only damage the NFT market but also congests the network as no other MEV bot does.

Battling with NFT bots

One solution to the MEV bot is adjusting the transaction gas fee, which increases the cost of sending spam requests on Solana. That is also the reason why the NFT MEV bots are less significant of a problem on other blockchains like Ethereum.

Another solution from Solana’s primary NFT minting program Metaplex is imposing a “tax” for invalid transactions. Which also increases the cost of sending invalid requests.

Metaplex also introduces Dynamic pricing Mint. Basically, the more popular an NFT is, the higher the launch price will be. Which disincentivized bots from swarming an NFT launch.

Both initiatives are announced recently, hoping to solve Solana’s botting problem.

Conclusion

There is always a lot to explore in MEV, especially with the latest Ethereum transition to proof-of-stake. If you want to experiment with MEV, you can do so with our MEV API on the Ethereum Mainnet and the Ethereum Goerli Testnet.

In this article, we talked about:

  • What is MEV and how it has evolved over time.
  • The differences between Solana and Ethereum.
  • What are the MEV activities on Solana and how do people tackle the issues.

Hope you find it useful and enjoy reading it.

For any questions, feel free to ping me on Twitter/Telegram/Discord.

Happy coding.

Cheers.

Have you already explored what you can achieve with Chainstack? Get started for free today.

SHARE THIS ARTICLE