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

vm.cool cheatcode #1340

Closed
2 tasks done
Philogy opened this issue Apr 17, 2022 · 6 comments · Fixed by #5830
Closed
2 tasks done

vm.cool cheatcode #1340

Philogy opened this issue Apr 17, 2022 · 6 comments · Fixed by #5830
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test D-hard Difficulty: hard P-low Priority: low T-feature Type: feature

Comments

@Philogy
Copy link

Philogy commented Apr 17, 2022

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (2865fa5 2022-04-14T21:44:28.244220110+00:00)

What command(s) is the bug in?

forge test

Operating System

Linux

Describe the bug

With the introduction of the Berlin hardfork EIP2929 was implemented and went live on the Ethereum blockchain. This EIP introduced cost changes to storage and account accessing opcodes, including (but not limited to): SLOAD, SSTORE, CALL, BALANCE etc. Specifically these opcodes received an additional cost the first time they are used to access storage slots and/or accounts within a transaction. These costs are however not always properly accounted for in foundry solidity tests. Specifically addresses and storage slots seem to remain warm between calls within the context of a single test, falsely reducing the cost of calls and certain contract executions. This not only leads to inaccurate traces but gas usage dependent tests may also incorrectly fail / pass.

This bug may or may not be a feature. It is likely more useful / straightforward if accounts and storage slots do not remain warm between calls within a single test by default. Cheat codes may be added to purposefully keep accounts and storage slots warm or potentially even pre-warm to simulate transactions with access lists (EIP2930).

EDIT(onbjerg): I am requesting a vm.cool(address) cheatcode to cool off warm accounts

@Philogy Philogy added the T-bug Type: bug label Apr 17, 2022
@onbjerg
Copy link
Member

onbjerg commented Apr 17, 2022

If you call the same contract multiple times within a single test, then the storage slot remains warm. This is intended, and largely a very very very hard fix, so I don't think the cost of changing this behavior is worth it. In some cases, it might even be the preferred behavior, further complicating the change, since we would probably need a way to switch between one or the other

However, the first time you call a contract within a test, that gas usage should be correct. It might be slightly off, see #960

@Philogy
Copy link
Author

Philogy commented Apr 17, 2022

Ah ok, must of overlooked it in the documentation. I guess I should create a feature request for cool off accounts and storage slots cheat code

@onbjerg onbjerg changed the title Cold/Warm Account and Storage Gas Costs Not Accounted For vm.cool cheatcode Apr 18, 2022
@onbjerg
Copy link
Member

onbjerg commented Apr 18, 2022

I changed the issue to request a vm.cool(address) cheatcode - does this make sense to you?

@Philogy
Copy link
Author

Philogy commented Apr 18, 2022

Yes, thank you!

@onbjerg onbjerg added T-feature Type: feature Cmd-forge-test Command: forge test C-forge Command: forge A-cheatcodes Area: cheatcodes P-low Priority: low D-hard Difficulty: hard and removed T-bug Type: bug labels Apr 18, 2022
@onbjerg onbjerg added this to Foundry Apr 18, 2022
@onbjerg onbjerg moved this to Todo in Foundry Apr 18, 2022
lnist added a commit to mangrovedao/mangrove-core that referenced this issue Aug 14, 2023
See test/core/gas/README.md

Adds a ./gas-measurement.sh for dumping measurements to out/gas-measurement.csv

Note: There are quite a bit of tests that inherit from other tests and override setup to change the test case. This is due to only setup being able to vary test data without warming stuff: foundry-rs/foundry#1340 .
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry Sep 14, 2023
@clauBv23
Copy link

Hi there,

If this cheatcode already on life?

I see this seems completed and #5830 is merged however I'm not able to use vm.cool and it is not in the documentation.

@norswap
Copy link

norswap commented Oct 8, 2024

@clauBv23 I came with the same question, looks like it was rollback and there is a new PR here, but it's pretty dead: #5852 (no activity since december)

An alternative is to use the --isolate option in forge test to make whatever changes you need to the slots in a first call, then do the code you care about in another call where the slots will be cool again. Doesn't cover all the use cases for vm.cool but it's probably going to work for us (yet to be tested though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge Cmd-forge-test Command: forge test D-hard Difficulty: hard P-low Priority: low T-feature Type: feature
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants