What is MEV Sandwiching?

Blocknative Ethereum Web3

How MEV Bots Execute Automated DeFi Strategies

Listen to this post:

 

Sandwiching represents a single category under the overarching classification of Maximal Extracted Value (MEV)—the value derived from transaction inclusion and ordering. This value is not only lucrative for the MEV searcher, but also for the validators that receive the bulk of the transaction fees, the block builders that include the searcher's transactions to create more profitable blocks, and the protocols that benefit from arbitrage trading that keeps prices relatively consistent across DeFi.

However, not all MEV is beneficial for the ecosystem. 

What is MEV?

MEV occurs in web3 due to the necessity for transactions to be ordered and included in a block before being committed on-chain. The flow of how MEV occurs looks like this: 

  • Due to the transparent nature of the mempool, all transactions are constantly being monitored. MEV occurs on any blockchain with a public mempool.
  • When network actors specializing in MEV see transactions that hold the potential for value extraction, it’s not a question of if  MEV will happen, it’s only a question of who will capture the value. 
  • Almost every transaction that exchanges tokens with independent values holds the potential for MEV.

The vast majority of MEV occurs via arbitrage. Arbitrage in the world of web3 is the same as in traditional finance. Investopedia describes traditional arbitrage as:

(T)he simultaneous purchase and sale of the same asset in different markets to profit from tiny differences in the asset's listed price.

However, whereas arbitrage in the real world is usually possible due to differences in physical realities (the price of a widget is 20% higher in Country A than Country B), arbitrage in web3 is made possible by the value of assets within different web3 ecosystems.

Consider a situation where the price of Ethereum is $2000 on Uniswap, but at the same time, it is $1990 on Sushiswap. An arbitrager can take advantage of this gap by buying ETH on Sushi to resell on Uniswap, instantly pocketing $10 per ETH (minus gas fees).

The example above is very basic but it illustrates a situation that happens thousands of times per day in the world of DeFi. Users buy and sell assets from different areas of the ecosystem, and MEV searchers look for arbitrage opportunities based on these price changes. They do this by using MEV bots that run algorithms to detect profitable opportunities. These bots automatically submit any profitable trades they discover to the network.

While arbitrage is a way for searchers to take advantage of these price discrepancies after they happen, there is another form of MEV that looks at transactions that are about to happen and takes action before (frontrunning) and after (backrunning) to make a profit. This combination of MEV transactions is known as sandwiching.

What is MEV Sandwiching?

While most web3 users may not know it, there is a high likelihood that they have contributed to MEV sandwiching. If you have ever interacted with a decentralized exchange or DeFi protocol on any blockchain, you have likely been the unknowing victim of sandwiching. 

Sandwiching, also sometimes referred to as a "sandwich attack," is a highly prevalent manipulation tactic within DeFi ecosystems. It occurs when an MEV searcher attempts to profit from an asset's price volatility. The searcher will jump ahead of the target's large purchase order, which raises the price of the asset. As a result, They will then place a sell order following the confirmation of the victim's order to take advantage of the purchase they knew was coming in advance.

The diagram below outlines the basic process for sandwiching. The searcher's bot identifies a transaction that will raise or lower the price of an asset. They then insert their transaction before the original to “front-run” the price change, allow the original transaction to execute at the new price, then complete a final transaction with the funds from their first transaction to capture the difference in price they knew would occur.

mev-sandwich-attack

Because MEV is a cutting-edge space of web3, the categorization of sandwich attacks continues to evolve. For example, one alternate type of sandwiching is known as a pool imbalance attack. With this strategy, the searcher swaps the relative sizes of distributed exchange liquidity pools during the front-run and resets them in the back-run. This type of MEV can sometimes result in the sandwiched transaction receiving almost nothing in return for their swap.

Seeing a Sandwiching Bot in Action

The website zeromev offers a frontrunning explorer that allows users to monitor on-chain transactions for sandwich attacks and other forms of MEV. The screenshots below illustrate the process of a rather large sandwich that occurred to a trader and the impact it had on the transaction's settlement.

In this case, the sandwiching bot identifies a transaction for a large purchase of the token Saitama in the mempool. This is the transaction labeled under the MEV column as “sandwich”. The bot then executes an MEV bundle so that they purchase the token before the large purchase of Saitama. This pushes up the price of the token in advance of the large purchase:

sandwich-frontrun-diagram

The sandwiched victim purchases at a worse price than they previously would have had. The bot then “backruns” the token by selling the Saitama they purchased beforehand for the newly inflated price the large purchase has set. Zeromev shows that this resulted in a huge profit for the bot of over $200,000:

sandwich-profit

You can also see in the image below that the sandwich was made possible by purposely delaying the inclusion of the initial transaction by 1 minute and 43 seconds:

sandwiching-delay

While the above screenshots illustrate an extremely high-value sandwich, most are lower in value. For example, this sandwich from block 16535401 totaled roughly $90:

smaller-sandwich-profit

MEV & Blocknative

MEV searchers can use Blocknative’s suite of tools to search with an edge and securely get MEV bundles on-chain by submitting to our RPC endpoint https://api.blocknative.com/v1/auction. You can learn more by visiting our MEV bundle RPC endpoint docs. Create a free Mempool Explorer account today and begin prototyping your strategies.

Validators can earn more by connecting MEV-Boost to the Blocknative Relay endpoint. Connect to our relay today to maximize your block rewards with MEV. If you’re a dapp or wallet interested in #ShareTheMEV, we would love to chat with you.

You can always join our Discord community for direct access to Blocknative employees. Or follow us on Twitter @Blocknative for the latest updates from our team.

Observe Ethereum

Blocknative's proven & powerful enterprise-grade infrastructure makes it easy for builders and traders to work with mempool data.

Visit ethernow.xyz

Want to keep reading?

Good choice! We have more articles.

no-more-decoding-headaches:-announcing-the-blocknative-decoding-api
Developer

No More Decoding Headaches: Announcing The Blocknative Decoding API

For builders working with Layer 2 (L2) solutions, one challenge has consistently slowed development..

blob-inversion:-an-investigation-into-the-june-20th-2024-blob-spike
Gas

Blob Inversion: An Investigation Into the June 20th 2024 Blob Spike

Thank you to all those who provided input and review on this piece, including Julian Ma, Soubhik..

ethereum's-eip-4844-dencun-upgrade:-a-85-day-analysis
EIP-4844

Ethereum's EIP 4844 Dencun Upgrade: A 85-Day Analysis

Ethereum's EIP 4844 Dencun Upgrade: An 85-Day Analysis Ethereum's EIP 4844, part of the Dencun..

Connect with us. Build with us.

We love to connect with teams who are building with Blocknative. Tell us about your team and what you would like to learn.

"After first building our own infrastructure, we appreciate that mempool management is a difficult, expensive problem to solve at scale. That's why we partner with Blocknative to power the transaction notifications in our next-generation wallet."

Schedule a demo