Earn $1 Million and Lose It in an Hour
MEV bot earned more than $1 million on successful arbitrage. But, almost an hour later, a hacker stole all the funds.
MEV bot earned more than $1 million on successful arbitrage. But, almost an hour later, a hacker stole all the funds.
MEV bot, arbitrage. Before moving on to the story, let's remember (or find out for the first time) what these concepts mean.
MEV is short for Maximal Extractable Value (formerly Miner Extractable Value). What does this mean? This is an indicator that shows the profit of a miner (or validator) from including, excluding or changing the order of transactions in the block being created.
Now, let's turn to the great Wikipedia for a concise definition of the word “arbitrage”:
“In economics and finance, arbitrage is the practice of taking advantage of a difference in prices in two or more markets; striking a combination of matching deals to capitalise on the difference, the profit being the difference between the market prices at which the unit is traded.”
Simply put, arbitrage is an opportunity to instantly buy something at a low price and sell at a high price. Manually, of course, it is not very convenient to do this. That's why MEV bots were invented. These are bots that automatically search for and use an arbitrage opportunity. Thereby, earning profit for the owner.
Great, we've sorted out the terms, let's talk about the story.
Robert Miller, an employee of the research and development organization Flashbots, earned 800ETH on his MEV bot with the prefix 0xbaDc0dE in one arbitrage. But Robert was not happy for a long time, because an hour later a hacker stole 1100ETH from the bot. Robert told this sad story on his Twitter.
Imagine making 800 ETH in a single arb
— @bertcmiller ⚡️🤖 (@bertcmiller) September 27, 2022
... and an hour later then losing 1100 ETH to a hacker
Here is the story of 0xbaDc0dE, an MEV bot who gained and lost it all in a few hours tonight
It all started with an incredible profitable arbitrage opportunity. Someone tried to sell $1.8 million in cUSDC on Uniswap V2, receiving about $500 in return.
Earlier today some poor soul tried to sell $1.8m in cUSDC on Uniswap v2 (!). They got ~$500 out in return. Yikes.
— @bertcmiller ⚡️🤖 (@bertcmiller) September 27, 2022
Meanwhile, this generated a massive arb opportunity.
tx: 0x96a129768ec66fd7d65114bf182f4e173bf0b73a44219adaf71f01381a3d0143 pic.twitter.com/fOAhVkFRgV
Robert's MEV bot did not miss a great opportunity and brought Robert 800ETH.
0xbaDc0dE dutifully backran the arb in the mempool (!) in a looong arb touching many protocols.
— @bertcmiller ⚡️🤖 (@bertcmiller) September 27, 2022
The profit from this was ~800 ETH!
tx: 0x2a615005a63785284f11a4c5cb803d1935d34e358c10a3b4d76398d2e7bb2f9d pic.twitter.com/h0GNO22y7y
But fortune did not stay on Robert's side for long. An hour later, an unknown hacker stole all the funds of the bot – 1100ETH.
... But just an hour later all of 0xbaDc0dE's ETH was stolen
— @bertcmiller ⚡️🤖 (@bertcmiller) September 27, 2022
I'll let the reader make the joke about the code themselves pic.twitter.com/c36stxrVeg
Robert suggested that the vulnerability was that the bot did not protect the function used to execute dYdX flashloans well enough.
When you get a flashloan the protocol you're borrowing from will call a standardized function on your contract.
— @bertcmiller ⚡️🤖 (@bertcmiller) September 27, 2022
In this case dYdX called "callFunction" on 0xbaDc0dE.
0xbaDc0dE's code unfortunately allowed for arbitrary execution.
PeckShield Inc., a blockchain security and data analytics company, also wrote about this vulnerability of the 0xbaDc0dE bot. The company analysed the situation and concluded that the error “is part of the MEV bot's callback routine, i.e., CallFunction(), which was exploited to approve an arbitrary address for spending.”
Our analysis shows the bug is part of the #MEV bot's callback routine, i.e., callFunction(), which was exploited to approve an arbitrary address for spending. Here is the related tx: https://t.co/A2LtcCfEkT https://t.co/vt9MLxEagp pic.twitter.com/06gcwdXtX7
— PeckShield Inc. (@peckshield) September 27, 2022
The vulnerability helped the hacker steal all of the bot's funds.
The attacker then simply transferred the weth out to their address.
— @bertcmiller ⚡️🤖 (@bertcmiller) September 27, 2022
tx: 0x631d206d49b930029197e5e57bbbb9a4da2eb00993560c77104cd9f4ae2d1a98
As Robert correctly pointed out, “bad code, great content.” Be careful, dear readers, always check your code. And we continue to observe.