Repository: ethereum/go-ethereum (language: go)

Issue:
Beacon root contract in dev mode and private chains
[EIP-4788](https://eips.ethereum.org/EIPS/eip-4788) introduces a system contract which is deployed as a normal contract to the state. However it is required for networks which have the Cancun fork enabled. It is a bug when a dev chain or private chain with Cancun enabled is deployed and it is missing the beacon root contract.

For dev-mode, we should add the beacon root contract to the [genesis alloc](https://github.com/ethereum/go-ethereum/blob/3705acd1a97b2cc9bbb092b326a9d8cfbc42037a/core/genesis.go#L576). As for private chain, IMO the least we should do is refuse `geth init` in case Cancun is enabled and the genesis alloc is missing the beacon root code at the correct address.


Discussion / hints:
> For dev-mode, we should add the beacon root contract to the [genesis alloc](https://github.com/ethereum/go-ethereum/blob/3705acd1a97b2cc9bbb092b326a9d8cfbc42037a/core/genesis.go#L576).

I agree

> the least we should do is refuse geth init in case Cancun is enabled and the genesis alloc is missing the beacon root code at the correct address.

Why? 
If they want it: deploy it. If they don't fine, the system call will have zero side-effects. 
Sorry, I forgot there was still a task to do here (add the beacon root contract to the [genesis alloc](https://github.com/ethereum/go-ethereum/blob/3705acd1a97b2cc9bbb092b326a9d8cfbc42037a/core/genesis.go#L576).)
Hi @holiman can I work on this? 
WIP, The PR is finishing soon :)
> Hi @holiman can I work on this?



Fix patch:
diff --git a/core/genesis.go b/core/genesis.go
index f05e84199ae4..b4cd92171e99 100644
--- a/core/genesis.go
+++ b/core/genesis.go
@@ -593,6 +593,8 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
 			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
+			// Pre-deploy EIP-4788 system contract
+			params.BeaconRootsAddress: types.Account{Nonce: 1, Code: params.BeaconRootsCode},
 		},
 	}
 	if faucet != nil {
diff --git a/params/protocol_params.go b/params/protocol_params.go
index 863cf58ece46..0617f47001c7 100644
--- a/params/protocol_params.go
+++ b/params/protocol_params.go
@@ -186,6 +186,10 @@ var (
 
 	// BeaconRootsAddress is the address where historical beacon roots are stored as per EIP-4788
 	BeaconRootsAddress = common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02")
+
+	// BeaconRootsCode is the code where historical beacon roots are stored as per EIP-4788
+	BeaconRootsCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500")
+
 	// SystemAddress is where the system-transaction is sent from as per EIP-4788
 	SystemAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe")
 )


Test patch:
diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go
index a2ec9e6507d4..6241f3fb6960 100644
--- a/core/chain_makers_test.go
+++ b/core/chain_makers_test.go
@@ -43,12 +43,11 @@ func TestGeneratePOSChain(t *testing.T) {
 		bb      = common.Address{0xbb}
 		funds   = big.NewInt(0).Mul(big.NewInt(1337), big.NewInt(params.Ether))
 		config  = *params.AllEthashProtocolChanges
-		asm4788 = common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500")
 		gspec   = &Genesis{
 			Config: &config,
 			Alloc: types.GenesisAlloc{
 				address:                   {Balance: funds},
-				params.BeaconRootsAddress: {Balance: common.Big0, Code: asm4788},
+				params.BeaconRootsAddress: {Code: params.BeaconRootsCode},
 			},
 			BaseFee:    big.NewInt(params.InitialBaseFee),
 			Difficulty: common.Big1,