Sitemap
Ashutosh Tiwari

Ashutosh Tiwari

Technical Writer & Researcher | Blockchain / AI

Understanding MEV.

What’s Really Happening Behind Your Crypto Trades?

9 min readNov 3, 2024

--

Press enter or click to view image in full size
An image of a searcher making profits from MEV

Let’s say you’re standing in line at a busy coffee shop. The person behind you hears your order and quickly jumps in front of you, buys all the remaining coffee, and sells it to you at a higher price. Something similar happens in the crypto world all the time — we call this MEV, or Maximal Extractable Value.

What is MEV

MEV used to mean “Miner Extractable Value,” but now it stands for “Maximal Extractable Value.” Why the change? Because it’s no longer just miners who can take advantage of it — others can too. Let’s make it easy to understand.

Press enter or click to view image in full size

Maximal extractable value (MEV) is the maximum value block producers (miners or validators) can obtain by including, reordering, or excluding transactions when producing a new block.

How Transactions Work:

But, first the main question is How does a transaction works? When you make a crypto transaction, like sending or swapping coins, it first goes into a waiting area called the “mempool.” Here, it waits its turn to be processed. Miners or validators then decide the order of transactions, choosing which ones go through first. Finally, the chosen transactions are grouped together and processed in blocks.

It happens in stages basically:

➩You click send or swap.
➩Your transaction joins a waiting line (called the mempool)
➩Someone (miners or validators) picks which transactions go through first.
➩These transactions get processed in blocks.

Press enter or click to view image in full size
source: helius.dev(blogpost)

If you’ve ever:

a)Swapped tokens on Uniswap or any DEX
b)Provided liquidity to a DeFi protocol
c)Made a large cryptocurrency transaction
d)Used any DeFi application

Then MEV has likely affected your trades, often without you realizing it. As the validator will then likely put the bot transactions ahead in the ordering of transactions in the block, because it will receive more in gas fees. This allows the bot’s transactions to beat the original user to execution and “extracts” the value for both the validator (in higher gas fees) and the bot itself. This is the simplest example, or pattern, of how MEV works, and is known as a “generalized frontrun.” Other examples — including decentralized exchange (DEX) arbitrage and sandwich trades — are covered next.

Press enter or click to view image in full size
source: research papers internet

As you can see from the above example that Users first pay the gas fees while making the transactions on the blockchain submits transaction and it went to transaction ordering where there are searchers builders and relayers waiting for the transaction to enter in the mempool

What is a Mempool?

When a user initiates a transaction on a blockchain network, it doesn’t immediately become part of the blockchain. Instead, it enters the mempool, where it waits to be picked up by miners or validators and included in the next block. The mempool is a pool for unconfirmed transactions.

The mempool is crucial to MEV because it provides a window of opportunity for MEV extractors. By observing the mempool, these actors can:

a)Identify profitable transactions before they’re included in a block
b)Insert their own transactions to capitalize on opportunities
c)Reorder transactions to maximize their profit

This “mempool watching” is the foundation of many MEV strategies, including front-running, back-running, and sandwich attacks, let’s have a look at each one of them.

Press enter or click to view image in full size
image credits: Transak.com

How the Mempool Works

  1. USERS: Users first sign and send the transaction and there can be that many users sending it to the mempool or memory pool.
  2. MEMORY POOL: Also known as “mempool” nodes in the network receive the transaction and add all the transactions that aren’t complete.
  3. MINER: Nodes perform preliminary checks on the transaction to ensure it’s valid (e.g., the sender has sufficient funds).
  4. BLOCK OF TRANSACTIONS: Miners or validators select transactions from the mempool to include in the next block, typically prioritizing those with higher gas fees.

If two transactions arrive at nearly the same time, both using about the same amount of gas, the user willing to pay more per unit of gas will be processed by the Ethereum Virtual Machine (EVM) first. Meaning users communicate their desire to be processed by the EVM through the price they are willing to pay for gas. This is similar to a classic first-price auction; in Ethereum, this process happens in groups of transactions every 12 seconds.

Types of MEV Strategies

MEV extraction comes in various forms, each with its own mechanics and implications. Let’s explore the most common MEV strategies:

Front-running

Front-running is perhaps the most well-known MEV strategy. It involves observing a pending transaction in the mempool and then submitting a similar transaction with a higher gas price to ensure it gets processed first.

Press enter or click to view image in full size
image credits: Rileygmi.substack

A malicious actor raises the gas fee on their transaction to give miners an extra incentive to process it first. By offering this higher fee, they encourage miners to prioritize their transaction over the original one in the block. Although this cuts into the attacker’s profit, the higher gas fee is key to the front-running strategy, making it more likely their transaction will go through first and ensuring the attack’s success.

Back-running

Back-running is the opposite of front-running. Instead of trying to get ahead of a transaction, back-runners aim to place their transaction immediately after a target transaction.

Press enter or click to view image in full size
image credits: Rileygmi.susbtack

How Back-running Works:

➩A back-running bot identifies a transaction that will cause a significant price change.
➩The bot submits its own transaction to be processed immediately after the target transaction.
➩The bot profits from the price discrepancy created by the original transaction.

