MEV Sandwich BOT- The Basics

Dark Forest.
5 min readAug 1, 2023

--

Before going directly to the topic, Let us first grasp the basic knowledge of MEV and related terms.

Maximal Extractable Value (MEV) refers to the maximum amount of value a blockchain miner or validator can make by including, excluding, or changing the order of transactions during the block production process.

MEV occurs when the block producers in a blockchain (e.g. miners, validators) are able to extract value by arbitrarily reordering, including, or excluding transactions within a block, often to the harm of users. Simply put, block producers can determine the order in which transactions are processed on the blockchain and exploit that power to their advantage.

Maximal vs Miner:

MEV is increasingly referred to as maximal extractable value instead of the original term miner extractable value. This is due to MEV not being limited to just miners in proof-of-work (PoW) blockchains, but also applying to validators in proof-of-stake (PoS) and other types of networks as well.

Role Of MEV in Blockchains:

Maximal Extractable Value (MEV) represents the monetization aspect within blockchain networks. In these networks, participants responsible for processing transactions, such as miners or validators, determine the sequence and execution of these transactions. This arrangement creates an opportunity for MEV bots to capitalize on price variations.

For instance, an MEV arbitrage bot could be utilized to monitor trades on decentralized exchanges (DEXes). When a substantial buy order is observed, it indicates an impending price increase for a specific cryptocurrency. The MEV bot seizes this opportunity and executes its own order, strategically placing a buy order at a slightly lower price just moments before the DEX order is executed.

By leveraging the subsequent price rise resulting from the DEX trade, the MEV arbitrage bot profits from the price discrepancy. Although MEV bots operate independently from miners/validators, they benefit from their transaction sequencing. It’s important to note that some MEV profit extraction strategies may be more manipulative than others.

April 2023: Sandwich MEV bots made $5.58M from automated techniques.

Let us now jump to some of the MEV Examples happening in our surrounding and why we all should know about them:

Frontrunning and Sandwich Attacks

Bots engaging in frontrunning activities on decentralized exchanges (DEXs) pose a direct threat to the user experience, impacting the fairness of transactions. Frontrunning bots take advantage of the public mempool, where unconfirmed blockchain transactions await processing, to detect significant trades made by users.

Here’s an explanation of how they operate: When a large trade is detected, the frontrunning bot duplicates the user’s trade and creates a transaction bundle, ensuring their own transaction is processed before the user’s trade. This manipulation causes the market price of the traded asset to shift, resulting in increased slippage for the user’s trade. Slippage represents the disparity between the expected trade price and the actual price executed.

After the user’s trade is processed, the market price continues to shift in favor of the frontrunner. This allows them to execute a profitable backrun trade, commonly known as a “sandwich attack,” where they sell their assets. Consequently, the user’s trade is executed at a suboptimal exchange rate, leading to higher costs associated with using decentralized exchanges. This unfavorable outcome can be perceived as an “invisible fee” since the user receives fewer tokens than initially anticipated.

Exchange Arbitrage and Liquidations

MEV can also manifest through third-party bots conducting arbitrage across multiple decentralized exchanges. Arbitrage opportunities arise when the price of a cryptocurrency asset deviates between exchanges, often triggered by substantial trades on one of the platforms. These arbitrage bots capitalize on these opportunities by purchasing the asset at a lower price on one exchange and selling it at a higher price on another, thereby restoring price equilibrium and generating profits.

Furthermore, arbitrage can occur not only between on-chain DEXs but also between on-chain DEXs and off-chain centralized exchanges or even between on-chain DEXs on different blockchain networks, known as cross-domain MEV.

As DeFi adoption increases and liquidity grows within DEXs, the occurrence and profitability of these arbitrage opportunities expand, leading to heightened competition among arbitrage bots. In a bid to outperform each other, these bots engage in bidding wars, continually raising the fees they are willing to pay block producers to include their transaction bundles in a produced block.

While arbitrage is a typical and beneficial market activity, MEV bots can disrupt the process by monitoring the transaction mempool and replicating trades, while paying higher fees to block producers. By doing so, they effectively steal arbitrage opportunities from other users, including the original arbitrage transactions. A similar situation can arise in the liquidation of collateralized loans within DeFi lending markets.

Generalized Frontrunning:

An advanced method for extracting MEV involves the use of bots engaging in “generalized frontrunning.” This technique entails a searcher scanning transactions within a public mempool and submitting an identical transaction with a higher fee to block producers. During this process, the bot replaces any occurrence of the user’s address in the transaction payload with its own. This approach has been observed in real-world scenarios, where even a well-intentioned attempt to rescue at-risk user funds was thwarted by a generalized frontrunner, who copied and replaced a critical transaction with its own.

The behavior of such bots is typically not focused on interpreting the transaction’s purpose but rather revolves around running an algorithm to scan mempool transactions, replacing addresses in the payload, and simulating its execution to identify profitable outcomes.

These examples demonstrate how MEV can be extracted and the potential adverse effects it can have on users. However, these instances are not exhaustive, as other situations may also allow for MEV. Moreover, if block producers increasingly capture MEV opportunities for themselves, it is possible that more sophisticated reordering strategies could be employed to further exploit users for value extraction.

Preview of DARK MEV Sandwich Bot:

DarkForest MEV Bot Introduction Page
List of Basic Commands in V1

Relevant Links related to $DARK:

Telegram: https://t.me/DarkForestERC

Twitter: https://twitter.com/DarkForestERC

Website: darkforest.pro

Study more about MEV here: https://ethereum.org/en/developers/docs/mev/

--

--

Dark Forest.
Dark Forest.

Written by Dark Forest.

Dark Forest is a cutting-edge platform designed to provide users with an intuitive interface and Tools to navigate Ethereum's mempools.

Responses (3)