-
Notifications
You must be signed in to change notification settings - Fork 49
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
Implement State Overrides for Simulations #18
Conversation
I tried to propose a change to make |
Hey @nlordell, firstly thanks a lot for contributing! 🙏 Makes sense to go down to the I've just merged another PR which means there are some small conflicts. Do you mind resolving those please? Finally, could you update the Once these items are closed off super happy to get this in. |
This makes the most sense to me. AFAICT there might be some small breaking changes that will affect other code so it makes sense to do it separately.
👍
Ah, nice - you merged the |
@devanoneth - updated the README with the new format and added an E2E test. Let me know if it looks OK. I also decided to go for "simpler" types to describe the state override object. Alternatively, you could specify it like (if my TS serves me well): export type StateOverride = {
balance?: string;
nonce?: number;
code?: string;
} & StateOverrideState;
export type StateOverrideState =
| { state?: Record<string, string>, stateDiff: undefined }
| { state: undefined, stateDiff?: Record<string, string> } But I found this harder to grok with little benefit over the current type (which also more closely matches how the type is represented on online documentation - for example Geth RPC documentation). |
Thanks for the updates @nlordell! Agreed on the types, simpler is better here. |
I started down this path, but it quite annoying ATM - it seems like Foundry is part using the new |
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