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

core/state, light, trie: add UpdateContractCode to the Trie interface #27476

Merged
merged 2 commits into from
Jun 22, 2023

Conversation

gballet
Copy link
Member

@gballet gballet commented Jun 14, 2023

Rationale: verkle trees store the code inside the trie. This PR changes the interface to pass the code, as well as the dirty flag to tell the trie package if the code is dirty and needs to be updated. This is a no-op for the MPT and the odr trie.

Copy link
Member Author

@gballet gballet left a comment

Choose a reason for hiding this comment

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

feedback by Martin during standup:

  • What happens when the code is overwritten/deleted? For deletion, codesize values should be written to disk to erase things, for the overwrite, things are more complicated and need to be tested.
  • as @rjl493456442 also pointed out, merging the code update with the tree update is uncanny, because the code DB update is only done to the dirty state. Even though there will be a check for dirty in the verkle implementation, it's better to streamline the client code by adding a new state update function that takes the tree as a parameter instead of the other way around.

@rjl493456442
Copy link
Member

rjl493456442 commented Jun 19, 2023

I think we can add a function UpdateContractCode(address common.Address, codeHash common.Hash, code []byte) to the Trie interface.

It's a bit weird that contract code is associated with a Trie, but we can leave it until we introduce StateReader/StateWriter interface.


The main difference between Verkle and MPT is: verkle puts everything in a single trie with its own (1) resource identifier scheme, defined https://notes.ethereum.org/@vbuterin/verkle_tree_eip (2) state encoding scheme.

But MPT has two-layer tree structure, and also stores contract code directly in key-value store by using hash as the identifier.

The better abstraction is: treat each state scheme as a state provider for EVM to consume/write-back. We can hide all the details inside of the implementation instead of exposing them in statedb package.


The current abstraction is not suitable between MPT and Verkle(and LES). The proper abstraction is:

  • define StateReader/StateWriter in state package for accessing/writing back states
  • define StateHasher in state package for deriving the hash root of state

The StateReader needs to provide APIs like:

  • GetAccount(address common.Address) *types.StateAccount
  • GetStorage(address common.Address, key []byte) []byte
  • GetContractCode(address common.Address, codeHash common.Hash, /* offset uint64*/) []byte

The StateWriter needs to provide APIs like:

  • UpdateAccount(address common.Address, account *types.StateAccount)
  • UpdateStorage(addr common.Address, key, value []byte)
  • UpdateContractCode(address common.Address, codeHash common.Hash, code []byte)
  • DeleteAccount(address common.Address)
  • DeleteStorage(addr common.Address, key []byte)
  • DeleteContractCode(address common.Address, codeHash common.Hash)
  • Commit() (common.Hash, *trienode.NodeSet)

The StateHasher needs to provide API like:

  • Hash() common.Hash

Btw it will be a big change. So I purpose to add UpdateContractCode(address common.Address, codeHash common.Hash) as the first step.

@gballet gballet changed the title core/state, light, trie: add the code to UpdateAccount's signature core/state, light, trie: add a UpdateContractCode function to the Trie interface Jun 22, 2023
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

Sure, it shouldn't break anything, so if you want it for easier verkle-integration, I guess that's fine

@holiman holiman changed the title core/state, light, trie: add a UpdateContractCode function to the Trie interface core/state, light, trie: add UpdateContractCode to the Trie interface Jun 22, 2023
@holiman holiman added this to the 1.12.1 milestone Jun 22, 2023
@holiman holiman merged commit 699243f into ethereum:master Jun 22, 2023
1 check passed
devopsbo3 pushed a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
…ethereum#27476)

Verkle trees store the code inside the trie. This PR changes the interface to pass the code, as well as the dirty flag to tell the trie package if the code is dirty and needs to be updated. This is a no-op for the MPT and the odr trie.
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
devopsbo3 added a commit to HorizenOfficial/go-ethereum that referenced this pull request Nov 10, 2023
This pull request was closed.
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.

3 participants