MEV (maximal extractable value) is an umbrella term referring to the measure of total value that can be extracted from manipulation of on-chain transactions. MEV encompasses activities that involve scouring publicly available backlogs of pending, unconfirmed blockchain transactions (mempools) and exploiting profitable opportunities created by them. Such activities are typically performed by bots and are value-extractive to other market actors. MEV takes various forms, but the most common are arbitrage, sandwich attacks, and liquidiations. This blog breaks down the forms of MEV that are most relevant to DEX users, so LPs and traders can better understand how they are impacted and why it matters.
Arbitrage
Impacts: Liquidity providers
DEX arbitrage is an MEV strategy whereby traders (usually bots) exploit price discrepancies between the same asset in different markets.
Arbitrage is executed by simultaneously purchasing an asset in one market and selling it in another for a profit. This is seen in both TradFi and DeFi. A simple example? Let’s say you’re a luxury watch collector with a deep network of collector friends. You’re at a vintage shop and spot a rare Patek priced under market value. The watch isn’t your style, but you know someone in your network will be interested. You message the group and agree to sell it to one of your friends at a price closer to market value. At the same time, you purchase the watch from the shop at the lower price, netting a profit. DEX arbitrage works similarly but involves arbitrageurs taking advantage of misaligned pricing between DEXs, DEXs and CEXs, or even the same DEX on different networks (cross-domain arbitrage). It also carries hidden consequences for other market participants.
Understanding how arbitrage impacts LPs requires a working knowledge of how DEXs operate under the hood. Most DEXs use an automated market maker mechanism (AMM) to algorithmically facilitate market making and price discovery for assets on the exchange. There are different AMM models, but the most commonly used is the constant product market maker (CPMM). Asset prices on CPMM-based DEXs (e.g., Uniswap, Bancor) are not dictated by external market prices. Rather, the CPMM is responsible for pricing tokens via a constant product formula (x*y=k), which moves exchange prices based on the ratio of assets in its liquidity pool. This means DEX token prices don’t move in lockstep with external markets, since they require a change in the pool’s token ratios to be affected. That’s where arbitrageurs come in. CPMMs require arbitrage trade to keep their prices in line with the rest of the market. Most DEX arbitrage activity is from arbitrage bots, which perpetually scan for profitable opportunities. At first glance, arbitrage bots appear to provide value to the DEX ecosystem by keeping markets efficient, but that comes at the expense of LPs.
The presence of arbitrage opportunities is typically considered a sign of an inefficient market. The CPMM design naturally produces inefficient markets, which results in the selling of underpriced assets to arbitrageurs. While arbitrage bots benefit from this, their profits are being siphoned from the pockets of LPs, who are essentially taking the other side of these trades. This creates impermanent loss. On the Ethereum blockchain alone, arbitrageurs have extracted $3.4M in profit (across all protocols) in just the past 30 days. AMMs are meant to facilitate trades on behalf of their liquidity providers, producing a return on capital in exchange for supplying liquidity for trading. It should be a win-win, but in the case of CPMMs, they are effectively running a trading strategy that loses money for LPs if prices of deposited assets move at all while in the pool (unless prices return to their exact origin before withdrawal, which is unlikely). As we have been seeing, impermanent loss has a very real impact on LP returns.
Front-Running & Sandwich Attacks
Impacts: Traders
Front-running involves entering a trade based on advance knowledge of a transaction that will influence the price of the underlying asset. The objective is to capitalize on the anticipated price impact by placing one’s own order before the incoming transaction. This is a common MEV strategy.
Front-running also occurs in traditional finance, but it’s executed differently in DeFi. When transactions are submitted on-chain, they are typically ordered by gas fee and queued in the mempool (short for memory pool) to be executed sequentially. Because mempools provide a public view of pending transactions, MEV bots can easily scan for significant trade orders and insert their own trades ahead of them by paying higher gas fees. This manipulation results in the attacker commandeering the purchase price their victim was supposed to receive, inflating the asset price immediately before the victim’s trade is executed. This creates increased slippage for the front-run trader. As anticipated, the attacker then reaps the benefits of the price impact created by the victim’s transaction. Front-running can also occur between arbitrage bots when one bot front-runs another to steal an arbitrage opportunity. Front-running is illegal in traditional finance because it leverages non-public information. In DeFi, however, this is not the case since mempools are public.
Sandwich attacks are an extension of front-running whereby an attacker identifies a target transaction in the mempool and sandwiches it between a front-run order and a back-run order. This technique results in a higher execution price for the unsuspecting victim, as seen with front-running, while the attacker extracts profit by selling their assets immediately after the “meat” transaction is executed. Sandwich attacks and front-running by bots siphon money directly from the pockets of normal traders. This is sometimes referred to as an “invisible fee” since the impacted trader receives fewer tokens from their trade than initially anticipated. In the past 30 days, sandwich attacks on Ethereum alone have successfully targeted over 72k victims across ~122k transactions for $1.86M profit.
Solutions
In the case of arbitrage, the most obvious solution is for DEXs to use AMM models that are designed to make efficient markets without the need for arbitrageurs. The CPMM is a first-generation AMM with a highly simplistic pricing formula. Simplicity was necessary at the time of its inception to keep computing resources (and thus gas fees) on Ethereum down. With the growth of L2s and alternative L1s, the AMM design space has since evolved to include more efficient models with more complex pricing formulas that obviate arbitrage altogether. Clipper’s formula market maker, for example, uses a sophisticated pricing function that factors in both token ratios and up-to-the-second external market prices from centralized and decentralized oracles. This design results in zero arbitrage opportunities for bots to exploit (and no need for them) and eliminates impermanent loss altogether. Impermanent loss is not inevitable, it’s simply a result of inefficient AMM designs.
As for front-running and sandwich attacks, different tools can be used to protect traders. One method is for DEXs and aggregators to create built-in countermeasures that protect users’ transactions from third-party visibility, such as 1inch’s Flashbot transactions. Another method is for traders themselves to reduce their exposure by decreasing their slippage tolerance on trades. This can be helpful since sandwich attacks rely on high-slippage tolerance. Clipper’s FMM design obviates front-running and sandwich attacks by only providing firm price quotes to traders. Because of this, slippage is fixed leaving no room for bots to manipulate transaction ordering. The result is lower slippage and better prices overall for all traders.
Written by
Published on