foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Forge crashes when running Create2 script

Open jarrel-b opened this issue 9 months ago • 0 comments

Component

Forge

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

  • [ ] Foundry
  • [ ] Foundryup

What version of Foundry are you on?

forge 0.2.0 (721eb94 2024-05-01T00:23:13.213668000Z)

What command(s) is the bug in?

forge script

Operating System

None

Describe the bug

Running the script below with the command:

forge script --broadcast Create2Debug
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import "forge-std/Script.sol";

contract Foo {
  constructor() {}
}

contract Create2Debug is Script {
  function run() public {
    vm.startBroadcast();

    bytes memory creationCode = type(Foo).creationCode;
    bytes32 salt = keccak256("a salt");
    address computed = Create2.computeAddress(salt, keccak256(creationCode));
    address deployed = Create2.deploy(0, salt, creationCode);
    require(computed == deployed, "address mismatch");

    vm.stopBroadcast();
  }
}

causes a crash:

forge script --broadcast Create2Debug
[⠊] Compiling...
[⠒] Compiling 60 files with 0.8.25
[⠒] Solc 0.8.25 finished in 3.13s
Compiler run successful!
The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/revm-8.0.0/src/inspector/handler_register.rs:198

This is a bug. Consider reporting it at https://github.com/foundry-rs/foundry

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 8 frames hidden ⋮
   9: core::panicking::panic::h3131e0868b9f8622
      at <unknown source file>:<unknown line>
  10: core::option::unwrap_failed::hdb518deb484b6610
      at <unknown source file>:<unknown line>
  11: revm::inspector::handler_register::inspector_handle_register::{{closure}}::hc58254a0768dcac7
      at <unknown source file>:<unknown line>
  12: revm::evm::Evm<EXT,DB>::transact::h5f18dc6e06b48bca
      at <unknown source file>:<unknown line>
  13: foundry_evm::executors::Executor::call_raw::hbb3b76ce34c66842
      at <unknown source file>:<unknown line>
  14: forge_script::runner::ScriptRunner::call::hfe8e0abc2f0ab3ad
      at <unknown source file>:<unknown line>
  15: forge_script::execute::PreExecutionState::execute::{{closure}}::hf8f362bc591a0da7
      at <unknown source file>:<unknown line>
  16: forge_script::ScriptArgs::run_script::{{closure}}::hf89b118edd824c49
      at <unknown source file>:<unknown line>
  17: forge::main::h765f0f05a345f80e
      at <unknown source file>:<unknown line>
  18: std::sys_common::backtrace::__rust_begin_short_backtrace::h09ae3530d8a1dd59
      at <unknown source file>:<unknown line>
  19: _main<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
zsh: abort      forge script --broadcast Create2Debug

Running with --rpc-url works when running anvil with defaults:

forge script --rpc-url localhost:8545 --broadcast Create2Debug

but it produces differing deployed and computed addresses. Weirdly, removing vm.startBroadcast and vm.stopBroadcast does compute the same deployed and computed address.

jarrel-b avatar May 25 '24 09:05 jarrel-b