HomeKnowledge BaseWhat is Frontrunning

What is Frontrunning

8 min read

MEV bots monitor pending transactions in the mempool and place their transaction ahead of others, capitalizing on the order of transactions within a block. This approach allows them to gain a significant edge, profiting from traders placing transactions. Frontrunning occurs when an MEV bot monitors the mempool for a trader’s pending transaction. Spotting a potential trade, the bot quickly duplicates the users transaction so that they can be the one to get the tokens or the opportunity that the user detected.

This issue permeates various blockchain ecosystems — from decentralized exchanges to non-fungible token (NFT) marketplaces.

According to recent data, over 2.7 million MEV transactions have been processed on Uniswap alone. This alarming statistic underscores the widespread and high-stakes nature of MEV exploitation.

How frontrunning works

Frontrunning takes advantage of the open nature of the blockchain mempool, as anyone can view transactions. MEV Bots exploit this transparency to hijack trades. Here’s a basic rundown of the process:

  1. Monitoring Pending Transactions: The first step involves monitoring the blockchain network’s mempool, a holding area for pending transactions. Here, frontrunners, who are often sophisticated bots, scan the mempool to identify transactions that can carry significant value that they want to snatch away or that could influence the price of a particular asset
  2. Selecting Profitable Transactions: The frontrunner will analyze the potential market impact once such a transaction is identified. For instance, if a large buy order for a specific token is detected, the frontrunner knows that this transaction could increase the asset’s price once processed
  3. Placing a New Transaction: The frontrunner will initiate their buy order for the same asset, intending to get their transaction processed before the initially detected transaction. They typically give the validators a higher “tip” to execute their transaction first in the block in comparison to the target transaction

Frontrunning examples

A notable example of DeFi frontrunning involves the notorious MEV bot named “jaredfromsubway.eth.” In one case, a user, 0x3a7822, intended to trade 2 ETH for another token, $BOB. This trade was noticed by the bot jaredfromsubway.eth, which continuously monitors the mempool for transactions it could take advantage of.

Once the transaction entered the mempool, Jaredfromsubway.eth quickly executed its own transaction to buy $BOB with ETH, strategically placing it as the first in the block, and knowing that he would get the assets at a discount as the transactions behind will pamp the pricer. MEV allows validators to prioritize transactions that are of the most value to them. Consequently, the bot’s transaction, being the first one in the block, was confirmed ahead of the user’s transaction.

1-frontrunning.webp

The frontrunning attack triggered an increase in the price of $BOB tokens due to the additional demand created before the user’s transaction was processed. When the user’s original order of 145M $BOB was executed, it was conducted at this now-inflated price, leading to user 0x3a7822 receiving way fewer $BOB tokens, hence losing out on the value they could have otherwise captured.

Jaredfromsubway.eth completed its MEV attack by selling its $BOB tokens at an increased price, resulting in a profit, a second move that made this MEV attack a sandwich attack. In this scenario, the price slippage triggered by the frontrunning bot meant that user 0x3a7822 encountered a worse trade-off, ultimately making a loss while the MEV bot profited — an estimated gain of 0.1 ETH.

Another form of frontrunning would have been for example, if user, 0x3a7822 identified an liquidation opportunity faster than anyone else and sent its transaction to the mempool to get the discounted assets from the liquidation in the first place, then Jaredfromsubway.eth would have seen this and would have replaced the users transactions with the transaction of its own, but with a higher gas fee, and thus more likelyhood to get processed faster, and effectively stealing the opportunity of capturing value away from the user.

How Harmful is Frontrunning?

While frontrunning may seem harmless or even clever to some, it can adversely affect individual traders and compromise the overall integrity of the Ethereum network. Here’s how:

  1. Impact on Traders: Frontrunning disrupts the fair operation of financial markets. By exploiting pending transactions, frontrunners manipulate market conditions to their benefit. This can lead to distorted prices, impacting regular traders who abide by market rules. What’s more, these traders miss out on the value they would have otherwise derived from their trades. But most importantly, frontrunning attacks prevent users from receiving the value of the trading opportunity they identified
  2. Long-term Market Consequences: Over time, persistent frontrunning can erode market confidence. As traders realize they are consistently at a disadvantage due to frontrunning, they may lose faith in the integrity of the market and choose to leave. This could result in diminished market participation and liquidity, both of which are critical for overall market health and efficiency
  3. Network Effects: Frontrunning can also have wider implications for the underlying network. It can cause network congestion, since unnecessary transactions in a block slow down transaction processing times

CoW Swap takes a firm stance against all forms of Maximal Extractable Value (MEV), including frontrunning, as they are detrimental to traders and the wider Ethereum ecosystem. CoW Swap was built to cultivate a fair and transparent trading environment that best serves the interests of all market participants.

How to protect against frontrunning?

Mitigating frontrunning and other forms of MEV can pose a challenge, given the transparent and permissionless nature of the Ethereum blockchain. However, CoW Swap gives traders the necessary tools to outsmart the MEV bots:

  1. Batch Auctions: Instead of executing orders immediately, CoW Swap orders are gathered and grouped into collections known as “batches.” Solvers, or the algorithms that provide an order settlement solution for a batch, compete to deliver optimized solutions. This batch auction method ensures all trades within a batch share the same uniform clearing price, preventing MEV Bots from reordering trades. Through batch auctions, CoW Swap affords traders the opportunity to pool liquidity among their orders, enabling users to trade directly with each other or access specialized markets to complete transactions that would otherwise be impossible to do in a peer-to-peer manner — this is known as Coincidence of Wants (CoW)
  2. MEV Blocker: MEV Blocker is a straightforward solution to the MEV problem. It is an RPC endpoint that protects all types of transactions from MEV. MEV Blocker organizes an auction among searchers, who are given the chance to backrun your transactions and forward up to 90% of the backrun value to the user. In exchange, they protect you from both frontrunning and sandwich attacks
  3. Use CoW Swap: CoW Swap is a meta DEX aggregator that uses batch auctions and facilitates an efficient trading process, preventing all forms of MEV, including frontrunning

The CoW approach to frontrunning

CoW Swap distinguishes itself in the trading ecosystem with its innovative and comprehensive approach to combating frontrunning and other MEV tactics, thereby creating a safer trading environment for users. The platform has meticulously crafted multiple layers of protection, each targeting a distinct aspect of the MEV issue.

The initial line of defense is Delegated Trade Execution. In conventional DeFi platforms, every transaction a user initiates is instantaneously visible in the public mempool, providing an opportunity for searchers to exploit it. As opposed to other exchanges, on CoW Swap, users sign an “intent to trade” which protects them from directly interacting with the mempool. CoW Swap directs all intents through a network of decentralized ‘solvers.’ These solvers are responsible for securing the best execution price for your trades, while also shielding you from direct exposure to the public mempool, effectively making you undetectable to MEV bots. Moreover, CoW Swap harnesses the power of ‘Coincidence of Wants’ (CoW). This allows the platform to match orders off-chain, fostering peer-to-peer trades that not only save on gas and liquidity provider fees but also substantially reduce the risk of MEV attacks by circumventing public liquidity pools. CoWs that don’t rely on on-chain liquidity pools eliminate a key opportunity for MEV exploits.

The platform also introduces a Uniform Clearing Price for all orders in a batch. In a typical decentralized exchange, simultaneous trades clear at marginally different prices in the same block due to sequential transaction processing. This provides an opening for MEV attacks. CoW Swap counters this by ensuring all orders within the same batch auction are settled at the same clearing price within a block. As a result, the order of transactions within a batch becomes irrelevant, effectively preventing MEV attacks and giving users in the batch a fair price.

CoW Swap’s strategy to tackle frontrunning hinges on eliminating opportunities for searchers to exploit trades. This helps maintain the integrity of user transactions and safeguards user value. By leveraging its unique batching technology, CoW Swap remains resilient against frontrunning and other MEV attacks.

Trade safe from MEV on CoW Swap

Given the severity and frequency of MEV attacks, protecting your trades from MEV should be a top priority. CoW Swap offers unparalleled protection with its pioneering anti-MEV features, making it an invaluable tool for every trader.

Get started with CoW Swap by placing your first trade and enjoy the freedom and peace of mind of the best prices and the best MEV protection!