Reproduced Exploit

Sweep n Flip — Premature createPair creates unusable delegated pairs

1. Wrapper addresses for ERC721 collections are CREATE2-predictable from the factory. 2. Ideal flow is createWrapper then createPair. An attacker can call createPair(usdc, precomputedWrapper) before the wrapper exists. 3. Because the address is not yet a registered wrapper, createPair marks the pai…

Nov 2024Otherlogic3 min read

Chain

Other

Category

logic

Date

Nov 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. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 46466-premature-createpair-function-call-will-result-in-the-creati. Standalone Foundry PoC and full write-up: 46466-premature-createpair-function-call-will-result-in-the-creati_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/missing-check · impact/mev/frontrun · frozen-funds · dos-resistance

Reproduction: self-contained Foundry PoC, offline, forge-std only. Full trace: output.txt. PoC: test/46466-premature-createpair-function-call-will-result-in-the-creati_exp.sol.


Key info#

ImpactHIGH — permanent DoS of legitimate ERC721-wrapper trading pairs
ProtocolSweep n Flip (UniswapV2-NFT AMM)
Vulnerable codeUniswapV2Factory.createPair — marks unknown tokens as delegated
Bug classCREATE2-precomputable wrapper address front-run → permanent delegated flag
FindingCantina — Sweep n Flip NFT AMM, Nov 2024 · #46466 · reporter slowfi
Reportcantina_sweepnflip_nft_amm_november2024.pdf
SourceAuditVault
StatusAudit finding — fixed in uniswap-v2-nft PR 5
Compiler^0.8.24 (PoC)

TL;DR#

  1. Wrapper addresses for ERC721 collections are CREATE2-predictable from the factory.
  2. Ideal flow is createWrapper then createPair. An attacker can call createPair(usdc, precomputedWrapper) before the wrapper exists.
  3. Because the address is not yet a registered wrapper, createPair marks the pair as delegated (external DEX).
  4. Later createWrapper deploys at the same address, but the delegated flag is never cleared — the pair is permanently unusable on Sweep n Flip.

The vulnerable code#

SOLIDITY
if (!isWrapper[token0] && !isWrapper[token1]) {
    delegates[token0][token1] = true; // @> VULN: marks precomputed (unregistered) wrapper as delegated forever
    delegates[token1][token0] = true;
}

Fix: require a registered wrapper (or matching extcodehash) before creating a native pair; or merge createWrapper + createPair.


Root cause#

createPair only checks the isWrapper registry, not whether an address is a CREATE2-precomputable future wrapper. Front-running createWrapper permanently poisons the pair as delegated.

Preconditions#

  • Factory uses CREATE2 for WERC721 with a salt derived from the collection address.
  • createPair is permissionless.
  • Target NFT collections are known / enumerable (top collections are few).

Attack walkthrough#

  1. Precompute wrapper = CREATE2(factory, salt(collection), WERC721 initcode).
  2. Call createPair(usdc, wrapper) — neither side is isWrapper yet → delegates = true.
  3. Legitimate createWrapper(collection) deploys at the same address and sets isWrapper.
  4. HARM: delegates(usdc, wrapper) remains true — Sweep n Flip native trading is DoS'd for that collection.

Diagrams#

sequenceDiagram participant Attacker participant Factory as UniswapV2Factory participant Honest as Honest user Attacker->>Factory: computeWrapperAddress(collection) Attacker->>Factory: createPair(usdc, precomputedWrapper) Note over Factory: isWrapper false → delegates = true Honest->>Factory: createWrapper(collection) Note over Factory: CREATE2 deploys at same address Honest->>Factory: try native trade on pair Note over Factory: pair stuck as delegated — DoS

Impact#

Denial of service for legitimate NFT-wrapper trading pairs. A handful of front-runs against top collections can brick the core product surface.

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.