Skip to content

bug: CreateCollision on a fork and contract upgrade. #12072

@haider-rs

Description

@haider-rs

Component

Other (please describe), Anvil, Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.3.5-stable
Commit SHA: 9979a41
Build Timestamp: 2025-09-09T04:48:08.305566906Z (1757393288)
Build Profile: maxperf

What version of Foundryup are you on?

1.3.0

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

I am having a weird bug i am running a anvil fork for base mainnet on a vm

nohup anvil --fork-url $BASE_RPC --host 0.0.0.0 --port 8545 > anvil.log 2>&1 &

and from my local machine i am trying to test a contract upgrade with a command:

cast rpc --rpc-url $ANVIL anvil_autoImpersonateAccount true && cast rpc --rpc-url $ANVIL anvil_impersonateAccount 0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49
forge script scripts/DeployV3.s.sol:DeployV3 --rpc-url $ANVIL --sender 0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49 --unlocked  --broadcast --slow -vvvv
[⠒] Compiling...
No files changed, compilation skipped
Traces:
  [172103895] DeployV3::run()
    ├─ [0] VM::startBroadcast(0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49)
    │   └─ ← [Return]
    ├─ [0] VM::getNonce(0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49) [staticcall]
    │   └─ ← [Return] 10
    ├─ [0] console::log("nonce:", 10) [staticcall]
    │   └─ ← [Stop]
    ├─ [0] VM::envOr("FOUNDRY_OUT", "out") [staticcall]
    │   └─ ← [Return] <env var value>
    ├─ [0] VM::split("BondingCurveV3.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["BondingCurveV3", ""]
    ├─ [0] VM::split("BondingCurveV3.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["BondingCurveV3", ""]
    ├─ [0] VM::replace("BondingCurveV3.sol", ".sol", "") [staticcall]
    │   └─ ← [Return] "BondingCurveV3"
    ├─ [0] VM::split("BondingCurveV3.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["BondingCurveV3", ""]
    ├─ [0] VM::projectRoot() [staticcall]
    │   └─ ← [Return] "userpath"
    ├─ [0] VM::readFile("userpath/out/BondingCurveV3.sol/BondingCurveV3.json") [staticcall]
    │   └─ ← [Return] <file>
    ├─ [0] VM::keyExistsJson("<JSON file>", ".ast") [staticcall]
    │   └─ ← [Return] true
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".ast.absolutePath") [staticcall]
    │   └─ ← [Return] "contracts/bonding-curve/BondingCurveV3.sol"
    ├─ [0] VM::keyExistsJson("<JSON file>", ".ast.license") [staticcall]
    │   └─ ← [Return] true
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".ast.license") [staticcall]
    │   └─ ← [Return] "GPL-3.0"
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".metadata.sources.['contracts/bonding-curve/BondingCurveV3.sol'].keccak256") [staticcall]
    │   └─ ← [Return] "0xb4d7e18a9cb9bcc96c31b1e501895f38f8d5465b842062bcd7450eb60a89c016"
    ├─ [0] VM::split("BondingCurveV2.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["BondingCurveV2", ""]
    ├─ [0] VM::split("BondingCurveV2.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["BondingCurveV2", ""]
    ├─ [0] VM::replace("BondingCurveV2.sol", ".sol", "") [staticcall]
    │   └─ ← [Return] "BondingCurveV2"
    ├─ [0] VM::split("BondingCurveV2.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["BondingCurveV2", ""]
    ├─ [0] VM::projectRoot() [staticcall]
    │   └─ ← [Return] "userpath"
    ├─ [0] VM::readFile("userpath/out/BondingCurveV2.sol/BondingCurveV2.json") [staticcall]
    │   └─ ← [Return] <file>
    ├─ [0] VM::keyExistsJson("<JSON file>", ".ast") [staticcall]
    │   └─ ← [Return] true
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".ast.absolutePath") [staticcall]
    │   └─ ← [Return] "contracts/bonding-curve/BondingCurveV2.sol"
    ├─ [0] VM::keyExistsJson("<JSON file>", ".ast.license") [staticcall]
    │   └─ ← [Return] true
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".ast.license") [staticcall]
    │   └─ ← [Return] "GPL-3.0"
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".metadata.sources.['contracts/bonding-curve/BondingCurveV2.sol'].keccak256") [staticcall]
    │   └─ ← [Return] "0x63c61eb67d607dbaf956dedfaaa58f2a68acf2434539c50b05679e36e94ddd60"
    ├─ [0] VM::envOr("OPENZEPPELIN_BASH_PATH", "bash") [staticcall]
    │   └─ ← [Return] <env var value>
    ├─ [0] VM::tryFfi(["bash", "-c", "npx @openzeppelin/upgrades-core@^1.37.0 validate out/build-info --contract contracts/bonding-curve/BondingCurveV3.sol:BondingCurveV3 --reference \"contracts/bonding-curve/BondingCurveV2.sol:BondingCurveV2\""])
    │   └─ ← [Return] (0, 0xe29c942020636f6e7472616374732f626f6e64696e672d63757276652f426f6e64696e67437572766556332e736f6c3a426f6e64696e6743757276655633202875706772616465732066726f6d20636f6e7472616374732f626f6e64696e672d63757276652f426f6e64696e67437572766556322e736f6c3a426f6e64696e6743757276655632290a0a53554343455353, 0x)
    ├─ [0] VM::contains("✔  contracts/bonding-curve/BondingCurveV3.sol:BondingCurveV3 (upgrades from contracts/bonding-curve/BondingCurveV2.sol:BondingCurveV2)\n\nSUCCESS", "SUCCESS")
    │   └─ ← [Return] true
    ├─ [0] VM::getCode("BondingCurveV3.sol") [staticcall]
    │   └─ ← [Return] 0x6080806040523460aa575f516...bytecodecontinuation
    ├─ [3354053] → new BondingCurveV3@0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c
    │   ├─ emit Initialized(version: 18446744073709551615 [1.844e19])
    │   └─ ← [Return] 16635 bytes of code
    ├─ [28922] 0x0C70050332A5404B522AB96aC0e236b9D9874153::upgradeBondingCurveImplementation(BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c])
    │   ├─ [24133] 0x20B44B71581833C919Fa324d735cCFdF4cd30D06::upgradeBondingCurveImplementation(BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c]) [delegatecall]
    │   │   ├─ [2832] 0xdf58969342997217c6d34F1B65D3Eaf929D7B84A::onlyAdmin(0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49) [staticcall]
    │   │   │   └─ ← [Stop]
    │   │   ├─ [8606] 0x0427836d799c095Cb1b1090B56b8a19FB12160F4::upgradeTo(BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c])
    │   │   │   ├─ emit Upgraded(implementation: BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c])
    │   │   │   └─ ← [Stop]
    │   │   ├─ emit BondingCurveImplementationUpdated(_bondingCurveImplementation: BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c])
    │   │   └─ ← [Return]
    │   └─ ← [Return]
    ├─ [0] console::log("BondingCurveV3 implementation deployed at:", BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c]) [staticcall]
    │   └─ ← [Stop]
    ├─ [0] VM::envOr("FOUNDRY_OUT", "out") [staticcall]
    │   └─ ← [Return] <env var value>
    ├─ [0] VM::split("PairV3.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["PairV3", ""]
    ├─ [0] VM::split("PairV3.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["PairV3", ""]
    ├─ [0] VM::replace("PairV3.sol", ".sol", "") [staticcall]
    │   └─ ← [Return] "PairV3"
    ├─ [0] VM::split("PairV3.sol", ".sol") [staticcall]
    │   └─ ← [Return] ["PairV3", ""]
    ├─ [0] VM::projectRoot() [staticcall]
    │   └─ ← [Return] "userpath"
    ├─ [0] VM::readFile("userpath/out/PairV3.sol/PairV3.json") [staticcall]
    │   └─ ← [Return] <file>
    ├─ [0] VM::keyExistsJson("<JSON file>", ".ast") [staticcall]
    │   └─ ← [Return] true
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".ast.absolutePath") [staticcall]
    │   └─ ← [Return] "contracts/swap/PairV3.sol"
    ├─ [0] VM::keyExistsJson("<JSON file>", ".ast.license") [staticcall]
    │   └─ ← [Return] true
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".ast.license") [staticcall]
    │   └─ ← [Return] "GPL-3.0"
    ├─ [0] VM::parseJsonString("<stringified JSON>", ".metadata.sources.['contracts/swap/PairV3.sol'].keccak256") [staticcall]
    │   └─ ← [Return] "0xf3f73adfdb76018a793284db3206343c47776f0a606f4c1101558868b751f00e"
    ├─ [0] VM::envOr("OPENZEPPELIN_BASH_PATH", "bash") [staticcall]
    │   └─ ← [Return] <env var value>
    ├─ [0] VM::tryFfi(["bash", "-c", "npx @openzeppelin/upgrades-core@^1.37.0 validate out/build-info --contract contracts/swap/PairV3.sol:PairV3"])
    │   └─ ← [Return] (0, 0xe29c942020636f6e7472616374732f737761702f5061697256332e736f6c3a5061697256330a0a53554343455353, 0x)
    ├─ [0] VM::contains("✔  contracts/swap/PairV3.sol:PairV3\n\nSUCCESS", "SUCCESS")
    │   └─ ← [Return] true
    ├─ [0] VM::getCode("PairV3.sol") [staticcall]
    │   └─ ← [Return] 0x6080806040523460aa575f516020614....bytecodecontinuation
    ├─ [3532280] → new PairV3@0x7aa17b7c7152c85e23EF46599EeF7C033809D208
    │   ├─ emit Initialized(version: 18446744073709551615 [1.844e19])
    │   └─ ← [Return] 17525 bytes of code
    ├─ [28868] 0xF0dB704Bf67149B9EAd4d9e80014057B39365D1A::upgradePairImplementation(PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208])
    │   ├─ [24079] 0xc3167b5D99DBA9c35FfD390d2089De8836112412::upgradePairImplementation(PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208]) [delegatecall]
    │   │   ├─ [832] 0xdf58969342997217c6d34F1B65D3Eaf929D7B84A::onlyAdmin(0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49) [staticcall]
    │   │   │   └─ ← [Stop]
    │   │   ├─ [8606] 0xbD14ea62411766a9858d0EFdE1917c1a7B6041E9::upgradeTo(PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208])
    │   │   │   ├─ emit Upgraded(implementation: PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208])
    │   │   │   └─ ← [Stop]
    │   │   ├─ emit PairImplementationUpgraded(newImplementation: PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208])
    │   │   └─ ← [Return]
    │   └─ ← [Return]
    ├─ [0] console::log("PairV3 implementation deployed at:", PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208]) [staticcall]
    │   └─ ← [Stop]
    ├─ [0] VM::stopBroadcast()
    │   └─ ← [Return]
    └─ ← [Return] BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c], PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208]


