-
Notifications
You must be signed in to change notification settings - Fork 77
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: implement anvil_dumpState
/anvil_loadState
API endpoints
#418
Comments
I am moving this back to backlog as there is some ambiguity on how this should work and I don't want to make anything half-baked that we will then have to support for the foreseeable future. POC branch here. ObservationsThis section contains some observations I have made about upstream Foundry's {
"accounts": {
"0x0000000000000000000000000000000000000000": {
"nonce": 0,
"balance": "0xa1f24a420c00",
"code": "0x",
"storage": {}
},
"0x5fbdb2315678afecb367f032d93f642f64180aa3": {
"nonce": 1,
"balance": "0x0",
"code": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c80630c55699c1461003b578063371303c014610059575b600080fd5b610043610063565b604051610050919061009b565b60405180910390f35b610061610069565b005b60005481565b60008081548092919061007b906100e5565b9190505550565b6000819050919050565b61009581610082565b82525050565b60006020820190506100b0600083018461008c565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006100f082610082565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610122576101216100b6565b5b60018201905091905056fea2646970667358221220ce715c269a6493f974b0599f932508687267018b4e3881d45acf952eac8aa45364736f6c63430008110033",
"storage": {
"0x0": "0x2"
}
}
}
}
QuestionsQuestion that came up while implementing this:
|
@dutterbutter @popzxc low priority but just wanted to update you guys on the status of this and that there is some ambiguity here ^ |
My general thoughts, helpful or not lol :
In my view, the interfaces with Anvil (e.g., API and CLI) should aim for as much parity as possible. That said, some differences in behaviour and output are inevitable due to our unique differences. We should document these divergences so its clear for devs.
|
Anvil state includes bytecode, right? So I believe it's meaningless for us until we have ZK OS. So it's fine to have different state formats. And to this point, incremental improvements are better than no improvements. On 2 & 3 -- I believe that our state is significantly different from L1 state (e.g. nonces are stored in a system contract, ETH balance is a balance on contract, etc). Probably I'd say that for now let's implement a custom format that supports versioning, and for now for simplicity dump state just as a flat set of storage keys to storage value mappings. Something like: {
"state_version": "1.0.0",
"state": {
"0x0000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000004",
"0x0000000000000000000000000000000000000005": "0x0000000000000000000000000000000000000006",
"0x0000000000000000000000000000000000000007": "0x0000000000000000000000000000000000000008",
}
} Then merging is trivial: we just insert new keys there. Given that we don't care about proving, we probably don't care about thins like initial writes etc. |
If it's easily doable, we can make it a bit more complex so that people can actually read the state, e.g.: {
"state_version": "1.0.0",
"state": {
// Key is the address that owns the storage. It doesn't mean anything for loading process, it's just a hint for people:
// e.g. if they want to manually edit the state file, they can look for the address of a particular contract
// and figure out the relevant storage slot
"0x0000000000000000000000000000000000000000": {
"0x0000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000002",
},
"0x0000000000000000000000000000000000000002": {
"0x0000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000004",
"0x0000000000000000000000000000000000000005": "0x0000000000000000000000000000000000000006",
"0x0000000000000000000000000000000000000007": "0x0000000000000000000000000000000000000008",
}
}
} |
Ah, good point!
Correct me if I am wrong but some parts of system contract's storage has information about things like current block, batch and potentially other things. Let's say we dump a node with 100 blocks and try to load it into another node with 1000 blocks: first 100 blocks will be overwritten as expected but also system contract's block/batch number will be overwritten as well. Nothing unsolvable of course, we just can't do merging in the most naive way I think.
That would be ideal and I think this is achievable with some effort but need a lot of refactoring on the storage layer. |
I may be completely wrong here, but from what I remember, we load this information right to the bootloader memory when executing batch (e.g. things like One thing that is stored in system contracts is nonces, but by looking at the anvil state example you provided, I believe nonces can be overridden in anvil too, so it's not that big of an issue. (but again -- I may be terribly wrong)
Makes sense. Well, I guess with versioning supported for storage format it shouldn't be an issue to add it later. |
We can likely reuse snapshot logic for this. Ideally #414 should be done before this is worked on to avoid changes in serialization format (although likely we don't want to provide any cross-version guarantees here).UPD: After spending some time implementing this I have realized the semantics for these methods is different from what I expected:
anvil_dumpState
only dumps storage data about accounts specificallyanvil_loadState
is supposed to be additive to the existing state (while overriding conflicting keys/txs/blocks)In short, we can't reuse snapshot logic at all
The text was updated successfully, but these errors were encountered: