In the early days of Bitcoin, miners could receive rewards for either mining a block or as commissions for a transaction with the highest gas price.
The logic behind forming a block was relatively simple
get all the valid unmined transactions from the mempool, sort them according to their gas price, form them into a block and then begin mining.In time, as blockchain got more and more advanced, we witnessed the development of Turing-complete smart contracts on Ethereum and then the whirlwind of DeFi growth.
With all that, block producers received additional methods of turning profit.
It turned out that by including, excluding and rearranging the order of transactions, block producers could now earn additional rewards.
This mechanism was called MEV (maximal extractable value)
the biggest sum that block producers could earn.The history of MEV
Even before Ethereum’s mainnet release, discussions regarding gaining additional profit began showing up online.
Users have discovered that the public decentralized nature of blockchain allows ‘sneaking’ a smaller transaction in front of a large one, so anyone can easily purchase assets at a lower price.
Because a larger purchase increases the asset’s value on decentralized exchanges, an earlier transaction can prove profitable, since the assets have been obtained prior to growth.
The term ‘MEV’ was coined in 2019 after the research Flash Boys 2.0 was published. It was the first comprehensive research on the matter which provided a detailed look into the issue.
How does it work
Usually, miners, validators or block producers have the authority to include, exclude and rearrange certain transactions.
Imagine a scenario
you see an opportunity to earn money on a protocol. You realize that the opportunity has been available to everyone for a while, yet it hasn’t been exploited.So, you prepare a transaction, send it and eagerly await its mining to receive the desired reward.
However, it turns out someone jumps right ahead of you with a similar transaction and steals the reward for themselves from under your nose.
It’s only reasonable to wonder what are the chances of two people simultaneously finding the same opportunity.
Pretty low, and to make matters worse, no one had been looking
here are programs and tools that automatically analyze the submitted transactions and then modify the ones that can prove profitable for the benefit of their owner.If this works, the copycat transaction is sent ahead using frontrunning.
MEV types
Arbitrage
Arbitrage is a way to profit from the price gaps on different platforms. Miners who notice said gaps can be the first to send their transactions to take advantage of them.
These actions are considered to have a positive influence on the market because they help maintain relatively similar asset prices on different platforms and exchanges since bigger gaps can prove problematic.
Frontrunning
An MEV transaction is placed ahead of the original one. We have already discussed them earlier, noting that when such a transaction is submitted ahead of the original one of a larger purchase on a DEX.
Another mechanism involves copying the original transaction with small adjustments for the attacker to get the profit instead of the initial sender.
Backrunning
It’s similar to frontrunning, except the transaction is placed right after the original one. An example of this usage is buying a token first right after the project launch
as soon as it becomes available on the DEX.Sandwich attack
It’s a combination of two previously described types of attack. The attacker sends two transactions
one before and one after the original one.This way, as opposed to a frontrun preceding a large purchase, the attacker can easily review and document their profit.
Liquidation
Lending protocols are often arranged in a way that allows a position to be liquidated by any user, which allows them to earn extra funds.
Users have to compete for sending the liquidation transaction to receive the profit.
MEV prevention
It’s obvious that the possibility of using MEVs imposes additional commissions on users and brings additional risks.
The Flashbots system was created specifically for combating MEVs. This system attempts to control MEVs by creating an open transaction auction.
Conclusion
The possibility of MEVs is a result of the open and decentralized structure of blockchain. This has both positive and negative effects.
It’s vital for blockchain users and developers to understand the way the technology works to minimize the risks of becoming a victim of an unexpected attack.
Gleb Zykov is the co-founder and CTO of HashEx Blockchain Security. He has more than 14 years of experience in the IT industry and over eight years in internet security, as well as a strong technical background in blockchain technology (Bitcoin, Ethereum and EVM-based blockchains).
Follow Us on Twitter Facebook Telegram
Generated Image: Midjourney