grug, mev, & me

grug, mev, & me

This was me. Except over drinks.

We had drinks at fig19

Crypto moves quickly. There is a lot of surface area and I still have a lot to catch up on. MEV being one such thing. Sandwich attacks, The Dark Forest, Samczsun...all buzzwords that I've nodded along to.

After meeting up with Grug in NYC, I figured it was time.

Down the MEV rabbit hole with Grug —

(Again, fair warning: this blog isn't technical).

Grug pls help

Grug is an investor in SIZE and also really proficient in all things MEV. He got into MEV in 2020 but has always been drawn to zero sum games. Over the last 2 years, he's done a ton of MEV plays predominantly in the NFT space & on AVAX during the big Avalanche season.
‌‌
‌Grug sent me 20+ articles to read. I asked a bunch of questions. He walked me through transactions, code to run MEV bots. I feel like I understand MEV a lot better but you can be the judge of that .

What is MEV?

MEV stands for Miner Extractable Value.  

(I warned this blog would start from ground 0).

MEV is the profit a miner gets from manipulating transactions on the blockchain. So, pretty much arbitrage for the tradfi people reading this on Linkedin.

Miners can reorder and drop transactions and make a lot of money from it.

Pls ELI5

There are different types of MEV but I'll do a front-running example. More on different MEV types later.

Bob wants to front-run an NFT drop.

  • Bob wants to buy 50% of an NFT collection at drop.
  • Bob pays a higher fee than other NFT buyers.
  • Bobs wins half of the collection.
  • Bob then can flip to buyers on secondary for profit.

Front-running isn't a new concept. Traders on wall street have done this for ages. Martha Stewart kind of, maybe, did this (not a lawyer, loyal fan).

Pls ELI5+5

Every transaction on the blockchain has an associated fee. Each transaction fee is a bid for block space.

All transactions are grouped in a mempool (memory pool). Mempools are how nodes store unconfirmed transactions. Nodes don't all share the same mempool. Dependent on how advanced the hardware and software is, the transaction history & timing varies. The number of nodes operators run also impacts how many unconfirmed transactions the operator can see. Ie. Spend more, get more.

Mempools contain transactions broadcast to the Ethereum network. So basically pending transactions fighting for block space. Mempools are surface area for MEV attacks. Transactions are prioritized and ordered. Transactions that win block space get connected to miners. Lower bids get pushed to the back of the line or dropped altogether.

Types of MEV attacks

There are different types of MEV plays: front-running, back-running, sandwich attacks, generalized front-running, liquidations, JIT etc. A little on each & some examples.

Front-running. The fastest transaction wins. So basically you pay more to win a gas auction.

  • AKA. Every NFT drop I have ever lost. Buyers pay to skip the line, buyers win NFT drop. Buyers probably flip the NFTs to losers for profit.

Generalized front-running (another example of front-running). Copy, paste, front-run. Simulate original attack but replace the transaction address with your own address. If the simulated attack is profitable, execute the transaction at a higher gas price.

  • The recent Nomad exploit was a good example of generalized front-running. In August, Nomad was drained of ~$200M. 41+ wallets drained ~80% funds. People raced to copy the original hacker's transaction, replace address etc.

Back-running. Back-run other transactions for profit. You look at prior trades to find new trade opportunities.

  • An example would be... A whale market buys $10M Eth on Sushi. The price of Eth on Sushi goes up. Back-runner buys on Uniswap, sells on Sushi for a profit. Transaction is done atomically within one transaction.

Sandwiching. Basically a combination of front-running and back-running. Sandwich another user's transaction and profit off of it. (Usually on DEXs).

  • Alice saw that someone is buying $5M LDO. Alice cranks up the gas and buys LDO prior which bumps up slippage. LDO price goes up. Alice then sells her LDO for profit. Usually all three transactions happen in the same block.

Liquidations.  Arbitrage defaulted loans for profit. Liquidators capitalize off of undercollateralized loans.

  • Let’s say the market tanked overnight. Borrowers on Compound wake up to find themselves below required collateral threshold. Liquidators can extract MEV by using a flash loan to liquidate users and snipe defaulted loans. Liquidator gets loan, receives collateral, sells collateral, repays flash loan, keeps profit. NB: Liquidators can use their own collateral if the flashloan isn’t gas efficient but it is obviously capital intensive.

Just In Time (JIT) Liquidity. Liquidity providers arbitrage AMM transaction fees. Identify large transactions, front-run those large transactions by providing liquidity at a super tight range. Profit off of transaction fee.

  • Bob submits a transaction of $1 million USDC for Matic on Uniswap. Grug wakes up and wants to do some MEV. Grug front-runs Bob's order and provides $1 million of liquidity at a tight price range. Grug captures most of the fee revenue. He then removes his liquidity and goes about his day.


WTF is the Dark Forest

I've talked a lot about mempools. Surprise, surprise, the mempool is the Dark Forest.

Mempools consist of thousands of transactions. The more complex the chain, the more transactions, the more surface area for MEV opportunities.

Bots relentlessly scan and analyze mempools for opportunities to pounce. That bot army is growing especially with quant firms entering the fray with increasingly complex algorithms & set ups. The forest has gotten crowded. The monsters bigger.

MEV has grown increasingly competitive and lucrative since 2021. Less opportunity, more competitive searchers, more advanced algorithms and hardware etc. Arbs/sandwiches/liquidations are a race to the bottom because only one searcher can capture an opportunity. As a result, miner bribes can get bid up to 90%+ and searchers give away most of the opportunity. As the space gets more saturated, searchers continue to migrate to alternate chains to look for more lucrative opportunities.

Flashbots has since emerged to help combat risks associated with MEV. Flashbots made it safer and more efficient to extract value from the Dark Forest. Flashbots connects searchers and validators (previously miners).

Flashbots has democratized access to MEV, helped provide transparency into transactions and generally helped to level the playing field for searchers. To get a bit more granular, Flashbots enabled sealed bid block space auctions where users submit transactions bids. Flashbots auctions are first-price sealed bid auctions which means that everyone submits blinded bids simultaneously and the highest bidder wins.

Flashbots eliminates a lot of chaos around MEV. Making it easier for people to participate while making MEV more price efficient, eliminating front-running, maximizing validator profit. So basically it is a marketplace for MEV.

The Merge & MEV

This blog wouldn't be complete if I didn't touch on MEV post merge. Since the merge, the MEV landscape has evolved.

MEV is no longer called Miner Extractable Value. Now it's called Maximal Extractable Value. Instead of miners profiting off of MEV, validators do.

Block building has emerged as a key role in the MEV ecosystem. The barrier to entry to become a validator is pretty low (32 eth) which means that new participants will probably have no idea how to optimize blocks for profit. Block builders specialize in optimizing transactions within a block aka who can build the most profitable block.

Fixed block times may lead to searcher & validator coordination. Previously, blocks were confirmed whenever. Now blocks are confirmed every 12 seconds. Fixed block time heightens MEV competition within blocks. It also gives searchers runway to avoid or target specific validators. Which leads into my next point...

Pressure to censor specific blocks. Centralized exchanges under regulatory scrutiny run the majority of validators. To date, custodians hold 35%+ staked ETH ( Coinbase 14%, Kraken 9%, Binance 7%). Separate but adjacent, we have Lido at 31% staked ETH etc. Validators under regulatory scrutiny may feel pressure to censor blocks that contain MEV. This literally impacts who can take part in MEV.

Is MEV good or bad?

Unsure.

People seem to have different viewpoints. Like everything else in a highly ambiguous and nascent space, there are pros and cons. It doesn't seem great to me but it also seems like arbitrage is a reality in any economic market. ‌I look at MEV as a reality versus a bug to solve.

First the pros to MEV. On the bright side, MEV has made Dapps more sturdy, improves mechanism design. The threat of impending adversarial attacks will do that. Arbs also make markets more efficient and lead to better quotes across pools.

On the not so bright side, MEV can lead to a worse user experience. We've all gotten front-run in NFT auctions, lost money on trades due to slippage etc.  MEV also increases gas prices which makes the network slower and more expensive. That said, Flashbots has helped mitigate the negative externalities imposed on users particularly by lowering fees by moving gas auctions off-chain. Lastly, there is the argument that MEV could theoretically destabilize the network. Validators could choose to make more money remining and reorging blocks. Not great for obvious reasons.

Stepping back, to be honest, my main revelation was that the mempool is the Dark Forest. That did not click prior. Obvious to most of you but it is what it is. I was also surprised and pretty fascinated by the number of different types of MEV plays and different strategies/tactics.

If you made it this far, thanks! Please let me know if I missed anything.

With that, I'll wrap it up. Thank you Grug!

Big thanks as well to Caleb Cheng (@mevcheb) who walked me through a ton of examples. & Seranged who helped me proof this. Some favorite resources below.

Articles


Show Comments