From 34bf14978e93ad60785fc7c02b373603c8abdec4 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Thu, 23 May 2024 23:03:59 +0800 Subject: [PATCH] fix `EmptyRootHash` & ZkTrie's `UpdateStorage`; fix genesis (#759) * ??? * fix `UpdateStorage` * draft fix * minor --- core/genesis.go | 59 ++++++++++++++++++++++---------------------- core/types/hashes.go | 4 ++- trie/zk_trie.go | 3 +-- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 49b1a8aec4..504aadabd9 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -450,36 +450,37 @@ func (g *Genesis) ToBlock() *types.Block { if g.Difficulty == nil && g.Mixhash == (common.Hash{}) { head.Difficulty = params.GenesisDifficulty } - if g.Config != nil && g.Config.IsLondon(common.Big0) { - if g.BaseFee != nil { - head.BaseFee = g.BaseFee - } else { - head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee) - } - } + // TODO: fix basefee + // if g.Config != nil && g.Config.IsLondon(common.Big0) { + // if g.BaseFee != nil { + // head.BaseFee = g.BaseFee + // } else { + // head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee) + // } + // } var withdrawals []*types.Withdrawal - if conf := g.Config; conf != nil { - num := big.NewInt(int64(g.Number)) - if conf.IsShanghai(num, g.Timestamp) { - head.WithdrawalsHash = &types.EmptyWithdrawalsHash - withdrawals = make([]*types.Withdrawal, 0) - } - if conf.IsCancun(num, g.Timestamp) { - // EIP-4788: The parentBeaconBlockRoot of the genesis block is always - // the zero hash. This is because the genesis block does not have a parent - // by definition. - head.ParentBeaconRoot = new(common.Hash) - // EIP-4844 fields - head.ExcessBlobGas = g.ExcessBlobGas - head.BlobGasUsed = g.BlobGasUsed - if head.ExcessBlobGas == nil { - head.ExcessBlobGas = new(uint64) - } - if head.BlobGasUsed == nil { - head.BlobGasUsed = new(uint64) - } - } - } + // if conf := g.Config; conf != nil { + // num := big.NewInt(int64(g.Number)) + // if conf.IsShanghai(num, g.Timestamp) { + // head.WithdrawalsHash = &types.EmptyWithdrawalsHash + // withdrawals = make([]*types.Withdrawal, 0) + // } + // if conf.IsCancun(num, g.Timestamp) { + // // EIP-4788: The parentBeaconBlockRoot of the genesis block is always + // // the zero hash. This is because the genesis block does not have a parent + // // by definition. + // head.ParentBeaconRoot = new(common.Hash) + // // EIP-4844 fields + // head.ExcessBlobGas = g.ExcessBlobGas + // head.BlobGasUsed = g.BlobGasUsed + // if head.ExcessBlobGas == nil { + // head.ExcessBlobGas = new(uint64) + // } + // if head.BlobGasUsed == nil { + // head.BlobGasUsed = new(uint64) + // } + // } + // } return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals) } diff --git a/core/types/hashes.go b/core/types/hashes.go index ed6283ad5b..0815925e36 100644 --- a/core/types/hashes.go +++ b/core/types/hashes.go @@ -23,8 +23,10 @@ import ( ) var ( + EmptyZkTrieHash = common.Hash{} + // EmptyRootHash is the known root hash of an empty trie. - EmptyRootHash = common.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") + EmptyRootHash = EmptyZkTrieHash // EmptyUncleHash is the known hash of the empty uncle set. EmptyUncleHash = rlpHash([]*Header(nil)) // 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 diff --git a/trie/zk_trie.go b/trie/zk_trie.go index 2533ff8238..b246b11be9 100644 --- a/trie/zk_trie.go +++ b/trie/zk_trie.go @@ -127,8 +127,7 @@ func (t *ZkTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte) e } func (t *ZkTrie) UpdateStorage(_ common.Address, key, value []byte) error { - v, _ := rlp.EncodeToBytes(value) - return t.TryUpdate(key, v) + return t.TryUpdate(key, value) } // Delete removes any existing value for key from the trie.