-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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(primitives): impl genesis state root helper #904
Conversation
* expands GenesisAccount to have the proper fields * implement Encodable and Decodable for GenesisAccount * add helper to calculate the state root from a GenesisAccount hashmap * add tests for simple state roots
cca7b79
to
bd927c8
Compare
let fixtures: Vec<(Address, H256)> = vec![ | ||
( | ||
hex!("9fe4abd71ad081f091bd06dd1c16f7e92927561e").into(), | ||
hex!("4b35be4231841d212ce2fa43aedbddeadd6eb7d420195664f9f0d55629db8c32").into(), | ||
), | ||
( | ||
hex!("c2ba9d87f8be0ade00c60d3656c1188e008fbfa2").into(), | ||
hex!("e1389256c47d63df8856d7729dec9dc2dae074a7f0cbc49acad1cf7b29f7fe94").into(), | ||
), | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how were these chosen? do we know this is the right state root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were chosen by doing the following:
- Generating an address
- Creating a
genesis.json
giving each addressesU256::max()
coins - Initializing and starting geth with this
genesis.json
- Retrieving the genesis block over RPC
- Getting the state root from the returned block
So these are not official test cases, and to reproduce these test cases the above procedure would have to be repeated or scripted in a test.
This implements a method to calculate the state root, given a
HashMap<Address, GenesisAccount>
.GenesisAccount
is expanded to include optionalcode
andstorage
fields.RLP traits
Encodable
andDecodable
are implemented forGenesisAccount
. This is necessary for state root calculation.The following tests are added for state root calculation:
genesis.json
with geth, gathering geth's reported state root over RPC.Conversions from
ethers_core::utils::GenesisAccount
toGenesisAccount
are also added.Extracted from #623