genesis.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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. package core
  17. import (
  18. "bytes"
  19. "encoding/hex"
  20. "encoding/json"
  21. "errors"
  22. "fmt"
  23. "math/big"
  24. "strings"
  25. "github.com/ethereum/go-ethereum/common"
  26. "github.com/ethereum/go-ethereum/common/hexutil"
  27. "github.com/ethereum/go-ethereum/common/math"
  28. "github.com/ethereum/go-ethereum/core/rawdb"
  29. "github.com/ethereum/go-ethereum/core/state"
  30. "github.com/ethereum/go-ethereum/core/types"
  31. "github.com/ethereum/go-ethereum/crypto"
  32. "github.com/ethereum/go-ethereum/ethdb"
  33. "github.com/ethereum/go-ethereum/log"
  34. "github.com/ethereum/go-ethereum/params"
  35. "github.com/ethereum/go-ethereum/rlp"
  36. "github.com/ethereum/go-ethereum/trie"
  37. )
  38. //go:generate go run github.com/fjl/gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
  39. //go:generate go run github.com/fjl/gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go
  40. var errGenesisNoConfig = errors.New("genesis has no chain configuration")
  41. // Genesis specifies the header fields, state of a genesis block. It also defines hard
  42. // fork switch-over blocks through the chain configuration.
  43. type Genesis struct {
  44. Config *params.ChainConfig `json:"config"`
  45. Nonce uint64 `json:"nonce"`
  46. Timestamp uint64 `json:"timestamp"`
  47. ExtraData []byte `json:"extraData"`
  48. GasLimit uint64 `json:"gasLimit" gencodec:"required"`
  49. Difficulty *big.Int `json:"difficulty" gencodec:"required"`
  50. Mixhash common.Hash `json:"mixHash"`
  51. Coinbase common.Address `json:"coinbase"`
  52. Alloc GenesisAlloc `json:"alloc" gencodec:"required"`
  53. // These fields are used for consensus tests. Please don't use them
  54. // in actual genesis blocks.
  55. Number uint64 `json:"number"`
  56. GasUsed uint64 `json:"gasUsed"`
  57. ParentHash common.Hash `json:"parentHash"`
  58. BaseFee *big.Int `json:"baseFeePerGas"`
  59. }
  60. // GenesisAlloc specifies the initial state that is part of the genesis block.
  61. type GenesisAlloc map[common.Address]GenesisAccount
  62. func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error {
  63. m := make(map[common.UnprefixedAddress]GenesisAccount)
  64. if err := json.Unmarshal(data, &m); err != nil {
  65. return err
  66. }
  67. *ga = make(GenesisAlloc)
  68. for addr, a := range m {
  69. (*ga)[common.Address(addr)] = a
  70. }
  71. return nil
  72. }
  73. // deriveHash computes the state root according to the genesis specification.
  74. func (ga *GenesisAlloc) deriveHash() (common.Hash, error) {
  75. // Create an ephemeral in-memory database for computing hash,
  76. // all the derived states will be discarded to not pollute disk.
  77. db := state.NewDatabase(rawdb.NewMemoryDatabase())
  78. statedb, err := state.New(common.Hash{}, db, nil)
  79. if err != nil {
  80. return common.Hash{}, err
  81. }
  82. for addr, account := range *ga {
  83. statedb.AddBalance(addr, account.Balance)
  84. statedb.SetCode(addr, account.Code)
  85. statedb.SetNonce(addr, account.Nonce)
  86. for key, value := range account.Storage {
  87. statedb.SetState(addr, key, value)
  88. }
  89. }
  90. return statedb.Commit(false)
  91. }
  92. // flush is very similar with deriveHash, but the main difference is
  93. // all the generated states will be persisted into the given database.
  94. // Also, the genesis state specification will be flushed as well.
  95. func (ga *GenesisAlloc) flush(db ethdb.Database) error {
  96. statedb, err := state.New(common.Hash{}, state.NewDatabaseWithConfig(db, &trie.Config{Preimages: true}), nil)
  97. if err != nil {
  98. return err
  99. }
  100. for addr, account := range *ga {
  101. statedb.AddBalance(addr, account.Balance)
  102. statedb.SetCode(addr, account.Code)
  103. statedb.SetNonce(addr, account.Nonce)
  104. for key, value := range account.Storage {
  105. statedb.SetState(addr, key, value)
  106. }
  107. }
  108. root, err := statedb.Commit(false)
  109. if err != nil {
  110. return err
  111. }
  112. err = statedb.Database().TrieDB().Commit(root, true, nil)
  113. if err != nil {
  114. return err
  115. }
  116. // Marshal the genesis state specification and persist.
  117. blob, err := json.Marshal(ga)
  118. if err != nil {
  119. return err
  120. }
  121. rawdb.WriteGenesisStateSpec(db, root, blob)
  122. return nil
  123. }
  124. // CommitGenesisState loads the stored genesis state with the given block
  125. // hash and commits them into the given database handler.
  126. func CommitGenesisState(db ethdb.Database, hash common.Hash) error {
  127. var alloc GenesisAlloc
  128. blob := rawdb.ReadGenesisStateSpec(db, hash)
  129. if len(blob) != 0 {
  130. if err := alloc.UnmarshalJSON(blob); err != nil {
  131. return err
  132. }
  133. } else {
  134. // Genesis allocation is missing and there are several possibilities:
  135. // the node is legacy which doesn't persist the genesis allocation or
  136. // the persisted allocation is just lost.
  137. // - supported networks(mainnet, testnets), recover with defined allocations
  138. // - private network, can't recover
  139. var genesis *Genesis
  140. switch hash {
  141. case params.MainnetGenesisHash:
  142. genesis = DefaultGenesisBlock()
  143. case params.RopstenGenesisHash:
  144. genesis = DefaultRopstenGenesisBlock()
  145. case params.RinkebyGenesisHash:
  146. genesis = DefaultRinkebyGenesisBlock()
  147. case params.GoerliGenesisHash:
  148. genesis = DefaultGoerliGenesisBlock()
  149. case params.SepoliaGenesisHash:
  150. genesis = DefaultSepoliaGenesisBlock()
  151. }
  152. if genesis != nil {
  153. alloc = genesis.Alloc
  154. } else {
  155. return errors.New("not found")
  156. }
  157. }
  158. return alloc.flush(db)
  159. }
  160. // GenesisAccount is an account in the state of the genesis block.
  161. type GenesisAccount struct {
  162. Code []byte `json:"code,omitempty"`
  163. Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
  164. Balance *big.Int `json:"balance" gencodec:"required"`
  165. Nonce uint64 `json:"nonce,omitempty"`
  166. PrivateKey []byte `json:"secretKey,omitempty"` // for tests
  167. }
  168. // field type overrides for gencodec
  169. type genesisSpecMarshaling struct {
  170. Nonce math.HexOrDecimal64
  171. Timestamp math.HexOrDecimal64
  172. ExtraData hexutil.Bytes
  173. GasLimit math.HexOrDecimal64
  174. GasUsed math.HexOrDecimal64
  175. Number math.HexOrDecimal64
  176. Difficulty *math.HexOrDecimal256
  177. BaseFee *math.HexOrDecimal256
  178. Alloc map[common.UnprefixedAddress]GenesisAccount
  179. }
  180. type genesisAccountMarshaling struct {
  181. Code hexutil.Bytes
  182. Balance *math.HexOrDecimal256
  183. Nonce math.HexOrDecimal64
  184. Storage map[storageJSON]storageJSON
  185. PrivateKey hexutil.Bytes
  186. }
  187. // storageJSON represents a 256 bit byte array, but allows less than 256 bits when
  188. // unmarshaling from hex.
  189. type storageJSON common.Hash
  190. func (h *storageJSON) UnmarshalText(text []byte) error {
  191. text = bytes.TrimPrefix(text, []byte("0x"))
  192. if len(text) > 64 {
  193. return fmt.Errorf("too many hex characters in storage key/value %q", text)
  194. }
  195. offset := len(h) - len(text)/2 // pad on the left
  196. if _, err := hex.Decode(h[offset:], text); err != nil {
  197. fmt.Println(err)
  198. return fmt.Errorf("invalid hex storage key/value %q", text)
  199. }
  200. return nil
  201. }
  202. func (h storageJSON) MarshalText() ([]byte, error) {
  203. return hexutil.Bytes(h[:]).MarshalText()
  204. }
  205. // GenesisMismatchError is raised when trying to overwrite an existing
  206. // genesis block with an incompatible one.
  207. type GenesisMismatchError struct {
  208. Stored, New common.Hash
  209. }
  210. func (e *GenesisMismatchError) Error() string {
  211. return fmt.Sprintf("database contains incompatible genesis (have %x, new %x)", e.Stored, e.New)
  212. }
  213. // SetupGenesisBlock writes or updates the genesis block in db.
  214. // The block that will be used is:
  215. //
  216. // genesis == nil genesis != nil
  217. // +------------------------------------------
  218. // db has no genesis | main-net default | genesis
  219. // db has genesis | from DB | genesis (if compatible)
  220. //
  221. // The stored chain configuration will be updated if it is compatible (i.e. does not
  222. // specify a fork block below the local head block). In case of a conflict, the
  223. // error is a *params.ConfigCompatError and the new, unwritten config is returned.
  224. //
  225. // The returned chain configuration is never nil.
  226. func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
  227. return SetupGenesisBlockWithOverride(db, genesis, nil, nil)
  228. }
  229. func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, overrideTerminalTotalDifficulty *big.Int, overrideTerminalTotalDifficultyPassed *bool) (*params.ChainConfig, common.Hash, error) {
  230. if genesis != nil && genesis.Config == nil {
  231. return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
  232. }
  233. applyOverrides := func(config *params.ChainConfig) {
  234. if config != nil {
  235. if overrideTerminalTotalDifficulty != nil {
  236. config.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
  237. }
  238. if overrideTerminalTotalDifficultyPassed != nil {
  239. config.TerminalTotalDifficultyPassed = *overrideTerminalTotalDifficultyPassed
  240. }
  241. }
  242. }
  243. // Just commit the new block if there is no stored genesis block.
  244. stored := rawdb.ReadCanonicalHash(db, 0)
  245. if (stored == common.Hash{}) {
  246. if genesis == nil {
  247. log.Info("Writing default main-net genesis block")
  248. genesis = DefaultGenesisBlock()
  249. } else {
  250. log.Info("Writing custom genesis block")
  251. }
  252. block, err := genesis.Commit(db)
  253. if err != nil {
  254. return genesis.Config, common.Hash{}, err
  255. }
  256. applyOverrides(genesis.Config)
  257. return genesis.Config, block.Hash(), nil
  258. }
  259. // We have the genesis block in database(perhaps in ancient database)
  260. // but the corresponding state is missing.
  261. header := rawdb.ReadHeader(db, stored, 0)
  262. if _, err := state.New(header.Root, state.NewDatabaseWithConfig(db, nil), nil); err != nil {
  263. if genesis == nil {
  264. genesis = DefaultGenesisBlock()
  265. }
  266. // Ensure the stored genesis matches with the given one.
  267. hash := genesis.ToBlock().Hash()
  268. if hash != stored {
  269. return genesis.Config, hash, &GenesisMismatchError{stored, hash}
  270. }
  271. block, err := genesis.Commit(db)
  272. if err != nil {
  273. return genesis.Config, hash, err
  274. }
  275. applyOverrides(genesis.Config)
  276. return genesis.Config, block.Hash(), nil
  277. }
  278. // Check whether the genesis block is already written.
  279. if genesis != nil {
  280. hash := genesis.ToBlock().Hash()
  281. if hash != stored {
  282. return genesis.Config, hash, &GenesisMismatchError{stored, hash}
  283. }
  284. }
  285. // Get the existing chain configuration.
  286. newcfg := genesis.configOrDefault(stored)
  287. applyOverrides(newcfg)
  288. if err := newcfg.CheckConfigForkOrder(); err != nil {
  289. return newcfg, common.Hash{}, err
  290. }
  291. storedcfg := rawdb.ReadChainConfig(db, stored)
  292. if storedcfg == nil {
  293. log.Warn("Found genesis block without chain config")
  294. rawdb.WriteChainConfig(db, stored, newcfg)
  295. return newcfg, stored, nil
  296. }
  297. // Special case: if a private network is being used (no genesis and also no
  298. // mainnet hash in the database), we must not apply the `configOrDefault`
  299. // chain config as that would be AllProtocolChanges (applying any new fork
  300. // on top of an existing private network genesis block). In that case, only
  301. // apply the overrides.
  302. if genesis == nil && stored != params.MainnetGenesisHash {
  303. newcfg = storedcfg
  304. applyOverrides(newcfg)
  305. }
  306. // Check config compatibility and write the config. Compatibility errors
  307. // are returned to the caller unless we're already at block zero.
  308. height := rawdb.ReadHeaderNumber(db, rawdb.ReadHeadHeaderHash(db))
  309. if height == nil {
  310. return newcfg, stored, fmt.Errorf("missing block number for head header hash")
  311. }
  312. compatErr := storedcfg.CheckCompatible(newcfg, *height)
  313. if compatErr != nil && *height != 0 && compatErr.RewindTo != 0 {
  314. return newcfg, stored, compatErr
  315. }
  316. rawdb.WriteChainConfig(db, stored, newcfg)
  317. return newcfg, stored, nil
  318. }
  319. func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
  320. switch {
  321. case g != nil:
  322. return g.Config
  323. case ghash == params.MainnetGenesisHash:
  324. return params.MainnetChainConfig
  325. case ghash == params.RopstenGenesisHash:
  326. return params.RopstenChainConfig
  327. case ghash == params.SepoliaGenesisHash:
  328. return params.SepoliaChainConfig
  329. case ghash == params.RinkebyGenesisHash:
  330. return params.RinkebyChainConfig
  331. case ghash == params.GoerliGenesisHash:
  332. return params.GoerliChainConfig
  333. case ghash == params.KilnGenesisHash:
  334. return DefaultKilnGenesisBlock().Config
  335. default:
  336. return params.AllEthashProtocolChanges
  337. }
  338. }
  339. // ToBlock returns the genesis block according to genesis specification.
  340. func (g *Genesis) ToBlock() *types.Block {
  341. root, err := g.Alloc.deriveHash()
  342. if err != nil {
  343. panic(err)
  344. }
  345. head := &types.Header{
  346. Number: new(big.Int).SetUint64(g.Number),
  347. Nonce: types.EncodeNonce(g.Nonce),
  348. Time: g.Timestamp,
  349. ParentHash: g.ParentHash,
  350. Extra: g.ExtraData,
  351. GasLimit: g.GasLimit,
  352. GasUsed: g.GasUsed,
  353. BaseFee: g.BaseFee,
  354. Difficulty: g.Difficulty,
  355. MixDigest: g.Mixhash,
  356. Coinbase: g.Coinbase,
  357. Root: root,
  358. }
  359. if g.GasLimit == 0 {
  360. head.GasLimit = params.GenesisGasLimit
  361. }
  362. if g.Difficulty == nil && g.Mixhash == (common.Hash{}) {
  363. head.Difficulty = params.GenesisDifficulty
  364. }
  365. if g.Config != nil && g.Config.IsLondon(common.Big0) {
  366. if g.BaseFee != nil {
  367. head.BaseFee = g.BaseFee
  368. } else {
  369. head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
  370. }
  371. }
  372. return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil))
  373. }
  374. // Commit writes the block and state of a genesis specification to the database.
  375. // The block is committed as the canonical head block.
  376. func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
  377. block := g.ToBlock()
  378. if block.Number().Sign() != 0 {
  379. return nil, errors.New("can't commit genesis block with number > 0")
  380. }
  381. config := g.Config
  382. if config == nil {
  383. config = params.AllEthashProtocolChanges
  384. }
  385. if err := config.CheckConfigForkOrder(); err != nil {
  386. return nil, err
  387. }
  388. if config.Clique != nil && len(block.Extra()) < 32+crypto.SignatureLength {
  389. return nil, errors.New("can't start clique chain without signers")
  390. }
  391. // All the checks has passed, flush the states derived from the genesis
  392. // specification as well as the specification itself into the provided
  393. // database.
  394. if err := g.Alloc.flush(db); err != nil {
  395. return nil, err
  396. }
  397. rawdb.WriteTd(db, block.Hash(), block.NumberU64(), block.Difficulty())
  398. rawdb.WriteBlock(db, block)
  399. rawdb.WriteReceipts(db, block.Hash(), block.NumberU64(), nil)
  400. rawdb.WriteCanonicalHash(db, block.Hash(), block.NumberU64())
  401. rawdb.WriteHeadBlockHash(db, block.Hash())
  402. rawdb.WriteHeadFastBlockHash(db, block.Hash())
  403. rawdb.WriteHeadHeaderHash(db, block.Hash())
  404. rawdb.WriteChainConfig(db, block.Hash(), config)
  405. return block, nil
  406. }
  407. // MustCommit writes the genesis block and state to db, panicking on error.
  408. // The block is committed as the canonical head block.
  409. func (g *Genesis) MustCommit(db ethdb.Database) *types.Block {
  410. block, err := g.Commit(db)
  411. if err != nil {
  412. panic(err)
  413. }
  414. return block
  415. }
  416. // DefaultGenesisBlock returns the Ethereum main net genesis block.
  417. func DefaultGenesisBlock() *Genesis {
  418. return &Genesis{
  419. Config: params.MainnetChainConfig,
  420. Nonce: 66,
  421. ExtraData: hexutil.MustDecode("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa"),
  422. GasLimit: 5000,
  423. Difficulty: big.NewInt(17179869184),
  424. Alloc: decodePrealloc(mainnetAllocData),
  425. }
  426. }
  427. // DefaultRopstenGenesisBlock returns the Ropsten network genesis block.
  428. func DefaultRopstenGenesisBlock() *Genesis {
  429. return &Genesis{
  430. Config: params.RopstenChainConfig,
  431. Nonce: 66,
  432. ExtraData: hexutil.MustDecode("0x3535353535353535353535353535353535353535353535353535353535353535"),
  433. GasLimit: 16777216,
  434. Difficulty: big.NewInt(1048576),
  435. Alloc: decodePrealloc(ropstenAllocData),
  436. }
  437. }
  438. // DefaultRinkebyGenesisBlock returns the Rinkeby network genesis block.
  439. func DefaultRinkebyGenesisBlock() *Genesis {
  440. return &Genesis{
  441. Config: params.RinkebyChainConfig,
  442. Timestamp: 1492009146,
  443. ExtraData: hexutil.MustDecode("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
  444. GasLimit: 4700000,
  445. Difficulty: big.NewInt(1),
  446. Alloc: decodePrealloc(rinkebyAllocData),
  447. }
  448. }
  449. // DefaultGoerliGenesisBlock returns the Görli network genesis block.
  450. func DefaultGoerliGenesisBlock() *Genesis {
  451. return &Genesis{
  452. Config: params.GoerliChainConfig,
  453. Timestamp: 1548854791,
  454. ExtraData: hexutil.MustDecode("0x22466c6578692069732061207468696e6722202d204166726900000000000000e0a2bd4258d2768837baa26a28fe71dc079f84c70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
  455. GasLimit: 10485760,
  456. Difficulty: big.NewInt(1),
  457. Alloc: decodePrealloc(goerliAllocData),
  458. }
  459. }
  460. // DefaultSepoliaGenesisBlock returns the Sepolia network genesis block.
  461. func DefaultSepoliaGenesisBlock() *Genesis {
  462. return &Genesis{
  463. Config: params.SepoliaChainConfig,
  464. Nonce: 0,
  465. ExtraData: []byte("Sepolia, Athens, Attica, Greece!"),
  466. GasLimit: 0x1c9c380,
  467. Difficulty: big.NewInt(0x20000),
  468. Timestamp: 1633267481,
  469. Alloc: decodePrealloc(sepoliaAllocData),
  470. }
  471. }
  472. // DefaultKilnGenesisBlock returns the kiln network genesis block.
  473. func DefaultKilnGenesisBlock() *Genesis {
  474. g := new(Genesis)
  475. reader := strings.NewReader(KilnAllocData)
  476. if err := json.NewDecoder(reader).Decode(g); err != nil {
  477. panic(err)
  478. }
  479. return g
  480. }
  481. // DeveloperGenesisBlock returns the 'geth --dev' genesis block.
  482. func DeveloperGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *Genesis {
  483. // Override the default period to the user requested one
  484. config := *params.AllCliqueProtocolChanges
  485. config.Clique = &params.CliqueConfig{
  486. Period: period,
  487. Epoch: config.Clique.Epoch,
  488. }
  489. // Assemble and return the genesis with the precompiles and faucet pre-funded
  490. return &Genesis{
  491. Config: &config,
  492. ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, crypto.SignatureLength)...),
  493. GasLimit: gasLimit,
  494. BaseFee: big.NewInt(params.InitialBaseFee),
  495. Difficulty: big.NewInt(1),
  496. Alloc: map[common.Address]GenesisAccount{
  497. common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
  498. common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256
  499. common.BytesToAddress([]byte{3}): {Balance: big.NewInt(1)}, // RIPEMD
  500. common.BytesToAddress([]byte{4}): {Balance: big.NewInt(1)}, // Identity
  501. common.BytesToAddress([]byte{5}): {Balance: big.NewInt(1)}, // ModExp
  502. common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd
  503. common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
  504. common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
  505. common.BytesToAddress([]byte{9}): {Balance: big.NewInt(1)}, // BLAKE2b
  506. faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
  507. },
  508. }
  509. }
  510. func decodePrealloc(data string) GenesisAlloc {
  511. var p []struct{ Addr, Balance *big.Int }
  512. if err := rlp.NewStream(strings.NewReader(data), 0).Decode(&p); err != nil {
  513. panic(err)
  514. }
  515. ga := make(GenesisAlloc, len(p))
  516. for _, account := range p {
  517. ga[common.BigToAddress(account.Addr)] = GenesisAccount{Balance: account.Balance}
  518. }
  519. return ga
  520. }