Immunefi
Published in

Immunefi

Hack Analysis: 0xbaDc0dE MEV Bot, September 2022

Introduction

Background

0xbad bytecode

Transaction Investigation

Transaction call trace on samczsun’s viewer
0xbad’s inferred storage layout, using Dedaub’s online decompiler
Usage of delegatecall in 0xbad
Snippet 1: Foundry test to read 0xbad storage
Foundry storage reading test output

Digging Deeper with a Proof of Concept

0xDd6B’s public methods, seen on EtherVM
Snippet 2: interfaces.sol implementing SoloMargin methods
Snippet 3: Attacker.sol, the contract trying to execute 0xbad’s logic
Foundry test contract
Foundry test output, showing the transaction being reverted
  1. WETH.allowance
  2. An exchange function on a Curve Finance contract
  3. USDT.allowance
  4. The same exchange function on Curve
  5. USDC.allowance
  6. UniswapV2Router.swapExactTokensForTokens
  1. WETH.allowance
  2. A swap function with a Balancer’s Vault
  3. wstETH.unwrap
  4. stETH.allowance
  5. An exchange function on a Curve Finance contract
  6. WETH.transfer
Some labels on the data field of a 0xbad transaction (0x8e56)

Exploiting the Vulnerability

Test trace after replacing 0xDd6B called addresses with Attacker address
Functions exchange and swapExactTokensForTokens on the Attacker contract
Final form of Attacker.attack
Test output of our final PoC

Conclusion

Snippet 7: All code.

--

--

Immunefi is the premier bug bounty platform for smart contracts and DeFi projects, where security researchers review code, disclose vulnerabilities, get paid, and make crypto safer. Immunefi removes security risk through bug bounties and comprehensive security services.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Immunefi

Immunefi is the premier bug bounty platform for smart contracts, where hackers review code, disclose vulnerabilities, get paid, and make crypto safer.