Skip to content
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

Merged
merged 2 commits into from
Jan 18, 2023

Conversation

Rjected
Copy link
Member

@Rjected Rjected commented Jan 17, 2023

This implements a method to calculate the state root, given a HashMap<Address, GenesisAccount>. GenesisAccount is expanded to include optional code and storage fields.

RLP traits Encodable and Decodable are implemented for GenesisAccount. This is necessary for state root calculation.

The following tests are added for state root calculation:

  • Simple single-account tests that were obtained by setting a custom genesis.json with geth, gathering geth's reported state root over RPC.
  • A test for the sepolia genesis state root.

Conversions from ethers_core::utils::GenesisAccount to GenesisAccount are also added.

Extracted from #623

@Rjected Rjected requested a review from gakonst as a code owner January 17, 2023 17:20
@Rjected Rjected added A-utils Related to commonly used utilities C-enhancement New feature or request labels Jan 17, 2023
 * 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
@Rjected Rjected force-pushed the dan/genesis-state-root branch from cca7b79 to bd927c8 Compare January 17, 2023 21:12
Comment on lines +143 to +152
let fixtures: Vec<(Address, H256)> = vec![
(
hex!("9fe4abd71ad081f091bd06dd1c16f7e92927561e").into(),
hex!("4b35be4231841d212ce2fa43aedbddeadd6eb7d420195664f9f0d55629db8c32").into(),
),
(
hex!("c2ba9d87f8be0ade00c60d3656c1188e008fbfa2").into(),
hex!("e1389256c47d63df8856d7729dec9dc2dae074a7f0cbc49acad1cf7b29f7fe94").into(),
),
];
Copy link
Member

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?

Copy link
Member Author

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 addresses U256::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.

@gakonst gakonst merged commit e1aae3e into main Jan 18, 2023
@gakonst gakonst deleted the dan/genesis-state-root branch January 18, 2023 00:15
literallymarvellous pushed a commit to literallymarvellous/reth that referenced this pull request Feb 5, 2023
literallymarvellous pushed a commit to literallymarvellous/reth that referenced this pull request Feb 5, 2023
literallymarvellous pushed a commit to literallymarvellous/reth that referenced this pull request Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-utils Related to commonly used utilities C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants