github.com/nnlgsakib/mind-dpos@v0.0.0-20230606105614-f3c8ca06f808/core/genesis.go (about)

     1  // Copyright 2014 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package core
    18  
    19  import (
    20  	"bytes"
    21  	"encoding/hex"
    22  	"encoding/json"
    23  	"errors"
    24  	"fmt"
    25  	"math/big"
    26  	"strings"
    27  
    28  	"github.com/TTCECO/gttc/common"
    29  	"github.com/TTCECO/gttc/common/hexutil"
    30  	"github.com/TTCECO/gttc/common/math"
    31  	"github.com/TTCECO/gttc/core/rawdb"
    32  	"github.com/TTCECO/gttc/core/state"
    33  	"github.com/TTCECO/gttc/core/types"
    34  	"github.com/TTCECO/gttc/ethdb"
    35  	"github.com/TTCECO/gttc/log"
    36  	"github.com/TTCECO/gttc/params"
    37  	"github.com/TTCECO/gttc/rlp"
    38  )
    39  
    40  //go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
    41  //go:generate gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go
    42  
    43  var errGenesisNoConfig = errors.New("genesis has no chain configuration")
    44  
    45  // Genesis specifies the header fields, state of a genesis block. It also defines hard
    46  // fork switch-over blocks through the chain configuration.
    47  type Genesis struct {
    48  	Config     *params.ChainConfig `json:"config"`
    49  	Nonce      uint64              `json:"nonce"`
    50  	Timestamp  uint64              `json:"timestamp"`
    51  	ExtraData  []byte              `json:"extraData"`
    52  	GasLimit   uint64              `json:"gasLimit"   gencodec:"required"`
    53  	Difficulty *big.Int            `json:"difficulty" gencodec:"required"`
    54  	Mixhash    common.Hash         `json:"mixHash"`
    55  	Coinbase   common.Address      `json:"coinbase"`
    56  	Alloc      GenesisAlloc        `json:"alloc"      gencodec:"required"`
    57  
    58  	// These fields are used for consensus tests. Please don't use them
    59  	// in actual genesis blocks.
    60  	Number     uint64      `json:"number"`
    61  	GasUsed    uint64      `json:"gasUsed"`
    62  	ParentHash common.Hash `json:"parentHash"`
    63  }
    64  
    65  // GenesisAlloc specifies the initial state that is part of the genesis block.
    66  type GenesisAlloc map[common.Address]GenesisAccount
    67  
    68  func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error {
    69  	m := make(map[common.UnprefixedAddress]GenesisAccount)
    70  	if err := json.Unmarshal(data, &m); err != nil {
    71  		return err
    72  	}
    73  	*ga = make(GenesisAlloc)
    74  	for addr, a := range m {
    75  		(*ga)[common.Address(addr)] = a
    76  	}
    77  	return nil
    78  }
    79  
    80  // GenesisAccount is an account in the state of the genesis block.
    81  type GenesisAccount struct {
    82  	Code       []byte                      `json:"code,omitempty"`
    83  	Storage    map[common.Hash]common.Hash `json:"storage,omitempty"`
    84  	Balance    *big.Int                    `json:"balance" gencodec:"required"`
    85  	Nonce      uint64                      `json:"nonce,omitempty"`
    86  	PrivateKey []byte                      `json:"secretKey,omitempty"` // for tests
    87  }
    88  
    89  // field type overrides for gencodec
    90  type genesisSpecMarshaling struct {
    91  	Nonce      math.HexOrDecimal64
    92  	Timestamp  math.HexOrDecimal64
    93  	ExtraData  hexutil.Bytes
    94  	GasLimit   math.HexOrDecimal64
    95  	GasUsed    math.HexOrDecimal64
    96  	Number     math.HexOrDecimal64
    97  	Difficulty *math.HexOrDecimal256
    98  	Alloc      map[common.UnprefixedAddress]GenesisAccount
    99  }
   100  
   101  type genesisAccountMarshaling struct {
   102  	Code       hexutil.Bytes
   103  	Balance    *math.HexOrDecimal256
   104  	Nonce      math.HexOrDecimal64
   105  	Storage    map[storageJSON]storageJSON
   106  	PrivateKey hexutil.Bytes
   107  }
   108  
   109  // storageJSON represents a 256 bit byte array, but allows less than 256 bits when
   110  // unmarshaling from hex.
   111  type storageJSON common.Hash
   112  
   113  func (h *storageJSON) UnmarshalText(text []byte) error {
   114  	text = bytes.TrimPrefix(text, []byte("0x"))
   115  	if len(text) > 64 {
   116  		return fmt.Errorf("too many hex characters in storage key/value %q", text)
   117  	}
   118  	offset := len(h) - len(text)/2 // pad on the left
   119  	if _, err := hex.Decode(h[offset:], text); err != nil {
   120  		fmt.Println(err)
   121  		return fmt.Errorf("invalid hex storage key/value %q", text)
   122  	}
   123  	return nil
   124  }
   125  
   126  func (h storageJSON) MarshalText() ([]byte, error) {
   127  	return hexutil.Bytes(h[:]).MarshalText()
   128  }
   129  
   130  // GenesisMismatchError is raised when trying to overwrite an existing
   131  // genesis block with an incompatible one.
   132  type GenesisMismatchError struct {
   133  	Stored, New common.Hash
   134  }
   135  
   136  func (e *GenesisMismatchError) Error() string {
   137  	return fmt.Sprintf("database already contains an incompatible genesis block (have %x, new %x)", e.Stored[:8], e.New[:8])
   138  }
   139  
   140  // SetupGenesisBlock writes or updates the genesis block in db.
   141  // The block that will be used is:
   142  //
   143  //                          genesis == nil       genesis != nil
   144  //                       +------------------------------------------
   145  //     db has no genesis |  main-net default  |  genesis
   146  //     db has genesis    |  from DB           |  genesis (if compatible)
   147  //
   148  // The stored chain configuration will be updated if it is compatible (i.e. does not
   149  // specify a fork block below the local head block). In case of a conflict, the
   150  // error is a *params.ConfigCompatError and the new, unwritten config is returned.
   151  //
   152  // The returned chain configuration is never nil.
   153  func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
   154  	if genesis != nil && genesis.Config == nil {
   155  		return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
   156  	}
   157  
   158  	// Just commit the new block if there is no stored genesis block.
   159  	stored := rawdb.ReadCanonicalHash(db, 0)
   160  	if (stored == common.Hash{}) {
   161  		if genesis == nil {
   162  			log.Info("Writing default main-net genesis block")
   163  			genesis = DefaultGenesisBlock()
   164  		} else {
   165  			log.Info("Writing custom genesis block")
   166  		}
   167  		block, err := genesis.Commit(db)
   168  		return genesis.Config, block.Hash(), err
   169  	}
   170  
   171  	// Check whether the genesis block is already written.
   172  	if genesis != nil {
   173  		hash := genesis.ToBlock(nil).Hash()
   174  		if hash != stored {
   175  			return genesis.Config, hash, &GenesisMismatchError{stored, hash}
   176  		}
   177  	}
   178  
   179  	// Get the existing chain configuration.
   180  	newcfg := genesis.configOrDefault(stored)
   181  	storedcfg := rawdb.ReadChainConfig(db, stored)
   182  	if storedcfg == nil {
   183  		log.Warn("Found genesis block without chain config")
   184  		rawdb.WriteChainConfig(db, stored, newcfg)
   185  		return newcfg, stored, nil
   186  	}
   187  	// Special case: don't change the existing config of a non-mainnet chain if no new
   188  	// config is supplied. These chains would get AllProtocolChanges (and a compat error)
   189  	// if we just continued here.
   190  	if genesis == nil && stored != params.MainnetGenesisHash {
   191  		return storedcfg, stored, nil
   192  	}
   193  
   194  	// Check config compatibility and write the config. Compatibility errors
   195  	// are returned to the caller unless we're already at block zero.
   196  	height := rawdb.ReadHeaderNumber(db, rawdb.ReadHeadHeaderHash(db))
   197  	if height == nil {
   198  		return newcfg, stored, fmt.Errorf("missing block number for head header hash")
   199  	}
   200  	compatErr := storedcfg.CheckCompatible(newcfg, *height)
   201  	if compatErr != nil && *height != 0 && compatErr.RewindTo != 0 {
   202  		return newcfg, stored, compatErr
   203  	}
   204  	rawdb.WriteChainConfig(db, stored, newcfg)
   205  	return newcfg, stored, nil
   206  }
   207  
   208  func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
   209  	switch {
   210  	case g != nil:
   211  		return g.Config
   212  	case ghash == params.MainnetGenesisHash:
   213  		return params.MainnetChainConfig
   214  	case ghash == params.TestnetGenesisHash:
   215  		return params.TestnetChainConfig
   216  	default:
   217  		return params.AllEthashProtocolChanges
   218  	}
   219  }
   220  
   221  // ToBlock creates the genesis block and writes state of a genesis specification
   222  // to the given database (or discards it if nil).
   223  func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
   224  	if db == nil {
   225  		db = ethdb.NewMemDatabase()
   226  	}
   227  	statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
   228  	for addr, account := range g.Alloc {
   229  		statedb.AddBalance(addr, account.Balance)
   230  		statedb.SetCode(addr, account.Code)
   231  		statedb.SetNonce(addr, account.Nonce)
   232  		for key, value := range account.Storage {
   233  			statedb.SetState(addr, key, value)
   234  		}
   235  	}
   236  	root := statedb.IntermediateRoot(false)
   237  	head := &types.Header{
   238  		Number:     new(big.Int).SetUint64(g.Number),
   239  		Nonce:      types.EncodeNonce(g.Nonce),
   240  		Time:       new(big.Int).SetUint64(g.Timestamp),
   241  		ParentHash: g.ParentHash,
   242  		Extra:      g.ExtraData,
   243  		GasLimit:   g.GasLimit,
   244  		GasUsed:    g.GasUsed,
   245  		Difficulty: g.Difficulty,
   246  		MixDigest:  g.Mixhash,
   247  		Coinbase:   g.Coinbase,
   248  		Root:       root,
   249  	}
   250  	if g.GasLimit == 0 {
   251  		head.GasLimit = params.GenesisGasLimit
   252  	}
   253  	if g.Difficulty == nil {
   254  		head.Difficulty = params.GenesisDifficulty
   255  	}
   256  	statedb.Commit(false)
   257  	statedb.Database().TrieDB().Commit(root, true)
   258  
   259  	return types.NewBlock(head, nil, nil, nil)
   260  }
   261  
   262  // Commit writes the block and state of a genesis specification to the database.
   263  // The block is committed as the canonical head block.
   264  func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
   265  	block := g.ToBlock(db)
   266  	if block.Number().Sign() != 0 {
   267  		return nil, fmt.Errorf("can't commit genesis block with number > 0")
   268  	}
   269  	rawdb.WriteTd(db, block.Hash(), block.NumberU64(), g.Difficulty)
   270  	rawdb.WriteBlock(db, block)
   271  	rawdb.WriteReceipts(db, block.Hash(), block.NumberU64(), nil)
   272  	rawdb.WriteCanonicalHash(db, block.Hash(), block.NumberU64())
   273  	rawdb.WriteHeadBlockHash(db, block.Hash())
   274  	rawdb.WriteHeadHeaderHash(db, block.Hash())
   275  
   276  	config := g.Config
   277  	if config == nil {
   278  		config = params.AllEthashProtocolChanges
   279  	}
   280  	rawdb.WriteChainConfig(db, block.Hash(), config)
   281  	return block, nil
   282  }
   283  
   284  // MustCommit writes the genesis block and state to db, panicking on error.
   285  // The block is committed as the canonical head block.
   286  func (g *Genesis) MustCommit(db ethdb.Database) *types.Block {
   287  	block, err := g.Commit(db)
   288  	if err != nil {
   289  		panic(err)
   290  	}
   291  	return block
   292  }
   293  
   294  // GenesisBlockForTesting creates and writes a block in which addr has the given wei balance.
   295  func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block {
   296  	g := Genesis{Alloc: GenesisAlloc{addr: {Balance: balance}}}
   297  	return g.MustCommit(db)
   298  }
   299  
   300  // DefaultGenesisBlock returns the Ethereum main net genesis block.
   301  func DefaultGenesisBlock() *Genesis {
   302  	mainnetAlloc := make(GenesisAlloc, 50)
   303  	for _, addr := range params.MainnetChainConfig.Alien.SelfVoteSigners {
   304  		balance, _ := new(big.Int).SetString("400000000000000000", 16)
   305  		mainnetAlloc[common.Address(addr)] = GenesisAccount{Balance: balance}
   306  	}
   307  
   308  	balance, _ := new(big.Int).SetString("26c566f0a2b77a000000000", 16)
   309  	mainnetAlloc[common.HexToAddress("t0bce13d77339971d1f5f00c38f523ba7ee44c95ed")] = GenesisAccount{Balance: balance}
   310  
   311  	return &Genesis{
   312  		Config:     params.MainnetChainConfig,
   313  		Timestamp:  1554004800,
   314  		Nonce:      0,
   315  		ExtraData:  hexutil.MustDecode("0x436f6769746f206572676f2073756d2e20457863657074206f7572206f776e2074686f75676874732c207468657265206973206e6f7468696e67206162736f6c7574656c7920696e206f757220706f7765722e20596f75206e656564206368616f7320696e20796f757220736f756c20746f206769766520626972746820746f20612064616e63696e6720737461722e20416c6561206961637461206573742e2020416c6c2063726564697420676f657320746f20746865207465616d3a2053686968616f2047756f2c2050656e67204c69752c205969204d6f2c204368617365204368616e672c2059697869616f2057616e672c20436520476f6e672c204865205a68616e672c2059756e6a69204d612c204a69652057752c205869616e6779616e672057616e672c204368656e687569204c752c204368656e6c69616e672057616e672c205765692050616e2c205175616e205975616e2c20577571696f6e67204c69752c204368616f204368656e2c204a756e6875612046616e2c20536875616e67205a68616f2c2059756e204c762c204a696e676a69652048652c204a696e68752044696e672c2059616e672048616e2c2053756d656920486f6e672c204c69616e67205a68616e672c204a75616e205a68656e672c204a69616e6a69616f204875616e672c204c756e205169616e2c205869616f7969204368656e2c205975666569205a68616e672c20516920416e2c205a6869636f6e67205975616e2c2059696e677975652053752c2048616e205a68616e672c204a69616e677765692057616e672c2046656970656e67204875616e672c205975746f6e6720446f6e672c2054656e67204d612c205169616e6c6569205368692c2059756e7869616f204c692c2052756971696e67205975652c205068696c6c6970204368756e2c205469616e7869616e672059752c204e61205a68616e672c2053687561692057616e672c2048616966656e672059616e2c204368656e6768616f2059696e2c2048656e67205a686f752c20536875616e67205a68616e672c204c696e7a68656e205869652c204b657368756e2058752c204a756e79692046616e672c204c696e66656e67204c692c20596f6e676c696e204c6920616e6420427269616e204368656f6e672e205370656369616c207468616e6b7320746f2053696d6f6e204b696d2c205279616e204b696d2c2053686f756a69205a686f752c205975616e205a68616e672c205468616e68204e677579656e2c204a69616e204361692c20486f6e677765692043616f2c205374656e204c61757265797373656e732e"),
   316  		GasLimit:   4700000,
   317  		Difficulty: big.NewInt(1),
   318  		Alloc:      mainnetAlloc,
   319  	}
   320  }
   321  
   322  // DefaultTestnetGenesisBlock returns the Ropsten network genesis block.
   323  func DefaultTestnetGenesisBlock() *Genesis {
   324  
   325  	testnetAlloc := make(GenesisAlloc, 3)
   326  	balance1, _ := new(big.Int).SetString("40000000000000000000000", 16)
   327  	testnetAlloc[common.HexToAddress("t0be6865ffcbbe5f9746bef5c84b912f2ad9e52075")] = GenesisAccount{Balance: balance1}
   328  
   329  	balance2, _ := new(big.Int).SetString("40000000000000000000000", 16)
   330  	testnetAlloc[common.HexToAddress("t04909b4e54395de9e313ad8a2254fe2dcda99e91c")] = GenesisAccount{Balance: balance2}
   331  
   332  	balance3, _ := new(big.Int).SetString("26c566f0a2b77a000000000", 16)
   333  	testnetAlloc[common.HexToAddress("t0a034350c8e80eb4d15ac62310657b29c711bb3d5")] = GenesisAccount{Balance: balance3}
   334  
   335  	return &Genesis{
   336  		Config:     params.TestnetChainConfig,
   337  		Timestamp:  1554004800,
   338  		Nonce:      0,
   339  		ExtraData:  hexutil.MustDecode("0x436f6769746f206572676f2073756d2e20457863657074206f7572206f776e2074686f75676874732c207468657265206973206e6f7468696e67206162736f6c7574656c7920696e206f757220706f7765722e20596f75206e656564206368616f7320696e20796f757220736f756c20746f206769766520626972746820746f20612064616e63696e6720737461722e20416c6561206961637461206573742e2020416c6c2063726564697420676f657320746f20746865207465616d3a2053686968616f2047756f2c2050656e67204c69752c205969204d6f2c204368617365204368616e672c2059697869616f2057616e672c20436520476f6e672c204865205a68616e672c2059756e6a69204d612c204a69652057752c205869616e6779616e672057616e672c204368656e687569204c752c204368656e6c69616e672057616e672c205765692050616e2c205175616e205975616e2c20577571696f6e67204c69752c204368616f204368656e2c204a756e6875612046616e2c20536875616e67205a68616f2c2059756e204c762c204a696e676a69652048652c204a696e68752044696e672c2059616e672048616e2c2053756d656920486f6e672c204c69616e67205a68616e672c204a75616e205a68656e672c204a69616e6a69616f204875616e672c204c756e205169616e2c205869616f7969204368656e2c205975666569205a68616e672c20516920416e2c205a6869636f6e67205975616e2c2059696e677975652053752c2048616e205a68616e672c204a69616e677765692057616e672c2046656970656e67204875616e672c205975746f6e6720446f6e672c2054656e67204d612c205169616e6c6569205368692c2059756e7869616f204c692c2052756971696e67205975652c205068696c6c6970204368756e2c205469616e7869616e672059752c204e61205a68616e672c2053687561692057616e672c2048616966656e672059616e2c204368656e6768616f2059696e2c2048656e67205a686f752c20536875616e67205a68616e672c204c696e7a68656e205869652c204b657368756e2058752c204a756e79692046616e672c204c696e66656e67204c692c20596f6e676c696e204c6920616e6420427269616e204368656f6e672e205370656369616c207468616e6b7320746f2053696d6f6e204b696d2c205279616e204b696d2c2053686f756a69205a686f752c205975616e205a68616e672c205468616e68204e677579656e2c204a69616e204361692c20486f6e677765692043616f2c205374656e204c61757265797373656e732e"),
   340  		GasLimit:   4700000,
   341  		Difficulty: big.NewInt(1),
   342  		Alloc:      testnetAlloc,
   343  	}
   344  }
   345  
   346  // DefaultSCGenesisBlock returns the Ropsten network genesis block.
   347  func DefaultSCGenesisBlock() *Genesis {
   348  
   349  	return &Genesis{
   350  		Config:     params.SideChainConfig,
   351  		Timestamp:  1554004800,
   352  		Nonce:      0,
   353  		ExtraData:  hexutil.MustDecode("0x436f6769746f206572676f2073756d2e20457863657074206f7572206f776e2074686f75676874732c207468657265206973206e6f7468696e67206162736f6c7574656c7920696e206f757220706f7765722e20596f75206e656564206368616f7320696e20796f757220736f756c20746f206769766520626972746820746f20612064616e63696e6720737461722e20416c6561206961637461206573742e2020416c6c2063726564697420676f657320746f20746865207465616d3a2053686968616f2047756f2c2050656e67204c69752c205969204d6f2c204368617365204368616e672c2059697869616f2057616e672c20436520476f6e672c204865205a68616e672c2059756e6a69204d612c204a69652057752c205869616e6779616e672057616e672c204368656e687569204c752c204368656e6c69616e672057616e672c205765692050616e2c205175616e205975616e2c20577571696f6e67204c69752c204368616f204368656e2c204a756e6875612046616e2c20536875616e67205a68616f2c2059756e204c762c204a696e676a69652048652c204a696e68752044696e672c2059616e672048616e2c2053756d656920486f6e672c204c69616e67205a68616e672c204a75616e205a68656e672c204a69616e6a69616f204875616e672c204c756e205169616e2c205869616f7969204368656e2c205975666569205a68616e672c20516920416e2c205a6869636f6e67205975616e2c2059696e677975652053752c2048616e205a68616e672c204a69616e677765692057616e672c2046656970656e67204875616e672c205975746f6e6720446f6e672c2054656e67204d612c205169616e6c6569205368692c2059756e7869616f204c692c2052756971696e67205975652c205068696c6c6970204368756e2c205469616e7869616e672059752c204e61205a68616e672c2053687561692057616e672c2048616966656e672059616e2c204368656e6768616f2059696e2c2048656e67205a686f752c20536875616e67205a68616e672c204c696e7a68656e205869652c204b657368756e2058752c204a756e79692046616e672c204c696e66656e67204c692c20596f6e676c696e204c6920616e6420427269616e204368656f6e672e205370656369616c207468616e6b7320746f2053696d6f6e204b696d2c205279616e204b696d2c2053686f756a69205a686f752c205975616e205a68616e672c205468616e68204e677579656e2c204a69616e204361692c20486f6e677765692043616f2c205374656e204c61757265797373656e732e"),
   354  		GasLimit:   4700000,
   355  		Difficulty: big.NewInt(1),
   356  		ParentHash: common.HexToHash("0x3210000000000000000000000000000000000000000000000000000000000000"),
   357  		Alloc:      make(GenesisAlloc),
   358  	}
   359  }
   360  
   361  // DefaultRinkebyGenesisBlock returns the Rinkeby network genesis block.
   362  func DefaultRinkebyGenesisBlock() *Genesis {
   363  	return &Genesis{
   364  		Config:     params.RinkebyChainConfig,
   365  		Timestamp:  1492009146,
   366  		ExtraData:  hexutil.MustDecode("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
   367  		GasLimit:   4700000,
   368  		Difficulty: big.NewInt(1),
   369  		Alloc:      decodePrealloc(rinkebyAllocData),
   370  	}
   371  }
   372  
   373  // DeveloperGenesisBlock returns the 'geth --dev' genesis block. Note, this must
   374  // be seeded with the
   375  func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis {
   376  	// Override the default period to the user requested one
   377  	config := *params.AllCliqueProtocolChanges
   378  	config.Clique.Period = period
   379  
   380  	// Assemble and return the genesis with the precompiles and faucet pre-funded
   381  	return &Genesis{
   382  		Config:     &config,
   383  		ExtraData:  append(append(make([]byte, 32), faucet[:]...), make([]byte, 65)...),
   384  		GasLimit:   6283185,
   385  		Difficulty: big.NewInt(1),
   386  		Alloc: map[common.Address]GenesisAccount{
   387  			common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
   388  			common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256
   389  			common.BytesToAddress([]byte{3}): {Balance: big.NewInt(1)}, // RIPEMD
   390  			common.BytesToAddress([]byte{4}): {Balance: big.NewInt(1)}, // Identity
   391  			common.BytesToAddress([]byte{5}): {Balance: big.NewInt(1)}, // ModExp
   392  			common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd
   393  			common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
   394  			common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
   395  			faucet:                           {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
   396  		},
   397  	}
   398  }
   399  
   400  func decodePrealloc(data string) GenesisAlloc {
   401  	var p []struct{ Addr, Balance *big.Int }
   402  	if err := rlp.NewStream(strings.NewReader(data), 0).Decode(&p); err != nil {
   403  		panic(err)
   404  	}
   405  	ga := make(GenesisAlloc, len(p))
   406  	for _, account := range p {
   407  		ga[common.BigToAddress(account.Addr)] = GenesisAccount{Balance: account.Balance}
   408  	}
   409  	return ga
   410  }