Add an "Authentic" execution mode for tests & scripts #6910
Labels
A-evm
Area: EVM
A-gas-snapshots
Area: gas snapshotting/reporting
Cmd-forge-script
Command: forge script
Cmd-forge-test
Command: forge test
T-feature
Type: feature
Milestone
Component
Forge
Describe the feature you would like
Core Description
I'd like a fundamentally different execution method in foundry. One that executes individual view calls using actual independent
eth_calls
against the environment and non-view calls as top-level transactions. This is unlike the current default and only execution mode which is all executed within 1 top-level transaction leading to several (often) undesirable side effects:selfdestruct
has no effect in test whereas a user expects it would #1543)0.8.24
#6903)There are likely more issues that I'm missing. The pain of the above issues is compounded when attempting to use foundry scripts for more special transaction sequences as this mismatch may lead to false positive reverts preventing the script runner from submitting transactions (#6825).
There are a bunch of separate feature requests attempting to address different aspects of this:
vm.cool
(feat:cool
cheatcode #5830)meterTxGas
(feat(cheatcodes): addvm.meterTxGas
cheatcode #6590)vm.clearTransientStorage
(feat: allowisolate
config to be defined inline #6908)While the current execution mode (using one big tx to run tests and simulations) is desirable for many use cases & reasons (faster test & sim execution, testing intra-tx changes). It's undesirable in many others. Instead of solving the different symptoms by adding new cheat codes I suggest taking a more holistic approach: adding a new execution mode.
The new Execution Mode
I'm likely oversimplifying (due to a lack of knowledge of revm and foundry internals please correct where required) but I wanted to offer a potential design/approach for this new mode. In this mode you'd run 2, separate instances of revm within foundry. One that runs the actual test/script and the other that maintains the actual simulated/forked state. CALLs and STATICCALLs made in the simulation environment are dispatched as
eth_call
s and actual top-level transactions into the second "world" environment. Results are relayed into the first.While this does add some overhead this solves all the aforementioned issues with one 1 (all be it larger) change without requiring the addition of many separate cheat codes and requiring devs to manually adds this everywhere just so their tests can accurately account gas.
The text was updated successfully, but these errors were encountered: