github.com/ubiq/go-ethereum@v3.0.1+incompatible/cmd/puppeth/genesis.go (about)

     1  // Copyright 2017 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU 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  // go-ethereum 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 General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"encoding/binary"
    21  	"errors"
    22  	"math"
    23  	"math/big"
    24  	"strings"
    25  
    26  	"github.com/ubiq/go-ubiq/common"
    27  	"github.com/ubiq/go-ubiq/common/hexutil"
    28  	math2 "github.com/ubiq/go-ubiq/common/math"
    29  	// "github.com/ubiq/go-ubiq/consensus/ubqhash"
    30  	"github.com/ubiq/go-ubiq/core"
    31  	"github.com/ubiq/go-ubiq/params"
    32  )
    33  
    34  var (
    35  	blockReward *big.Int = big.NewInt(8e+18) // Block reward in wei for successfully mining a block
    36  )
    37  
    38  // alethGenesisSpec represents the genesis specification format used by the
    39  // C++ Ethereum implementation.
    40  type alethGenesisSpec struct {
    41  	SealEngine string `json:"sealEngine"`
    42  	Params     struct {
    43  		AccountStartNonce       math2.HexOrDecimal64   `json:"accountStartNonce"`
    44  		MaximumExtraDataSize    hexutil.Uint64         `json:"maximumExtraDataSize"`
    45  		HomesteadForkBlock      hexutil.Uint64         `json:"homesteadForkBlock"`
    46  		DaoHardforkBlock        math2.HexOrDecimal64   `json:"daoHardforkBlock"`
    47  		EIP150ForkBlock         hexutil.Uint64         `json:"EIP150ForkBlock"`
    48  		EIP158ForkBlock         hexutil.Uint64         `json:"EIP158ForkBlock"`
    49  		ByzantiumForkBlock      hexutil.Uint64         `json:"byzantiumForkBlock"`
    50  		ConstantinopleForkBlock hexutil.Uint64         `json:"constantinopleForkBlock"`
    51  		MinGasLimit             hexutil.Uint64         `json:"minGasLimit"`
    52  		MaxGasLimit             hexutil.Uint64         `json:"maxGasLimit"`
    53  		TieBreakingGas          bool                   `json:"tieBreakingGas"`
    54  		GasLimitBoundDivisor    math2.HexOrDecimal64   `json:"gasLimitBoundDivisor"`
    55  		MinimumDifficulty       *hexutil.Big           `json:"minimumDifficulty"`
    56  		DifficultyBoundDivisor  *math2.HexOrDecimal256 `json:"difficultyBoundDivisor"`
    57  		DurationLimit           *math2.HexOrDecimal256 `json:"durationLimit"`
    58  		BlockReward             *hexutil.Big           `json:"blockReward"`
    59  		NetworkID               hexutil.Uint64         `json:"networkID"`
    60  		ChainID                 hexutil.Uint64         `json:"chainID"`
    61  		AllowFutureBlocks       bool                   `json:"allowFutureBlocks"`
    62  	} `json:"params"`
    63  
    64  	Genesis struct {
    65  		Nonce      hexutil.Bytes  `json:"nonce"`
    66  		Difficulty *hexutil.Big   `json:"difficulty"`
    67  		MixHash    common.Hash    `json:"mixHash"`
    68  		Author     common.Address `json:"author"`
    69  		Timestamp  hexutil.Uint64 `json:"timestamp"`
    70  		ParentHash common.Hash    `json:"parentHash"`
    71  		ExtraData  hexutil.Bytes  `json:"extraData"`
    72  		GasLimit   hexutil.Uint64 `json:"gasLimit"`
    73  	} `json:"genesis"`
    74  
    75  	Accounts map[common.UnprefixedAddress]*alethGenesisSpecAccount `json:"accounts"`
    76  }
    77  
    78  // alethGenesisSpecAccount is the prefunded genesis account and/or precompiled
    79  // contract definition.
    80  type alethGenesisSpecAccount struct {
    81  	Balance     *math2.HexOrDecimal256   `json:"balance"`
    82  	Nonce       uint64                   `json:"nonce,omitempty"`
    83  	Precompiled *alethGenesisSpecBuiltin `json:"precompiled,omitempty"`
    84  }
    85  
    86  // alethGenesisSpecBuiltin is the precompiled contract definition.
    87  type alethGenesisSpecBuiltin struct {
    88  	Name          string                         `json:"name,omitempty"`
    89  	StartingBlock hexutil.Uint64                 `json:"startingBlock,omitempty"`
    90  	Linear        *alethGenesisSpecLinearPricing `json:"linear,omitempty"`
    91  }
    92  
    93  type alethGenesisSpecLinearPricing struct {
    94  	Base uint64 `json:"base"`
    95  	Word uint64 `json:"word"`
    96  }
    97  
    98  // newAlethGenesisSpec converts a go-ethereum genesis block into a Aleth-specific
    99  // chain specification format.
   100  func newAlethGenesisSpec(network string, genesis *core.Genesis) (*alethGenesisSpec, error) {
   101  	// Only ubqhash is currently supported between go-ethereum and aleth
   102  	if genesis.Config.Ubqhash == nil {
   103  		return nil, errors.New("unsupported consensus engine")
   104  	}
   105  	// Reconstruct the chain spec in Aleth format
   106  	spec := &alethGenesisSpec{
   107  		SealEngine: "Ubqhash",
   108  	}
   109  	// Some defaults
   110  	spec.Params.AccountStartNonce = 0
   111  	spec.Params.TieBreakingGas = false
   112  	spec.Params.AllowFutureBlocks = false
   113  	spec.Params.DaoHardforkBlock = 0
   114  
   115  	spec.Params.HomesteadForkBlock = (hexutil.Uint64)(genesis.Config.HomesteadBlock.Uint64())
   116  	spec.Params.EIP150ForkBlock = (hexutil.Uint64)(genesis.Config.EIP150Block.Uint64())
   117  	spec.Params.EIP158ForkBlock = (hexutil.Uint64)(genesis.Config.EIP158Block.Uint64())
   118  
   119  	// Byzantium
   120  	if num := genesis.Config.ByzantiumBlock; num != nil {
   121  		spec.setByzantium(num)
   122  	}
   123  	// Constantinople
   124  	if num := genesis.Config.ConstantinopleBlock; num != nil {
   125  		spec.setConstantinople(num)
   126  	}
   127  
   128  	spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   129  	spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   130  	spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize)
   131  	spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit)
   132  	spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxInt64)
   133  	spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
   134  	spec.Params.DifficultyBoundDivisor = (*math2.HexOrDecimal256)(params.DifficultyBoundDivisor)
   135  	spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor)
   136  	spec.Params.DurationLimit = (*math2.HexOrDecimal256)(params.DurationLimit)
   137  	spec.Params.BlockReward = (*hexutil.Big)(blockReward)
   138  
   139  	spec.Genesis.Nonce = (hexutil.Bytes)(make([]byte, 8))
   140  	binary.LittleEndian.PutUint64(spec.Genesis.Nonce[:], genesis.Nonce)
   141  
   142  	spec.Genesis.MixHash = genesis.Mixhash
   143  	spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty)
   144  	spec.Genesis.Author = genesis.Coinbase
   145  	spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp)
   146  	spec.Genesis.ParentHash = genesis.ParentHash
   147  	spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData)
   148  	spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit)
   149  
   150  	for address, account := range genesis.Alloc {
   151  		spec.setAccount(address, account)
   152  	}
   153  
   154  	spec.setPrecompile(1, &alethGenesisSpecBuiltin{Name: "ecrecover",
   155  		Linear: &alethGenesisSpecLinearPricing{Base: 3000}})
   156  	spec.setPrecompile(2, &alethGenesisSpecBuiltin{Name: "sha256",
   157  		Linear: &alethGenesisSpecLinearPricing{Base: 60, Word: 12}})
   158  	spec.setPrecompile(3, &alethGenesisSpecBuiltin{Name: "ripemd160",
   159  		Linear: &alethGenesisSpecLinearPricing{Base: 600, Word: 120}})
   160  	spec.setPrecompile(4, &alethGenesisSpecBuiltin{Name: "identity",
   161  		Linear: &alethGenesisSpecLinearPricing{Base: 15, Word: 3}})
   162  	if genesis.Config.ByzantiumBlock != nil {
   163  		spec.setPrecompile(5, &alethGenesisSpecBuiltin{Name: "modexp",
   164  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())})
   165  		spec.setPrecompile(6, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_add",
   166  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()),
   167  			Linear:        &alethGenesisSpecLinearPricing{Base: 500}})
   168  		spec.setPrecompile(7, &alethGenesisSpecBuiltin{Name: "alt_bn128_G1_mul",
   169  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()),
   170  			Linear:        &alethGenesisSpecLinearPricing{Base: 40000}})
   171  		spec.setPrecompile(8, &alethGenesisSpecBuiltin{Name: "alt_bn128_pairing_product",
   172  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())})
   173  	}
   174  	return spec, nil
   175  }
   176  
   177  func (spec *alethGenesisSpec) setPrecompile(address byte, data *alethGenesisSpecBuiltin) {
   178  	if spec.Accounts == nil {
   179  		spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount)
   180  	}
   181  	addr := common.UnprefixedAddress(common.BytesToAddress([]byte{address}))
   182  	if _, exist := spec.Accounts[addr]; !exist {
   183  		spec.Accounts[addr] = &alethGenesisSpecAccount{}
   184  	}
   185  	spec.Accounts[addr].Precompiled = data
   186  }
   187  
   188  func (spec *alethGenesisSpec) setAccount(address common.Address, account core.GenesisAccount) {
   189  	if spec.Accounts == nil {
   190  		spec.Accounts = make(map[common.UnprefixedAddress]*alethGenesisSpecAccount)
   191  	}
   192  
   193  	a, exist := spec.Accounts[common.UnprefixedAddress(address)]
   194  	if !exist {
   195  		a = &alethGenesisSpecAccount{}
   196  		spec.Accounts[common.UnprefixedAddress(address)] = a
   197  	}
   198  	a.Balance = (*math2.HexOrDecimal256)(account.Balance)
   199  	a.Nonce = account.Nonce
   200  
   201  }
   202  
   203  func (spec *alethGenesisSpec) setByzantium(num *big.Int) {
   204  	spec.Params.ByzantiumForkBlock = hexutil.Uint64(num.Uint64())
   205  }
   206  
   207  func (spec *alethGenesisSpec) setConstantinople(num *big.Int) {
   208  	spec.Params.ConstantinopleForkBlock = hexutil.Uint64(num.Uint64())
   209  }
   210  
   211  // parityChainSpec is the chain specification format used by Parity.
   212  type parityChainSpec struct {
   213  	Name    string `json:"name"`
   214  	Datadir string `json:"dataDir"`
   215  	Engine  struct {
   216  		Ubqhash struct {
   217  			Params struct {
   218  				MinimumDifficulty      *hexutil.Big      `json:"minimumDifficulty"`
   219  				DifficultyBoundDivisor *hexutil.Big      `json:"difficultyBoundDivisor"`
   220  				DurationLimit          *hexutil.Big      `json:"durationLimit"`
   221  				BlockReward            map[string]string `json:"blockReward"`
   222  				DifficultyBombDelays   map[string]string `json:"difficultyBombDelays"`
   223  				HomesteadTransition    hexutil.Uint64    `json:"homesteadTransition"`
   224  				EIP100bTransition      hexutil.Uint64    `json:"eip100bTransition"`
   225  			} `json:"params"`
   226  		} `json:"Ubqhash"`
   227  	} `json:"engine"`
   228  
   229  	Params struct {
   230  		AccountStartNonce        hexutil.Uint64       `json:"accountStartNonce"`
   231  		MaximumExtraDataSize     hexutil.Uint64       `json:"maximumExtraDataSize"`
   232  		MinGasLimit              hexutil.Uint64       `json:"minGasLimit"`
   233  		GasLimitBoundDivisor     math2.HexOrDecimal64 `json:"gasLimitBoundDivisor"`
   234  		NetworkID                hexutil.Uint64       `json:"networkID"`
   235  		ChainID                  hexutil.Uint64       `json:"chainID"`
   236  		MaxCodeSize              hexutil.Uint64       `json:"maxCodeSize"`
   237  		MaxCodeSizeTransition    hexutil.Uint64       `json:"maxCodeSizeTransition"`
   238  		EIP98Transition          hexutil.Uint64       `json:"eip98Transition"`
   239  		EIP150Transition         hexutil.Uint64       `json:"eip150Transition"`
   240  		EIP160Transition         hexutil.Uint64       `json:"eip160Transition"`
   241  		EIP161abcTransition      hexutil.Uint64       `json:"eip161abcTransition"`
   242  		EIP161dTransition        hexutil.Uint64       `json:"eip161dTransition"`
   243  		EIP155Transition         hexutil.Uint64       `json:"eip155Transition"`
   244  		EIP140Transition         hexutil.Uint64       `json:"eip140Transition"`
   245  		EIP211Transition         hexutil.Uint64       `json:"eip211Transition"`
   246  		EIP214Transition         hexutil.Uint64       `json:"eip214Transition"`
   247  		EIP658Transition         hexutil.Uint64       `json:"eip658Transition"`
   248  		EIP145Transition         hexutil.Uint64       `json:"eip145Transition"`
   249  		EIP1014Transition        hexutil.Uint64       `json:"eip1014Transition"`
   250  		EIP1052Transition        hexutil.Uint64       `json:"eip1052Transition"`
   251  		EIP1283Transition        hexutil.Uint64       `json:"eip1283Transition"`
   252  		EIP1283DisableTransition hexutil.Uint64       `json:"eip1283DisableTransition"`
   253  	} `json:"params"`
   254  
   255  	Genesis struct {
   256  		Seal struct {
   257  			Ethereum struct {
   258  				Nonce   hexutil.Bytes `json:"nonce"`
   259  				MixHash hexutil.Bytes `json:"mixHash"`
   260  			} `json:"ethereum"`
   261  		} `json:"seal"`
   262  
   263  		Difficulty *hexutil.Big   `json:"difficulty"`
   264  		Author     common.Address `json:"author"`
   265  		Timestamp  hexutil.Uint64 `json:"timestamp"`
   266  		ParentHash common.Hash    `json:"parentHash"`
   267  		ExtraData  hexutil.Bytes  `json:"extraData"`
   268  		GasLimit   hexutil.Uint64 `json:"gasLimit"`
   269  	} `json:"genesis"`
   270  
   271  	Nodes    []string                                             `json:"nodes"`
   272  	Accounts map[common.UnprefixedAddress]*parityChainSpecAccount `json:"accounts"`
   273  }
   274  
   275  // parityChainSpecAccount is the prefunded genesis account and/or precompiled
   276  // contract definition.
   277  type parityChainSpecAccount struct {
   278  	Balance math2.HexOrDecimal256   `json:"balance"`
   279  	Nonce   math2.HexOrDecimal64    `json:"nonce,omitempty"`
   280  	Builtin *parityChainSpecBuiltin `json:"builtin,omitempty"`
   281  }
   282  
   283  // parityChainSpecBuiltin is the precompiled contract definition.
   284  type parityChainSpecBuiltin struct {
   285  	Name       string                  `json:"name,omitempty"`
   286  	ActivateAt math2.HexOrDecimal64    `json:"activate_at,omitempty"`
   287  	Pricing    *parityChainSpecPricing `json:"pricing,omitempty"`
   288  }
   289  
   290  // parityChainSpecPricing represents the different pricing models that builtin
   291  // contracts might advertise using.
   292  type parityChainSpecPricing struct {
   293  	Linear       *parityChainSpecLinearPricing       `json:"linear,omitempty"`
   294  	ModExp       *parityChainSpecModExpPricing       `json:"modexp,omitempty"`
   295  	AltBnPairing *parityChainSpecAltBnPairingPricing `json:"alt_bn128_pairing,omitempty"`
   296  }
   297  
   298  type parityChainSpecLinearPricing struct {
   299  	Base uint64 `json:"base"`
   300  	Word uint64 `json:"word"`
   301  }
   302  
   303  type parityChainSpecModExpPricing struct {
   304  	Divisor uint64 `json:"divisor"`
   305  }
   306  
   307  type parityChainSpecAltBnPairingPricing struct {
   308  	Base uint64 `json:"base"`
   309  	Pair uint64 `json:"pair"`
   310  }
   311  
   312  // newParityChainSpec converts a go-ethereum genesis block into a Parity specific
   313  // chain specification format.
   314  func newParityChainSpec(network string, genesis *core.Genesis, bootnodes []string) (*parityChainSpec, error) {
   315  	// Only ubqhash is currently supported between go-ethereum and Parity
   316  	if genesis.Config.Ubqhash == nil {
   317  		return nil, errors.New("unsupported consensus engine")
   318  	}
   319  	// Reconstruct the chain spec in Parity's format
   320  	spec := &parityChainSpec{
   321  		Name:    network,
   322  		Nodes:   bootnodes,
   323  		Datadir: strings.ToLower(network),
   324  	}
   325  	spec.Engine.Ubqhash.Params.BlockReward = make(map[string]string)
   326  	spec.Engine.Ubqhash.Params.DifficultyBombDelays = make(map[string]string)
   327  	// Frontier
   328  	spec.Engine.Ubqhash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
   329  	spec.Engine.Ubqhash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor)
   330  	spec.Engine.Ubqhash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit)
   331  	spec.Engine.Ubqhash.Params.BlockReward["0x0"] = hexutil.EncodeBig(blockReward)
   332  
   333  	// Homestead
   334  	spec.Engine.Ubqhash.Params.HomesteadTransition = hexutil.Uint64(genesis.Config.HomesteadBlock.Uint64())
   335  
   336  	// Tangerine Whistle : 150
   337  	// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-608.md
   338  	spec.Params.EIP150Transition = hexutil.Uint64(genesis.Config.EIP150Block.Uint64())
   339  
   340  	// Spurious Dragon: 155, 160, 161, 170
   341  	// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-607.md
   342  	spec.Params.EIP155Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64())
   343  	spec.Params.EIP160Transition = hexutil.Uint64(genesis.Config.EIP155Block.Uint64())
   344  	spec.Params.EIP161abcTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64())
   345  	spec.Params.EIP161dTransition = hexutil.Uint64(genesis.Config.EIP158Block.Uint64())
   346  
   347  	// Byzantium
   348  	if num := genesis.Config.ByzantiumBlock; num != nil {
   349  		spec.setByzantium(num)
   350  	}
   351  	// Constantinople
   352  	if num := genesis.Config.ConstantinopleBlock; num != nil {
   353  		spec.setConstantinople(num)
   354  	}
   355  	// ConstantinopleFix (remove eip-1283)
   356  	if num := genesis.Config.PetersburgBlock; num != nil {
   357  		spec.setConstantinopleFix(num)
   358  	}
   359  
   360  	spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize)
   361  	spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit)
   362  	spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor)
   363  	spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   364  	spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   365  	spec.Params.MaxCodeSize = params.MaxCodeSize
   366  	// gubiq has it set from zero
   367  	spec.Params.MaxCodeSizeTransition = 0
   368  
   369  	// Disable this one
   370  	spec.Params.EIP98Transition = math.MaxInt64
   371  
   372  	spec.Genesis.Seal.Ethereum.Nonce = (hexutil.Bytes)(make([]byte, 8))
   373  	binary.LittleEndian.PutUint64(spec.Genesis.Seal.Ethereum.Nonce[:], genesis.Nonce)
   374  
   375  	spec.Genesis.Seal.Ethereum.MixHash = (hexutil.Bytes)(genesis.Mixhash[:])
   376  	spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty)
   377  	spec.Genesis.Author = genesis.Coinbase
   378  	spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp)
   379  	spec.Genesis.ParentHash = genesis.ParentHash
   380  	spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData)
   381  	spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit)
   382  
   383  	spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount)
   384  	for address, account := range genesis.Alloc {
   385  		bal := math2.HexOrDecimal256(*account.Balance)
   386  
   387  		spec.Accounts[common.UnprefixedAddress(address)] = &parityChainSpecAccount{
   388  			Balance: bal,
   389  			Nonce:   math2.HexOrDecimal64(account.Nonce),
   390  		}
   391  	}
   392  	spec.setPrecompile(1, &parityChainSpecBuiltin{Name: "ecrecover",
   393  		Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 3000}}})
   394  
   395  	spec.setPrecompile(2, &parityChainSpecBuiltin{
   396  		Name: "sha256", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 60, Word: 12}},
   397  	})
   398  	spec.setPrecompile(3, &parityChainSpecBuiltin{
   399  		Name: "ripemd160", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 600, Word: 120}},
   400  	})
   401  	spec.setPrecompile(4, &parityChainSpecBuiltin{
   402  		Name: "identity", Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 15, Word: 3}},
   403  	})
   404  	if genesis.Config.ByzantiumBlock != nil {
   405  		blnum := math2.HexOrDecimal64(genesis.Config.ByzantiumBlock.Uint64())
   406  		spec.setPrecompile(5, &parityChainSpecBuiltin{
   407  			Name: "modexp", ActivateAt: blnum, Pricing: &parityChainSpecPricing{ModExp: &parityChainSpecModExpPricing{Divisor: 20}},
   408  		})
   409  		spec.setPrecompile(6, &parityChainSpecBuiltin{
   410  			Name: "alt_bn128_add", ActivateAt: blnum, Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 500}},
   411  		})
   412  		spec.setPrecompile(7, &parityChainSpecBuiltin{
   413  			Name: "alt_bn128_mul", ActivateAt: blnum, Pricing: &parityChainSpecPricing{Linear: &parityChainSpecLinearPricing{Base: 40000}},
   414  		})
   415  		spec.setPrecompile(8, &parityChainSpecBuiltin{
   416  			Name: "alt_bn128_pairing", ActivateAt: blnum, Pricing: &parityChainSpecPricing{AltBnPairing: &parityChainSpecAltBnPairingPricing{Base: 100000, Pair: 80000}},
   417  		})
   418  	}
   419  	return spec, nil
   420  }
   421  
   422  func (spec *parityChainSpec) setPrecompile(address byte, data *parityChainSpecBuiltin) {
   423  	if spec.Accounts == nil {
   424  		spec.Accounts = make(map[common.UnprefixedAddress]*parityChainSpecAccount)
   425  	}
   426  	a := common.UnprefixedAddress(common.BytesToAddress([]byte{address}))
   427  	if _, exist := spec.Accounts[a]; !exist {
   428  		spec.Accounts[a] = &parityChainSpecAccount{}
   429  	}
   430  	spec.Accounts[a].Builtin = data
   431  }
   432  
   433  func (spec *parityChainSpec) setByzantium(num *big.Int) {
   434  	spec.Engine.Ubqhash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(blockReward)
   435  	spec.Engine.Ubqhash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(3000000)
   436  	n := hexutil.Uint64(num.Uint64())
   437  	spec.Engine.Ubqhash.Params.EIP100bTransition = n
   438  	spec.Params.EIP140Transition = n
   439  	spec.Params.EIP211Transition = n
   440  	spec.Params.EIP214Transition = n
   441  	spec.Params.EIP658Transition = n
   442  }
   443  
   444  func (spec *parityChainSpec) setConstantinople(num *big.Int) {
   445  	spec.Engine.Ubqhash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(blockReward)
   446  	spec.Engine.Ubqhash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(2000000)
   447  	n := hexutil.Uint64(num.Uint64())
   448  	spec.Params.EIP145Transition = n
   449  	spec.Params.EIP1014Transition = n
   450  	spec.Params.EIP1052Transition = n
   451  	spec.Params.EIP1283Transition = n
   452  }
   453  
   454  func (spec *parityChainSpec) setConstantinopleFix(num *big.Int) {
   455  	spec.Params.EIP1283DisableTransition = hexutil.Uint64(num.Uint64())
   456  }
   457  
   458  // pyEthereumGenesisSpec represents the genesis specification format used by the
   459  // Python Ethereum implementation.
   460  type pyEthereumGenesisSpec struct {
   461  	Nonce      hexutil.Bytes     `json:"nonce"`
   462  	Timestamp  hexutil.Uint64    `json:"timestamp"`
   463  	ExtraData  hexutil.Bytes     `json:"extraData"`
   464  	GasLimit   hexutil.Uint64    `json:"gasLimit"`
   465  	Difficulty *hexutil.Big      `json:"difficulty"`
   466  	Mixhash    common.Hash       `json:"mixhash"`
   467  	Coinbase   common.Address    `json:"coinbase"`
   468  	Alloc      core.GenesisAlloc `json:"alloc"`
   469  	ParentHash common.Hash       `json:"parentHash"`
   470  }
   471  
   472  // newPyEthereumGenesisSpec converts a go-ethereum genesis block into a Parity specific
   473  // chain specification format.
   474  func newPyEthereumGenesisSpec(network string, genesis *core.Genesis) (*pyEthereumGenesisSpec, error) {
   475  	// Only ubqhash is currently supported between go-ethereum and pyethereum
   476  	if genesis.Config.Ubqhash == nil {
   477  		return nil, errors.New("unsupported consensus engine")
   478  	}
   479  	spec := &pyEthereumGenesisSpec{
   480  		Timestamp:  (hexutil.Uint64)(genesis.Timestamp),
   481  		ExtraData:  genesis.ExtraData,
   482  		GasLimit:   (hexutil.Uint64)(genesis.GasLimit),
   483  		Difficulty: (*hexutil.Big)(genesis.Difficulty),
   484  		Mixhash:    genesis.Mixhash,
   485  		Coinbase:   genesis.Coinbase,
   486  		Alloc:      genesis.Alloc,
   487  		ParentHash: genesis.ParentHash,
   488  	}
   489  	spec.Nonce = (hexutil.Bytes)(make([]byte, 8))
   490  	binary.LittleEndian.PutUint64(spec.Nonce[:], genesis.Nonce)
   491  
   492  	return spec, nil
   493  }