| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | // Copyright 2017 The go-ethereum Authors | 
					
						
							|  |  |  | // This file is part of go-ethereum. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // go-ethereum is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | // (at your option) any later version. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // go-ethereum is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
					
						
							|  |  |  | // GNU General Public License for more details. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"errors" | 
					
						
							|  |  |  | 	"math" | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	"math/big" | 
					
						
							|  |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/common" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/common/hexutil" | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	math2 "github.com/ethereum/go-ethereum/common/math" | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	"github.com/ethereum/go-ethereum/consensus/ethash" | 
					
						
							|  |  |  | 	"github.com/ethereum/go-ethereum/core" | 
					
						
							| 
									
										
										
										
											2019-11-20 10:26:31 -05:00
										 |  |  | 	"github.com/ethereum/go-ethereum/core/types" | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	"github.com/ethereum/go-ethereum/params" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | // alethGenesisSpec represents the genesis specification format used by the | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | // C++ Ethereum implementation. | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | type alethGenesisSpec struct { | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	SealEngine string `json:"sealEngine"` | 
					
						
							|  |  |  | 	Params     struct { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		AccountStartNonce          math2.HexOrDecimal64   `json:"accountStartNonce"` | 
					
						
							|  |  |  | 		MaximumExtraDataSize       hexutil.Uint64         `json:"maximumExtraDataSize"` | 
					
						
							|  |  |  | 		HomesteadForkBlock         *hexutil.Big           `json:"homesteadForkBlock,omitempty"` | 
					
						
							|  |  |  | 		DaoHardforkBlock           math2.HexOrDecimal64   `json:"daoHardforkBlock"` | 
					
						
							|  |  |  | 		EIP150ForkBlock            *hexutil.Big           `json:"EIP150ForkBlock,omitempty"` | 
					
						
							|  |  |  | 		EIP158ForkBlock            *hexutil.Big           `json:"EIP158ForkBlock,omitempty"` | 
					
						
							|  |  |  | 		ByzantiumForkBlock         *hexutil.Big           `json:"byzantiumForkBlock,omitempty"` | 
					
						
							|  |  |  | 		ConstantinopleForkBlock    *hexutil.Big           `json:"constantinopleForkBlock,omitempty"` | 
					
						
							|  |  |  | 		ConstantinopleFixForkBlock *hexutil.Big           `json:"constantinopleFixForkBlock,omitempty"` | 
					
						
							|  |  |  | 		IstanbulForkBlock          *hexutil.Big           `json:"istanbulForkBlock,omitempty"` | 
					
						
							|  |  |  | 		MinGasLimit                hexutil.Uint64         `json:"minGasLimit"` | 
					
						
							|  |  |  | 		MaxGasLimit                hexutil.Uint64         `json:"maxGasLimit"` | 
					
						
							|  |  |  | 		TieBreakingGas             bool                   `json:"tieBreakingGas"` | 
					
						
							|  |  |  | 		GasLimitBoundDivisor       math2.HexOrDecimal64   `json:"gasLimitBoundDivisor"` | 
					
						
							|  |  |  | 		MinimumDifficulty          *hexutil.Big           `json:"minimumDifficulty"` | 
					
						
							|  |  |  | 		DifficultyBoundDivisor     *math2.HexOrDecimal256 `json:"difficultyBoundDivisor"` | 
					
						
							|  |  |  | 		DurationLimit              *math2.HexOrDecimal256 `json:"durationLimit"` | 
					
						
							|  |  |  | 		BlockReward                *hexutil.Big           `json:"blockReward"` | 
					
						
							|  |  |  | 		NetworkID                  hexutil.Uint64         `json:"networkID"` | 
					
						
							|  |  |  | 		ChainID                    hexutil.Uint64         `json:"chainID"` | 
					
						
							|  |  |  | 		AllowFutureBlocks          bool                   `json:"allowFutureBlocks"` | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	} `json:"params"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Genesis struct { | 
					
						
							| 
									
										
										
										
											2019-11-20 10:26:31 -05:00
										 |  |  | 		Nonce      types.BlockNonce `json:"nonce"` | 
					
						
							|  |  |  | 		Difficulty *hexutil.Big     `json:"difficulty"` | 
					
						
							|  |  |  | 		MixHash    common.Hash      `json:"mixHash"` | 
					
						
							|  |  |  | 		Author     common.Address   `json:"author"` | 
					
						
							|  |  |  | 		Timestamp  hexutil.Uint64   `json:"timestamp"` | 
					
						
							|  |  |  | 		ParentHash common.Hash      `json:"parentHash"` | 
					
						
							|  |  |  | 		ExtraData  hexutil.Bytes    `json:"extraData"` | 
					
						
							|  |  |  | 		GasLimit   hexutil.Uint64   `json:"gasLimit"` | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	} `json:"genesis"` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	Accounts map[common.UnprefixedAddress]*alethGenesisSpecAccount `json:"accounts"` | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | // alethGenesisSpecAccount is the prefunded genesis account and/or precompiled | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | // contract definition. | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | type alethGenesisSpecAccount struct { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 	Balance     *math2.HexOrDecimal256   `json:"balance,omitempty"` | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	Nonce       uint64                   `json:"nonce,omitempty"` | 
					
						
							|  |  |  | 	Precompiled *alethGenesisSpecBuiltin `json:"precompiled,omitempty"` | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | // alethGenesisSpecBuiltin is the precompiled contract definition. | 
					
						
							|  |  |  | type alethGenesisSpecBuiltin struct { | 
					
						
							|  |  |  | 	Name          string                         `json:"name,omitempty"` | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 	StartingBlock *hexutil.Big                   `json:"startingBlock,omitempty"` | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	Linear        *alethGenesisSpecLinearPricing `json:"linear,omitempty"` | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | type alethGenesisSpecLinearPricing struct { | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	Base uint64 `json:"base"` | 
					
						
							|  |  |  | 	Word uint64 `json:"word"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | // newAlethGenesisSpec converts a go-ethereum genesis block into a Aleth-specific | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | // chain specification format. | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | func newAlethGenesisSpec(network string, genesis *core.Genesis) (*alethGenesisSpec, error) { | 
					
						
							|  |  |  | 	// Only ethash is currently supported between go-ethereum and aleth | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	if genesis.Config.Ethash == nil { | 
					
						
							|  |  |  | 		return nil, errors.New("unsupported consensus engine") | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	// Reconstruct the chain spec in Aleth format | 
					
						
							|  |  |  | 	spec := &alethGenesisSpec{ | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 		SealEngine: "Ethash", | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	// Some defaults | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	spec.Params.AccountStartNonce = 0 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Params.TieBreakingGas = false | 
					
						
							|  |  |  | 	spec.Params.AllowFutureBlocks = false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 	// Dao hardfork block is a special one. The fork block is listed as 0 in the | 
					
						
							|  |  |  | 	// config but aleth will sync with ETC clients up until the actual dao hard | 
					
						
							|  |  |  | 	// fork block. | 
					
						
							|  |  |  | 	spec.Params.DaoHardforkBlock = 0 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 	if num := genesis.Config.HomesteadBlock; num != nil { | 
					
						
							|  |  |  | 		spec.Params.HomesteadForkBlock = (*hexutil.Big)(num) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if num := genesis.Config.EIP150Block; num != nil { | 
					
						
							|  |  |  | 		spec.Params.EIP150ForkBlock = (*hexutil.Big)(num) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if num := genesis.Config.EIP158Block; num != nil { | 
					
						
							|  |  |  | 		spec.Params.EIP158ForkBlock = (*hexutil.Big)(num) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	if num := genesis.Config.ByzantiumBlock; num != nil { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		spec.Params.ByzantiumForkBlock = (*hexutil.Big)(num) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if num := genesis.Config.ConstantinopleBlock; num != nil { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		spec.Params.ConstantinopleForkBlock = (*hexutil.Big)(num) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if num := genesis.Config.PetersburgBlock; num != nil { | 
					
						
							|  |  |  | 		spec.Params.ConstantinopleFixForkBlock = (*hexutil.Big)(num) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if num := genesis.Config.IstanbulBlock; num != nil { | 
					
						
							|  |  |  | 		spec.Params.IstanbulForkBlock = (*hexutil.Big)(num) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-05 03:31:34 -07:00
										 |  |  | 	spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) | 
					
						
							| 
									
										
										
										
											2017-11-13 13:47:27 +02:00
										 |  |  | 	spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxInt64) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Params.DifficultyBoundDivisor = (*math2.HexOrDecimal256)(params.DifficultyBoundDivisor) | 
					
						
							|  |  |  | 	spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor) | 
					
						
							|  |  |  | 	spec.Params.DurationLimit = (*math2.HexOrDecimal256)(params.DurationLimit) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	spec.Params.BlockReward = (*hexutil.Big)(ethash.FrontierBlockReward) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 10:26:31 -05:00
										 |  |  | 	spec.Genesis.Nonce = types.EncodeNonce(genesis.Nonce) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	spec.Genesis.MixHash = genesis.Mixhash | 
					
						
							|  |  |  | 	spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) | 
					
						
							|  |  |  | 	spec.Genesis.Author = genesis.Coinbase | 
					
						
							|  |  |  | 	spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) | 
					
						
							|  |  |  | 	spec.Genesis.ParentHash = genesis.ParentHash | 
					
						
							|  |  |  | 	spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) | 
					
						
							|  |  |  | 	spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for address, account := range genesis.Alloc { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		spec.setAccount(address, account) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spec.setPrecompile(1, &alethGenesisSpecBuiltin{Name: "ecrecover", | 
					
						
							|  |  |  | 		Linear: &alethGenesisSpecLinearPricing{Base: 3000}}) | 
					
						
							|  |  |  | 	spec.setPrecompile(2, &alethGenesisSpecBuiltin{Name: "sha256", | 
					
						
							|  |  |  | 		Linear: &alethGenesisSpecLinearPricing{Base: 60, Word: 12}}) | 
					
						
							|  |  |  | 	spec.setPrecompile(3, &alethGenesisSpecBuiltin{Name: "ripemd160", | 
					
						
							|  |  |  | 		Linear: &alethGenesisSpecLinearPricing{Base: 600, Word: 120}}) | 
					
						
							|  |  |  | 	spec.setPrecompile(4, &alethGenesisSpecBuiltin{Name: "identity", | 
					
						
							|  |  |  | 		Linear: &alethGenesisSpecLinearPricing{Base: 15, Word: 3}}) | 
					
						
							|  |  |  | 	if genesis.Config.ByzantiumBlock != nil { | 
					
						
							|  |  |  | 		spec.setPrecompile(5, &alethGenesisSpecBuiltin{Name: "modexp", | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 			StartingBlock: (*hexutil.Big)(genesis.Config.ByzantiumBlock)}) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		spec.setPrecompile(6, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_add", | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 			StartingBlock: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 			Linear:        &alethGenesisSpecLinearPricing{Base: 500}}) | 
					
						
							|  |  |  | 		spec.setPrecompile(7, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_mul", | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 			StartingBlock: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 			Linear:        &alethGenesisSpecLinearPricing{Base: 40000}}) | 
					
						
							|  |  |  | 		spec.setPrecompile(8, &alethGenesisSpecBuiltin{Name: "alt_bn128_pairing_product", | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 			StartingBlock: (*hexutil.Big)(genesis.Config.ByzantiumBlock)}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if genesis.Config.IstanbulBlock != nil { | 
					
						
							|  |  |  | 		if genesis.Config.ByzantiumBlock == nil { | 
					
						
							|  |  |  | 			return nil, errors.New("invalid genesis, istanbul fork is enabled while byzantium is not") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		spec.setPrecompile(6, &alethGenesisSpecBuiltin{ | 
					
						
							|  |  |  | 			Name:          "alt_bn128_G1_add", | 
					
						
							|  |  |  | 			StartingBlock: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 		}) // Aleth hardcoded the gas policy | 
					
						
							|  |  |  | 		spec.setPrecompile(7, &alethGenesisSpecBuiltin{ | 
					
						
							|  |  |  | 			Name:          "alt_bn128_G1_mul", | 
					
						
							|  |  |  | 			StartingBlock: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 		}) // Aleth hardcoded the gas policy | 
					
						
							|  |  |  | 		spec.setPrecompile(9, &alethGenesisSpecBuiltin{ | 
					
						
							|  |  |  | 			Name:          "blake2_compression", | 
					
						
							|  |  |  | 			StartingBlock: (*hexutil.Big)(genesis.Config.IstanbulBlock), | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	return spec, nil | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (spec *alethGenesisSpec) setPrecompile(address byte, data *alethGenesisSpecBuiltin) { | 
					
						
							|  |  |  | 	if spec.Accounts == nil { | 
					
						
							|  |  |  | 		spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-01-04 14:48:15 +07:00
										 |  |  | 	addr := common.UnprefixedAddress(common.BytesToAddress([]byte{address})) | 
					
						
							|  |  |  | 	if _, exist := spec.Accounts[addr]; !exist { | 
					
						
							|  |  |  | 		spec.Accounts[addr] = &alethGenesisSpecAccount{} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spec.Accounts[addr].Precompiled = data | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (spec *alethGenesisSpec) setAccount(address common.Address, account core.GenesisAccount) { | 
					
						
							|  |  |  | 	if spec.Accounts == nil { | 
					
						
							|  |  |  | 		spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount) | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	a, exist := spec.Accounts[common.UnprefixedAddress(address)] | 
					
						
							|  |  |  | 	if !exist { | 
					
						
							|  |  |  | 		a = &alethGenesisSpecAccount{} | 
					
						
							|  |  |  | 		spec.Accounts[common.UnprefixedAddress(address)] = a | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	a.Balance = (*math2.HexOrDecimal256)(account.Balance) | 
					
						
							|  |  |  | 	a.Nonce = account.Nonce | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | // parityChainSpec is the chain specification format used by Parity. | 
					
						
							|  |  |  | type parityChainSpec struct { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	Name    string `json:"name"` | 
					
						
							|  |  |  | 	Datadir string `json:"dataDir"` | 
					
						
							|  |  |  | 	Engine  struct { | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 		Ethash struct { | 
					
						
							|  |  |  | 			Params struct { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 				MinimumDifficulty      *hexutil.Big      `json:"minimumDifficulty"` | 
					
						
							|  |  |  | 				DifficultyBoundDivisor *hexutil.Big      `json:"difficultyBoundDivisor"` | 
					
						
							|  |  |  | 				DurationLimit          *hexutil.Big      `json:"durationLimit"` | 
					
						
							|  |  |  | 				BlockReward            map[string]string `json:"blockReward"` | 
					
						
							|  |  |  | 				DifficultyBombDelays   map[string]string `json:"difficultyBombDelays"` | 
					
						
							|  |  |  | 				HomesteadTransition    hexutil.Uint64    `json:"homesteadTransition"` | 
					
						
							|  |  |  | 				EIP100bTransition      hexutil.Uint64    `json:"eip100bTransition"` | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 			} `json:"params"` | 
					
						
							|  |  |  | 		} `json:"Ethash"` | 
					
						
							|  |  |  | 	} `json:"engine"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Params struct { | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		AccountStartNonce         hexutil.Uint64       `json:"accountStartNonce"` | 
					
						
							|  |  |  | 		MaximumExtraDataSize      hexutil.Uint64       `json:"maximumExtraDataSize"` | 
					
						
							|  |  |  | 		MinGasLimit               hexutil.Uint64       `json:"minGasLimit"` | 
					
						
							|  |  |  | 		GasLimitBoundDivisor      math2.HexOrDecimal64 `json:"gasLimitBoundDivisor"` | 
					
						
							|  |  |  | 		NetworkID                 hexutil.Uint64       `json:"networkID"` | 
					
						
							|  |  |  | 		ChainID                   hexutil.Uint64       `json:"chainID"` | 
					
						
							|  |  |  | 		MaxCodeSize               hexutil.Uint64       `json:"maxCodeSize"` | 
					
						
							|  |  |  | 		MaxCodeSizeTransition     hexutil.Uint64       `json:"maxCodeSizeTransition"` | 
					
						
							|  |  |  | 		EIP98Transition           hexutil.Uint64       `json:"eip98Transition"` | 
					
						
							|  |  |  | 		EIP150Transition          hexutil.Uint64       `json:"eip150Transition"` | 
					
						
							|  |  |  | 		EIP160Transition          hexutil.Uint64       `json:"eip160Transition"` | 
					
						
							|  |  |  | 		EIP161abcTransition       hexutil.Uint64       `json:"eip161abcTransition"` | 
					
						
							|  |  |  | 		EIP161dTransition         hexutil.Uint64       `json:"eip161dTransition"` | 
					
						
							|  |  |  | 		EIP155Transition          hexutil.Uint64       `json:"eip155Transition"` | 
					
						
							|  |  |  | 		EIP140Transition          hexutil.Uint64       `json:"eip140Transition"` | 
					
						
							|  |  |  | 		EIP211Transition          hexutil.Uint64       `json:"eip211Transition"` | 
					
						
							|  |  |  | 		EIP214Transition          hexutil.Uint64       `json:"eip214Transition"` | 
					
						
							|  |  |  | 		EIP658Transition          hexutil.Uint64       `json:"eip658Transition"` | 
					
						
							|  |  |  | 		EIP145Transition          hexutil.Uint64       `json:"eip145Transition"` | 
					
						
							|  |  |  | 		EIP1014Transition         hexutil.Uint64       `json:"eip1014Transition"` | 
					
						
							|  |  |  | 		EIP1052Transition         hexutil.Uint64       `json:"eip1052Transition"` | 
					
						
							|  |  |  | 		EIP1283Transition         hexutil.Uint64       `json:"eip1283Transition"` | 
					
						
							|  |  |  | 		EIP1283DisableTransition  hexutil.Uint64       `json:"eip1283DisableTransition"` | 
					
						
							|  |  |  | 		EIP1283ReenableTransition hexutil.Uint64       `json:"eip1283ReenableTransition"` | 
					
						
							|  |  |  | 		EIP1344Transition         hexutil.Uint64       `json:"eip1344Transition"` | 
					
						
							|  |  |  | 		EIP1884Transition         hexutil.Uint64       `json:"eip1884Transition"` | 
					
						
							|  |  |  | 		EIP2028Transition         hexutil.Uint64       `json:"eip2028Transition"` | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	} `json:"params"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Genesis struct { | 
					
						
							|  |  |  | 		Seal struct { | 
					
						
							|  |  |  | 			Ethereum struct { | 
					
						
							| 
									
										
										
										
											2019-11-20 10:26:31 -05:00
										 |  |  | 				Nonce   types.BlockNonce `json:"nonce"` | 
					
						
							|  |  |  | 				MixHash hexutil.Bytes    `json:"mixHash"` | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 			} `json:"ethereum"` | 
					
						
							|  |  |  | 		} `json:"seal"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Difficulty *hexutil.Big   `json:"difficulty"` | 
					
						
							|  |  |  | 		Author     common.Address `json:"author"` | 
					
						
							|  |  |  | 		Timestamp  hexutil.Uint64 `json:"timestamp"` | 
					
						
							|  |  |  | 		ParentHash common.Hash    `json:"parentHash"` | 
					
						
							|  |  |  | 		ExtraData  hexutil.Bytes  `json:"extraData"` | 
					
						
							|  |  |  | 		GasLimit   hexutil.Uint64 `json:"gasLimit"` | 
					
						
							|  |  |  | 	} `json:"genesis"` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	Nodes    []string                                             `json:"nodes"` | 
					
						
							|  |  |  | 	Accounts map[common.UnprefixedAddress]*parityChainSpecAccount `json:"accounts"` | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // parityChainSpecAccount is the prefunded genesis account and/or precompiled | 
					
						
							|  |  |  | // contract definition. | 
					
						
							|  |  |  | type parityChainSpecAccount struct { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	Balance math2.HexOrDecimal256   `json:"balance"` | 
					
						
							|  |  |  | 	Nonce   math2.HexOrDecimal64    `json:"nonce,omitempty"` | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	Builtin *parityChainSpecBuiltin `json:"builtin,omitempty"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // parityChainSpecBuiltin is the precompiled contract definition. | 
					
						
							|  |  |  | type parityChainSpecBuiltin struct { | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 	Name       string       `json:"name"`                  // Each builtin should has it own name | 
					
						
							|  |  |  | 	Pricing    interface{}  `json:"pricing"`               // Each builtin should has it own price strategy | 
					
						
							|  |  |  | 	ActivateAt *hexutil.Big `json:"activate_at,omitempty"` // ActivateAt can't be omitted if empty, default means no fork | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // parityChainSpecPricing represents the different pricing models that builtin | 
					
						
							|  |  |  | // contracts might advertise using. | 
					
						
							|  |  |  | type parityChainSpecPricing struct { | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 	Linear *parityChainSpecLinearPricing `json:"linear,omitempty"` | 
					
						
							|  |  |  | 	ModExp *parityChainSpecModExpPricing `json:"modexp,omitempty"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Before the https://github.com/paritytech/parity-ethereum/pull/11039, | 
					
						
							|  |  |  | 	// Parity uses this format to config bn pairing price policy. | 
					
						
							|  |  |  | 	AltBnPairing *parityChainSepcAltBnPairingPricing `json:"alt_bn128_pairing,omitempty"` | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// Blake2F is the price per round of Blake2 compression | 
					
						
							|  |  |  | 	Blake2F *parityChainSpecBlakePricing `json:"blake2_f,omitempty"` | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type parityChainSpecLinearPricing struct { | 
					
						
							|  |  |  | 	Base uint64 `json:"base"` | 
					
						
							|  |  |  | 	Word uint64 `json:"word"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type parityChainSpecModExpPricing struct { | 
					
						
							|  |  |  | 	Divisor uint64 `json:"divisor"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | // parityChainSpecAltBnConstOperationPricing defines the price | 
					
						
							|  |  |  | // policy for bn const operation(used after istanbul) | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | type parityChainSpecAltBnConstOperationPricing struct { | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 	Price uint64 `json:"price"` | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | // parityChainSepcAltBnPairingPricing defines the price policy | 
					
						
							|  |  |  | // for bn pairing. | 
					
						
							|  |  |  | type parityChainSepcAltBnPairingPricing struct { | 
					
						
							|  |  |  | 	Base uint64 `json:"base"` | 
					
						
							|  |  |  | 	Pair uint64 `json:"pair"` | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | // parityChainSpecBlakePricing defines the price policy for blake2 f | 
					
						
							|  |  |  | // compression. | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | type parityChainSpecBlakePricing struct { | 
					
						
							|  |  |  | 	GasPerRound uint64 `json:"gas_per_round"` | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | type parityChainSpecAlternativePrice struct { | 
					
						
							|  |  |  | 	AltBnConstOperationPrice *parityChainSpecAltBnConstOperationPricing `json:"alt_bn128_const_operations,omitempty"` | 
					
						
							|  |  |  | 	AltBnPairingPrice        *parityChainSepcAltBnPairingPricing        `json:"alt_bn128_pairing,omitempty"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // parityChainSpecVersionedPricing represents a single version price policy. | 
					
						
							|  |  |  | type parityChainSpecVersionedPricing struct { | 
					
						
							|  |  |  | 	Price *parityChainSpecAlternativePrice `json:"price,omitempty"` | 
					
						
							|  |  |  | 	Info  string                           `json:"info,omitempty"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | // newParityChainSpec converts a go-ethereum genesis block into a Parity specific | 
					
						
							|  |  |  | // chain specification format. | 
					
						
							|  |  |  | func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []string) (*parityChainSpec, error) { | 
					
						
							|  |  |  | 	// Only ethash is currently supported between go-ethereum and Parity | 
					
						
							|  |  |  | 	if genesis.Config.Ethash == nil { | 
					
						
							|  |  |  | 		return nil, errors.New("unsupported consensus engine") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// Reconstruct the chain spec in Parity's format | 
					
						
							|  |  |  | 	spec := &parityChainSpec{ | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		Name:    network, | 
					
						
							|  |  |  | 		Nodes:   bootnodes, | 
					
						
							|  |  |  | 		Datadir: strings.ToLower(network), | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Engine.Ethash.Params.BlockReward = make(map[string]string) | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.DifficultyBombDelays = make(map[string]string) | 
					
						
							|  |  |  | 	// Frontier | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	spec.Engine.Ethash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty) | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor) | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Engine.Ethash.Params.BlockReward["0x0"] = hexutil.EncodeBig(ethash.FrontierBlockReward) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Homestead | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.HomesteadTransition = hexutil.Uint64(genesis.Config.HomesteadBlock.Uint64()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Tangerine Whistle : 150 | 
					
						
							|  |  |  | 	// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-608.md | 
					
						
							|  |  |  | 	spec.Params.EIP150Transition = hexutil.Uint64(genesis.Config.EIP150Block.Uint64()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Spurious Dragon: 155, 160, 161, 170 | 
					
						
							|  |  |  | 	// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-607.md | 
					
						
							|  |  |  | 	spec.Params.EIP155Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.EIP160Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.EIP161abcTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.EIP161dTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64()) | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	// Byzantium | 
					
						
							|  |  |  | 	if num := genesis.Config.ByzantiumBlock; num != nil { | 
					
						
							|  |  |  | 		spec.setByzantium(num) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// Constantinople | 
					
						
							|  |  |  | 	if num := genesis.Config.ConstantinopleBlock; num != nil { | 
					
						
							|  |  |  | 		spec.setConstantinople(num) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-01-24 11:36:30 +01:00
										 |  |  | 	// ConstantinopleFix (remove eip-1283) | 
					
						
							|  |  |  | 	if num := genesis.Config.PetersburgBlock; num != nil { | 
					
						
							|  |  |  | 		spec.setConstantinopleFix(num) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 	// Istanbul | 
					
						
							|  |  |  | 	if num := genesis.Config.IstanbulBlock; num != nil { | 
					
						
							|  |  |  | 		spec.setIstanbul(num) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize) | 
					
						
							| 
									
										
										
										
											2017-11-13 13:47:27 +02:00
										 |  |  | 	spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor) | 
					
						
							| 
									
										
										
										
											2018-06-05 03:31:34 -07:00
										 |  |  | 	spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64()) | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	spec.Params.MaxCodeSize = params.MaxCodeSize | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	// geth has it set from zero | 
					
						
							|  |  |  | 	spec.Params.MaxCodeSizeTransition = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Disable this one | 
					
						
							|  |  |  | 	spec.Params.EIP98Transition = math.MaxInt64 | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-20 10:26:31 -05:00
										 |  |  | 	spec.Genesis.Seal.Ethereum.Nonce = types.EncodeNonce(genesis.Nonce) | 
					
						
							|  |  |  | 	spec.Genesis.Seal.Ethereum.MixHash = (genesis.Mixhash[:]) | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty) | 
					
						
							|  |  |  | 	spec.Genesis.Author = genesis.Coinbase | 
					
						
							|  |  |  | 	spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp) | 
					
						
							|  |  |  | 	spec.Genesis.ParentHash = genesis.ParentHash | 
					
						
							|  |  |  | 	spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData) | 
					
						
							|  |  |  | 	spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount) | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	for address, account := range genesis.Alloc { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		bal := math2.HexOrDecimal256(*account.Balance) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		spec.Accounts[common.UnprefixedAddress(address)] = &parityChainSpecAccount{ | 
					
						
							|  |  |  | 			Balance: bal, | 
					
						
							|  |  |  | 			Nonce:   math2.HexOrDecimal64(account.Nonce), | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	spec.setPrecompile(1, &parityChainSpecBuiltin{Name: "ecrecover", | 
					
						
							|  |  |  | 		Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 3000}}}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spec.setPrecompile(2, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 		Name: "sha256", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 60, Word: 12}}, | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	spec.setPrecompile(3, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 		Name: "ripemd160", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 600, Word: 120}}, | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 	spec.setPrecompile(4, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 		Name: "identity", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 15, Word: 3}}, | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	if genesis.Config.ByzantiumBlock != nil { | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		spec.setPrecompile(5, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "modexp", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 			Pricing: &parityChainSpecPricing{ | 
					
						
							|  |  |  | 				ModExp: &parityChainSpecModExpPricing{Divisor: 20}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 		spec.setPrecompile(6, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "alt_bn128_add", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 			Pricing: &parityChainSpecPricing{ | 
					
						
							|  |  |  | 				Linear: &parityChainSpecLinearPricing{Base: 500, Word: 0}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 		spec.setPrecompile(7, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "alt_bn128_mul", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 			Pricing: &parityChainSpecPricing{ | 
					
						
							|  |  |  | 				Linear: &parityChainSpecLinearPricing{Base: 40000, Word: 0}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 		spec.setPrecompile(8, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "alt_bn128_pairing", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 			Pricing: &parityChainSpecPricing{ | 
					
						
							|  |  |  | 				AltBnPairing: &parityChainSepcAltBnPairingPricing{Base: 100000, Pair: 80000}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if genesis.Config.IstanbulBlock != nil { | 
					
						
							|  |  |  | 		if genesis.Config.ByzantiumBlock == nil { | 
					
						
							|  |  |  | 			return nil, errors.New("invalid genesis, istanbul fork is enabled while byzantium is not") | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		spec.setPrecompile(6, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "alt_bn128_add", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 			Pricing: map[*hexutil.Big]*parityChainSpecVersionedPricing{ | 
					
						
							|  |  |  | 				(*hexutil.Big)(big.NewInt(0)): { | 
					
						
							|  |  |  | 					Price: &parityChainSpecAlternativePrice{ | 
					
						
							|  |  |  | 						AltBnConstOperationPrice: &parityChainSpecAltBnConstOperationPricing{Price: 500}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				(*hexutil.Big)(genesis.Config.IstanbulBlock): { | 
					
						
							|  |  |  | 					Price: &parityChainSpecAlternativePrice{ | 
					
						
							|  |  |  | 						AltBnConstOperationPrice: &parityChainSpecAltBnConstOperationPricing{Price: 150}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 		spec.setPrecompile(7, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "alt_bn128_mul", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 			Pricing: map[*hexutil.Big]*parityChainSpecVersionedPricing{ | 
					
						
							|  |  |  | 				(*hexutil.Big)(big.NewInt(0)): { | 
					
						
							|  |  |  | 					Price: &parityChainSpecAlternativePrice{ | 
					
						
							|  |  |  | 						AltBnConstOperationPrice: &parityChainSpecAltBnConstOperationPricing{Price: 40000}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				(*hexutil.Big)(genesis.Config.IstanbulBlock): { | 
					
						
							|  |  |  | 					Price: &parityChainSpecAlternativePrice{ | 
					
						
							|  |  |  | 						AltBnConstOperationPrice: &parityChainSpecAltBnConstOperationPricing{Price: 6000}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 		spec.setPrecompile(8, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "alt_bn128_pairing", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.ByzantiumBlock), | 
					
						
							|  |  |  | 			Pricing: map[*hexutil.Big]*parityChainSpecVersionedPricing{ | 
					
						
							|  |  |  | 				(*hexutil.Big)(big.NewInt(0)): { | 
					
						
							|  |  |  | 					Price: &parityChainSpecAlternativePrice{ | 
					
						
							|  |  |  | 						AltBnPairingPrice: &parityChainSepcAltBnPairingPricing{Base: 100000, Pair: 80000}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				(*hexutil.Big)(genesis.Config.IstanbulBlock): { | 
					
						
							|  |  |  | 					Price: &parityChainSpecAlternativePrice{ | 
					
						
							|  |  |  | 						AltBnPairingPrice: &parityChainSepcAltBnPairingPricing{Base: 45000, Pair: 34000}, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 		spec.setPrecompile(9, &parityChainSpecBuiltin{ | 
					
						
							| 
									
										
										
										
											2019-11-20 18:46:35 +08:00
										 |  |  | 			Name:       "blake2_f", | 
					
						
							|  |  |  | 			ActivateAt: (*hexutil.Big)(genesis.Config.IstanbulBlock), | 
					
						
							|  |  |  | 			Pricing: &parityChainSpecPricing{ | 
					
						
							|  |  |  | 				Blake2F: &parityChainSpecBlakePricing{GasPerRound: 1}, | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2017-10-20 11:14:10 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return spec, nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-24 23:22:25 +01:00
										 |  |  | func (spec *parityChainSpec) setPrecompile(address byte, data *parityChainSpecBuiltin) { | 
					
						
							|  |  |  | 	if spec.Accounts == nil { | 
					
						
							|  |  |  | 		spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	a := common.UnprefixedAddress(common.BytesToAddress([]byte{address})) | 
					
						
							|  |  |  | 	if _, exist := spec.Accounts[a]; !exist { | 
					
						
							|  |  |  | 		spec.Accounts[a] = &parityChainSpecAccount{} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spec.Accounts[a].Builtin = data | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (spec *parityChainSpec) setByzantium(num *big.Int) { | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ByzantiumBlockReward) | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(3000000) | 
					
						
							|  |  |  | 	n := hexutil.Uint64(num.Uint64()) | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.EIP100bTransition = n | 
					
						
							|  |  |  | 	spec.Params.EIP140Transition = n | 
					
						
							|  |  |  | 	spec.Params.EIP211Transition = n | 
					
						
							|  |  |  | 	spec.Params.EIP214Transition = n | 
					
						
							|  |  |  | 	spec.Params.EIP658Transition = n | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (spec *parityChainSpec) setConstantinople(num *big.Int) { | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(ethash.ConstantinopleBlockReward) | 
					
						
							|  |  |  | 	spec.Engine.Ethash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(2000000) | 
					
						
							|  |  |  | 	n := hexutil.Uint64(num.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.EIP145Transition = n | 
					
						
							|  |  |  | 	spec.Params.EIP1014Transition = n | 
					
						
							|  |  |  | 	spec.Params.EIP1052Transition = n | 
					
						
							|  |  |  | 	spec.Params.EIP1283Transition = n | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-24 11:36:30 +01:00
										 |  |  | func (spec *parityChainSpec) setConstantinopleFix(num *big.Int) { | 
					
						
							|  |  |  | 	spec.Params.EIP1283DisableTransition = hexutil.Uint64(num.Uint64()) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-04 16:41:29 +08:00
										 |  |  | func (spec *parityChainSpec) setIstanbul(num *big.Int) { | 
					
						
							|  |  |  | 	spec.Params.EIP1344Transition = hexutil.Uint64(num.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.EIP1884Transition = hexutil.Uint64(num.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.EIP2028Transition = hexutil.Uint64(num.Uint64()) | 
					
						
							|  |  |  | 	spec.Params.EIP1283ReenableTransition = hexutil.Uint64(num.Uint64()) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | // pyEthereumGenesisSpec represents the genesis specification format used by the | 
					
						
							|  |  |  | // Python Ethereum implementation. | 
					
						
							|  |  |  | type pyEthereumGenesisSpec struct { | 
					
						
							| 
									
										
										
										
											2019-11-20 10:26:31 -05:00
										 |  |  | 	Nonce      types.BlockNonce  `json:"nonce"` | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 	Timestamp  hexutil.Uint64    `json:"timestamp"` | 
					
						
							|  |  |  | 	ExtraData  hexutil.Bytes     `json:"extraData"` | 
					
						
							|  |  |  | 	GasLimit   hexutil.Uint64    `json:"gasLimit"` | 
					
						
							|  |  |  | 	Difficulty *hexutil.Big      `json:"difficulty"` | 
					
						
							|  |  |  | 	Mixhash    common.Hash       `json:"mixhash"` | 
					
						
							|  |  |  | 	Coinbase   common.Address    `json:"coinbase"` | 
					
						
							|  |  |  | 	Alloc      core.GenesisAlloc `json:"alloc"` | 
					
						
							|  |  |  | 	ParentHash common.Hash       `json:"parentHash"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // newPyEthereumGenesisSpec converts a go-ethereum genesis block into a Parity specific | 
					
						
							|  |  |  | // chain specification format. | 
					
						
							|  |  |  | func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereumGenesisSpec, error) { | 
					
						
							|  |  |  | 	// Only ethash is currently supported between go-ethereum and pyethereum | 
					
						
							|  |  |  | 	if genesis.Config.Ethash == nil { | 
					
						
							|  |  |  | 		return nil, errors.New("unsupported consensus engine") | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spec := &pyEthereumGenesisSpec{ | 
					
						
							| 
									
										
										
										
											2019-11-20 10:26:31 -05:00
										 |  |  | 		Nonce:      types.EncodeNonce(genesis.Nonce), | 
					
						
							| 
									
										
										
										
											2017-10-23 12:24:25 +03:00
										 |  |  | 		Timestamp:  (hexutil.Uint64)(genesis.Timestamp), | 
					
						
							|  |  |  | 		ExtraData:  genesis.ExtraData, | 
					
						
							|  |  |  | 		GasLimit:   (hexutil.Uint64)(genesis.GasLimit), | 
					
						
							|  |  |  | 		Difficulty: (*hexutil.Big)(genesis.Difficulty), | 
					
						
							|  |  |  | 		Mixhash:    genesis.Mixhash, | 
					
						
							|  |  |  | 		Coinbase:   genesis.Coinbase, | 
					
						
							|  |  |  | 		Alloc:      genesis.Alloc, | 
					
						
							|  |  |  | 		ParentHash: genesis.ParentHash, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return spec, nil | 
					
						
							|  |  |  | } |