Get Ashutosh Tiwari’s stories in your inbox

Join Medium for free to get updates from this writer.

Back-running is often used in larger trades for arbitrage strategies, taking advantage of price change

MEV Sandwiching

MEV Sandwiching combine elements of both front-running and back-running. In this strategy, an MEV extractor “sandwiches” a target transaction between two of their own.

Press enter or click to view image in full size
image credits:blocknative.com

MEV sandwiching or “sandwich attacks” is a tactic in Defi in which an MEV searcher profits from price changes. Here’s how it works: the searcher places a buy order just before a large purchase to push the price up. Once the large purchase is confirmed, they quickly sell at the higher price, taking advantage of the predictable price jump.

How Sandwich Attacks Work:

➩The searcher spots a large pending trade in the mempool.
➩They place a buy order just before the target transaction (front-running).
➩The target transaction is executed, driving up the price.
➩The searcher immediately sells at the higher price (back-running).

Sandwich attacks can be highly profitable but also carry more risk, as they require precise timing and execution and that’s why chances of it happening is lesser.

DEX Arbitrage

A DEX arbitrage happens when the same token is priced differently on two decentralized exchanges (DEX), like Balancer and 1inch. A bot spots this price difference and buys the token at the lower price on one exchange, then sells it at the higher price on the other — all within a single transaction. This trade is “risk-free” because the transactions are happening together both buy and sell are taking place in the same transaction. If anything goes wrong, the whole transaction fails, so the bot doesn’t lose money on just the purchase.

Press enter or click to view image in full size
source: antier.solutions

How Arbitrage Work:

➩A Searcher start with asset 1 and sell it for asset 2 on the exchange where asset 2 is cheaper.
➩ Then, he take asset 2 and sell it back for asset 1 on a different exchange, where he ends up with more of asset 2 that he started with.

Currently, this type of arbitrage is very competitive, with many MEV searchers racing to complete these trades first.

Liquidations

On-chain lending platforms let users borrow tokens up to a certain amount based on their deposited collateral. As market prices fluctuate, the ratio of the loan amount to the collateral changes, but the required ratio set by the protocol stays the same. If the value of the collateral drops too much, falling below the protocol’s requirements, the loan is liquidated (i.e., canceled), and a fee is charged to the borrower.

Third parties (often bots) handle these liquidations, receiving part of the fee as a reward. MEV bots, for example, can monitor the blockchain for loans close to liquidation, then perform a “margin call” transaction to liquidate the loan and earn the fee.

Liquidations help clear risky or bad debt, ensuring borrowers get back what remains of their collateral and that non-performing loans are closed. But, they can also be misused.

Press enter or click to view image in full size
image credits: galaxy

For example, a bot might manipulate token prices to trigger a liquidation that wouldn’t have happened otherwise. Or, a bot could block a borrower’s attempt to add more collateral to save their loan, forcing them into liquidation. These strategies allow bots to profit from others a disadvantage in ways that can be seen as harmful.

Conclusion

Over the past year, opportunities for MEV have grown along with the rise of DeFi. Some types of MEV, like sandwiching, make money by taking advantage of regular traders, while others, like arbitrage, are considered helpful because they make the market more efficient and liquid. The most common types of MEV on Ethereum are arbitrage, liquidations, and sandwiching, although new techniques are constantly emerging as DeFi evolves.

MEV exists because Ethereum validators can choose the order of transactions in each block they create. This power was meant to prevent spam, but it’s led to a system similar to high-frequency trading in traditional finance. Both MEV and high-frequency trading profit by placing transactions in a specific order, often ahead of others, which can harm regular traders. This has led some users to look for private ways to trade.

Unlike traditional finance, Ethereum has no central authority to control MEV. The only “rules” are coded into Ethereum itself, so it’s up to protocol developers, dApp users, and the Ethereum community to decide which types of MEV are okay and which aren’t.

Trying to control MEV comes with compromises. Flash-bots Auction, for example, has brought transparency to MEV but also made it easier for miners to rely on it for extra profit. Flash-bots moved much of the MEV competition off-chain, reducing network congestion but creating a centralized system that most miners now depend on.

Future upgrades to Flash-bots aim to make it less centralized, but transaction order manipulation is likely to remain. As MEV and DeFi keep growing, the real challenge will be to keep trust and stability in the Ethereum ecosystem over time.

In my next article, I’ll cover the ways to mitigate MEV and prevent losses from it. Until then, feel free to reach out on X @Ashutosh01225 — I’d love to hear your feedback!

……………………………………………………………………………………………..

References

1.https://www.galaxy.com/insights/research/mev-how-flashboys-became-flashbots/

2.https://rileygmi.substack.com/p/what-is-mev-a-simple-guide

3.https://chain.link/education-hub/maximal-extractable-value-mev

4.https://bitquery.io/blog/different-mev-attacks

5.https://www.blocknative.com/blog/mev-and-creating-a-basic-arbitrage-bot-on-ethereum-mainnet

--

--