github.com/cryptotooltop/go-ethereum@v0.0.0-20231103184714-151d1922f3e5/params/config.go (about)

     1  // Copyright 2016 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package params
    18  
    19  import (
    20  	"encoding/binary"
    21  	"fmt"
    22  	"math/big"
    23  
    24  	"golang.org/x/crypto/sha3"
    25  
    26  	"github.com/scroll-tech/go-ethereum/common"
    27  	"github.com/scroll-tech/go-ethereum/rollup/rcfg"
    28  )
    29  
    30  // Genesis hashes to enforce below configs on.
    31  var (
    32  	MainnetGenesisHash       = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
    33  	RopstenGenesisHash       = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
    34  	SepoliaGenesisHash       = common.HexToHash("0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9")
    35  	RinkebyGenesisHash       = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
    36  	GoerliGenesisHash        = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
    37  	ScrollAlphaGenesisHash   = common.HexToHash("0xa4fc62b9b0643e345bdcebe457b3ae898bef59c7203c3db269200055e037afda")
    38  	ScrollSepoliaGenesisHash = common.HexToHash("0xaa62d1a8b2bffa9e5d2368b63aae0d98d54928bd713125e3fd9e5c896c68592c")
    39  	ScrollMainnetGenesisHash = common.HexToHash("0xbbc05efd412b7cd47a2ed0e5ddfcf87af251e414ea4c801d78b6784513180a80")
    40  )
    41  
    42  // TrustedCheckpoints associates each known checkpoint with the genesis hash of
    43  // the chain it belongs to.
    44  var TrustedCheckpoints = map[common.Hash]*TrustedCheckpoint{
    45  	MainnetGenesisHash: MainnetTrustedCheckpoint,
    46  	RopstenGenesisHash: RopstenTrustedCheckpoint,
    47  	SepoliaGenesisHash: SepoliaTrustedCheckpoint,
    48  	RinkebyGenesisHash: RinkebyTrustedCheckpoint,
    49  	GoerliGenesisHash:  GoerliTrustedCheckpoint,
    50  }
    51  
    52  // CheckpointOracles associates each known checkpoint oracles with the genesis hash of
    53  // the chain it belongs to.
    54  var CheckpointOracles = map[common.Hash]*CheckpointOracleConfig{
    55  	MainnetGenesisHash: MainnetCheckpointOracle,
    56  	RopstenGenesisHash: RopstenCheckpointOracle,
    57  	RinkebyGenesisHash: RinkebyCheckpointOracle,
    58  	GoerliGenesisHash:  GoerliCheckpointOracle,
    59  }
    60  
    61  var (
    62  	// MainnetChainConfig is the chain parameters to run a node on the main network.
    63  	MainnetChainConfig = &ChainConfig{
    64  		ChainID:             big.NewInt(1),
    65  		HomesteadBlock:      big.NewInt(1_150_000),
    66  		DAOForkBlock:        big.NewInt(1_920_000),
    67  		DAOForkSupport:      true,
    68  		EIP150Block:         big.NewInt(2_463_000),
    69  		EIP150Hash:          common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
    70  		EIP155Block:         big.NewInt(2_675_000),
    71  		EIP158Block:         big.NewInt(2_675_000),
    72  		ByzantiumBlock:      big.NewInt(4_370_000),
    73  		ConstantinopleBlock: big.NewInt(7_280_000),
    74  		PetersburgBlock:     big.NewInt(7_280_000),
    75  		IstanbulBlock:       big.NewInt(9_069_000),
    76  		MuirGlacierBlock:    big.NewInt(9_200_000),
    77  		BerlinBlock:         big.NewInt(12_244_000),
    78  		LondonBlock:         big.NewInt(12_965_000),
    79  		ArrowGlacierBlock:   big.NewInt(13_773_000),
    80  		Ethash:              new(EthashConfig),
    81  	}
    82  
    83  	// MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network.
    84  	MainnetTrustedCheckpoint = &TrustedCheckpoint{
    85  		SectionIndex: 413,
    86  		SectionHead:  common.HexToHash("0x8aa8e64ceadcdc5f23bc41d2acb7295a261a5cf680bb00a34f0e01af08200083"),
    87  		CHTRoot:      common.HexToHash("0x008af584d385a2610706c5a439d39f15ddd4b691c5d42603f65ae576f703f477"),
    88  		BloomRoot:    common.HexToHash("0x5a081af71a588f4d90bced242545b08904ad4fb92f7effff2ceb6e50e6dec157"),
    89  	}
    90  
    91  	// MainnetCheckpointOracle contains a set of configs for the main network oracle.
    92  	MainnetCheckpointOracle = &CheckpointOracleConfig{
    93  		Address: common.HexToAddress("0x9a9070028361F7AAbeB3f2F2Dc07F82C4a98A02a"),
    94  		Signers: []common.Address{
    95  			common.HexToAddress("0x1b2C260efc720BE89101890E4Db589b44E950527"), // Peter
    96  			common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
    97  			common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
    98  			common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
    99  			common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume
   100  		},
   101  		Threshold: 2,
   102  	}
   103  
   104  	// RopstenChainConfig contains the chain parameters to run a node on the Ropsten test network.
   105  	RopstenChainConfig = &ChainConfig{
   106  		ChainID:             big.NewInt(3),
   107  		HomesteadBlock:      big.NewInt(0),
   108  		DAOForkBlock:        nil,
   109  		DAOForkSupport:      true,
   110  		EIP150Block:         big.NewInt(0),
   111  		EIP150Hash:          common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
   112  		EIP155Block:         big.NewInt(10),
   113  		EIP158Block:         big.NewInt(10),
   114  		ByzantiumBlock:      big.NewInt(1_700_000),
   115  		ConstantinopleBlock: big.NewInt(4_230_000),
   116  		PetersburgBlock:     big.NewInt(4_939_394),
   117  		IstanbulBlock:       big.NewInt(6_485_846),
   118  		MuirGlacierBlock:    big.NewInt(7_117_117),
   119  		BerlinBlock:         big.NewInt(9_812_189),
   120  		LondonBlock:         big.NewInt(10_499_401),
   121  		Ethash:              new(EthashConfig),
   122  	}
   123  
   124  	// RopstenTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network.
   125  	RopstenTrustedCheckpoint = &TrustedCheckpoint{
   126  		SectionIndex: 346,
   127  		SectionHead:  common.HexToHash("0xafa0384ebd13a751fb7475aaa7fc08ac308925c8b2e2195bca2d4ab1878a7a84"),
   128  		CHTRoot:      common.HexToHash("0x522ae1f334bfa36033b2315d0b9954052780700b69448ecea8d5877e0f7ee477"),
   129  		BloomRoot:    common.HexToHash("0x4093fd53b0d2cc50181dca353fe66f03ae113e7cb65f869a4dfb5905de6a0493"),
   130  	}
   131  
   132  	// RopstenCheckpointOracle contains a set of configs for the Ropsten test network oracle.
   133  	RopstenCheckpointOracle = &CheckpointOracleConfig{
   134  		Address: common.HexToAddress("0xEF79475013f154E6A65b54cB2742867791bf0B84"),
   135  		Signers: []common.Address{
   136  			common.HexToAddress("0x32162F3581E88a5f62e8A61892B42C46E2c18f7b"), // Peter
   137  			common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
   138  			common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
   139  			common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
   140  			common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume
   141  		},
   142  		Threshold: 2,
   143  	}
   144  
   145  	// SepoliaChainConfig contains the chain parameters to run a node on the Sepolia test network.
   146  	SepoliaChainConfig = &ChainConfig{
   147  		ChainID:             big.NewInt(11155111),
   148  		HomesteadBlock:      big.NewInt(0),
   149  		DAOForkBlock:        nil,
   150  		DAOForkSupport:      true,
   151  		EIP150Block:         big.NewInt(0),
   152  		EIP155Block:         big.NewInt(0),
   153  		EIP158Block:         big.NewInt(0),
   154  		ByzantiumBlock:      big.NewInt(0),
   155  		ConstantinopleBlock: big.NewInt(0),
   156  		PetersburgBlock:     big.NewInt(0),
   157  		IstanbulBlock:       big.NewInt(0),
   158  		MuirGlacierBlock:    big.NewInt(0),
   159  		BerlinBlock:         big.NewInt(0),
   160  		LondonBlock:         big.NewInt(0),
   161  		Ethash:              new(EthashConfig),
   162  	}
   163  
   164  	// SepoliaTrustedCheckpoint contains the light client trusted checkpoint for the Sepolia test network.
   165  	SepoliaTrustedCheckpoint = &TrustedCheckpoint{
   166  		SectionIndex: 1,
   167  		SectionHead:  common.HexToHash("0x5dde65e28745b10ff9e9b86499c3a3edc03587b27a06564a4342baf3a37de869"),
   168  		CHTRoot:      common.HexToHash("0x042a0d914f7baa4f28f14d12291e5f346e88c5b9d95127bf5422a8afeacd27e8"),
   169  		BloomRoot:    common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),
   170  	}
   171  
   172  	// RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
   173  	RinkebyChainConfig = &ChainConfig{
   174  		ChainID:             big.NewInt(4),
   175  		HomesteadBlock:      big.NewInt(1),
   176  		DAOForkBlock:        nil,
   177  		DAOForkSupport:      true,
   178  		EIP150Block:         big.NewInt(2),
   179  		EIP150Hash:          common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
   180  		EIP155Block:         big.NewInt(3),
   181  		EIP158Block:         big.NewInt(3),
   182  		ByzantiumBlock:      big.NewInt(1_035_301),
   183  		ConstantinopleBlock: big.NewInt(3_660_663),
   184  		PetersburgBlock:     big.NewInt(4_321_234),
   185  		IstanbulBlock:       big.NewInt(5_435_345),
   186  		MuirGlacierBlock:    nil,
   187  		BerlinBlock:         big.NewInt(8_290_928),
   188  		LondonBlock:         big.NewInt(8_897_988),
   189  		ArrowGlacierBlock:   nil,
   190  		Clique: &CliqueConfig{
   191  			Period: 15,
   192  			Epoch:  30000,
   193  		},
   194  	}
   195  
   196  	// RinkebyTrustedCheckpoint contains the light client trusted checkpoint for the Rinkeby test network.
   197  	RinkebyTrustedCheckpoint = &TrustedCheckpoint{
   198  		SectionIndex: 292,
   199  		SectionHead:  common.HexToHash("0x4185c2f1bb85ecaa04409d1008ff0761092ea2e94e8a71d64b1a5abc37b81414"),
   200  		CHTRoot:      common.HexToHash("0x03b0191e6140effe0b88bb7c97bfb794a275d3543cb3190662fb72d9beea423c"),
   201  		BloomRoot:    common.HexToHash("0x3d5f6edccc87536dcbc0dd3aae97a318205c617dd3957b4261470c71481629e2"),
   202  	}
   203  
   204  	// RinkebyCheckpointOracle contains a set of configs for the Rinkeby test network oracle.
   205  	RinkebyCheckpointOracle = &CheckpointOracleConfig{
   206  		Address: common.HexToAddress("0xebe8eFA441B9302A0d7eaECc277c09d20D684540"),
   207  		Signers: []common.Address{
   208  			common.HexToAddress("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"), // Peter
   209  			common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
   210  			common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
   211  			common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
   212  		},
   213  		Threshold: 2,
   214  	}
   215  
   216  	// GoerliChainConfig contains the chain parameters to run a node on the Görli test network.
   217  	GoerliChainConfig = &ChainConfig{
   218  		ChainID:             big.NewInt(5),
   219  		HomesteadBlock:      big.NewInt(0),
   220  		DAOForkBlock:        nil,
   221  		DAOForkSupport:      true,
   222  		EIP150Block:         big.NewInt(0),
   223  		EIP155Block:         big.NewInt(0),
   224  		EIP158Block:         big.NewInt(0),
   225  		ByzantiumBlock:      big.NewInt(0),
   226  		ConstantinopleBlock: big.NewInt(0),
   227  		PetersburgBlock:     big.NewInt(0),
   228  		IstanbulBlock:       big.NewInt(1_561_651),
   229  		MuirGlacierBlock:    nil,
   230  		BerlinBlock:         big.NewInt(4_460_644),
   231  		LondonBlock:         big.NewInt(5_062_605),
   232  		ArrowGlacierBlock:   nil,
   233  		Clique: &CliqueConfig{
   234  			Period: 15,
   235  			Epoch:  30000,
   236  		},
   237  	}
   238  
   239  	// GoerliTrustedCheckpoint contains the light client trusted checkpoint for the Görli test network.
   240  	GoerliTrustedCheckpoint = &TrustedCheckpoint{
   241  		SectionIndex: 176,
   242  		SectionHead:  common.HexToHash("0x2de018858528434f93adb40b1f03f2304a86d31b4ef2b1f930da0134f5c32427"),
   243  		CHTRoot:      common.HexToHash("0x8c17e497d38088321c147abe4acbdfb3c0cab7d7a2b97e07404540f04d12747e"),
   244  		BloomRoot:    common.HexToHash("0x02a41b6606bd3f741bd6ae88792d75b1ad8cf0ea5e28fbaa03bc8b95cbd20034"),
   245  	}
   246  
   247  	// GoerliCheckpointOracle contains a set of configs for the Goerli test network oracle.
   248  	GoerliCheckpointOracle = &CheckpointOracleConfig{
   249  		Address: common.HexToAddress("0x18CA0E045F0D772a851BC7e48357Bcaab0a0795D"),
   250  		Signers: []common.Address{
   251  			common.HexToAddress("0x4769bcaD07e3b938B7f43EB7D278Bc7Cb9efFb38"), // Peter
   252  			common.HexToAddress("0x78d1aD571A1A09D60D9BBf25894b44e4C8859595"), // Martin
   253  			common.HexToAddress("0x286834935f4A8Cfb4FF4C77D5770C2775aE2b0E7"), // Zsolt
   254  			common.HexToAddress("0xb86e2B0Ab5A4B1373e40c51A7C712c70Ba2f9f8E"), // Gary
   255  			common.HexToAddress("0x0DF8fa387C602AE62559cC4aFa4972A7045d6707"), // Guillaume
   256  		},
   257  		Threshold: 2,
   258  	}
   259  
   260  	// ScrollAlphaChainConfig contains the chain parameters to run a node on the Scroll Alpha test network.
   261  	ScrollMaxTxPerBlock             = 100
   262  	ScrollMaxTxPayloadBytesPerBlock = 120 * 1024
   263  
   264  	ScrollAlphaChainConfig = &ChainConfig{
   265  		ChainID:             big.NewInt(534353),
   266  		HomesteadBlock:      big.NewInt(0),
   267  		DAOForkBlock:        nil,
   268  		DAOForkSupport:      true,
   269  		EIP150Block:         big.NewInt(0),
   270  		EIP155Block:         big.NewInt(0),
   271  		EIP158Block:         big.NewInt(0),
   272  		ByzantiumBlock:      big.NewInt(0),
   273  		ConstantinopleBlock: big.NewInt(0),
   274  		PetersburgBlock:     big.NewInt(0),
   275  		IstanbulBlock:       big.NewInt(0),
   276  		MuirGlacierBlock:    nil,
   277  		BerlinBlock:         big.NewInt(0),
   278  		LondonBlock:         big.NewInt(0),
   279  		ArrowGlacierBlock:   nil,
   280  		ArchimedesBlock:     big.NewInt(2646311),
   281  		ShanghaiBlock:       nil,
   282  		Clique: &CliqueConfig{
   283  			Period: 3,
   284  			Epoch:  30000,
   285  		},
   286  		Scroll: ScrollConfig{
   287  			UseZktrie:                 true,
   288  			MaxTxPerBlock:             &ScrollMaxTxPerBlock,
   289  			MaxTxPayloadBytesPerBlock: &ScrollMaxTxPayloadBytesPerBlock,
   290  			FeeVaultAddress:           &rcfg.ScrollFeeVaultAddress,
   291  			EnableEIP2718:             false,
   292  			EnableEIP1559:             false,
   293  			L1Config: &L1Config{
   294  				L1ChainId:             5,
   295  				L1MessageQueueAddress: common.HexToAddress("0x79DB48002Aa861C8cb189cabc21c6B1468BC83BB"),
   296  				NumL1MessagesPerBlock: 0,
   297  				ScrollChainAddress:    common.HexToAddress("0x3C584eC7f0f2764CC715ac3180Ae9828465E9833"),
   298  			},
   299  		},
   300  	}
   301  
   302  	ScrollSepoliaChainConfig = &ChainConfig{
   303  		ChainID:             big.NewInt(534351),
   304  		HomesteadBlock:      big.NewInt(0),
   305  		DAOForkBlock:        nil,
   306  		DAOForkSupport:      true,
   307  		EIP150Block:         big.NewInt(0),
   308  		EIP155Block:         big.NewInt(0),
   309  		EIP158Block:         big.NewInt(0),
   310  		ByzantiumBlock:      big.NewInt(0),
   311  		ConstantinopleBlock: big.NewInt(0),
   312  		PetersburgBlock:     big.NewInt(0),
   313  		IstanbulBlock:       big.NewInt(0),
   314  		MuirGlacierBlock:    nil,
   315  		BerlinBlock:         big.NewInt(0),
   316  		LondonBlock:         big.NewInt(0),
   317  		ArrowGlacierBlock:   nil,
   318  		ArchimedesBlock:     big.NewInt(0),
   319  		ShanghaiBlock:       big.NewInt(0),
   320  		Clique: &CliqueConfig{
   321  			Period: 3,
   322  			Epoch:  30000,
   323  		},
   324  		Scroll: ScrollConfig{
   325  			UseZktrie:                 true,
   326  			MaxTxPerBlock:             &ScrollMaxTxPerBlock,
   327  			MaxTxPayloadBytesPerBlock: &ScrollMaxTxPayloadBytesPerBlock,
   328  			FeeVaultAddress:           &rcfg.ScrollFeeVaultAddress,
   329  			EnableEIP2718:             false,
   330  			EnableEIP1559:             false,
   331  			L1Config: &L1Config{
   332  				L1ChainId:             11155111,
   333  				L1MessageQueueAddress: common.HexToAddress("0xF0B2293F5D834eAe920c6974D50957A1732de763"),
   334  				NumL1MessagesPerBlock: 10,
   335  				ScrollChainAddress:    common.HexToAddress("0x2D567EcE699Eabe5afCd141eDB7A4f2D0D6ce8a0"),
   336  			},
   337  		},
   338  	}
   339  
   340  	ScrollMainnetChainConfig = &ChainConfig{
   341  		ChainID:             big.NewInt(534352),
   342  		HomesteadBlock:      big.NewInt(0),
   343  		DAOForkBlock:        nil,
   344  		DAOForkSupport:      true,
   345  		EIP150Block:         big.NewInt(0),
   346  		EIP155Block:         big.NewInt(0),
   347  		EIP158Block:         big.NewInt(0),
   348  		ByzantiumBlock:      big.NewInt(0),
   349  		ConstantinopleBlock: big.NewInt(0),
   350  		PetersburgBlock:     big.NewInt(0),
   351  		IstanbulBlock:       big.NewInt(0),
   352  		MuirGlacierBlock:    nil,
   353  		BerlinBlock:         big.NewInt(0),
   354  		LondonBlock:         big.NewInt(0),
   355  		ArrowGlacierBlock:   nil,
   356  		ArchimedesBlock:     big.NewInt(0),
   357  		ShanghaiBlock:       big.NewInt(0),
   358  		Clique: &CliqueConfig{
   359  			Period: 3,
   360  			Epoch:  30000,
   361  		},
   362  		Scroll: ScrollConfig{
   363  			UseZktrie:                 true,
   364  			MaxTxPerBlock:             &ScrollMaxTxPerBlock,
   365  			MaxTxPayloadBytesPerBlock: &ScrollMaxTxPayloadBytesPerBlock,
   366  			FeeVaultAddress:           &rcfg.ScrollFeeVaultAddress,
   367  			EnableEIP2718:             false,
   368  			EnableEIP1559:             false,
   369  			L1Config: &L1Config{
   370  				L1ChainId:             1,
   371  				L1MessageQueueAddress: common.HexToAddress("0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B"),
   372  				NumL1MessagesPerBlock: 10,
   373  				ScrollChainAddress:    common.HexToAddress("0xa13BAF47339d63B743e7Da8741db5456DAc1E556"),
   374  			},
   375  		},
   376  	}
   377  
   378  	// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
   379  	// and accepted by the Ethereum core developers into the Ethash consensus.
   380  	//
   381  	// This configuration is intentionally not using keyed fields to force anyone
   382  	// adding flags to the config to also have to set these fields.
   383  	AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil,
   384  		ScrollConfig{
   385  			UseZktrie:                 false,
   386  			FeeVaultAddress:           nil,
   387  			EnableEIP2718:             true,
   388  			EnableEIP1559:             true,
   389  			MaxTxPerBlock:             nil,
   390  			MaxTxPayloadBytesPerBlock: nil,
   391  			L1Config:                  &L1Config{5, common.HexToAddress("0x0000000000000000000000000000000000000000"), 0, common.HexToAddress("0x0000000000000000000000000000000000000000")},
   392  		}}
   393  
   394  	// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
   395  	// and accepted by the Ethereum core developers into the Clique consensus.
   396  	//
   397  	// This configuration is intentionally not using keyed fields to force anyone
   398  	// adding flags to the config to also have to set these fields.
   399  	AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000},
   400  		ScrollConfig{
   401  			UseZktrie:                 false,
   402  			FeeVaultAddress:           nil,
   403  			EnableEIP2718:             true,
   404  			EnableEIP1559:             true,
   405  			MaxTxPerBlock:             nil,
   406  			MaxTxPayloadBytesPerBlock: nil,
   407  			L1Config:                  &L1Config{5, common.HexToAddress("0x0000000000000000000000000000000000000000"), 0, common.HexToAddress("0x0000000000000000000000000000000000000000")},
   408  		}}
   409  
   410  	TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil,
   411  		ScrollConfig{
   412  			UseZktrie:                 false,
   413  			FeeVaultAddress:           &common.Address{123},
   414  			EnableEIP2718:             true,
   415  			EnableEIP1559:             true,
   416  			MaxTxPerBlock:             nil,
   417  			MaxTxPayloadBytesPerBlock: nil,
   418  			L1Config:                  &L1Config{5, common.HexToAddress("0x0000000000000000000000000000000000000000"), 0, common.HexToAddress("0x0000000000000000000000000000000000000000")},
   419  		}}
   420  	TestRules = TestChainConfig.Rules(new(big.Int))
   421  
   422  	TestNoL1DataFeeChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil,
   423  		ScrollConfig{
   424  			UseZktrie:                 false,
   425  			FeeVaultAddress:           nil,
   426  			EnableEIP2718:             true,
   427  			EnableEIP1559:             true,
   428  			MaxTxPerBlock:             nil,
   429  			MaxTxPayloadBytesPerBlock: nil,
   430  			L1Config:                  &L1Config{5, common.HexToAddress("0x0000000000000000000000000000000000000000"), 0, common.HexToAddress("0x0000000000000000000000000000000000000000")},
   431  		}}
   432  )
   433  
   434  // TrustedCheckpoint represents a set of post-processed trie roots (CHT and
   435  // BloomTrie) associated with the appropriate section index and head hash. It is
   436  // used to start light syncing from this checkpoint and avoid downloading the
   437  // entire header chain while still being able to securely access old headers/logs.
   438  type TrustedCheckpoint struct {
   439  	SectionIndex uint64      `json:"sectionIndex"`
   440  	SectionHead  common.Hash `json:"sectionHead"`
   441  	CHTRoot      common.Hash `json:"chtRoot"`
   442  	BloomRoot    common.Hash `json:"bloomRoot"`
   443  }
   444  
   445  // HashEqual returns an indicator comparing the itself hash with given one.
   446  func (c *TrustedCheckpoint) HashEqual(hash common.Hash) bool {
   447  	if c.Empty() {
   448  		return hash == common.Hash{}
   449  	}
   450  	return c.Hash() == hash
   451  }
   452  
   453  // Hash returns the hash of checkpoint's four key fields(index, sectionHead, chtRoot and bloomTrieRoot).
   454  func (c *TrustedCheckpoint) Hash() common.Hash {
   455  	var sectionIndex [8]byte
   456  	binary.BigEndian.PutUint64(sectionIndex[:], c.SectionIndex)
   457  
   458  	w := sha3.NewLegacyKeccak256()
   459  	w.Write(sectionIndex[:])
   460  	w.Write(c.SectionHead[:])
   461  	w.Write(c.CHTRoot[:])
   462  	w.Write(c.BloomRoot[:])
   463  
   464  	var h common.Hash
   465  	w.Sum(h[:0])
   466  	return h
   467  }
   468  
   469  // Empty returns an indicator whether the checkpoint is regarded as empty.
   470  func (c *TrustedCheckpoint) Empty() bool {
   471  	return c.SectionHead == (common.Hash{}) || c.CHTRoot == (common.Hash{}) || c.BloomRoot == (common.Hash{})
   472  }
   473  
   474  // CheckpointOracleConfig represents a set of checkpoint contract(which acts as an oracle)
   475  // config which used for light client checkpoint syncing.
   476  type CheckpointOracleConfig struct {
   477  	Address   common.Address   `json:"address"`
   478  	Signers   []common.Address `json:"signers"`
   479  	Threshold uint64           `json:"threshold"`
   480  }
   481  
   482  // ChainConfig is the core config which determines the blockchain settings.
   483  //
   484  // ChainConfig is stored in the database on a per block basis. This means
   485  // that any network, identified by its genesis block, can have its own
   486  // set of configuration options.
   487  type ChainConfig struct {
   488  	ChainID *big.Int `json:"chainId"` // chainId identifies the current chain and is used for replay protection
   489  
   490  	HomesteadBlock *big.Int `json:"homesteadBlock,omitempty"` // Homestead switch block (nil = no fork, 0 = already homestead)
   491  
   492  	DAOForkBlock   *big.Int `json:"daoForkBlock,omitempty"`   // TheDAO hard-fork switch block (nil = no fork)
   493  	DAOForkSupport bool     `json:"daoForkSupport,omitempty"` // Whether the nodes supports or opposes the DAO hard-fork
   494  
   495  	// EIP150 implements the Gas price changes (https://github.com/ethereum/EIPs/issues/150)
   496  	EIP150Block *big.Int    `json:"eip150Block,omitempty"` // EIP150 HF block (nil = no fork)
   497  	EIP150Hash  common.Hash `json:"eip150Hash,omitempty"`  // EIP150 HF hash (needed for header only clients as only gas pricing changed)
   498  
   499  	EIP155Block *big.Int `json:"eip155Block,omitempty"` // EIP155 HF block
   500  	EIP158Block *big.Int `json:"eip158Block,omitempty"` // EIP158 HF block
   501  
   502  	ByzantiumBlock      *big.Int `json:"byzantiumBlock,omitempty"`      // Byzantium switch block (nil = no fork, 0 = already on byzantium)
   503  	ConstantinopleBlock *big.Int `json:"constantinopleBlock,omitempty"` // Constantinople switch block (nil = no fork, 0 = already activated)
   504  	PetersburgBlock     *big.Int `json:"petersburgBlock,omitempty"`     // Petersburg switch block (nil = same as Constantinople)
   505  	IstanbulBlock       *big.Int `json:"istanbulBlock,omitempty"`       // Istanbul switch block (nil = no fork, 0 = already on istanbul)
   506  	MuirGlacierBlock    *big.Int `json:"muirGlacierBlock,omitempty"`    // Eip-2384 (bomb delay) switch block (nil = no fork, 0 = already activated)
   507  	BerlinBlock         *big.Int `json:"berlinBlock,omitempty"`         // Berlin switch block (nil = no fork, 0 = already on berlin)
   508  	LondonBlock         *big.Int `json:"londonBlock,omitempty"`         // London switch block (nil = no fork, 0 = already on london)
   509  	ArrowGlacierBlock   *big.Int `json:"arrowGlacierBlock,omitempty"`   // Eip-4345 (bomb delay) switch block (nil = no fork, 0 = already activated)
   510  	ArchimedesBlock     *big.Int `json:"archimedesBlock,omitempty"`     // Archimedes switch block (nil = no fork, 0 = already on archimedes)
   511  	ShanghaiBlock       *big.Int `json:"shanghaiBlock,omitempty"`       // Shanghai switch block (nil = no fork, 0 = already on shanghai)
   512  
   513  	// TerminalTotalDifficulty is the amount of total difficulty reached by
   514  	// the network that triggers the consensus upgrade.
   515  	TerminalTotalDifficulty *big.Int `json:"terminalTotalDifficulty,omitempty"`
   516  
   517  	// Various consensus engines
   518  	Ethash *EthashConfig `json:"ethash,omitempty"`
   519  	Clique *CliqueConfig `json:"clique,omitempty"`
   520  
   521  	// Scroll genesis extension: enable scroll rollup-related traces & state transition
   522  	Scroll ScrollConfig `json:"scroll,omitempty"`
   523  }
   524  
   525  type ScrollConfig struct {
   526  	// Use zktrie [optional]
   527  	UseZktrie bool `json:"useZktrie,omitempty"`
   528  
   529  	// Maximum number of transactions per block [optional]
   530  	MaxTxPerBlock *int `json:"maxTxPerBlock,omitempty"`
   531  
   532  	// Maximum tx payload size of blocks that we produce [optional]
   533  	MaxTxPayloadBytesPerBlock *int `json:"maxTxPayloadBytesPerBlock,omitempty"`
   534  
   535  	// Transaction fee vault address [optional]
   536  	FeeVaultAddress *common.Address `json:"feeVaultAddress,omitempty"`
   537  
   538  	// Enable EIP-2718 in tx pool [optional]
   539  	EnableEIP2718 bool `json:"enableEIP2718,omitempty"`
   540  
   541  	// Enable EIP-1559 in tx pool, EnableEIP2718 should be true too [optional]
   542  	EnableEIP1559 bool `json:"enableEIP1559,omitempty"`
   543  
   544  	// L1 config
   545  	L1Config *L1Config `json:"l1Config,omitempty"`
   546  }
   547  
   548  // L1Config contains the l1 parameters needed to sync l1 contract events (e.g., l1 messages, commit/revert/finalize batches) in the sequencer
   549  type L1Config struct {
   550  	L1ChainId             uint64         `json:"l1ChainId,string,omitempty"`
   551  	L1MessageQueueAddress common.Address `json:"l1MessageQueueAddress,omitempty"`
   552  	NumL1MessagesPerBlock uint64         `json:"numL1MessagesPerBlock,string,omitempty"`
   553  	ScrollChainAddress    common.Address `json:"scrollChainAddress,omitempty"`
   554  }
   555  
   556  func (c *L1Config) String() string {
   557  	if c == nil {
   558  		return "<nil>"
   559  	}
   560  
   561  	return fmt.Sprintf("{l1ChainId: %v, l1MessageQueueAddress: %v, numL1MessagesPerBlock: %v, ScrollChainAddress: %v}",
   562  		c.L1ChainId, c.L1MessageQueueAddress.Hex(), c.NumL1MessagesPerBlock, c.ScrollChainAddress.Hex())
   563  }
   564  
   565  func (s ScrollConfig) BaseFeeEnabled() bool {
   566  	return s.EnableEIP2718 && s.EnableEIP1559
   567  }
   568  
   569  func (s ScrollConfig) FeeVaultEnabled() bool {
   570  	return s.FeeVaultAddress != nil
   571  }
   572  
   573  func (s ScrollConfig) ZktrieEnabled() bool {
   574  	return s.UseZktrie
   575  }
   576  
   577  func (s ScrollConfig) ShouldIncludeL1Messages() bool {
   578  	return s.L1Config != nil && s.L1Config.NumL1MessagesPerBlock > 0
   579  }
   580  
   581  func (s ScrollConfig) String() string {
   582  	maxTxPerBlock := "<nil>"
   583  	if s.MaxTxPerBlock != nil {
   584  		maxTxPerBlock = fmt.Sprintf("%v", *s.MaxTxPerBlock)
   585  	}
   586  
   587  	maxTxPayloadBytesPerBlock := "<nil>"
   588  	if s.MaxTxPayloadBytesPerBlock != nil {
   589  		maxTxPayloadBytesPerBlock = fmt.Sprintf("%v", *s.MaxTxPayloadBytesPerBlock)
   590  	}
   591  
   592  	return fmt.Sprintf("{useZktrie: %v, maxTxPerBlock: %v, MaxTxPayloadBytesPerBlock: %v, feeVaultAddress: %v, enableEIP2718: %v, enableEIP1559: %v, l1Config: %v}",
   593  		s.UseZktrie, maxTxPerBlock, maxTxPayloadBytesPerBlock, s.FeeVaultAddress, s.EnableEIP2718, s.EnableEIP1559, s.L1Config.String())
   594  }
   595  
   596  // IsValidTxCount returns whether the given block's transaction count is below the limit.
   597  // This limit corresponds to the number of ECDSA signature checks that we can fit into the zkEVM.
   598  func (s ScrollConfig) IsValidTxCount(count int) bool {
   599  	return s.MaxTxPerBlock == nil || count <= *s.MaxTxPerBlock
   600  }
   601  
   602  // IsValidBlockSize returns whether the given block's transaction payload size is below the limit.
   603  func (s ScrollConfig) IsValidBlockSize(size common.StorageSize) bool {
   604  	return s.MaxTxPayloadBytesPerBlock == nil || size <= common.StorageSize(*s.MaxTxPayloadBytesPerBlock)
   605  }
   606  
   607  // EthashConfig is the consensus engine configs for proof-of-work based sealing.
   608  type EthashConfig struct{}
   609  
   610  // String implements the stringer interface, returning the consensus engine details.
   611  func (c *EthashConfig) String() string {
   612  	return "ethash"
   613  }
   614  
   615  // CliqueConfig is the consensus engine configs for proof-of-authority based sealing.
   616  type CliqueConfig struct {
   617  	Period uint64 `json:"period"` // Number of seconds between blocks to enforce
   618  	Epoch  uint64 `json:"epoch"`  // Epoch length to reset votes and checkpoint
   619  }
   620  
   621  // String implements the stringer interface, returning the consensus engine details.
   622  func (c *CliqueConfig) String() string {
   623  	return "clique"
   624  }
   625  
   626  // String implements the fmt.Stringer interface.
   627  func (c *ChainConfig) String() string {
   628  	var engine interface{}
   629  	switch {
   630  	case c.Ethash != nil:
   631  		engine = c.Ethash
   632  	case c.Clique != nil:
   633  		engine = c.Clique
   634  	default:
   635  		engine = "unknown"
   636  	}
   637  	return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Berlin: %v, London: %v, Arrow Glacier: %v, Archimedes: %v, Shanghai: %v, Engine: %v, Scroll config: %v}",
   638  		c.ChainID,
   639  		c.HomesteadBlock,
   640  		c.DAOForkBlock,
   641  		c.DAOForkSupport,
   642  		c.EIP150Block,
   643  		c.EIP155Block,
   644  		c.EIP158Block,
   645  		c.ByzantiumBlock,
   646  		c.ConstantinopleBlock,
   647  		c.PetersburgBlock,
   648  		c.IstanbulBlock,
   649  		c.MuirGlacierBlock,
   650  		c.BerlinBlock,
   651  		c.LondonBlock,
   652  		c.ArrowGlacierBlock,
   653  		c.ArchimedesBlock,
   654  		c.ShanghaiBlock,
   655  		engine,
   656  		c.Scroll,
   657  	)
   658  }
   659  
   660  // IsHomestead returns whether num is either equal to the homestead block or greater.
   661  func (c *ChainConfig) IsHomestead(num *big.Int) bool {
   662  	return isForked(c.HomesteadBlock, num)
   663  }
   664  
   665  // IsDAOFork returns whether num is either equal to the DAO fork block or greater.
   666  func (c *ChainConfig) IsDAOFork(num *big.Int) bool {
   667  	return isForked(c.DAOForkBlock, num)
   668  }
   669  
   670  // IsEIP150 returns whether num is either equal to the EIP150 fork block or greater.
   671  func (c *ChainConfig) IsEIP150(num *big.Int) bool {
   672  	return isForked(c.EIP150Block, num)
   673  }
   674  
   675  // IsEIP155 returns whether num is either equal to the EIP155 fork block or greater.
   676  func (c *ChainConfig) IsEIP155(num *big.Int) bool {
   677  	return isForked(c.EIP155Block, num)
   678  }
   679  
   680  // IsEIP158 returns whether num is either equal to the EIP158 fork block or greater.
   681  func (c *ChainConfig) IsEIP158(num *big.Int) bool {
   682  	return isForked(c.EIP158Block, num)
   683  }
   684  
   685  // IsByzantium returns whether num is either equal to the Byzantium fork block or greater.
   686  func (c *ChainConfig) IsByzantium(num *big.Int) bool {
   687  	return isForked(c.ByzantiumBlock, num)
   688  }
   689  
   690  // IsConstantinople returns whether num is either equal to the Constantinople fork block or greater.
   691  func (c *ChainConfig) IsConstantinople(num *big.Int) bool {
   692  	return isForked(c.ConstantinopleBlock, num)
   693  }
   694  
   695  // IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater.
   696  func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool {
   697  	return isForked(c.MuirGlacierBlock, num)
   698  }
   699  
   700  // IsPetersburg returns whether num is either
   701  // - equal to or greater than the PetersburgBlock fork block,
   702  // - OR is nil, and Constantinople is active
   703  func (c *ChainConfig) IsPetersburg(num *big.Int) bool {
   704  	return isForked(c.PetersburgBlock, num) || c.PetersburgBlock == nil && isForked(c.ConstantinopleBlock, num)
   705  }
   706  
   707  // IsIstanbul returns whether num is either equal to the Istanbul fork block or greater.
   708  func (c *ChainConfig) IsIstanbul(num *big.Int) bool {
   709  	return isForked(c.IstanbulBlock, num)
   710  }
   711  
   712  // IsBerlin returns whether num is either equal to the Berlin fork block or greater.
   713  func (c *ChainConfig) IsBerlin(num *big.Int) bool {
   714  	return isForked(c.BerlinBlock, num)
   715  }
   716  
   717  // IsLondon returns whether num is either equal to the London fork block or greater.
   718  func (c *ChainConfig) IsLondon(num *big.Int) bool {
   719  	return isForked(c.LondonBlock, num)
   720  }
   721  
   722  // IsArrowGlacier returns whether num is either equal to the Arrow Glacier (EIP-4345) fork block or greater.
   723  func (c *ChainConfig) IsArrowGlacier(num *big.Int) bool {
   724  	return isForked(c.ArrowGlacierBlock, num)
   725  }
   726  
   727  // IsArchimedes returns whether num is either equal to the Archimedes fork block or greater.
   728  func (c *ChainConfig) IsArchimedes(num *big.Int) bool {
   729  	return isForked(c.ArchimedesBlock, num)
   730  }
   731  
   732  // IsShanghai returns whether num is either equal to the Shanghai fork block or greater.
   733  func (c *ChainConfig) IsShanghai(num *big.Int) bool {
   734  	return isForked(c.ShanghaiBlock, num)
   735  }
   736  
   737  // IsTerminalPoWBlock returns whether the given block is the last block of PoW stage.
   738  func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *big.Int) bool {
   739  	if c.TerminalTotalDifficulty == nil {
   740  		return false
   741  	}
   742  	return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0
   743  }
   744  
   745  // CheckCompatible checks whether scheduled fork transitions have been imported
   746  // with a mismatching chain configuration.
   747  func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
   748  	bhead := new(big.Int).SetUint64(height)
   749  
   750  	// Iterate checkCompatible to find the lowest conflict.
   751  	var lasterr *ConfigCompatError
   752  	for {
   753  		err := c.checkCompatible(newcfg, bhead)
   754  		if err == nil || (lasterr != nil && err.RewindTo == lasterr.RewindTo) {
   755  			break
   756  		}
   757  		lasterr = err
   758  		bhead.SetUint64(err.RewindTo)
   759  	}
   760  	return lasterr
   761  }
   762  
   763  // CheckConfigForkOrder checks that we don't "skip" any forks, geth isn't pluggable enough
   764  // to guarantee that forks can be implemented in a different order than on official networks
   765  func (c *ChainConfig) CheckConfigForkOrder() error {
   766  	type fork struct {
   767  		name     string
   768  		block    *big.Int
   769  		optional bool // if true, the fork may be nil and next fork is still allowed
   770  	}
   771  	var lastFork fork
   772  	for _, cur := range []fork{
   773  		{name: "homesteadBlock", block: c.HomesteadBlock},
   774  		{name: "daoForkBlock", block: c.DAOForkBlock, optional: true},
   775  		{name: "eip150Block", block: c.EIP150Block},
   776  		{name: "eip155Block", block: c.EIP155Block},
   777  		{name: "eip158Block", block: c.EIP158Block},
   778  		{name: "byzantiumBlock", block: c.ByzantiumBlock},
   779  		{name: "constantinopleBlock", block: c.ConstantinopleBlock},
   780  		{name: "petersburgBlock", block: c.PetersburgBlock},
   781  		{name: "istanbulBlock", block: c.IstanbulBlock},
   782  		{name: "muirGlacierBlock", block: c.MuirGlacierBlock, optional: true},
   783  		{name: "berlinBlock", block: c.BerlinBlock},
   784  		{name: "londonBlock", block: c.LondonBlock},
   785  		{name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true},
   786  		{name: "archimedesBlock", block: c.ArchimedesBlock, optional: true},
   787  		{name: "shanghaiBlock", block: c.ShanghaiBlock, optional: true},
   788  	} {
   789  		if lastFork.name != "" {
   790  			// Next one must be higher number
   791  			if lastFork.block == nil && cur.block != nil {
   792  				return fmt.Errorf("unsupported fork ordering: %v not enabled, but %v enabled at %v",
   793  					lastFork.name, cur.name, cur.block)
   794  			}
   795  			if lastFork.block != nil && cur.block != nil {
   796  				if lastFork.block.Cmp(cur.block) > 0 {
   797  					return fmt.Errorf("unsupported fork ordering: %v enabled at %v, but %v enabled at %v",
   798  						lastFork.name, lastFork.block, cur.name, cur.block)
   799  				}
   800  			}
   801  		}
   802  		// If it was optional and not set, then ignore it
   803  		if !cur.optional || cur.block != nil {
   804  			lastFork = cur
   805  		}
   806  	}
   807  	return nil
   808  }
   809  
   810  func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *ConfigCompatError {
   811  	if isForkIncompatible(c.HomesteadBlock, newcfg.HomesteadBlock, head) {
   812  		return newCompatError("Homestead fork block", c.HomesteadBlock, newcfg.HomesteadBlock)
   813  	}
   814  	if isForkIncompatible(c.DAOForkBlock, newcfg.DAOForkBlock, head) {
   815  		return newCompatError("DAO fork block", c.DAOForkBlock, newcfg.DAOForkBlock)
   816  	}
   817  	if c.IsDAOFork(head) && c.DAOForkSupport != newcfg.DAOForkSupport {
   818  		return newCompatError("DAO fork support flag", c.DAOForkBlock, newcfg.DAOForkBlock)
   819  	}
   820  	if isForkIncompatible(c.EIP150Block, newcfg.EIP150Block, head) {
   821  		return newCompatError("EIP150 fork block", c.EIP150Block, newcfg.EIP150Block)
   822  	}
   823  	if isForkIncompatible(c.EIP155Block, newcfg.EIP155Block, head) {
   824  		return newCompatError("EIP155 fork block", c.EIP155Block, newcfg.EIP155Block)
   825  	}
   826  	if isForkIncompatible(c.EIP158Block, newcfg.EIP158Block, head) {
   827  		return newCompatError("EIP158 fork block", c.EIP158Block, newcfg.EIP158Block)
   828  	}
   829  	if c.IsEIP158(head) && !configNumEqual(c.ChainID, newcfg.ChainID) {
   830  		return newCompatError("EIP158 chain ID", c.EIP158Block, newcfg.EIP158Block)
   831  	}
   832  	if isForkIncompatible(c.ByzantiumBlock, newcfg.ByzantiumBlock, head) {
   833  		return newCompatError("Byzantium fork block", c.ByzantiumBlock, newcfg.ByzantiumBlock)
   834  	}
   835  	if isForkIncompatible(c.ConstantinopleBlock, newcfg.ConstantinopleBlock, head) {
   836  		return newCompatError("Constantinople fork block", c.ConstantinopleBlock, newcfg.ConstantinopleBlock)
   837  	}
   838  	if isForkIncompatible(c.PetersburgBlock, newcfg.PetersburgBlock, head) {
   839  		// the only case where we allow Petersburg to be set in the past is if it is equal to Constantinople
   840  		// mainly to satisfy fork ordering requirements which state that Petersburg fork be set if Constantinople fork is set
   841  		if isForkIncompatible(c.ConstantinopleBlock, newcfg.PetersburgBlock, head) {
   842  			return newCompatError("Petersburg fork block", c.PetersburgBlock, newcfg.PetersburgBlock)
   843  		}
   844  	}
   845  	if isForkIncompatible(c.IstanbulBlock, newcfg.IstanbulBlock, head) {
   846  		return newCompatError("Istanbul fork block", c.IstanbulBlock, newcfg.IstanbulBlock)
   847  	}
   848  	if isForkIncompatible(c.MuirGlacierBlock, newcfg.MuirGlacierBlock, head) {
   849  		return newCompatError("Muir Glacier fork block", c.MuirGlacierBlock, newcfg.MuirGlacierBlock)
   850  	}
   851  	if isForkIncompatible(c.BerlinBlock, newcfg.BerlinBlock, head) {
   852  		return newCompatError("Berlin fork block", c.BerlinBlock, newcfg.BerlinBlock)
   853  	}
   854  	if isForkIncompatible(c.LondonBlock, newcfg.LondonBlock, head) {
   855  		return newCompatError("London fork block", c.LondonBlock, newcfg.LondonBlock)
   856  	}
   857  	if isForkIncompatible(c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock, head) {
   858  		return newCompatError("Arrow Glacier fork block", c.ArrowGlacierBlock, newcfg.ArrowGlacierBlock)
   859  	}
   860  	if isForkIncompatible(c.ArchimedesBlock, newcfg.ArchimedesBlock, head) {
   861  		return newCompatError("Archimedes fork block", c.ArchimedesBlock, newcfg.ArchimedesBlock)
   862  	}
   863  	if isForkIncompatible(c.ShanghaiBlock, newcfg.ShanghaiBlock, head) {
   864  		return newCompatError("Shanghai fork block", c.ShanghaiBlock, newcfg.ShanghaiBlock)
   865  	}
   866  	return nil
   867  }
   868  
   869  // isForkIncompatible returns true if a fork scheduled at s1 cannot be rescheduled to
   870  // block s2 because head is already past the fork.
   871  func isForkIncompatible(s1, s2, head *big.Int) bool {
   872  	return (isForked(s1, head) || isForked(s2, head)) && !configNumEqual(s1, s2)
   873  }
   874  
   875  // isForked returns whether a fork scheduled at block s is active at the given head block.
   876  func isForked(s, head *big.Int) bool {
   877  	if s == nil || head == nil {
   878  		return false
   879  	}
   880  	return s.Cmp(head) <= 0
   881  }
   882  
   883  func configNumEqual(x, y *big.Int) bool {
   884  	if x == nil {
   885  		return y == nil
   886  	}
   887  	if y == nil {
   888  		return x == nil
   889  	}
   890  	return x.Cmp(y) == 0
   891  }
   892  
   893  // ConfigCompatError is raised if the locally-stored blockchain is initialised with a
   894  // ChainConfig that would alter the past.
   895  type ConfigCompatError struct {
   896  	What string
   897  	// block numbers of the stored and new configurations
   898  	StoredConfig, NewConfig *big.Int
   899  	// the block number to which the local chain must be rewound to correct the error
   900  	RewindTo uint64
   901  }
   902  
   903  func newCompatError(what string, storedblock, newblock *big.Int) *ConfigCompatError {
   904  	var rew *big.Int
   905  	switch {
   906  	case storedblock == nil:
   907  		rew = newblock
   908  	case newblock == nil || storedblock.Cmp(newblock) < 0:
   909  		rew = storedblock
   910  	default:
   911  		rew = newblock
   912  	}
   913  	err := &ConfigCompatError{what, storedblock, newblock, 0}
   914  	if rew != nil && rew.Sign() > 0 {
   915  		err.RewindTo = rew.Uint64() - 1
   916  	}
   917  	return err
   918  }
   919  
   920  func (err *ConfigCompatError) Error() string {
   921  	return fmt.Sprintf("mismatching %s in database (have %d, want %d, rewindto %d)", err.What, err.StoredConfig, err.NewConfig, err.RewindTo)
   922  }
   923  
   924  // Rules wraps ChainConfig and is merely syntactic sugar or can be used for functions
   925  // that do not have or require information about the block.
   926  //
   927  // Rules is a one time interface meaning that it shouldn't be used in between transition
   928  // phases.
   929  type Rules struct {
   930  	ChainID                                                 *big.Int
   931  	IsHomestead, IsEIP150, IsEIP155, IsEIP158               bool
   932  	IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
   933  	IsBerlin, IsLondon, IsArchimedes, IsShanghai            bool
   934  }
   935  
   936  // Rules ensures c's ChainID is not nil.
   937  func (c *ChainConfig) Rules(num *big.Int) Rules {
   938  	chainID := c.ChainID
   939  	if chainID == nil {
   940  		chainID = new(big.Int)
   941  	}
   942  	return Rules{
   943  		ChainID:          new(big.Int).Set(chainID),
   944  		IsHomestead:      c.IsHomestead(num),
   945  		IsEIP150:         c.IsEIP150(num),
   946  		IsEIP155:         c.IsEIP155(num),
   947  		IsEIP158:         c.IsEIP158(num),
   948  		IsByzantium:      c.IsByzantium(num),
   949  		IsConstantinople: c.IsConstantinople(num),
   950  		IsPetersburg:     c.IsPetersburg(num),
   951  		IsIstanbul:       c.IsIstanbul(num),
   952  		IsBerlin:         c.IsBerlin(num),
   953  		IsLondon:         c.IsLondon(num),
   954  		IsArchimedes:     c.IsArchimedes(num),
   955  		IsShanghai:       c.IsShanghai(num),
   956  	}
   957  }