Getting Slipped? Or getting MEV’d?

Have you ever encountered the term MEV bot or slippage? This post will explore what these terms mean and how they work.

What Are MEV Bots?

MEV, or Maximum Extractable Value bots, are automated programs designed to identify profitable opportunities within a blockchain’s transaction pool (mempool) and reorder, insert, or front-run transactions to extract value. These actions are often malicious and harm the original transaction sender.

How do MEV Bots Work?

  1. Arbitrage: MEV bots scan decentralized exchanges (DEX) for price discrepancies between different platforms and capitalize on arbitrage opportunities. If the price of a token is lower on one DEX and higher on another, the bot will buy low and sell high in a single transaction, capturing the difference. This is generally not malicious because it helps tokens keep the same price across all exchanges.

  2. Front-Running: MEV bots monitor the mempool (where unconfirmed transactions are visible) for large trades that might impact market prices. The bot can then front-run these trades by submitting a similar transaction with a higher gas fee, ensuring it gets processed before the original one, thus potentially making the original transaction invalid. By doing so, the bot gets all the benefits of the executed transaction.

  3. Sandwich Attacks: These are more malicious tactics. Sandwich attacks occur when the bot sees a large trade that will move the price of an asset significantly. The bot places one trade just before (buy) and one trade just after (sell) the large trade. As a result, it profits from the price swing while negatively impacting the original trader.

Why MEV Bots Matter

For miners or validators, MEV presents an opportunity to extract additional profits. However, for regular users, MEV bots can be problematic. When MEV bots front-run or executes sandwich attacks, they create a less predictable and often more costly trading experience. Traders can lose out on profits or pay more for a token than anticipated.

What is Slippage?

Slippage refers to the difference between the expected price of a trade and the actual price at which the trade is executed. In volatile markets, where token prices can change rapidly, slippage is a common occurrence, especially when large orders are involved or liquidity is limited.

Causes of Slippage

  1. Market Volatility: In decentralized markets, token prices can fluctuate significantly within seconds, particularly when large trades are executed. If a trade is initiated at a given price but completed at a later block, the price might change, causing slippage.

  2. Mev Bots: Bots increase the slippage by front-running your transaction or by sandwiching it.

  3. Execution Delays: On blockchain networks, transactions are not instantaneous. A delay in processing, particularly when the network is congested, can result in a different price by the time the transaction is mined, leading to slippage.

Minimizing Slippage

  • Setting Slippage Tolerance: Many DEXs allow users to set a slippage tolerance, which limits how much price movement is acceptable for their trade. If the price moves beyond this threshold, the trade will fail, preventing the user from making an unfavorable trade.

  • Trading in Low Volatility Periods: Waiting for times of lower market volatility or trading assets with higher liquidity can help minimize slippage.

  • Smaller Trades: Breaking large trades into smaller chunks can reduce the impact on the price of a token, thus minimizing slippage.

How MEV Bots and Slippage Interact

MEV bots can abuse slippage, particularly through tactics like front-running and sandwich attacks. Here’s how:

  1. Front-Running and Slippage: When a user submits a trade, an MEV bot can spot this in the mempool and submit a similar transaction with a higher gas fee, causing the user’s trade to execute later at a worse price, thus increasing slippage. The user expected to trade at a specific price, but due to the bot’s manipulation, the actual price at execution is higher.

  2. Sandwich Attacks and Slippage: In a sandwich attack, the MEV bot places a buy order right before a large trade, driving up the price. Then, after the large trade completes (at a higher price due to the bot’s initial buy), the bot sells, locking in a profit. This leaves the user facing increased slippage, often paying more for the trade than expected.

Sandwich attack example 1:

In this example, a smaller sandwich attack happenened. One might say that it is unsuccessful one.

MEV Buy: Ethereum Transaction Hash (Txhash) Details | Etherscan - transaction index 10

VICTIM Buy: Ethereum Transaction Hash (Txhash) Details | Etherscan - transaction index 11

MEV Sell: Ethereum Transaction Hash (Txhash) Details | Etherscan -transaction index 12

In this case, the victim purchased $ICP for 0.382 ETH. Before this transaction, a MEV bot executed a buy order for $ICP, spending 0.09915 ETH. The bot then sold all the $ ICP in a subsequent transaction for 0.10035 ETH, resulting in a profit of 0.0012 ETH (approximately $3).

This profit, however, does not seem to cover the high transaction costs on Ethereum. It's likely that this was either a test run of the MEV bot or the bot wasn't functioning optimally, as the low buy amount kept slippage minimal, which ultimately protected the victim.

Sandwich attack example 2:

In this second example, we encounter a more harmful sandwich attack in which the MEV bot made a significant profit at the victim's expense.

MEV Buy: Ethereum Transaction Hash (Txhash) Details | Etherscan - transaction 14

VICTIM Buy: Ethereum Transaction Hash (Txhash) Details | Etherscan - transaction 15

MEV Sell: Ethereum Transaction Hash (Txhash) Details | Etherscan -transaction 16

In this case, the victim purchased $HACHI for 0.4995 ETH. Before this transaction, an MEV bot executed a buy order for $HACHI, spending 1.8328 ETH. The bot sold all the $HACHI shortly after the victim's trade, selling for 1.8471 ETH.

This resulted in a profit of 0.01429 ETH (33$) for the MEV, but if we didn't include the transaction fees. Unlike the first example, the profit here is much higher, indicating a more successful sandwich attack in which the victim faced higher slippage, increasing the cost of their transaction.

Protecting Yourself Against MEV Bots and Slippage

While MEV bots and slippage risks in decentralized finance, there are strategies and tools to mitigate their effects:

  1. Use of MEV-Protected Platforms: Some DeFi platforms and solutions, such as Flashbots, aim to reduce the impact of MEV by allowing users to submit transactions directly to miners, bypassing the public mempool. This reduces the risk of front-running and sandwich attacks.

  2. Higher Gas Fees: Offering higher gas fees can ensure that your transaction gets processed more quickly, reducing the window of opportunity for MEV bots to exploit it.

  3. Slippage Settings: Setting a slippage tolerance on platforms like Uniswap or SushiSwap ensures that your trade doesn’t go through if the price changes too much, helping you avoid unexpected losses.

  4. Private Transaction Services: Certain services allow users to submit transactions privately, preventing MEV bots from seeing them in the mempool. This can be a useful option when executing large or time-sensitive trades.

Last updated