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

all: distinguish empty state root in merkle and verkle #30896

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Dec 11, 2024

This pull request distinguishes the different empty tree hash in merkle tree and verkle tree.

Copy link
Member

@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.

I get the whole point of the PR, I would recommend making the following changes though:

  • Keeping the name EmptyRootHash for now, in order to reduce the footprint of that PR
  • Actually implementing the related verkle code, e.g. in the snapshot. In the past, it already happened that some changes were made that greatly broke the verkle model, but we merged them anyway thinking it was going to help.
  • don't bother making a difference between an account's state root being an MPT or a verkle root, verkle accounts don't have state roots.

@@ -427,7 +427,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB {
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true})
sdb := state.NewDatabase(tdb, nil)
statedb, _ := state.New(types.EmptyRootHash, sdb)
statedb, _ := state.New(types.EmptyMerkleHash, sdb) // TODO support verkle node in t8n
Copy link
Member

Choose a reason for hiding this comment

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

you don't have to worry about that, we have an upcoming PR for it

core/genesis.go Outdated Show resolved Hide resolved
{DefaultSepoliaGenesisBlock(), params.SepoliaGenesisHash},

// TODO (rjl493456442, gballet) add verkle genesis tests
Copy link
Member

Choose a reason for hiding this comment

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

I can help you with that, but if all these changes are meant for verkle, we should include verkle tests as well. Otherwise we get in the same situation, when the base branch drifted and broke a ton of verkle use cases.

@@ -89,7 +97,7 @@ func SlimAccountRLP(account StateAccount) []byte {

// FullAccount decodes the data on the 'slim RLP' format and returns
// the consensus format account.
func FullAccount(data []byte) (*StateAccount, error) {
func FullAccount(data []byte, isVerkle bool) (*StateAccount, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this is necessary: verkle trees don't have the concept of Root so if it's set to EmptyMerkleRoot it doesn't matter, this code should never be used in the first place. And it would greatly reduce the footprint of this PR,

Copy link
Member

Choose a reason for hiding this comment

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

I've managed quite far without having to do this change, I think we should do the same - it should be very easy to circumvent.

triedb/pathdb/database_test.go Show resolved Hide resolved
@@ -171,7 +171,7 @@ func deleteAccount(ctx *context, db database.NodeDatabase, addr common.Address)
}
}
root, result := st.Commit(false)
if root != types.EmptyRootHash {
if root != types.EmptyMerkleHash { // TODO (rjl493456442) support verkle
Copy link
Member

Choose a reason for hiding this comment

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

you're not supposed to delete an account in verkle anyway, regardless of whether or not state deletions are possible. So we should never get to this point, and so this comment could be removed.

core/vm/evm.go Outdated
@@ -467,7 +467,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
storageRoot := evm.StateDB.GetStorageRoot(address)
if evm.StateDB.GetNonce(address) != 0 ||
(contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) || // non-empty code
(storageRoot != (common.Hash{}) && storageRoot != types.EmptyRootHash) { // non-empty storage
(storageRoot != (common.Hash{}) && storageRoot != types.EmptyMerkleHash) { // non-empty storage TODO (rjl493456442) support verkle
Copy link
Member

Choose a reason for hiding this comment

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

verkle here is already supported: in trie/verkle.go, it will return 0 as its root. So we can remove this TODO

eth/protocols/snap/protocol.go Outdated Show resolved Hide resolved
internal/ethapi/api.go Show resolved Hide resolved
tests/state_test_util.go Outdated Show resolved Hide resolved
@rjl493456442 rjl493456442 force-pushed the empty-tree-root branch 2 times, most recently from 1c30900 to b1d43c6 Compare December 16, 2024 07:59
@rjl493456442
Copy link
Member Author

rjl493456442 commented Dec 16, 2024

Deployed it on 7 (full sync) and 8 (snap sync) to quickly validate the changes.

  • Full sync: OK
  • Snap sync: OK

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.

2 participants