From fba21c6bd47fc5d9381f16538a0133fdec30c207 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Tue, 25 Jul 2023 03:09:24 +0300 Subject: [PATCH] move genesis verify to vm (#753) * move genesis verify to vm * fix comment * set a correct default from genesis * fix log * revert change to vm.go --------- Co-authored-by: Darioush Jalali --- core/genesis.go | 32 +++++++++++++++++--------------- plugin/evm/vm.go | 4 ++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 65b9aa8aad..db52a157d7 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -183,21 +183,6 @@ func SetupGenesisBlock( if genesis.Config == nil { return nil, common.Hash{}, errGenesisNoConfig } - // Make sure genesis gas limit is consistent in SubnetEVM fork - if genesis.Config.IsSubnetEVM(genesis.Timestamp) { - gasLimitConfig := genesis.Config.FeeConfig.GasLimit.Uint64() - if gasLimitConfig != genesis.GasLimit { - return nil, common.Hash{}, fmt.Errorf( - "gas limit in fee config (%d) does not match gas limit in header (%d)", - gasLimitConfig, - genesis.GasLimit, - ) - } - // Verify config - if err := genesis.Config.Verify(); err != nil { - return nil, common.Hash{}, err - } - } // Just commit the new block if there is no stored genesis block. stored := rawdb.ReadCanonicalHash(db, 0) @@ -396,6 +381,23 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block { return block } +func (g *Genesis) Verify() error { + // Make sure genesis gas limit is consistent + gasLimitConfig := g.Config.FeeConfig.GasLimit.Uint64() + if gasLimitConfig != g.GasLimit { + return fmt.Errorf( + "gas limit in fee config (%d) does not match gas limit in header (%d)", + gasLimitConfig, + g.GasLimit, + ) + } + // Verify config + if err := g.Config.Verify(); err != nil { + return err + } + return nil +} + // GenesisBlockForTesting creates and writes a block in which addr has the given wei balance. func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block { g := Genesis{ diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index b55907f594..f5afc1f13f 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -314,6 +314,10 @@ func (vm *VM) Initialize( g.Config.FeeConfig = params.DefaultFeeConfig } + if err := g.Verify(); err != nil { + return fmt.Errorf("failed to verify genesis: %w", err) + } + vm.ethConfig = ethconfig.NewDefaultConfig() vm.ethConfig.Genesis = g // NetworkID here is different than Avalanche's NetworkID.