https://mirror.xyz/unitzero.eth/XOWkcDGhjy3nM3WdjcpWXR6tPufD3uLTEKUsy6YDay8

By Katsuragi

[data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%271200%27%20height=%27800%27/%3e](data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%271200%27%20height=%27800%27/%3e)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f18e783d-90fc-4f65-b05e-9a7fc66c0031/image

There’s been much ado about MEV lately. Why is it so hot right now? No telling, really. MEV has been widely present (and captured) on Ethereum for many months now. Proper understanding eludes the masses due to its complex technical nature, so we set out to share our thoughts on it and why it is important. The existence of MEV on state-rich blockchains like Ethereum creates powerful incentive structure that can pervert the decentralized nature of the EVM itself, as we will explore.

Let’s start at the beginning: what is MEV? MEV, or Maximal/Miner Extractable Value, can be defined as a measure of the profit a miner can make through their ability to arbitrarily re-order transactions within the blocks they produce. Since Miners can re-order transactions based on what is most profitable for them, therein lies an opportunity for users to take advantage of. Below is a chart on the gross profit of cumulatively extracted MEV, which reached almost $600 million in just a few months:

source: Flashbots

The concept of MEV is better understood in the context of high-frequency trading on Wall Street. Michael Lewis’ seminal book Flash Boys tells the story of the traditional finance world’s battle over best execution in markets. By setting up trading operations strategically located near purpose-built fiber optic cables, traders could cut time to execution by a few milliseconds. In the arena of high-frequency trading, this enables a disproportionate advantage over competitors, due to the ability to capture better prices based on those mere milliseconds.

MEV on EVM-based blockchains is mechanically very different, but can be qualified similarly in the arena of DeFi. Since miners are able to include, exclude, or re-order transactions based on who is willing to pay the most in gas, algorithms employed by “searchers” (individuals attempting to exploit MEV opportunities) are able to capture value for themselves from various types of transaction activity within the blocks that miners are confirming.

Enter the Dark Forest: the Mempool

The mempool is often referred to as a Dark Forest. A frightening and lonely place, filled with predators laying in wait to strike and frontrun your transactions. To the uninitiated, a venture into this realm quickly becomes a cautionary tale. To the predator, it’s a battleground more akin to the Roman Colosseum than an enchanted mystical place.

The mempool is the blockchain’s waiting room that all transactions must pass through before they are ordered neatly to be submitted into sequential blocks. It is both a gateway and a warzone. Recall that transactions can be ordered on priority via the amount of gas submitted. As transactions vie with each other to be selected into the next block, myriad opportunities open up to be exploited by an experienced searcher.

Consider attempting to mint an NFT for a popular project. There are hundreds of thousands of individuals in the Discord, and the moment minting on the contract opens, the Ethereum Virtual Machine is slammed with transaction attempts by whales, shrimps, and bots alike in a mad dash to acquire the NFTs before they sell out. If its your first time participating in such an event, you’re likely to end up disappointed; you waited 10 minutes for your transaction to confirm before you finally submitted a cancellation request, resulting in the loss of gas and no NFT yet. So you try again; Ope! look at that, you waited too long. Now the NFT is sold out and you must pay double to acquire it on the secondary market.

This type of scenario presents ripe opportunities for value extraction. Aside from larger-order bidders cutting to the front of the line by setting gas considerably higher than a normal participant would, searchers can front-run the mint transactions sent to the mempool up and down the board. But what do these opportunities look like?

MEV Strategies

MEV extraction by searchers exist in a variety of forms, but we’ll stick to the most common strategies as they make up a majority of MEV extracted (for this reason, they are also likely to be the least profitable for new searchers):

Generalized frontrunning is perhaps the most obvious use case to anyone familiar with normal marketplace mechanics. This strategy’s simplest form can be boiled down to the process of reviewing all publicly available transactions in the mempool, and simulating whether frontrunning any of them would result in a profit. If person A attempts to send a transaction to a liquidity pool, and person B (i.e., the frontrunner) can identify a profitable arbitrage by beating the order to confirmation, person B will execute the frontrunning transaction and subsequently sell person A their desired asset, albeit at a slightly higher price. Various strategies in this category can quickly become infinitely more complex, but for the purposes of this article we want to keep it very basic, and thus will loosely define this strategy as the ability to capture arbitrage opportunities solely by mimicking a given sender’s behavior and beating them to execution.

The sandwich attack is a form of frontrunning based on exploiting the existence of pending transactions waiting to be confirmed in the mempool. The sandwich attack is the closest parallel to the strategies employed by high-frequency traders on Wall Street. If you can observe an individual sending an order in the mempool to Uniswap and recognize that this order will cause a price impact, you can frontrun said transaction, and then quickly turn around and sell the asset back to the individual sending the original transaction at a higher price, keeping the difference for yourself. The key difference between this and other generalized frontrunning strategies is a function of price impact when transacting on various AMMs. Since Uniswap uses a constant product market maker function, you can factor these formulas into a MEV bot algorithm to determine a transactions price impact, and thus the potential profitability.

The atomic arbitrage is another strategy. Definitionally, basic arbitrage is the practice of buying an asset at a discount on one exchange and simultaneously selling it on another exchange at fair value. This might sound nefarious, however it is a strategy executed across all markets by many participants, and it serves the purpose of enabling better price discovery for an asset. A core tenant of financial arbitrage is that is essentially riskless - i.e., in the attempt to discover a discrepancy in price among bids and asks, one can assess the profitability prior to execution. Any time an asset is arbitraged, the price of the asset on one exchange gets closer to the price on another exchange. Atomic arbitrage, however, includes a twist on this. Since blocks on Ethereum are ordered sequentially, searchers are able to attempt to arbitrage a transaction in a single block re-ordering, but if the attempt contains a check on whether or not the transaction will return a profit for the searcher, the transaction can fail and revert back to the original state if, indeed, the results determine it will not be a profitable transaction.