Skip to content

anvil_fork.sh: CharonLiquidator deploy collides with BSC mainnet bytecode at deterministic CREATE addr #412

@obchain

Description

@obchain

Symptom

First forge create against a fresh anvil fork (per Notion Local commands cheat sheet, Pane B) reverts with:

Error: server returned an error response: error code -32603: EVM error CreateCollision

Reproduces every time on the documented happy path.

Root cause

scripts/anvil_fork.sh resets dev-account-0 nonce to 0 so the first forge create lands at the deterministic Foundry CREATE address 0x5FbDB2315678afecb367f032d93F642f64180aa3. That address is baked into [liquidator.bnb].contract_address in config/fork.toml.

Problem: BSC mainnet already has a deployed contract at 0x5FbDB2315678afecb367f032d93F642f64180aa3. When anvil forks BSC, that bytecode is inherited at the fork. EIP-684 collision check (code == empty AND nonce == 0) trips on the existing code/nonce → CREATE reverts.

Verified locally:

$ cast code 0x5FbDB2315678afecb367f032d93F642f64180aa3 --rpc-url http://127.0.0.1:8545 | head -c 80
0x608060405234801561000f575f80fd5b5060043610610086575f3560e01c80636744bb26116100

The slot is occupied with non-empty bytecode on the fork.

Workaround (manual)

cast rpc anvil_setCode  0x5FbDB2315678afecb367f032d93F642f64180aa3 0x      --rpc-url http://127.0.0.1:8545
cast rpc anvil_setNonce 0x5FbDB2315678afecb367f032d93F642f64180aa3 '"0x0"' --rpc-url http://127.0.0.1:8545

After both, forge create lands cleanly at the expected address.

Proposed fix

Extend the dev-0 nonce-reset block in scripts/anvil_fork.sh (around the existing cast rpc anvil_setNonce for dev-0) to also wipe code+nonce at the deterministic deploy address. Same CHARON_SKIP_DEV0_NONCE_RESET=1 escape hatch applies. Update the in-script comment + emit an info line so operators see the wipe happen.

Impact

Hard blocker on the documented local end-to-end run. Every operator hits this on first attempt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions