🥪 bots watch the mempool for users buying on DEXes and 🥪 them:
1.🥪bot buys an asset to push the price up 2. victim buys at an inflated price, pushes price up more 3. 🥪 bot dumps at a profit at the victim's expense
Thread failed to post, hold on folks
Those 3 txs (🥪buy, victim tx,🥪sell) make up a bundle
~200 days ago the 1st 🥪 bots were rekt by the likes of @NathanWorsley_ and @code0x2, who deployed poisonous bait tokens now known as "salmonella"
The core idea of salmonella is simple: get a 🥪 bot to buy a token & prevent them from selling
By doing so the 🥪 bot's ETH would be sitting in a Uniswap pool where it could be drained (e.g. by selling a premined portion of tokens in the next block)
Here's one instance of a successful salmonella, where the 🥪 bot lost 100 ETH to an attacker!
There have been a few of these totaling well over $1m
One such aggregator is 1inch, which has a special quirk: the contract lets you specify which pools to trade on
The regular user never knows this, but this quirk was critical to baiting 🥪 bots.
To be a bit more clear this is how that works:
- User makes trade on an aggregator
- 1inch routes some of that trade to Uniswap
- 🥪 bot notices the 1inch trade
- 🥪 bot 🥪s the Uniswap portion of the 1inch trade
End result: 🥪 bots monitoring all DEX aggregator trades too
Amusingly it seems that many 🥪 bots watched 1inch but did NOT validate that the pools users were trading on were valid
If an attacker injected a trap into their 1inch trade they could get 🥪 bots to interact with it
One attacker, Kaiji, did exactly this
Here's how the attack looked in practice
🥪 bots saw the 1inch trade & tried to sandwich it
1st they tried to buy tokens from the trap, sending 17 ETH
Then they tried to sell tokens, but got close to nothing and their 17 ETH was now in a place the attacker could get it
Note how weird this 🥪 looks. There are no tokens being traded here! It's only ETH. This fact confused me for awhile.
So how did the trap work?
Decompiling the trap I immediately noticed getReserves() and a standard Uniswap error message, which is what you'd expect to see in a Uniswap pool.
Using a different tool to decompile, I notice block.coinbase was being called to check the miner of a block. That's an old trick used to throw off bot simulations!
func_022c0d9f felt familiar. I realized that this was actually function selector for the Uniswap v2 pool swap() function
Selectors are pretty low level but the tl;dr is that functions are identified by hashing their names/inputs
So I *knew* this function was swap()
It was at this point it hit me that the trap was a fake Uniswap v2 pool.
The attacker had implemented the functions you'd need to interact with a v2 pool but with custom logic designed to take 🥪 bot's ETH instead
A little later there was some conditional logic which looked for transactions from the attacker, which made sense. You don't want to trap yourself.
Still, I didn't have the whole picture... until the attacker kindly sent me their code
Here's the real swap() function. It simply checked to see if the caller was not the owner and if the miner was real (to throw off simulation).
If so it returned way less ETH.
As far as I can tell it didn't even bother handling the other token in this Uniswap "pool," which explains why there weren't any tokens in the trades before.
In total the attacker made ~30 ETH with this bait.
Still yet the defenses against this are very simple:
- check the pools you interact with, even if they come from aggregators
- fail your sell transaction if you end up with less ETH than you started.
It is likely that victims weren't making this ETH check to save a bit of gas
Lastly, the attacker took to the Flashbots discord where they were a savage
Here's Kaizi talking to their victim 0x2 - who long ago salmonella'd other bots themselves 😅😂
That's all for today!
If you're interested in working on MEV we're hiring at Flashbots :)
Today Flashbots is releasing v0.4 and introducing mega bundles to the Flashbots Network
Mega bundles will let us innovate faster, support more bundles and will lead to new searcher strategies and more miner revenue
A thread on mega bundles 🧵👇🏻
Flashbots is an open MEV marketplace. On 1 side of the market users submit "bundles" of txs. On the other miners run an auction & place the highest gas price bundles at the top of blocks.
This allows miners of any size to extract MEV, which is important for economic security.
In the early days of Flashbots only 1 bundle could be included in a block. That greatly limited our impact.
Our v0.2 release introduced multiple bundles per block through a merging process & gave miners control the number bundles they wanted to include
Contrary to Multicoin's claims, minimizing MEV is core to Flashbots' mission & products.
That shows from our funding of fairness and ethics research, work on MEV aware dApps, & 100s of users that have used Flashbots to skip the mempool & protect themselves from frontrunning.
More importantly, Multicoin is lying about Eden: it is not permissionless OR transparent.
Eden is a permissioned system with a multisig that has exclusive control over MEV payouts to miners. The Eden team alone decides whether miners are mining "Eden blocks" and should be paid.
Dropping what is probably the most alpha packed thing I've written so far: an in-depth writeup of my strategy for a highly competitive MEV opportunity, the Synthetix Ether Collateral Liquidations, along with code
Blog post contains:
- My process from start the finish
- Explanation of why I made the design decisions I did
- How I sped up data collection
- A few gas optimizations
- Explanation of my economic strategy
- My novel bundle submission strategy
- Code snippets
- Many links
Repo contains:
- The only (I think?) open source example of how to backrun transactions
- Monitoring tools I made
- Contracts used for execution, including dydx flashloan
- Contract for data collection
- my somewhat embarrassing messy Hardhat testing env
The beating heart of every blockchain is how space is allocated within a block.
With major changes to how Ethereum's blockspace market works in the near and medium term we'd like to share how Flashbots thinks about designing MEV marketplaces.
2nd: attest to this with a proof-of-work and propagate it to the network.
Prior to widespread MEV extraction, the 1st job was mainly ordering txs by their gas price, with optimization at the network lvl.
However, since MEV extraction is widespread now, the the job of miners has changed. Now to produce the most profitable block miners must find the optimal ordering of transactions within a block.
This is exponentially more difficult than sorting by gas price.