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.19k stars 1.7k forks source link

bug(`forge script`): `--skip-simulation` does not skip simulation #6825

Open Philogy opened 8 months ago

Philogy commented 8 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 (24abca6 2024-01-16T00:26:29.551032000Z)

What command(s) is the bug in?

forge script --skip-simulation

Operating System

macOS (Apple Silicon)

Describe the bug

Often there are things that my script depends on that foundry is unable to simulate correctly (self-destruct reinit, hot/cold storage gas cost).

Whether --skip-simulation is provided or not forge script will simulate the script first before attempting to broadcast it. Meaning that if it's incorrectly failing in the simulation I'm unable to broadcast transactions using foundry.

The --skip-simulation flag does however get the script runner to exclaim "SKIPPING ON CHAIN SIMULATION." after it has successfully ran the simulation 😅 image

mattsse commented 8 months ago

thanks for flagging, possible regression, fixing asap

mattsse commented 8 months ago

do you have a minimal repro for this?

Sabnock01 commented 8 months ago

Had some previous discussion in #5776

Philogy commented 8 months ago

Yeah based on @Evalir's comment here: https://github.com/foundry-rs/foundry/issues/5776#issuecomment-1867287499 it does seem like this intentional and kind of unavoidable based on how scripts currently work.

Unfortunately, this does mean that forge script is unusable for me in many use-cases. Specifically because of the simulation being in 1 tx (meaning gas accounting for warm/cold storage slots will be off and self-destruct / reinit doesn't work).

Not sure how you'd fix this exactly, maybe have a separate environment in which the script contract is run and the actual simulation itself, any external CALLs made in one are captured and emitted as transactions in the actual environment?

Philogy commented 8 months ago

Here's a minimal repro

This seems like a niche case but there are others like self-destruct, reinit or other weird dependencies like gas-price that would cause the same issue

plotchy commented 8 months ago

copying good background provided by @evalir from #5776 :

--skip-simulation avoids using the provided URL to do gas estimation. It does not prevent foundry from simulating the script locally. The latter is not possible to disable, as we must simulate the script to gather all the transactions to broadcast. If the local simulation fails, the whole script fails.

much of my experience with wanting this feature to avoid local sim was around similar edge cases. On-chain randomness where the randomness is seeded by things like gas, gas-limit, coinbase, etc that is difficult to match exactly in a forge script.

Xenoset77 commented 6 months ago

Can we get an ETA on this?