You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A useful feature was introduced by @dbeal-eth in #2256 for dumping the current state of the evm and loading it back in. However, the returned hex string is not deterministic. Running it on the same evm state, calling anvil_dumpState back to back results in different strings.
I suspect this is due to the fact that the resulting bytes are serialized from a rust HashMap:
Even though the end-result of loading the dumped state into anvil results in the same state no matter the order of the keys, it's not easy to verify whether two dumped states are identical by just looking at the hex strings. We want to use this as an extra sanity check on our deployments - we deploy our contracts on anvil using forge script, then run anvil_dumpState and see if it matches the expected result. Right now it is not possible.
The text was updated successfully, but these errors were encountered:
Component
Anvil
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (d896050 2022-12-01T21:20:45.538002477Z)
What command(s) is the bug in?
anvil_dumpState
Operating System
Linux
Describe the bug
A useful feature was introduced by @dbeal-eth in #2256 for dumping the current state of the evm and loading it back in. However, the returned hex string is not deterministic. Running it on the same evm state, calling
anvil_dumpState
back to back results in different strings.I suspect this is due to the fact that the resulting bytes are serialized from a rust
HashMap
:And according to https://doc.rust-lang.org/std/collections/struct.HashMap.html, the hashmap is randomly seeded. Seems like the solution is either to sort the keys before serializing, or initialize the hashmap with a deterministic seed with e.g. https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.with_hasher . What do you think?
Why is this even an issue?
Even though the end-result of loading the dumped state into anvil results in the same state no matter the order of the keys, it's not easy to verify whether two dumped states are identical by just looking at the hex strings. We want to use this as an extra sanity check on our deployments - we deploy our contracts on anvil using
forge script
, then runanvil_dumpState
and see if it matches the expected result. Right now it is not possible.The text was updated successfully, but these errors were encountered: