Flashbots RPCs and Crypto Trading Agents
Introduction to MEV
The Unseen Value in a Block
When you send a transaction on Ethereum, it doesn't get added to the blockchain instantly. First, it goes to a public waiting area called the mempool, along with thousands of other pending transactions. From this pool, validators (previously miners) select transactions to bundle into the next block. They can choose which transactions to include and, crucially, in what order.
This power to order transactions creates an opportunity to capture value. This value is known as Maximal Extractable Value, or MEV.
MEV
noun
The maximum value that can be extracted from block production in excess of the standard block reward and gas fees by including, excluding, and changing the order of transactions in a block.
Think of it like being the editor of a newspaper's financial section. You receive two press releases at the same time: one announcing a massive new partnership for a company, and another from an investor planning to buy a huge number of its shares. Knowing the partnership news will drive the stock price up, you could publish the news first, then the buy order. Or, you could publish the buy order first, then the news. The order matters.
On Ethereum, validators have this editorial power. Specialized bots, called searchers, constantly scan the mempool for profitable opportunities. They then create their own transactions and offer high gas fees (a tip) to validators to get their preferred ordering. The validator, motivated by profit, will often arrange the block in the way that pays them the most.
Common MEV Strategies
MEV isn't just one thing; it's a category of strategies. Some are relatively harmless, like arbitrage between two decentralized exchanges. Others are more predatory and can directly impact users.
Front-running is the act of getting your transaction ordered before a known future transaction.
Imagine a searcher sees a huge buy order for a token in the mempool. They know this purchase will raise the token's price. The searcher can execute a front-running strategy:
- They submit their own buy order for the same token, but with a higher gas fee to ensure it gets processed first.
- Their transaction is placed in the block just before the large order.
- The large order executes, pushing the price up.
- The searcher then immediately sells their tokens at the new, higher price for a quick profit.
Back-running is the opposite. It involves placing a transaction immediately after a specific transaction to capitalize on the state change it creates. For example, if a large trade on Uniswap creates a price difference between it and another exchange like Sushiswap, a searcher can back-run the trade to capture that arbitrage profit.
A sandwich attack combines front-running and back-running to exploit a user's trade.
In a sandwich attack, the attacker wraps a victim's transaction between two of their own. Let's say you're trying to buy a large amount of a token.
- An MEV searcher sees your trade in the mempool.
- They front-run you by buying the same token first, pushing the price up slightly.
- Your trade then goes through, but you get a worse price and fewer tokens than you expected. Your own purchase pushes the price up even more.
- The attacker then back-runs you by selling their tokens at this newly inflated price, capturing the difference as profit.
You, the victim, are "sandwiched" between their buy and sell orders.
The Impact of MEV
MEV has a significant effect on the Ethereum ecosystem. For everyday users, it often results in a worse user experience through something called slippage, which is the difference between the expected price of a trade and the price at which it's actually executed. Sandwich attacks are a direct cause of higher slippage.
At a network level, the competition to capture MEV can lead to bidding wars for block space. Searchers will pay higher and higher gas fees to get their transactions ordered favorably, which can clog the network and drive up costs for everyone. This dynamic also raises questions about fairness. Is a network truly decentralized if a few sophisticated players can systematically profit at the expense of regular users?
While some forms of MEV, like arbitrage, are essential for market efficiency, the more predatory strategies remain a major challenge. The existence of MEV creates a complex, high-stakes game that plays out within every single block on Ethereum.
Now, let's test your understanding of these concepts.
What is the primary role of the "mempool" in the context of Ethereum transactions?
A user submits a large buy order for a token. An MEV bot sees this, places a buy order for the same token immediately before the user's transaction, and then a sell order immediately after. What is this strategy called?