Understanding Ethereum's invisible tax – MEV.
A thread. 🧵
Blockchain technology is the main driving force behind cryptocurrencies and DeFi.
In a blockchain network, miners and validators get paid some amount of gas fee to validate transactions and mine new blocks onto the blockchain.
However, earning block reward isn't the only way for miners to get paid.
As new transactions sit pending in the Mempool, miners or validators have found a way to maximize their profits using a strategy called MEV.
✨What is MEV?✨
MEV (Miner/Maximal Extractable Value) refers to the maximum amount of profit a miner or validator can extract by including, excluding or reordering transactions in a block.
✨How does MEV work?✨
To understand how MEV works, first, let's try to understand how transactions flow in a blockchain.
When a user makes a txn, it's sent to a public mempool where all pending txns sit, waiting to be added to a block.
All these txns are public and visible to everyone, including miners/validators.
All these txns are ordered & packaged by miners through a Priority Gas Auction (PGA).
PGA means that txns with higher gas fee gets batched & executed first and added to the block.
So, let's say a user named Bob makes a large order to buy 20 ETH on a DEX like Uniswap.
Here's how a simple MEV attack would work:
1️⃣ Bob sends a transaction to purchase 20 ETH on Uniswap.
2️⃣ A miner named Alice identifies the txn in mempool and places a similar trade to buy ETH from same liquidity pool.
Since the miners have control over which txn to execute first, Alice executes her txn before Bob's.
As a result, increasing the price of ETH & Bob's trade gets executed at a suboptimal exchange rate.
Additionally, there are predatory bots that can identify & copy Bob's txn and place it with higher gas fee incentivizing miners like Alice to execute their txn before Bob's.
This technique is known as a Front-Running Attack.
Searchers often use generalized front-runner bots to scan mempool to capture lucrative MEV opportunities.
3️⃣ Bob's transaction get executed & added to the block.
4️⃣ Now that the price of ETH has increased, Alice then orders a second txn to sell the recently purchased ETH, making an arbitrage trade.
This technique is known as back-running.
This entire process of combining front-running and back-running is known as a Sandwich attack.
It is one of the most common MEV strategies to make profits from arbitrage opportunities.
Apart from miners/validators, there are other players such as searchers and bots in the MEV process, trying to profit from pending transactions.
Searchers are independent participants in the blockchain network that constantly seek MEV opportunities by running complex algorithms,
and setting up bots to submit transactions with higher gas prices and capture MEV.
However, miners are best placed to extract MEV by front-running other participants since they are the ones deciding which transactions get executed first.
And since searchers are willing to pay a higher gas fee to have their transactions executed first, miners still receive a percentage of the MEV in the form of gas fee.
Also, please consider subscribing to my blog & get content like this delivered right into your inbox. ⬇️
cryptoshuriken.com/#/portal/
PS - I'm doing a #30Days30Threads challenge!
This was the thirteenth one, 17 more to go!
Stick around for tweets on:
→ Blockchain Development
→ Web3, in general
→ Content Creation
13/30 ✅