-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: vm.finalize
#2844
Comments
vm.finalize
Any progress on this? |
I can see how this is useful. just to summarize, vm.finalize should commit the current state changes in a transaction? what should happen with the current (in memory) state of the test at this point? Like all variables etc.? would cheatcodes that load/unload address/slots be equivalent here? |
The
I don't think there's a need to change the state of the memory of the stack, since those don't affect external calls. The way I see it is that usually the 'real' tx are the external calls done to the source code, and It'd also be nice if there would be an option to set the finalize function to run automatically between each call from the test-code to an external function in the source code, since that's when it's normally needed (people are just unaware of this issue currently, and are getting wrong gas calculations due to that. Enabling this auto-finalize by default would help them get more accurate result without putting too much effort). But this might be too complicated to implement so I'll understand if you'll skip this 'auto-finalize'. |
I guess a yearly poke is in order. Any update on this? Not being able to inform the VM to reset access lists effectively makes almost all gas reports generated by forge useless, so I'd consider this to be a pretty important feature, or dare I say, fix. Thanks! |
We've recently added support for isolation mode ( Marking this as |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (6b3db2a 2022-08-19T00:04:42.579272325Z)
What command(s) is the bug in?
forge test --gas-report
Operating System
Linux
Describe the bug
#1543 discusses 'each test being considered one tx' regarding
selfdestruct
.However there's another aspect that this affects - gas reports.
Since some opcodes depend on whether the address/key is warm or cold (i.e. if it has been used in current tx), considering the test as one tx can make the gas cost estimation significantly lower (since using cold key/address are very expensive, for example warm
sload
would cost 0.1K units while a cold one would cost 2.1K).I've created a gist that demonstrates that.
For full list of opcodes that are affected by this, see this link.
Solution
As suggested in #1543, maybe allow to
finalize
a tx from the test (maybe also allow an auto-finalizing before each call to non-test contracts).The text was updated successfully, but these errors were encountered: