Maximal Extractable Value (MEV) is the (potential) profits for miners or validators producing blocks on a blockchain. They do this by picking and re-ordering transactions within blocks. You can view MEV as a tax on users of the blockchain.
MEV is a small industry. Currently, around 100.000 dollars per day is squeezed from blockchain transactions by MEV bots. (see MEV-Explore).
How does MEV work? The simplest and most harmless form of MEV has always been standard practice In Bitcoin. Miners determine which transactions from the mempool (waiting line) they want to included in a block. They do this mostly based on how the height of the transaction fees they can claim for different transactions. Ethereum offers more opportunity for MEV, as it is a smart contract platform where a lot of trading orders are processed.
Even though the existence of MEV was already foretold in 2014, it wasn't until 2020/21 that it became an industry. A vivid description in a blog post helped to popularize the term, comparing Ethereum’s mempool to a dark forest: 'an environment in which detection means certain death at the hands of advanced predators. [...] In the Ethereum mempool, these apex predators take the form of “arbitrage bots.”
Frontrunning and sandwiching
How do miners or validators benefit from the fact that they can determine the order of transactions? First, an example from the world of traditional finance may illustrate this. Let's say you're a broker and an investor asks you to buy a hundred thousand shares of a company. You know this will move the price higher and that's why you buy some shares of the company before placing your client's order. After the price jump, you sell your shares again. You've benefited by what is called front-running the market.
The crypto version of this trade is legal in the context of MEV and is called a sandwich attack: a so-called searcher (a bot) detects a large pending trade on a decentralized exchange and places a trade right before and right after it to benefit from an artificial price change.
Similarly, so-called generalized frontrunners look in the mempool for any transaction that they could profitably frontrun by copying it and replacing addresses with their own. By using higher gas fees, they make sure their transaction is included instead of the one they want to replace.
Another way to benefit for bots is liquidation opportunities. When users on dexes are close to being liquidated (if they can't pay back their loan) other uses may compete to liquidate (sell) the collateral and earn a fee for that. Searcher bots will hunt and compete those opportunities too.
Is MEV good or bad?
In crypto, miners and validators are allowed to benefit from their private knowledge of the orderbook which is the mempool. If this may seem unfair, this 'private' knowledge is available on a free market: everyone could become a miner or validator and compete.
In some cases, this helps all participants by creating fair markets. For example, there are bots arbitraging price differences across dexes. This kind of arbitrage saves users a headache: they don't have to worry that the price listed on their dex differs too much from other dexes.
At the same time, ordinary users pay a price for these kinds of 'MEV services'. If their trade gets sandwiched, they will pay a higher price, for the token. In other cases, users pay in the form of higher gas prices.
There are initiatives to use MEV activity for good. Flashbots lets users send transactions directly to miners, instead of for all to see in the mempool. This protects them against for example their transaction being 'sandwiched'. This should create a 'fair ecosystem for efficient MEV extraction'.