Beginner's Guide to MEV (2024)

September 10, 2024

(Updated:

)

Arkham
Research Team

Table of contents

    Beginner's Guide to MEV

    INTRODUCTION

    In most blockchains, transactions that have been submitted to the mempool are arranged into a block before being added to the existing chain of prior blocks by validators or miners. 

    Maximal Extractable Value (MEV), also called Miner Extractable Value, refers to strategies that can be employed to profit from this process by rearranging, including or omitting specific transactions from a block. These strategies are executed by experienced blockchain users, known as MEV searchers, using bots to automate, accelerate, and scale their activities.

    The profit derived from MEV strategies is sometimes referred to as ‘invisible tax’ as most casual blockchain users are unaware of its existence while bearing the cost of negative externalities generated by MEV activity.

    SUMMARY:

    • MEV refers to the maximum profit that can be generated by rearranging, including or removing transactions from a block before it is finalized.
    • MEV searchers compete with one another to find profitable MEV opportunities.
    • These opportunities can range from beneficial to users, in the case of arbitrage, to directly harmful to users, in the case of sandwich attacks and frontrunning.
    • The negative impacts of MEV can be mitigated through strategies such as private RPC endpoints, specific DApp level design or even blockchain level architecture.

    HOW DOES MEV WORK?

    To understand how MEV works, one must first understand how blockchains work. For simplicity, these examples will reference the Ethereum blockchain.

    When a user submits a transaction, it is not immediately executed and added to the blockchain. First, it is received by an Ethereum node, which then broadcasts the transaction to its peer nodes. As nodes receive the transaction, they will perform checks to ensure that the submitted transaction is valid. These checks include signature validity, whether the user has sufficient funds on their wallet and more. Once deemed valid, the node adds the transaction to their own mempool. When in this unconfirmed state between the initial broadcast and finalization on-chain, transactions are considered to be in the ‘mempool’ (derived from the words “memory” and “pool”).

    Validators pick up transactions from the mempool to form the next Ethereum block. Under ordinary circumstances, transactions are included and ordered into each block in decreasing order of ‘gas price’. A ‘gas price’ is how much a certain transaction is willing to pay for ‘gas’, which is used to allocate Ethereum’s blockspace. Transactions with a low gas price may end up stuck in the mempool for prolonged durations or even dropped entirely. Once the transaction is added to the chain in a new block, nodes will see the transaction on the chain and subsequently remove it from their mempools.

    Block Building Diagram
    Block builders organize transactions based on fees (Source: Chainlink)

    Since there is a time gap between a transaction reaching the mempool and it being added to a block, there is a window of opportunity for MEV searchers. These searchers can submit transactions to be ordered before and/or after target transactions by paying specific amounts of gas. This changes the final transaction order of the block, resulting in a profit for the MEV searcher. 

    COMMON MEV STRATEGIES

    FRONT-RUNNING

    ‘Front-running’ refers to a MEV searcher identifying another trader’s buy or sell order in the mempool and placing an identical order before the trader, profiting from the price impact of the victim’s transaction.

    For example, an MEV searcher scanning the mempool might notice a large pending buy transaction - this would result in a positive impact on the target token price. The MEV searcher can then place a buy transaction with a higher gas price than the target. This usually means that their order will be processed before the target at a lower price, and will profit once the target’s transaction has been finalized. In the process, the target suffers a loss as they are buying at a higher price, due to the price impact from the MEV searcher’s buy transaction.

    SANDWICH ATTACKS

    A sandwich attack is a subset of the front-running strategy, in which the MEV searcher places a transaction immediately before and after the target transaction.

    Sandwich Attacks Explained
    Understanding sandwich attacks (Source: Medium)

    Let’s say we have two users, Alice and Bob, where Alice is the victim and Bob is the MEV searcher. Alice places a buy order for PEPE on Ethereum, which is then broadcasted to the Ethereum mempool. Bob’s MEV Bot notices her transaction in the mempool and decides to ‘sandwich attack’ it. His bot submits an order to purchase a large amount of PEPE, paying a higher gas fee than Alice to make sure that his transaction is placed before hers. At the same time, Bob’s MEV Bot also submits a sell transaction for the entire amount he bought, but this time with lower gas than Alice’s transaction.

    Bob’s buy order causes the price of PEPE to rise, causing Alice’s buy to be executed at a higher price than she initially expected. Bob’s second transaction, the sell order, is processed immediately afterwards, where he can sell the PEPE tokens for a gain, taking advantage of the price impact of Alice’s buy order. This completes the sandwich attack. For tokens with less liquidity, a lower amount of capital is required to create the price impact required for the sandwich attack and vice versa.

    According to MEV data aggregator EigenPhi, sandwich attacks are the second most common MEV strategy, netting MEV searchers $1.2 million in profit over the last 30 days as of May 2024.

    ARBITRAGE

    Arbitrage is a trading strategy involving the simultaneous purchase and sale of the same asset on two separate markets in order to profit from a divergence in price on the two markets. On centralized exchanges and in traditional finance, this is a commonly executed strategy by high frequency traders. On the blockchain, this strategy plays out slightly differently due to the way blockchain transactions are processed.

    The process starts when MEV searchers notice a buy or sell transaction in the mempool with a significant price impact on an individual liquidity pool. For example, a trader buying ETH with USDT on Uniswap will result in a price impact in the Uniswap liquidity pool, but not on a different decentralized exchange (DEX) such as Sushiswap. As such, the MEV searcher can submit two transactions simultaneously in a bundle, to take advantage of the divergence in price between the two liquidity pools. In the above example - if a trader buys ETH on Uniswap, a MEV Bot might have the opportunity for profit by buying ETH on Sushiswap with USDT, and selling it on Uniswap for a slight gain in USDT.

    Since DEXs process billions in transactions daily, arbitrage transactions make up the majority of MEV transactions, generating $4.4 million in profit over a 30 day period in May 2024 according to EigenPhi.

    LIQUIDATIONS

    In DeFi lending protocols, users can take loans against their crypto assets with defined liquidation thresholds. If the value of the crypto assets provided as collateral falls below the loan’s liquidation threshold, the loan will become eligible for liquidation. This means that the user’s crypto assets are sold off to pay for the assets they had borrowed. Lending protocols rely on liquidators, who buy up the remaining collateral at a discount to market value, then repay the initial loan. Any remaining funds will form the liquidator’s profit.

    Since liquidating someone else’s loan is often seen as a risk-free profit, this makes liquidations another avenue in which MEV searchers compete for profit opportunities.

    JIT LIQUIDITY PROVISION

    With the advent of concentrated liquidity on automated market makers (AMMs), liquidity provision has also turned into a highly profitable MEV driven strategy which is sometimes known as Just-in-Time Liquidity Provision.

    Example Diagram of JIT Liquidity Provision
    An example of Just-in-Time Liquidity Provision (Source: Uniswap)

    In this strategy, a MEV searcher first detects a large swap in the mempool, and calculates the price range in which this transaction will occur. The MEV searcher deposits liquidity in the required price range immediately before the transaction is processed, earning the bulk of the trading fee, then removes the liquidity immediately after the target transaction takes place.

    ENTITIES WHICH RUN MEV STRATEGIES

    Many large funds and trading firms operate MEV Bots on-chain. These entities can be easily identified on Arkham by searching for the “MEV” tag.

    Arkham MEV Tags Page
    Some of the prominent MEV players on Arkham

    One such group is Symbolic Capital Partners, a crypto fund which regularly participates in MEV strategies such as arbitrage and liquidations.

    Looking at one of their past arbitrage transactions, the MEV bot arbitraged a divergence in the price of Maple Finance’s governance token, MPL. The bot first swaps 0.00005 WETH for 17.06886 MPL tokens on Uniswap V2 while simultaneously swapping the same amount of MPL tokens to 0.0544 ETH on a Balancer liquidity pool. From the transaction alone, this earned the bot a profit of 0.054337 ETH. After accounting for the priority fee of 0.0347 ETH paid to the block builder, this arbitrage transaction netted the bot a profit of 0.015 ETH. A relatively small profit, but these profits can add up when MEV strategies are executed automatically at scale.

    Transactions by Symbolic Capital Partners
    Arbitrage transaction by Symbolic Capital Partners' MEV bot (0xA69)

    THE IMPACT OF MEV ON BLOCKCHAIN USERS

    MEV strategies used in liquidation and arbitrage scenarios tend to provide a net benefit for individual traders. Arbitrage keeps DEX markets operating efficiently and Liquidations prevent lending protocols from taking on bad debt.

    That said, some MEV strategies also extract value from individual traders’ orders. Front-running and sandwich attacks directly profit from the victim’s losses on slippage. In severe cases, where users mistakenly set high or no slippage limits on their swaps, users can lose most or all of their order in a single swap.

    Additionally, since successful MEV strategies often rely on bots manipulating gas prices, a high profit MEV opportunity will often result in a spike in gas prices, or ‘gas war’. During a ‘gas war’, it is common for gas prices to spike by more than 10-20 times the standard levels, as many different MEV Bots bid for each profit opportunity. This makes it many times more expensive for users to transact on-chain during periods of heightened MEV activity, although this has been somewhat remedied thanks to off-chain MEV auctions through Flashbots

    STRATEGIES TO MITIGATE THE HARMS FROM MEV

    A number of different measures have been developed to mitigate the negative impact of MEV on crypto users.

    One measure is through using MEV-protected or private RPC endpoints. The majority of MEV searchers only scan the public mempool, which allows anyone to view pending transactions and attempt to profit from those orders. Private RPC endpoints do not broadcast transactions publicly in the mempool, and instead submit them directly to the block builders. This prevents MEV searchers from viewing the details of potentially vulnerable transactions before they are finalized.

    At the application level, MEV-protected DEX Aggregators such as CoWSwap have emerged to protect their users from harmful MEV attacks. A user making a trade through CoWSwap will submit their trade through signing an off-chain “intent to trade” message rather than submitting a typical swap transaction. These trades are then passed on to a network of “solvers”, which use sophisticated strategies to find the best route for the end user.

    Unlike swapping on DEXs, CoWSwap transactions are processed in batches - all user trades in a fixed time period are included in the same batch and fulfilled at a uniform price. On a DEX, transactions even in the same block are processed sequentially based upon gas order - which leaves room for MEV, as the order of transactions in a single block may heavily influence the price at which a user’s trade is confirmed.

    CoWSwap Batch Auctions Visualized
    CoWSwap’s batch auctions (Source: CoWSwap Documentation)

    At the chain level, Ethereum has implemented a solution to combat centralized MEV: Proposer-Builder Separation (PBS). Previously, validators served both the functions of block builder and block proposer, which enabled institutions who could more efficiently extract MEV to out-compete other validators in terms of profitability. PBS introduced a new class of entities known as block builders, which order transactions and build blocks, while validators simply select the highest-paying block to add to Ethereum. While MEV now moves to the block builder level, validators still receive the MEV earnings from these blocks, enabling fairer distribution of MEV rewards to individual validators and solo stakers. This prevents institutional validators from out-optimizing solo stakers, who may not be as proficient at MEV extraction.

    CONCLUSION 

    MEV refers to value that can be extracted from the mining and validation process in blockchains. Fundamentally, this represents market inefficiencies that can be exploited in the same block as they are processed. These inefficiencies may occur through an excessively large order size, a poorly optimized protocol or a period of high on-chain activity.

    Some MEV strategies, such as arbitrage and liquidations, perform a role that is widely deemed as neutral or even beneficial to DeFi. However, MEV strategies such as sandwiching (and in some cases, JIT liquidity provision) take advantage of the existing structure of DEX order processing in order to extract value directly from speculators and/or LP’s.

    The debate on how to ‘solve’ MEV, or minimize its impact on new users is still ongoing. Some chains and rollups have resorted to entirely private mempools and/or centralized validator sets in order to prevent DEX order processing from being exploited by 3rd party participants.

    Top traders on public chains such as Ethereum are diligent when making trades - double checking slippage settings before signing any transaction, and confirming that their orders are not being routed through low-liquidity trading pools. Many traders use DEX aggregators and/or private RPC’s to prevent their orders from being identified by 3rd party MEV Bots.

    Information provided herein is for general educational purposes only and is not intended to constitute investment or other advice on financial products. Such information is not, and should not be read as, an offer or recommendation to buy or sell or a solicitation of an offer or recommendation to buy or sell any particular digital asset or to use any particular investment strategy. Arkham makes no representations as to the accuracy, completeness, timeliness, suitability, or validity of any information on this website and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. Digital assets, including stablecoins and NFTs, are subject to market volatility, involve a high degree of risk, can lose value, and can even become worthless; additionally, digital assets are not covered by insurance against potential losses and are not subject to FDIC or SIPC protections. Historical returns are not indicative of future returns.