Implement State Overrides for Simulations #18
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for state overrides to the simulator.
At first, I wanted to use some of the built-in state overriding methods to the
foundry_evm::Executor
(namelyset_balance
andset_nonce
). The issue was that thefoundry_evm::Executor
does not expose APIs for overriding code or storage slots. If you usefoundry_evm::Executor::backend_mut
, you additionally getfoundry_evm::Backend::insert_account_info
, but since there is no direct mutable access to the underlyingrevm::CacheDB
instance (it is private unfortunately) you still cannot override storage slots. In a slightly more recent version offoundry_evm
(would require updating the version inCargo.toml
which felt a bit more delecate), they added methods for manipulating account storage but there is still no way to completely override the storage for an account (when usingstorageOverrides[address].state
and notstateDiff
).The solution is to use
revm::DatabaseCommit
implementation (sinceBackend
is anrevm
database that implements this) and update the database as if a transaction happened.Test Plan
Should I implement automated tests for this?.
I did some (admittedly) not very complete manual testing locally:
Get
vitalik.eth
's CoW Protocol token balanceTurn
vitalik.eth
into a CoW Protocol maxi