Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an "Authentic" execution mode for tests & scripts #6910

Closed
Philogy opened this issue Jan 26, 2024 · 4 comments
Closed

Add an "Authentic" execution mode for tests & scripts #6910

Philogy opened this issue Jan 26, 2024 · 4 comments
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

Comments

@Philogy
Copy link

Philogy commented Jan 26, 2024

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:

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:

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_calls 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.

@Philogy Philogy added the T-feature Type: feature label Jan 26, 2024
@gakonst gakonst added this to Foundry Jan 26, 2024
@github-project-automation github-project-automation bot moved this to Todo in Foundry Jan 26, 2024
@emo-eth
Copy link
Contributor

emo-eth commented Feb 18, 2024

@Philogy I’ve thought about this a lot, but this approach gives me a new idea:

If anvil supports importing state, maybe it’d be possible to dump the journaled state from test setup, spin up an anvil fork that loads that state, and then broadcast the actual test logic as a transaction against the fork. Multiple broadcasts with more set up in between might require multiple forks, though.

It seems like there’s hesitance to address this at the REVM level (which seems possible), and seeing as it could have downstream effects for projects like reth, I suppose I can appreciate that.

@Philogy
Copy link
Author

Philogy commented Feb 20, 2024

If anvil supports importing state, maybe it’d be possible to dump the journaled state from test setup, spin up an anvil fork that loads that state, and then broadcast the actual test logic as a transaction against the fork. Multiple broadcasts with more set up in between might require multiple forks, though.

@emo-eth not sure if that'd work, the recorded trace may be affected by the outcome of the constituent transactions and lead to an inconsistent result plus I don't fully see how that'd solve the simulation issue?

@Evalir Evalir added this to the v1.0.0 milestone Feb 25, 2024
@Evalir Evalir added A-evm Area: EVM Cmd-forge-test Command: forge test A-gas-snapshots Area: gas snapshotting/reporting Cmd-forge-script Command: forge script labels Feb 25, 2024
@Evalir
Copy link
Member

Evalir commented Apr 9, 2024

Wonder if this can be considered "closed" with the addition of the --isolate flag? @Philogy / @emo-eth

@zerosnacks
Copy link
Member

Tentatively marking this ticket as resolved with the following tickets outstanding and being followed up:

Feel free to open specific tickets if you are running into additional aspects not sufficiently covered by the --isolate mode.

@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
Archived in project
Development

No branches or pull requests

4 participants