From bb52ad61fb1f1e962dd83afbe9ac907713466af2 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 11 Sep 2023 18:35:10 +0800 Subject: [PATCH] core/genesis: panic if overwrite precompiled account Signed-off-by: jsvisa --- core/genesis.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 5e8845691a..4487ece10b 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -608,18 +608,24 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet common.Address, genesisAlloc common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing common.BytesToAddress([]byte{9}): {Balance: big.NewInt(1)}, // BLAKE2b - faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, } if genesisAlloc != nil { + precompiled := map[common.Address]struct{}{} + for addr := range alloc { + precompiled[addr] = struct{}{} + } for addr, account := range *genesisAlloc { // Don't overwrite the precompiled accounts - if _, ok := alloc[addr]; !ok { - alloc[addr] = account + if _, ok := precompiled[addr]; ok { + log.Crit("DeveloperGenesisBlock: can't overwrite precompiled account", "address", addr) } + alloc[addr] = account } } + alloc[faucet] = GenesisAccount{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))} + // Assemble and return the genesis with the precompiles and faucet pre-funded return &Genesis{ Config: &config,