Hack Analysis 0xbadc0de Mev Bot September 2022
The 0xbad MEV bot's proxy contract delegated calls to an unverified implementation that executed arbitrary encoded actions without validating the target addresses or function signatures. An attacker could abuse the dYdX SoloMargin flash-loan callback to make the bot approve the attacker's contract for its entire WETH balance and then transfer those funds out.
immunefi.com
Published on immunefi.com
On September 27th, 2022, a smart contract MEV bot was hacked on the Ethereum blockchain, losing around 1,101 WETH, which amounted to approximately $1.46m on the day of the exploit. Interestingly, the hack took place just 30 minutes after the MEV bot pulled off a notoriously profitable arbitration that earned it 804…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the implementation contract executed caller-supplied encoded actions (target addresses and function selectors) without validating them, and it auto-approved the caller for its full token balance when the allowance was zero.
Impact
The attacker could drain all of the MEV bot's WETH, around 1,101 WETH or roughly $1.46m at the time; the write-up demonstrates this on a local fork rather than the live chain.
What the attacker needed
Ability to call dYdX SoloMargin operate; a deployed attacker contract; knowledge of a past callFunction payload
The fix
The contract should validate the target addresses and function selectors in caller-supplied action data and should not automatically grant unlimited allowance to the caller.
How it was found
- Call dYdX SoloMargin's operate function with a Call action whose otherAddress is the MEV bot.
- Observe that the call reaches the bot's callFunction callback but reverts inside its logic.
- Reuse the data field from a past successful callFunction transaction and update the expired deadline.
- Replace the called protocol addresses in the data with the attacker contract's address.
- Implement the expected exchange and swap functions returning the original values so the bot's checks pass.
- After operate, use the granted allowance to transfer all the bot's WETH to the attacker.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A smart contract is a program on a blockchain that can hold money. This bot let another contract (dYdX) trigger its internal logic, and that logic trusted instructions supplied by the caller. By pretending to be that trusted caller, the attacker made the bot hand over permission to spend all its funds, then took them.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.