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

fix(--isolate): correctly handle staticcalls #9940

Merged
merged 2 commits into from
Feb 23, 2025
Merged

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Feb 23, 2025

Motivation

Closes #9564

RIght now slots warmed by CALLs or test contract itself are never marked cold before STATICCALLs making gas usage of those affected by other calls.

This PR simply goes over state and marks everything cold before every STATICCALL if isolation is enabled

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense! Just a note that there's a chance test-isolate CI job to fail but if so we can fix in subsequent PR

@klkvr klkvr merged commit 9066359 into master Feb 23, 2025
23 checks passed
@klkvr klkvr deleted the klkvr/isolate-staticcalls branch February 23, 2025 19:10
@klkvr
Copy link
Member Author

klkvr commented Feb 23, 2025

@grandizzy yeah there's indeed a failure for arbitraryStorage cheatcode tests

it's happening because of this condition

if value.is_cold && value.data.is_zero() {

I believe the idea here is to only generate random value on first slot access. With --isolate we can't assume that slot will always be cold on first access, so I guess the only way to solve this would be to keep a separate track of slots which we shouldn't generate random values for

@grandizzy
Copy link
Collaborator

makes sense, we do have another similae cheatcode marked as not working with isolate https://book.getfoundry.sh/cheatcodes/mock-function#description so could be just a doc until then

@grandizzy
Copy link
Collaborator

@klkvr actually we already keep that mapping here:

/// Mapping of arbitrary storage addresses to generated values (slot, arbitrary value).
/// (SLOADs return random value if storage slot wasn't accessed).
/// Changed values are recorded and used to copy storage to different addresses.
pub values: HashMap<Address, HashMap<U256, U256>>,

but I think is better just to ignore addresses with arbitraryStorage, I made a PR #9945 which is passing isolate tests: /~https://github.com/foundry-rs/foundry/actions/runs/13499915297

@klkvr klkvr self-assigned this Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

bug(forge test): --isolate does not work as expected with setUp()
2 participants