Front-running and MEV are common practices to extract maximum value in DeFi
- What Is Front-running And MEV?
- How Do They Work?
- Notable Instances of MEV
- Preventing MEV
- Real World Examples
What Is Front-running And MEV?
Front-running isn’t a new term born from the DeFi world. In traditional finance, particularly the stock market, front-running refers to the act of acting upon prior knowledge of a big incoming purchase. Someone might get wind of this and strategically place their order just ahead of it, anticipating the price surge and aiming for a profit. However, within the context of blockchain, it gets more complicated. Given the public and immutable nature of the blockchain, transactions are visible to everyone, making it easier for people to exploit them. Therefore, users are able to see yet-to-be-executed transactions in the mempool — a sort of waiting room for transactions — and are able to jump ahead of the queue by placing their own transactions with higher gas fees than the previous ones.
Now, Maximum Extractable Value (formerly Miner Extractable Value), or MEV, is a broader term that encapsulates front-running and many other forms of value extraction opportunities within blockchain technology. MEV occurs because miners (or validators in PoS) can choose the order of transactions within the blocks they mine. Consequently, they can capitalize on opportunities to profit by inserting, excluding, or reordering transactions.
How Do They Work?
As we mentioned above, because of the public nature of blockchain, naturally people are able to take advantage of what they can see. This type of visibility enables users to see pending transactions and act on them before they are confirmed. The typical steps may involve:
Spotting a Potentially Profitable Transaction: Monitoring tools are used to watch the mempool for large or impactful transactions, especially on decentralized exchanges. For instance, if someone is about to make a large buy order of a token, its price is expected to rise.
Creating a Competitive Transaction: After spotting a potential transaction, the user will create a similar transaction.
Paying a Higher Gas Fee: The user will then pay a higher gas fee for their transaction, incentivizing miners to prioritize and confirm it before the original transaction.
Profit: Once the user’s transaction gets confirmed first, they can then benefit from the subsequent price action. If they were buying a token, they could then sell it at a higher price after the original large transaction gets confirmed.
It’s important to note that front-running is an unethical practice and is not recommended.
Now let’s talk about MEV because it’s more than just front-running and can involve more or less steps depending on what the user’s aim is:
Transaction Reordering: By determining which transactions are confirmed in what order, miners can prioritize transactions that offer them the highest reward or from which they can derive indirect profit.
Transaction Insertion: Miners can insert their transactions to capitalize on the information they have. For instance, they can sandwich a user’s transaction with their own, benefiting from the price changes the user’s transaction will cause.
Transaction Excluding: Sometimes, by excluding certain transactions from a block, miners can increase the value they extract from other transactions.
Notable Instances of MEV
Perhaps the most common and well-recognized form of MEV is arbitrage. Don’t know how it works? Imagine two markets, where a token is cheaper in one and more expensive in another. A knowledgeable trader can buy from the cheaper market and quickly sell in the more expensive one, pocketing the difference. But in a blockchain environment, there’s a difference. Other observers can see this trade waiting to happen and jump ahead by offering to pay a slightly higher transaction fee. By doing so, they will take the profitable trade before the original user can execute it. Quite often users will set up arbitrage bots in order to automate this process and they are generally must faster than someone manually doing it.
Liquidations introduce another dimension. Within DeFi, users often borrow funds by providing collateral. But if the value of this collateral drops suddenly, these loans become at risk of liquidation. Applications then need to liquidate these under-collateralized positions at a discount. Users aware of this keep an eye out, ready to take advantage of these discounted assets. Again, the race is on, as multiple actors fight to be the first to capitalize on these liquidation events, and more often than not they are bots.
Something you may have heard of more recently and a more intricate tactic is what’s called a sandwich attack. In this scenario, a trader spots another user’s trade waiting for confirmation. They decide to place a transaction right before and right after the user’s trade. This encloses, or “sandwiches”, the user’s transaction. The user’s trade, especially if it’s large, can influence the asset’s price, which the attacker exploits by the surrounding transactions, buying just before the price increases and selling just after.
One advanced strategy that’s seen a lot of action is Just-In-Time (JIT) Liquidity Provision. Traditional trading often involves traders providing liquidity and waiting for an opportunity. In contrast, JIT liquidity provision is about seizing the moment. When traders detect a profitable instance but find that there’s not enough liquidity to execute it, they borrow the required assets, provide the necessary liquidity, complete the trade, and then immediately retract their liquidity, all within a single block.
While these instances of MEV all sound concerning, there are multiple ways that the community and platforms have taken to prevent MEV. Most notable is Flashbots, a transparent suite of software products that enable Ethereum users and infrastructure providers to capture and mitigate MEV. With Flashbots, bots send transaction bundles directly to miners via a relay, bypassing the public mempool. Miners evaluate these bundles and sequence them in a way that’s most beneficial to the network’s health and their own profit. This direct channel reduces the negative externalities of MEV, like network congestion due to bidding wars in the mempool.
To combat specific MEV challenges like liquidations, user-operated networks can be effective. Platforms like the Keep3r Network decentralize operations, delegating them to registered users called keepers. These keepers manage tasks, including liquidations, thereby reducing the competitive race and mitigating the impact of MEV extractions.
Borrowing from the traditional finance playbook, time-weighted order books aim to reduce the MEV problem by altering the order-execution dynamic. Instead of the conventional first-come-first-serve model based on gas prices, this approach executes orders based on an algorithmic function of time. It reduces the advantage of speed, making it harder for bots to game the system.
Commit-reveal is an age-old cryptographic tactic that’s found utility in countering MEV. Users first commit to a particular action without revealing its specifics. Only after all commitments are gathered does the reveal phase take place, where the actual intent of the transaction is shown. By obscuring transaction details until the last moment, the window for potential front-runners is significantly narrowed.
Real World Examples
On July 30th, Curve Finance fell victim to an exploit that resulted in one of the largest MEV reward blocks ever recorded. This event increased rewards for MEV bots which capitalized on front-running opportunities. The root cause was a vulnerability with Vyper versions 0.2.15, 0.2.16, and 0.3.0 which were vulnerable to malfunctioning reentrancy locks. This led to remarkable MEV rewards, with one block alone earning 584.05 ETH — equivalent to over $1 million. Additionally, there were three more large MEV rewards during this time, totaling 345 ETH, 247 ETH, and 51 ETH.
Another example is the MEV bot called “jaredfromsubway.eth”, which in April of this year gained attention by earning over $1 million within a week through sandwich attacks on traders of two new meme coins. From April 18 to 19, this bot alone accounted for 7% of all Ethereum gas fees. Most of the bot’s profits came from trades of the meme coins, Pepe (PEPE), and Wojak (WOJAK), making it the top gas user during that time.
DeFi is driven by the blockchain’s inherent transparency, which has ultimately made revolutionary financial tools readily available. However, with this innovation comes challenges. Front-running and MEV stand out as significant pain points, with actors capitalizing on the visibility of transactions to gain advantages.
However, initiatives such as Flashbots offer direct channels for transaction confirmations, while platforms like Keep3r Network aim to decentralize certain operations to reduce MEV’s impact. Methods like time-weighted order books and commit-reveal schemes further showcase the sector’s resilience and adaptability.