The concept of Sandwiching falls under the broader category of Maximal Extracted Value (MEV) in the world of blockchain—a term that refers to the value derived from transaction inclusion and ordering. This value not only benefits the MEV searcher but also rewards the validators who earn transaction fees, the block builders who incorporate the searcher’s transactions into more profitable blocks, and the DeFi protocols that thrive on arbitrage trading, which helps maintain price consistency across decentralized finance.
However, it’s important to note that not all MEV contributes positively to the ecosystem.
Demystifying MEV
MEV is a phenomenon inherent to web3 platforms, driven by the need to sequence and include transactions within blocks before they are confirmed on-chain. The process of MEV unfolds as follows:
- Given the transparent nature of the mempool, all transactions are continually observed. MEV can manifest on any blockchain with a public mempool.
- When actors in the network, specializing in MEV, identify transactions with potential for value extraction, it’s not a matter of whether MEV will occur, but rather who will capture this value.
- Nearly every transaction involving the exchange of tokens with distinct values holds the potential for MEV.
The majority of MEV arises from arbitrage—a concept familiar from traditional finance. In traditional arbitrage, investors profit from tiny differences in the price of the same asset in different markets:
“(T)he simultaneous purchase and sale of the same asset in different markets to profit from tiny differences in the asset’s listed price.” - Investopedia
However, in web3, arbitrage exploits the varying values of assets within different web3 ecosystems. Imagine a scenario where Ethereum is priced at $2000 on Uniswap but $1990 on Sushiswap. An arbitrageur can capitalize on this price difference by buying ETH on Sushiswap and selling it on Uniswap, instantly pocketing $10 per ETH (minus gas fees).
While this example is simplistic, it reflects a situation that occurs frequently in the DeFi world. Users trade assets across different parts of the ecosystem, and MEV seekers actively hunt for profitable arbitrage opportunities. They employ MEV bots equipped with algorithms to identify these opportunities and automatically execute profitable trades.
Arbitrage is one way MEV seekers exploit price discrepancies after they materialize. Another form of MEV involves predicting and acting upon transactions before (frontrunning) and after (backrunning) they occur, creating a profit-generating combination known as “sandwiching.”
Unveiling MEV Sandwiching
Chances are, even if you’re a casual web3 user, you’ve unwittingly encountered MEV sandwiching when interacting with decentralized exchanges or DeFi protocols on any blockchain.
Sandwiching, sometimes referred to as a “sandwich attack,” is a prevalent manipulation tactic within DeFi ecosystems. It unfolds when an MEV seeker aims to profit from the price volatility of an asset. The seeker anticipates a significant purchase order for an asset, causing its price to rise. They then position themselves ahead of this purchase, raise the price, and subsequently place a sell order after the original purchase to profit from the premeditated price increase.
The diagram below provides an overview of the basic sandwiching process. The seeker’s bot identifies a transaction that will impact an asset’s price, inserts their transaction to “front-run” the price change, allows the original transaction to execute at the new price, and then concludes with a final transaction to capture the price difference they predicted.
MEV is an evolving field in web3, and the classification of sandwich attacks continues to expand. For instance, one alternative form of sandwiching is the “pool imbalance attack.” In this strategy, the seeker alters the sizes of decentralized exchange liquidity pools during the front-run and resets them in the back-run, sometimes resulting in minimal gains for the sandwiched transaction.
Witnessing a Sandwiching Bot in Action
The website zeromev offers a frontrunning explorer, enabling users to monitor on-chain transactions for sandwich attacks and other MEV activities. The screenshots below illustrate a significant sandwiching incident that affected a trader’s transaction settlement.
In this instance, the sandwiching bot identifies a transaction involving a substantial purchase of the Saitama token in the mempool, marked as “sandwich” under the MEV category. The bot initiates an MEV bundle, purchasing the token ahead of the large Saitama order, thereby driving up its price:
The sandwiched victim ends up purchasing the token at a higher price than they initially would have, while the bot “backruns” the token by selling the previously acquired Saitama at the inflated price set by the large purchase. Zeromev data indicates that this maneuver yielded a substantial profit for the bot, exceeding $200,000:
Additionally, you can observe in the image below that the sandwich attack was made possible by intentionally delaying the inclusion of the initial transaction by 1 minute and 43 seconds:
Although the screenshots above depict an exceptionally high-value sandwich attack, most sandwich attacks involve smaller sums. For example, this sandwich from block 16535401 amounted to approximately $90:
Understanding MEV sandwiching is crucial for navigating the DeFi landscape, where such tactics can impact traders and investors significantly. Stay informed to make informed decisions in this dynamic and evolving field.