github.com/susy-go/susy-graviton@v0.0.0-20190614130430-36cddae42305/cmd/puppsof/genesis.go (about)

     1  // Copyleft 2017 The susy-graviton Authors
     2  // This file is part of susy-graviton.
     3  //
     4  // susy-graviton 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  // susy-graviton is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MSRCHANTABILITY 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 susy-graviton. 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/susy-go/susy-graviton/common"
    27  	"github.com/susy-go/susy-graviton/common/hexutil"
    28  	math2 "github.com/susy-go/susy-graviton/common/math"
    29  	"github.com/susy-go/susy-graviton/consensus/sofash"
    30  	"github.com/susy-go/susy-graviton/core"
    31  	"github.com/susy-go/susy-graviton/params"
    32  )
    33  
    34  // alsofGenesisSpec represents the genesis specification format used by the
    35  // C++ Sophon implementation.
    36  type alsofGenesisSpec struct {
    37  	SealEngine string `json:"sealEngine"`
    38  	Params     struct {
    39  		AccountStartNonce       math2.HexOrDecimal64   `json:"accountStartNonce"`
    40  		MaximumExtraDataSize    hexutil.Uint64         `json:"maximumExtraDataSize"`
    41  		HomesteadForkBlock      hexutil.Uint64         `json:"homesteadForkBlock"`
    42  		DaoHardforkBlock        math2.HexOrDecimal64   `json:"daoHardforkBlock"`
    43  		SIP150ForkBlock         hexutil.Uint64         `json:"SIP150ForkBlock"`
    44  		SIP158ForkBlock         hexutil.Uint64         `json:"SIP158ForkBlock"`
    45  		ByzantiumForkBlock      hexutil.Uint64         `json:"byzantiumForkBlock"`
    46  		ConstantinopleForkBlock hexutil.Uint64         `json:"constantinopleForkBlock"`
    47  		MinGasLimit             hexutil.Uint64         `json:"minGasLimit"`
    48  		MaxGasLimit             hexutil.Uint64         `json:"maxGasLimit"`
    49  		TieBreakingGas          bool                   `json:"tieBreakingGas"`
    50  		GasLimitBoundDivisor    math2.HexOrDecimal64   `json:"gasLimitBoundDivisor"`
    51  		MinimumDifficulty       *hexutil.Big           `json:"minimumDifficulty"`
    52  		DifficultyBoundDivisor  *math2.HexOrDecimal256 `json:"difficultyBoundDivisor"`
    53  		DurationLimit           *math2.HexOrDecimal256 `json:"durationLimit"`
    54  		BlockReward             *hexutil.Big           `json:"blockReward"`
    55  		NetworkID               hexutil.Uint64         `json:"networkID"`
    56  		ChainID                 hexutil.Uint64         `json:"chainID"`
    57  		AllowFutureBlocks       bool                   `json:"allowFutureBlocks"`
    58  	} `json:"params"`
    59  
    60  	Genesis struct {
    61  		Nonce      hexutil.Bytes  `json:"nonce"`
    62  		Difficulty *hexutil.Big   `json:"difficulty"`
    63  		MixHash    common.Hash    `json:"mixHash"`
    64  		Author     common.Address `json:"author"`
    65  		Timestamp  hexutil.Uint64 `json:"timestamp"`
    66  		ParentHash common.Hash    `json:"parentHash"`
    67  		ExtraData  hexutil.Bytes  `json:"extraData"`
    68  		GasLimit   hexutil.Uint64 `json:"gasLimit"`
    69  	} `json:"genesis"`
    70  
    71  	Accounts map[common.UnprefixedAddress]*alsofGenesisSpecAccount `json:"accounts"`
    72  }
    73  
    74  // alsofGenesisSpecAccount is the prefunded genesis account and/or precompiled
    75  // contract definition.
    76  type alsofGenesisSpecAccount struct {
    77  	Balance     *math2.HexOrDecimal256   `json:"balance"`
    78  	Nonce       uint64                   `json:"nonce,omitempty"`
    79  	Precompiled *alsofGenesisSpecBuiltin `json:"precompiled,omitempty"`
    80  }
    81  
    82  // alsofGenesisSpecBuiltin is the precompiled contract definition.
    83  type alsofGenesisSpecBuiltin struct {
    84  	Name          string                         `json:"name,omitempty"`
    85  	StartingBlock hexutil.Uint64                 `json:"startingBlock,omitempty"`
    86  	Linear        *alsofGenesisSpecLinearPricing `json:"linear,omitempty"`
    87  }
    88  
    89  type alsofGenesisSpecLinearPricing struct {
    90  	Base uint64 `json:"base"`
    91  	Word uint64 `json:"word"`
    92  }
    93  
    94  // newAlsofGenesisSpec converts a susy-graviton genesis block into a Alsof-specific
    95  // chain specification format.
    96  func newAlsofGenesisSpec(network string, genesis *core.Genesis) (*alsofGenesisSpec, error) {
    97  	// Only sofash is currently supported between susy-graviton and alsof
    98  	if genesis.Config.Sofash == nil {
    99  		return nil, errors.New("unsupported consensus engine")
   100  	}
   101  	// Reconstruct the chain spec in Alsof format
   102  	spec := &alsofGenesisSpec{
   103  		SealEngine: "Sofash",
   104  	}
   105  	// Some defaults
   106  	spec.Params.AccountStartNonce = 0
   107  	spec.Params.TieBreakingGas = false
   108  	spec.Params.AllowFutureBlocks = false
   109  	spec.Params.DaoHardforkBlock = 0
   110  
   111  	spec.Params.HomesteadForkBlock = (hexutil.Uint64)(genesis.Config.HomesteadBlock.Uint64())
   112  	spec.Params.SIP150ForkBlock = (hexutil.Uint64)(genesis.Config.SIP150Block.Uint64())
   113  	spec.Params.SIP158ForkBlock = (hexutil.Uint64)(genesis.Config.SIP158Block.Uint64())
   114  
   115  	// Byzantium
   116  	if num := genesis.Config.ByzantiumBlock; num != nil {
   117  		spec.setByzantium(num)
   118  	}
   119  	// Constantinople
   120  	if num := genesis.Config.ConstantinopleBlock; num != nil {
   121  		spec.setConstantinople(num)
   122  	}
   123  
   124  	spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   125  	spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   126  	spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize)
   127  	spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit)
   128  	spec.Params.MaxGasLimit = (hexutil.Uint64)(math.MaxInt64)
   129  	spec.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
   130  	spec.Params.DifficultyBoundDivisor = (*math2.HexOrDecimal256)(params.DifficultyBoundDivisor)
   131  	spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor)
   132  	spec.Params.DurationLimit = (*math2.HexOrDecimal256)(params.DurationLimit)
   133  	spec.Params.BlockReward = (*hexutil.Big)(sofash.FrontierBlockReward)
   134  
   135  	spec.Genesis.Nonce = (hexutil.Bytes)(make([]byte, 8))
   136  	binary.LittleEndian.PutUint64(spec.Genesis.Nonce[:], genesis.Nonce)
   137  
   138  	spec.Genesis.MixHash = genesis.Mixhash
   139  	spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty)
   140  	spec.Genesis.Author = genesis.Coinbase
   141  	spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp)
   142  	spec.Genesis.ParentHash = genesis.ParentHash
   143  	spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData)
   144  	spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit)
   145  
   146  	for address, account := range genesis.Alloc {
   147  		spec.setAccount(address, account)
   148  	}
   149  
   150  	spec.setPrecompile(1, &alsofGenesisSpecBuiltin{Name: "ecrecover",
   151  		Linear: &alsofGenesisSpecLinearPricing{Base: 3000}})
   152  	spec.setPrecompile(2, &alsofGenesisSpecBuiltin{Name: "sha256",
   153  		Linear: &alsofGenesisSpecLinearPricing{Base: 60, Word: 12}})
   154  	spec.setPrecompile(3, &alsofGenesisSpecBuiltin{Name: "ripemd160",
   155  		Linear: &alsofGenesisSpecLinearPricing{Base: 600, Word: 120}})
   156  	spec.setPrecompile(4, &alsofGenesisSpecBuiltin{Name: "identity",
   157  		Linear: &alsofGenesisSpecLinearPricing{Base: 15, Word: 3}})
   158  	if genesis.Config.ByzantiumBlock != nil {
   159  		spec.setPrecompile(5, &alsofGenesisSpecBuiltin{Name: "modexp",
   160  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())})
   161  		spec.setPrecompile(6, &alsofGenesisSpecBuiltin{Name: "alt_bn128_G1_add",
   162  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()),
   163  			Linear:        &alsofGenesisSpecLinearPricing{Base: 500}})
   164  		spec.setPrecompile(7, &alsofGenesisSpecBuiltin{Name: "alt_bn128_G1_mul",
   165  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64()),
   166  			Linear:        &alsofGenesisSpecLinearPricing{Base: 40000}})
   167  		spec.setPrecompile(8, &alsofGenesisSpecBuiltin{Name: "alt_bn128_pairing_product",
   168  			StartingBlock: (hexutil.Uint64)(genesis.Config.ByzantiumBlock.Uint64())})
   169  	}
   170  	return spec, nil
   171  }
   172  
   173  func (spec *alsofGenesisSpec) setPrecompile(address byte, data *alsofGenesisSpecBuiltin) {
   174  	if spec.Accounts == nil {
   175  		spec.Accounts = make(map[common.UnprefixedAddress]*alsofGenesisSpecAccount)
   176  	}
   177  	addr := common.UnprefixedAddress(common.BytesToAddress([]byte{address}))
   178  	if _, exist := spec.Accounts[addr]; !exist {
   179  		spec.Accounts[addr] = &alsofGenesisSpecAccount{}
   180  	}
   181  	spec.Accounts[addr].Precompiled = data
   182  }
   183  
   184  func (spec *alsofGenesisSpec) setAccount(address common.Address, account core.GenesisAccount) {
   185  	if spec.Accounts == nil {
   186  		spec.Accounts = make(map[common.UnprefixedAddress]*alsofGenesisSpecAccount)
   187  	}
   188  
   189  	a, exist := spec.Accounts[common.UnprefixedAddress(address)]
   190  	if !exist {
   191  		a = &alsofGenesisSpecAccount{}
   192  		spec.Accounts[common.UnprefixedAddress(address)] = a
   193  	}
   194  	a.Balance = (*math2.HexOrDecimal256)(account.Balance)
   195  	a.Nonce = account.Nonce
   196  
   197  }
   198  
   199  func (spec *alsofGenesisSpec) setByzantium(num *big.Int) {
   200  	spec.Params.ByzantiumForkBlock = hexutil.Uint64(num.Uint64())
   201  }
   202  
   203  func (spec *alsofGenesisSpec) setConstantinople(num *big.Int) {
   204  	spec.Params.ConstantinopleForkBlock = hexutil.Uint64(num.Uint64())
   205  }
   206  
   207  // susyChainSpec is the chain specification format used by Susy.
   208  type susyChainSpec struct {
   209  	Name    string `json:"name"`
   210  	Datadir string `json:"dataDir"`
   211  	Engine  struct {
   212  		Sofash struct {
   213  			Params struct {
   214  				MinimumDifficulty      *hexutil.Big      `json:"minimumDifficulty"`
   215  				DifficultyBoundDivisor *hexutil.Big      `json:"difficultyBoundDivisor"`
   216  				DurationLimit          *hexutil.Big      `json:"durationLimit"`
   217  				BlockReward            map[string]string `json:"blockReward"`
   218  				DifficultyBombDelays   map[string]string `json:"difficultyBombDelays"`
   219  				HomesteadTransition    hexutil.Uint64    `json:"homesteadTransition"`
   220  				SIP100bTransition      hexutil.Uint64    `json:"sip100bTransition"`
   221  			} `json:"params"`
   222  		} `json:"Sofash"`
   223  	} `json:"engine"`
   224  
   225  	Params struct {
   226  		AccountStartNonce        hexutil.Uint64       `json:"accountStartNonce"`
   227  		MaximumExtraDataSize     hexutil.Uint64       `json:"maximumExtraDataSize"`
   228  		MinGasLimit              hexutil.Uint64       `json:"minGasLimit"`
   229  		GasLimitBoundDivisor     math2.HexOrDecimal64 `json:"gasLimitBoundDivisor"`
   230  		NetworkID                hexutil.Uint64       `json:"networkID"`
   231  		ChainID                  hexutil.Uint64       `json:"chainID"`
   232  		MaxCodeSize              hexutil.Uint64       `json:"maxCodeSize"`
   233  		MaxCodeSizeTransition    hexutil.Uint64       `json:"maxCodeSizeTransition"`
   234  		SIP98Transition          hexutil.Uint64       `json:"sip98Transition"`
   235  		SIP150Transition         hexutil.Uint64       `json:"sip150Transition"`
   236  		SIP160Transition         hexutil.Uint64       `json:"sip160Transition"`
   237  		SIP161abcTransition      hexutil.Uint64       `json:"sip161abcTransition"`
   238  		SIP161dTransition        hexutil.Uint64       `json:"sip161dTransition"`
   239  		SIP155Transition         hexutil.Uint64       `json:"sip155Transition"`
   240  		SIP140Transition         hexutil.Uint64       `json:"sip140Transition"`
   241  		SIP211Transition         hexutil.Uint64       `json:"sip211Transition"`
   242  		SIP214Transition         hexutil.Uint64       `json:"sip214Transition"`
   243  		SIP658Transition         hexutil.Uint64       `json:"sip658Transition"`
   244  		SIP145Transition         hexutil.Uint64       `json:"sip145Transition"`
   245  		SIP1014Transition        hexutil.Uint64       `json:"sip1014Transition"`
   246  		SIP1052Transition        hexutil.Uint64       `json:"sip1052Transition"`
   247  		SIP1283Transition        hexutil.Uint64       `json:"sip1283Transition"`
   248  		SIP1283DisableTransition hexutil.Uint64       `json:"sip1283DisableTransition"`
   249  	} `json:"params"`
   250  
   251  	Genesis struct {
   252  		Seal struct {
   253  			Sophon struct {
   254  				Nonce   hexutil.Bytes `json:"nonce"`
   255  				MixHash hexutil.Bytes `json:"mixHash"`
   256  			} `json:"sophon"`
   257  		} `json:"seal"`
   258  
   259  		Difficulty *hexutil.Big   `json:"difficulty"`
   260  		Author     common.Address `json:"author"`
   261  		Timestamp  hexutil.Uint64 `json:"timestamp"`
   262  		ParentHash common.Hash    `json:"parentHash"`
   263  		ExtraData  hexutil.Bytes  `json:"extraData"`
   264  		GasLimit   hexutil.Uint64 `json:"gasLimit"`
   265  	} `json:"genesis"`
   266  
   267  	Nodes    []string                                             `json:"nodes"`
   268  	Accounts map[common.UnprefixedAddress]*susyChainSpecAccount `json:"accounts"`
   269  }
   270  
   271  // susyChainSpecAccount is the prefunded genesis account and/or precompiled
   272  // contract definition.
   273  type susyChainSpecAccount struct {
   274  	Balance math2.HexOrDecimal256   `json:"balance"`
   275  	Nonce   math2.HexOrDecimal64    `json:"nonce,omitempty"`
   276  	Builtin *susyChainSpecBuiltin `json:"builtin,omitempty"`
   277  }
   278  
   279  // susyChainSpecBuiltin is the precompiled contract definition.
   280  type susyChainSpecBuiltin struct {
   281  	Name       string                  `json:"name,omitempty"`
   282  	ActivateAt math2.HexOrDecimal64    `json:"activate_at,omitempty"`
   283  	Pricing    *susyChainSpecPricing `json:"pricing,omitempty"`
   284  }
   285  
   286  // susyChainSpecPricing represents the different pricing models that builtin
   287  // contracts might advertise using.
   288  type susyChainSpecPricing struct {
   289  	Linear       *susyChainSpecLinearPricing       `json:"linear,omitempty"`
   290  	ModExp       *susyChainSpecModExpPricing       `json:"modexp,omitempty"`
   291  	AltBnPairing *susyChainSpecAltBnPairingPricing `json:"alt_bn128_pairing,omitempty"`
   292  }
   293  
   294  type susyChainSpecLinearPricing struct {
   295  	Base uint64 `json:"base"`
   296  	Word uint64 `json:"word"`
   297  }
   298  
   299  type susyChainSpecModExpPricing struct {
   300  	Divisor uint64 `json:"divisor"`
   301  }
   302  
   303  type susyChainSpecAltBnPairingPricing struct {
   304  	Base uint64 `json:"base"`
   305  	Pair uint64 `json:"pair"`
   306  }
   307  
   308  // newSusyChainSpec converts a susy-graviton genesis block into a Susy specific
   309  // chain specification format.
   310  func newSusyChainSpec(network string, genesis *core.Genesis, bootnodes []string) (*susyChainSpec, error) {
   311  	// Only sofash is currently supported between susy-graviton and Susy
   312  	if genesis.Config.Sofash == nil {
   313  		return nil, errors.New("unsupported consensus engine")
   314  	}
   315  	// Reconstruct the chain spec in Susy's format
   316  	spec := &susyChainSpec{
   317  		Name:    network,
   318  		Nodes:   bootnodes,
   319  		Datadir: strings.ToLower(network),
   320  	}
   321  	spec.Engine.Sofash.Params.BlockReward = make(map[string]string)
   322  	spec.Engine.Sofash.Params.DifficultyBombDelays = make(map[string]string)
   323  	// Frontier
   324  	spec.Engine.Sofash.Params.MinimumDifficulty = (*hexutil.Big)(params.MinimumDifficulty)
   325  	spec.Engine.Sofash.Params.DifficultyBoundDivisor = (*hexutil.Big)(params.DifficultyBoundDivisor)
   326  	spec.Engine.Sofash.Params.DurationLimit = (*hexutil.Big)(params.DurationLimit)
   327  	spec.Engine.Sofash.Params.BlockReward["0x0"] = hexutil.EncodeBig(sofash.FrontierBlockReward)
   328  
   329  	// Homestead
   330  	spec.Engine.Sofash.Params.HomesteadTransition = hexutil.Uint64(genesis.Config.HomesteadBlock.Uint64())
   331  
   332  	// Tangerine Whistle : 150
   333  	// https://github.com/susy-go/SIPs/blob/master/SIPS/sip-608.md
   334  	spec.Params.SIP150Transition = hexutil.Uint64(genesis.Config.SIP150Block.Uint64())
   335  
   336  	// Spurious Dragon: 155, 160, 161, 170
   337  	// https://github.com/susy-go/SIPs/blob/master/SIPS/sip-607.md
   338  	spec.Params.SIP155Transition = hexutil.Uint64(genesis.Config.SIP155Block.Uint64())
   339  	spec.Params.SIP160Transition = hexutil.Uint64(genesis.Config.SIP155Block.Uint64())
   340  	spec.Params.SIP161abcTransition = hexutil.Uint64(genesis.Config.SIP158Block.Uint64())
   341  	spec.Params.SIP161dTransition = hexutil.Uint64(genesis.Config.SIP158Block.Uint64())
   342  
   343  	// Byzantium
   344  	if num := genesis.Config.ByzantiumBlock; num != nil {
   345  		spec.setByzantium(num)
   346  	}
   347  	// Constantinople
   348  	if num := genesis.Config.ConstantinopleBlock; num != nil {
   349  		spec.setConstantinople(num)
   350  	}
   351  	// ConstantinopleFix (remove sip-1283)
   352  	if num := genesis.Config.PetersburgBlock; num != nil {
   353  		spec.setConstantinopleFix(num)
   354  	}
   355  
   356  	spec.Params.MaximumExtraDataSize = (hexutil.Uint64)(params.MaximumExtraDataSize)
   357  	spec.Params.MinGasLimit = (hexutil.Uint64)(params.MinGasLimit)
   358  	spec.Params.GasLimitBoundDivisor = (math2.HexOrDecimal64)(params.GasLimitBoundDivisor)
   359  	spec.Params.NetworkID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   360  	spec.Params.ChainID = (hexutil.Uint64)(genesis.Config.ChainID.Uint64())
   361  	spec.Params.MaxCodeSize = params.MaxCodeSize
   362  	// graviton has it set from zero
   363  	spec.Params.MaxCodeSizeTransition = 0
   364  
   365  	// Disable this one
   366  	spec.Params.SIP98Transition = math.MaxInt64
   367  
   368  	spec.Genesis.Seal.Sophon.Nonce = (hexutil.Bytes)(make([]byte, 8))
   369  	binary.LittleEndian.PutUint64(spec.Genesis.Seal.Sophon.Nonce[:], genesis.Nonce)
   370  
   371  	spec.Genesis.Seal.Sophon.MixHash = (hexutil.Bytes)(genesis.Mixhash[:])
   372  	spec.Genesis.Difficulty = (*hexutil.Big)(genesis.Difficulty)
   373  	spec.Genesis.Author = genesis.Coinbase
   374  	spec.Genesis.Timestamp = (hexutil.Uint64)(genesis.Timestamp)
   375  	spec.Genesis.ParentHash = genesis.ParentHash
   376  	spec.Genesis.ExtraData = (hexutil.Bytes)(genesis.ExtraData)
   377  	spec.Genesis.GasLimit = (hexutil.Uint64)(genesis.GasLimit)
   378  
   379  	spec.Accounts = make(map[common.UnprefixedAddress]*susyChainSpecAccount)
   380  	for address, account := range genesis.Alloc {
   381  		bal := math2.HexOrDecimal256(*account.Balance)
   382  
   383  		spec.Accounts[common.UnprefixedAddress(address)] = &susyChainSpecAccount{
   384  			Balance: bal,
   385  			Nonce:   math2.HexOrDecimal64(account.Nonce),
   386  		}
   387  	}
   388  	spec.setPrecompile(1, &susyChainSpecBuiltin{Name: "ecrecover",
   389  		Pricing: &susyChainSpecPricing{Linear: &susyChainSpecLinearPricing{Base: 3000}}})
   390  
   391  	spec.setPrecompile(2, &susyChainSpecBuiltin{
   392  		Name: "sha256", Pricing: &susyChainSpecPricing{Linear: &susyChainSpecLinearPricing{Base: 60, Word: 12}},
   393  	})
   394  	spec.setPrecompile(3, &susyChainSpecBuiltin{
   395  		Name: "ripemd160", Pricing: &susyChainSpecPricing{Linear: &susyChainSpecLinearPricing{Base: 600, Word: 120}},
   396  	})
   397  	spec.setPrecompile(4, &susyChainSpecBuiltin{
   398  		Name: "identity", Pricing: &susyChainSpecPricing{Linear: &susyChainSpecLinearPricing{Base: 15, Word: 3}},
   399  	})
   400  	if genesis.Config.ByzantiumBlock != nil {
   401  		blnum := math2.HexOrDecimal64(genesis.Config.ByzantiumBlock.Uint64())
   402  		spec.setPrecompile(5, &susyChainSpecBuiltin{
   403  			Name: "modexp", ActivateAt: blnum, Pricing: &susyChainSpecPricing{ModExp: &susyChainSpecModExpPricing{Divisor: 20}},
   404  		})
   405  		spec.setPrecompile(6, &susyChainSpecBuiltin{
   406  			Name: "alt_bn128_add", ActivateAt: blnum, Pricing: &susyChainSpecPricing{Linear: &susyChainSpecLinearPricing{Base: 500}},
   407  		})
   408  		spec.setPrecompile(7, &susyChainSpecBuiltin{
   409  			Name: "alt_bn128_mul", ActivateAt: blnum, Pricing: &susyChainSpecPricing{Linear: &susyChainSpecLinearPricing{Base: 40000}},
   410  		})
   411  		spec.setPrecompile(8, &susyChainSpecBuiltin{
   412  			Name: "alt_bn128_pairing", ActivateAt: blnum, Pricing: &susyChainSpecPricing{AltBnPairing: &susyChainSpecAltBnPairingPricing{Base: 100000, Pair: 80000}},
   413  		})
   414  	}
   415  	return spec, nil
   416  }
   417  
   418  func (spec *susyChainSpec) setPrecompile(address byte, data *susyChainSpecBuiltin) {
   419  	if spec.Accounts == nil {
   420  		spec.Accounts = make(map[common.UnprefixedAddress]*susyChainSpecAccount)
   421  	}
   422  	a := common.UnprefixedAddress(common.BytesToAddress([]byte{address}))
   423  	if _, exist := spec.Accounts[a]; !exist {
   424  		spec.Accounts[a] = &susyChainSpecAccount{}
   425  	}
   426  	spec.Accounts[a].Builtin = data
   427  }
   428  
   429  func (spec *susyChainSpec) setByzantium(num *big.Int) {
   430  	spec.Engine.Sofash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(sofash.ByzantiumBlockReward)
   431  	spec.Engine.Sofash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(3000000)
   432  	n := hexutil.Uint64(num.Uint64())
   433  	spec.Engine.Sofash.Params.SIP100bTransition = n
   434  	spec.Params.SIP140Transition = n
   435  	spec.Params.SIP211Transition = n
   436  	spec.Params.SIP214Transition = n
   437  	spec.Params.SIP658Transition = n
   438  }
   439  
   440  func (spec *susyChainSpec) setConstantinople(num *big.Int) {
   441  	spec.Engine.Sofash.Params.BlockReward[hexutil.EncodeBig(num)] = hexutil.EncodeBig(sofash.ConstantinopleBlockReward)
   442  	spec.Engine.Sofash.Params.DifficultyBombDelays[hexutil.EncodeBig(num)] = hexutil.EncodeUint64(2000000)
   443  	n := hexutil.Uint64(num.Uint64())
   444  	spec.Params.SIP145Transition = n
   445  	spec.Params.SIP1014Transition = n
   446  	spec.Params.SIP1052Transition = n
   447  	spec.Params.SIP1283Transition = n
   448  }
   449  
   450  func (spec *susyChainSpec) setConstantinopleFix(num *big.Int) {
   451  	spec.Params.SIP1283DisableTransition = hexutil.Uint64(num.Uint64())
   452  }
   453  
   454  // pySophonGenesisSpec represents the genesis specification format used by the
   455  // Python Sophon implementation.
   456  type pySophonGenesisSpec struct {
   457  	Nonce      hexutil.Bytes     `json:"nonce"`
   458  	Timestamp  hexutil.Uint64    `json:"timestamp"`
   459  	ExtraData  hexutil.Bytes     `json:"extraData"`
   460  	GasLimit   hexutil.Uint64    `json:"gasLimit"`
   461  	Difficulty *hexutil.Big      `json:"difficulty"`
   462  	Mixhash    common.Hash       `json:"mixhash"`
   463  	Coinbase   common.Address    `json:"coinbase"`
   464  	Alloc      core.GenesisAlloc `json:"alloc"`
   465  	ParentHash common.Hash       `json:"parentHash"`
   466  }
   467  
   468  // newPySophonGenesisSpec converts a susy-graviton genesis block into a Susy specific
   469  // chain specification format.
   470  func newPySophonGenesisSpec(network string, genesis *core.Genesis) (*pySophonGenesisSpec, error) {
   471  	// Only sofash is currently supported between susy-graviton and pysophon
   472  	if genesis.Config.Sofash == nil {
   473  		return nil, errors.New("unsupported consensus engine")
   474  	}
   475  	spec := &pySophonGenesisSpec{
   476  		Timestamp:  (hexutil.Uint64)(genesis.Timestamp),
   477  		ExtraData:  genesis.ExtraData,
   478  		GasLimit:   (hexutil.Uint64)(genesis.GasLimit),
   479  		Difficulty: (*hexutil.Big)(genesis.Difficulty),
   480  		Mixhash:    genesis.Mixhash,
   481  		Coinbase:   genesis.Coinbase,
   482  		Alloc:      genesis.Alloc,
   483  		ParentHash: genesis.ParentHash,
   484  	}
   485  	spec.Nonce = (hexutil.Bytes)(make([]byte, 8))
   486  	binary.LittleEndian.PutUint64(spec.Nonce[:], genesis.Nonce)
   487  
   488  	return spec, nil
   489  }