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

Update state network to use address_hash instead of address #329

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

KolbyML
Copy link
Member

@KolbyML KolbyML commented Aug 1, 2024

Issue

Currently you can't walk or download a whole state snapshot from the State Portal network. There is no way to get an address well walking the account trie. Which means it isn't possible to walk storage tries or get contracts as currently they require an address, which isn't a native concept in the execution layer.

  • It isn't possible to download a state snapshot from State Network
  • Can't fully navigate trie without 3rd party data (for address_hash to address mappings)

How to fix this?

Instead of using the address for storage_key and contract_key use the address_hash

One of the main reasons for this is the address_hash is retrivalible from walking the account trie as the address_hash can be recovered from the path of the account.

Doing this allows us to

  • gossip whole state snapshots including account storage and contracts and not only account diffs. So we could gossip a whole .era2 file. Currenting a node bootstrapping from a .era2 file can only gossip storage trie changes after block + 1 of the snapshot.
  • This allows glados to walk all the state without getting reverse address_hash -> address mappings from a 3rd party
  • This allows EL clients to download full state snapshots without a 3rd party for address mappings

In short this makes the Portal State Network much more usable and more aligned with how Ethereum's state actually looks like from an Ethereum perspective

@KolbyML KolbyML self-assigned this Aug 1, 2024
Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objections that jump out to me.

Are there any areas or use cases that you've identified where using address_hash has a downside or where we'd end up needing the pre-image map?

(I think this should get more than my approval before merge)

@KolbyML
Copy link
Member Author

KolbyML commented Aug 1, 2024

Are there any areas or use cases that you've identified where using address_hash has a downside or where we'd end up needing the pre-image map?

One thing I will bring up is currently there is no mechanism to obtain a pre-image map from any of the Portal Networks. So I don't think this change adds a downside as the pre-images weren't obtainable in the first place.

@KolbyML
Copy link
Member Author

KolbyML commented Aug 1, 2024

If we were to provide pre-image mappings I think that should be its own Portal network, like the transaction index network

The Portal Address mapping network or something

Copy link
Contributor

@morph-dev morph-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support this change. The address is currently used only as part of the content-key, and can't be obtained if one doesn't have it. So using address_hash doesn't seem to have any downsides (except making keys 12 bytes longer, which is negligible) while it has benefits.

This PR should also fix the test vectors in state-network-test-vectors.md.

Once merged, we should also update files in portal-spec-tests repo.

@@ -209,7 +209,7 @@ content_for_retrieval := Container(node: TrieNode)
These data types represent a node from an individual contract storage trie.

```
storage_trie_node_key := Container(address: Address, path: Nibbles, node_hash: Bytes32)
storage_trie_node_key := Container(address_hash: keccak(Address), path: Nibbles, node_hash: Bytes32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: In my opinion, this should be: address_hash: AddressHash and in the "Helper Data Types" section above, you would define AddressHash := Bytes32 with brief explanation.

@@ -129,6 +129,14 @@ Examples:
[1, 2, a, b, c] -> [0x11, 0x2a, 0xbc]
```

##### Address Hash

An address hash is a sha256 of an Ethereum Address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not keccak?

@KolbyML
Copy link
Member Author

KolbyML commented Aug 2, 2024

Ok I have PR's for ethereum/trin and ethereum/portal-spec-tests so when we are ready 2 merge this PR things are in place to update Trin to match the spec

@web3-developer
Copy link

I have no objections to this change. When implementing the Fluffy state bridge I found the need to store the account preimages so that I could get the address for a given addressHash in order to build contract trie and contract code offers. With this change we can likely save space by avoid the requirement to store preimages. Looks good to me.

Copy link
Contributor

@ScottyPoi ScottyPoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants