bug(`forge script`): `--skip-simulation` does not skip simulation
Component
Forge
Have you ensured that all of these are up to date?
- [X] Foundry
- [X] Foundryup
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 😅
thanks for flagging, possible regression, fixing asap
do you have a minimal repro for this?
Had some previous discussion in #5776
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?
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
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.
Can we get an ETA on this?
+1 to this change. It's very annoying to deploy something like a price from an oracle feed since the price data will expire before being persisted on chain with large deployment scripts & especially on slow networks like ETH.
this is a thorough re-design of forge script, putting into backlog
this seems to still be an issue
Still an issue
wtf................
Still an issue. @mattsse could you help?
This would be a very helpful workaround when developing on EVM's that have precompile contracts, which currently forge is unable to call/staticcall (I'm not sure why) and complains that the simulation would revert call to non-contract address...