fix EmptyRootHash & ZkTrie's UpdateStorage; fix genesis (#759)

* ???

* fix `UpdateStorage`

* draft fix

* minor
This commit is contained in:
HAOYUatHZ 2024-05-23 23:03:59 +08:00 committed by GitHub
parent 62c81eee01
commit 34bf14978e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 32 deletions

View file

@ -450,36 +450,37 @@ func (g *Genesis) ToBlock() *types.Block {
if g.Difficulty == nil && g.Mixhash == (common.Hash{}) { if g.Difficulty == nil && g.Mixhash == (common.Hash{}) {
head.Difficulty = params.GenesisDifficulty head.Difficulty = params.GenesisDifficulty
} }
if g.Config != nil && g.Config.IsLondon(common.Big0) { // TODO: fix basefee
if g.BaseFee != nil { // if g.Config != nil && g.Config.IsLondon(common.Big0) {
head.BaseFee = g.BaseFee // if g.BaseFee != nil {
} else { // head.BaseFee = g.BaseFee
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee) // } else {
} // head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
} // }
// }
var withdrawals []*types.Withdrawal var withdrawals []*types.Withdrawal
if conf := g.Config; conf != nil { // if conf := g.Config; conf != nil {
num := big.NewInt(int64(g.Number)) // num := big.NewInt(int64(g.Number))
if conf.IsShanghai(num, g.Timestamp) { // if conf.IsShanghai(num, g.Timestamp) {
head.WithdrawalsHash = &types.EmptyWithdrawalsHash // head.WithdrawalsHash = &types.EmptyWithdrawalsHash
withdrawals = make([]*types.Withdrawal, 0) // withdrawals = make([]*types.Withdrawal, 0)
} // }
if conf.IsCancun(num, g.Timestamp) { // if conf.IsCancun(num, g.Timestamp) {
// EIP-4788: The parentBeaconBlockRoot of the genesis block is always // // EIP-4788: The parentBeaconBlockRoot of the genesis block is always
// the zero hash. This is because the genesis block does not have a parent // // the zero hash. This is because the genesis block does not have a parent
// by definition. // // by definition.
head.ParentBeaconRoot = new(common.Hash) // head.ParentBeaconRoot = new(common.Hash)
// EIP-4844 fields // // EIP-4844 fields
head.ExcessBlobGas = g.ExcessBlobGas // head.ExcessBlobGas = g.ExcessBlobGas
head.BlobGasUsed = g.BlobGasUsed // head.BlobGasUsed = g.BlobGasUsed
if head.ExcessBlobGas == nil { // if head.ExcessBlobGas == nil {
head.ExcessBlobGas = new(uint64) // head.ExcessBlobGas = new(uint64)
} // }
if head.BlobGasUsed == nil { // if head.BlobGasUsed == nil {
head.BlobGasUsed = new(uint64) // head.BlobGasUsed = new(uint64)
} // }
} // }
} // }
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals) return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals)
} }

View file

@ -23,8 +23,10 @@ import (
) )
var ( var (
EmptyZkTrieHash = common.Hash{}
// EmptyRootHash is the known root hash of an empty trie. // 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 is the known hash of the empty uncle set.
EmptyUncleHash = rlpHash([]*Header(nil)) // 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 EmptyUncleHash = rlpHash([]*Header(nil)) // 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347

View file

@ -127,8 +127,7 @@ func (t *ZkTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte) e
} }
func (t *ZkTrie) UpdateStorage(_ common.Address, key, value []byte) error { func (t *ZkTrie) UpdateStorage(_ common.Address, key, value []byte) error {
v, _ := rlp.EncodeToBytes(value) return t.TryUpdate(key, value)
return t.TryUpdate(key, v)
} }
// Delete removes any existing value for key from the trie. // Delete removes any existing value for key from the trie.