Script ran successfully.

== Return ==
curvev3: address 0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c
pairv3: address 0x7aa17b7c7152c85e23EF46599EeF7C033809D208

== Logs ==
  nonce: 10
  BondingCurveV3 implementation deployed at: 0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c
  PairV3 implementation deployed at: 0x7aa17b7c7152c85e23EF46599EeF7C033809D208

## Setting up 1 EVM.
==========================
Simulated On-chain Traces:

Error: Failed with `EvmError: CreateCollision`:

Error: Failed with `EvmError: CreateCollision`:

  [0] → new <unknown>@0xb078c0884dBd4D3ec41875b8bA85130EFcAA0E88
    └─ ← [CreateCollision]

  [24152] 0x0C70050332A5404B522AB96aC0e236b9D9874153::upgradeBondingCurveImplementation(BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c])
    ├─ [19356] 0x20B44B71581833C919Fa324d735cCFdF4cd30D06::upgradeBondingCurveImplementation(BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c]) [delegatecall]
    │   ├─ [2832] 0xdf58969342997217c6d34F1B65D3Eaf929D7B84A::onlyAdmin(0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49) [staticcall]
    │   │   └─ ← [Stop]
    │   ├─ [4972] 0x0427836d799c095Cb1b1090B56b8a19FB12160F4::upgradeTo(BondingCurveV3: [0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c])
    │   │   └─ ← [Revert] BeaconInvalidImplementation(0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c)
    │   └─ ← [Revert] BeaconInvalidImplementation(0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c)
    └─ ← [Revert] BeaconInvalidImplementation(0x0325E8829C611EF8c6C49B19F8EA8edb48945E3c)

  [0] → new <unknown>@0xa1199ebeea1291b67c1e779E5aAcb064Fde7D715
    └─ ← [CreateCollision]

  [28508] 0xF0dB704Bf67149B9EAd4d9e80014057B39365D1A::upgradePairImplementation(PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208])
    ├─ [23712] 0xc3167b5D99DBA9c35FfD390d2089De8836112412::upgradePairImplementation(PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208]) [delegatecall]
    │   ├─ [2832] 0xdf58969342997217c6d34F1B65D3Eaf929D7B84A::onlyAdmin(0xf65c671Fa6d2e5624C233EB144Dc66a04571EE49) [staticcall]
    │   │   └─ ← [Stop]
    │   ├─ [4972] 0xbD14ea62411766a9858d0EFdE1917c1a7B6041E9::upgradeTo(PairV3: [0x7aa17b7c7152c85e23EF46599EeF7C033809D208])
    │   │   └─ ← [Revert] BeaconInvalidImplementation(0x7aa17b7c7152c85e23EF46599EeF7C033809D208)
    │   └─ ← [Revert] BeaconInvalidImplementation(0x7aa17b7c7152c85e23EF46599EeF7C033809D208)
    └─ ← [Revert] BeaconInvalidImplementation(0x7aa17b7c7152c85e23EF46599EeF7C033809D208)

Error: Simulated execution failed.

the weirdest part is sometimes it works fine without any error on a new anvil fork instance and sometimes it just throws CreateCollision.

these contracts:
0xb078c0884dBd4D3ec41875b8bA85130EFcAA0E88, 0xa1199ebeea1291b67c1e779E5aAcb064Fde7D715 are already available on the base mainnet deployed by the same user with the nonce 0 and 2 and as you can see the current nonce of user is 10 logged in logs

my script just uses foundry-upgrades to deploy the implementation. Sample code is below

        Options memory opts;
        opts.referenceContract = "BondingCurveV2.sol";
        address newBondingCurveImpl = Upgrades.deployImplementation("BondingCurveV3.sol", opts);

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions