Reproduced Exploit

g8keep: migration swaps 1 wei and leaves 1000 tokens unmigrated

_adjustPoolPrice adds temporary liquidity, then swaps. When the pool price is below the target it calls swap with int256(uint256(1)). One wei stops at the constrained tick, sqrt price 1001. The target is 5000, so adjustFailed stays true and migrate returns without moving the inventory. 1000 tokens…

Dec 2024•Ethereum•dos•4 min read

Loss

1000 tokens stay in the migrator. The pool receives 0

Chain

Ethereum

Category

dos

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: 45306-h-01-migration-will-fail-trying-to-swap-1-wei-of-tokens-to-r. Standalone Foundry PoC and full write-up: 45306-h-01-migration-will-fail-trying-to-swap-1-wei-of-tokens-to-r_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/dos/frozen-funds · vuln/logic/price-calculation

Key info#

FieldValue
Loss1000 tokens stay in the migrator. The pool receives 0
Vulnerable contractMigrator._adjustPoolPrice
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2024-12
Compilersolc 0.8.27, cancun, via IR
Bug classHardcoded 1 wei swap cannot reach the target sqrt price

TL;DR#

_adjustPoolPrice adds temporary liquidity, then swaps. When the pool price is below the target it calls swap with int256(uint256(1)). One wei stops at the constrained tick, sqrt price 1001. The target is 5000, so adjustFailed stays true and migrate returns without moving the inventory. 1000 tokens remain in the migrator and the pool balance is 0. Swapping the 4000 units between the start price and the target reaches 5000 and moves all 1000 tokens.

Background#

Pashov Audit Group's g8keep review of 12 December 2024, finding H-01, against g8keep/audit-v2 at 7ed875cf8104c6267be505ca8c31372448a6f16e. The curve migrates its inventory into a Uniswap V3 pool only after the pool price equals the target. The report says a 1 wei ETH swap reaches constrainedTickUpper and not the target, so migration cannot complete.

The vulnerable code#

SOLIDITY
if (sqrtPriceX96Start > sqrtPriceX96) {
    pool.swap(address(this), true, int256(uint256(tokenAmount)), sqrtPriceX96, "");
} else {
    // @> VULN: 1 wei stops at constrainedTickUpper and cannot reach sqrtPriceX96
    pool.swap(address(this), false, int256(uint256(1)), sqrtPriceX96, "");
}
(uint160 sqrtPriceX96New,,,,,,) = pool.slot0();
adjustFailed = sqrtPriceX96 != sqrtPriceX96New;

The recommended change uses the amount required to reach the target, and allows a small tolerance when comparing the resulting price with that target.

DIFF
- pool.swap(address(this), false, int256(uint256(1)), sqrtPriceX96, "");
+ pool.swap(address(this), false, int256(sqrtPriceX96 - sqrtPriceX96Start), sqrtPriceX96, "");

Root cause#

The upward swap hardcodes 1 wei. In this reduction the pool moves one price unit per wei and caps an amount of 1 at the constrained tick, which is start plus 1. Start is 1000 and the target is 5000, so the post-swap slot0 price is 1001. adjustFailed is true and the transfer into the pool is skipped.

The pool here is a mock of that price step. It is not a full Uniswap V3 deployment. The mocked step is the one the report describes: 1 wei reaches the constrained tick and not the target.

Preconditions#

  • The curve already holds the migration inventory. This run uses 1000 tokens.
  • The current sqrt price is 1000 and the target is 5000, so the code takes the else branch.
  • Temporary liquidity is added before the swap, as in _adjustPoolPrice.

Attack walkthrough#

  1. 1000 tokens are minted and transferred to the migrator.
  2. migrate reads the start price 1000 and the target 5000.
  3. Temporary liquidity is recorded, then swap is called with amount 1.
  4. The pool price becomes 1001. slot0 does not match 5000.
  5. adjustFailed is stored and migrate returns. The pool balance stays 0.
  6. The control swaps 4000 units, the price becomes 5000, and the pool holds the 1000 tokens.

Diagrams#

flowchart TD A["Migrator holds 1000 tokens"] --> B["Start price 1000 and target 5000"] B --> C["VULN swap uses 1 wei"] C --> D["Price stops at the constrained tick 1001"] D --> E["adjustFailed is true"] E --> F["1000 tokens stay in the migrator"] B --> G["Control swaps the 4000 unit gap"] G --> H["Price is 5000 and the pool receives 1000"]

Impact#

The migration inventory of 1000 tokens never leaves the migrator. The Uniswap pool that should have received them holds 0. Holders cannot complete the move to the secondary pool. The control, which swaps the distance to the target, empties the migrator and leaves 1000 tokens in the pool.

Remediation#

Pass the amount that reaches sqrtPriceX96, not 1, and compare the resulting price with a small tolerance instead of strict equality. That is the change recommended on H-01.

How to reproduce#

BASH
cd 45306-h-01-migration-will-fail-trying-to-swap-1-wei-of-tokens-to-r_exp
forge test -vv

test_exploit_one_wei_swap_leaves_1000_tokens_unmigrated asserts adjustFailed, a price of 1001, and 1000 tokens still on the migrator. test_control_exact_swap_migrates_1000_tokens asserts a price of 5000 and 1000 tokens in the pool. 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.