foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.06k stars 1.65k forks source link

`TryFromSliceError` when using `forge script` #7279

Open Ferret-san opened 6 months ago

Ferret-san commented 6 months ago

Component

Forge

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

What version of Foundry are you on?

forge 0.2.0 (551bcb5 2024-02-28T07:38:22.868037648Z)

What command(s) is the bug in?

forge script DeployContract --slow --force --rpc-url $rpc --private-key $PRIVATE_KEY --broadcast

Operating System

Linux

Describe the bug

While trying to deploy some contracts to a private geth instance using forge script, I encounter the following error:

## Setting up 1 EVM.
The application panicked (crashed).
Message:  called `Result::unwrap()` on an `Err` value: TryFromSliceError(())
Location: /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-primitives-0.6.3/src/bits/address.rs:45

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

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 8 frames hidden ⋮                               
   9: forge::cmd::script::executor::<impl forge::cmd::script::ScriptArgs>::onchain_simulation::{{closure}}::{{closure}}::{{closure}}::h5aaade165f1efd1a
      at <unknown source file>:<unknown line>
  10: forge::cmd::script::executor::<impl forge::cmd::script::ScriptArgs>::onchain_simulation::{{closure}}::he96a0d8255cf660b
      at <unknown source file>:<unknown line>
  11: forge::cmd::script::broadcast::<impl forge::cmd::script::ScriptArgs>::handle_broadcastable_transactions::{{closure}}::he0bc92b85116869c
      at <unknown source file>:<unknown line>
  12: forge::cmd::script::cmd::<impl forge::cmd::script::ScriptArgs>::run_script::{{closure}}::hca035b8b6b28bd0f
      at <unknown source file>:<unknown line>
  13: foundry_cli::utils::block_on::h8ef4f295b5547e14
      at <unknown source file>:<unknown line>
  14: forge::main::h17970edc50ecff80
      at <unknown source file>:<unknown line>
  15: std::sys_common::backtrace::__rust_begin_short_backtrace::h5929a785cc8208a7
      at <unknown source file>:<unknown line>
  16: main<unknown>
      at <unknown source file>:<unknown line>
  17: __libc_start_call_main<unknown>
      at ./csu/../sysdeps/nptl/libc_start_call_main.h:58
  18: __libc_start_main_impl<unknown>
      at ./csu/../csu/libc-start.c:392
  19: _start<unknown>
      at <unknown source file>:<unknown line>

Note that it seems like the contracts do get deployed on my local instance, but perhaps some after-deployment logic is being hit and results in this issue.

DaniPopes commented 6 months ago

Tracked it down to Address::from_slice, this is the only call in forge script (and all of forge): https://github.com/foundry-rs/foundry/blob/6818c846ad54455721deae0adc10efbf87a0f11f/crates/script/src/transaction.rs#L79

cc @klkvr can we bundle the fix for this in https://github.com/foundry-rs/foundry/pull/7247? Not very familiar with this code

klkvr commented 6 months ago

it's probably related to create2 deployer not being present on the forked chain, however, we should detect that before simulation.

@Ferret-san are you using any uncommon patterns with create2 deployments? Would be great if you could provide a repro for this

Ferret-san commented 6 months ago

it's probably related to create2 deployer not being present on the forked chain, however, we should detect that before simulation.

@Ferret-san are you using any uncommon patterns with create2 deployments? Would be great if you could provide a repro for this

hm, the only issue I can think of is that I'm running the scripts against a local private geth network, in which I load the bytecode for the CREATE2 deployer into the genesis block

zerosnacks commented 1 month ago

I think it makes sense to transform this ticket into a feature request to detect and throw an error if the create2 deployer is not being present on the forked chain before simulation

@Ferret-san, any extra additional details (and especially a minimal reproduction) would be great

klkvr commented 1 month ago

I think it makes sense to transform this ticket into a feature request to detect and throw an error if the create2 deployer is not being present on the forked chain before simulation

Yeah, we are already detecting this here https://github.com/foundry-rs/foundry/blob/6bb5c8ea8dcd00ccbc1811f1175cabed3cb4c116/crates/evm/core/src/utils.rs#L160

this looks like some edge case when this is missed