Reproduced Exploit

g8keep: a failed migration stores the bonding-curve reserves backwards

After a failed migration the curve holds 5 WETH and 500 G8. _handleMigrationFailed stores the token amount in reserve0 and the ETH amount in reserve1. buy uses reserve0 as the input reserve, so 1 WETH quotes dust instead of about 83 G8. The curve keeps the WETH.

Dec 2024•Other•logic•2 min read

Loss

1 WETH buys dust G8; the fair quote is more than 80 G8

Chain

Other

Category

logic

Date

Dec 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: 45307-h-02-incorrect-reserve-assignment-leads-to-reserve-mismatch. Standalone Foundry PoC and full write-up: 45307-h-02-incorrect-reserve-assignment-leads-to-reserve-mismatch_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/state-update · vuln/logic/price-calculation

Key info#

FieldValue
Loss1 WETH buys dust G8; the fair quote is more than 80 G8
Vulnerable contractBondingCurve._handleMigrationFailed
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateLocal synthetic · 2024-12
Compilersolc 0.8.27, cancun, via IR
Bug classtokenAmount is written into reserve0, the ETH reserve

TL;DR#

After a failed migration the curve holds 5 WETH and 500 G8. _handleMigrationFailed stores the token amount in reserve0 and the ETH amount in reserve1. buy uses reserve0 as the input reserve, so 1 WETH quotes dust instead of about 83 G8. The curve keeps the WETH.

The vulnerable code#

SOLIDITY
function _handleMigrationFailed(uint256 ethAmount, uint112 tokenAmount) internal {
    curveStatus = curveStatus | 1;
    reserve0 = tokenAmount;
    reserve1 = uint112(ethAmount);
}

The assignment should be reserve0 = uint112(ethAmount) and reserve1 = tokenAmount.

Root cause#

The two reserve slots are filled in the opposite order from the one buy and getAmountOut assume.

Preconditions#

  • The curve already holds 5 WETH and 500 G8.
  • A failed migration is recorded with those amounts.

Attack walkthrough#

  1. handleMigrationFailed(5 WETH, 500 G8) sets the failed-migration flag.
  2. reserve0 becomes 500 G8 and reserve1 becomes 5 WETH.
  3. The buyer pays 1 WETH.
  4. The quote uses the swapped reserves. The output is less than a thousandth of the fair buy, and the curve's WETH balance is 6.

Diagrams#

flowchart TD A["Curve holds 5 WETH and 500 G8"] --> B["Failed migration writes reserves"] B --> C["reserve0 is 500 G8 and reserve1 is 5 WETH"] C --> D["buy quotes 1 WETH against those slots"] D --> E["Buyer receives dust and the curve keeps the WETH"]

Impact#

Buys and sells price the pool backwards. This run pays 1 WETH for dust G8 while the true reserves would return more than 80 G8.

How to reproduce#

BASH
cd 45307-h-02-incorrect-reserve-assignment-leads-to-reserve-mismatch_exp
forge test -vv

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.