Reproduced Exploit

Bunni: a 1 wei donation makes rebalanceOrderPreHook revert

The August review's prehook requires currency.balanceOfSelf() == args.amount. Donating 1 wei first makes the balance amount + 1 after the order pull. The hook reverts with BunniHook__PrehookPostConditionFailed. A pull of exactly amount onto an empty hook succeeds.

Aug 2024•Ethereum•dos•3 min read

Loss

The 1000-token rebalance order cannot execute. rebalanced stays false

Chain

Ethereum

Category

dos

Date

Aug 2024

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 43549-h-04-attacker-can-dos-the-rebalance-mechanism-pashov-audit-g. Standalone Foundry PoC and full write-up: 43549-h-04-attacker-can-dos-the-rebalance-mechanism-pashov-audit-g_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/dos/frozen-funds · vuln/logic/missing-check

Key info#

FieldValue
LossThe 1000-token rebalance order cannot execute. rebalanced stays false
Vulnerable contractBunniHook.rebalanceOrderPreHook
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-08
Compilersolc 0.8.27, cancun, via IR
Bug classAbsolute balance check instead of a balance delta

TL;DR#

The August review's prehook requires currency.balanceOfSelf() == args.amount. Donating 1 wei first makes the balance amount + 1 after the order pull. The hook reverts with BunniHook__PrehookPostConditionFailed. A pull of exactly amount onto an empty hook succeeds.

The vulnerable code#

SOLIDITY
if (currency.balanceOfSelf() != amount) { // @> VULN: the whole balance must equal the order amount, so a 1 wei donation makes the check fail
    revert BunniHook__PrehookPostConditionFailed();
}

The review says to compare the increase in balance with args.amount, not the total balance. balanceOfSelf is the v4 Currency helper, inlined into the hook.

Root cause#

The hook can already hold manager fees when am-AMM is on, and anyone can transfer the order token to the hook. Either residue breaks an equality check against the order size.

Preconditions#

  • The order amount is 1000 tokens.
  • The hook's token balance is 1 wei before the pull.
  • The prehook pulls amount and then compares the whole balance.

Attack walkthrough#

  1. Donate 1 wei to the hook.
  2. Call the prehook with amount 1000 tokens.
  3. The pull would make the balance 1000 tokens plus 1 wei.
  4. The equality reverts. rebalanced is false.
  5. The control, with an empty hook, sets rebalanced and holds exactly 1000 tokens.

Diagrams#

flowchart TD A["Hook is donated 1 wei"] --> B["Order pulls 1000 tokens"] B --> C["VULN balance is not equal to amount"] C --> D["Prehook reverts"] D --> E["rebalanced stays false"] F["Empty hook pulls exactly 1000"] --> G["Control rebalance succeeds"]

Impact#

Autonomous rebalancing does not run. The order cannot be filled while any unexpected token balance sits on the hook. One wei is enough. The same revert happens when am-AMM manager fees are already on the hook.

Remediation#

Measure the balance before the pull and require that the increase equals args.amount. Do not require the total balance to equal args.amount.

How to reproduce#

BASH
cd 43549-h-04-attacker-can-dos-the-rebalance-mechanism-pashov-audit-g_exp
forge test -vv

Captured output is output.txt.

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.