From 746ae51ddd893d520977dde60028f48bea41a4f6 Mon Sep 17 00:00:00 2001 From: 0xbeny <55846654+0xbeny@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:28:32 +0000 Subject: [PATCH 1/7] core: support EIP-4788 Pre-deploy contract to dev environment --- core/genesis.go | 3 +++ params/protocol_params.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/core/genesis.go b/core/genesis.go index f05e84199ae4..ce2a26f3ae1c 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -595,6 +595,9 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis { common.BytesToAddress([]byte{9}): {Balance: big.NewInt(1)}, // BLAKE2b }, } + // Pre-deploy EIP-4788 system contract + genesis.Alloc[params.BeaconRootsAddress] = types.Account{Code: params.BeaconRootsCode} + if faucet != nil { genesis.Alloc[*faucet] = types.Account{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))} } diff --git a/params/protocol_params.go b/params/protocol_params.go index 863cf58ece46..55661c3750f9 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 = []byte("3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500") + // SystemAddress is where the system-transaction is sent from as per EIP-4788 SystemAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") ) From 25f8f81f6713c3f487e4c211e3b09c6888431cbf Mon Sep 17 00:00:00 2001 From: 0xbeny <55846654+0xbeny@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:38:29 +0000 Subject: [PATCH 2/7] core: refactor DeveloperGenesisBlock --- core/genesis.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index ce2a26f3ae1c..2184393b3d83 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -593,11 +593,10 @@ 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{Code: params.BeaconRootsCode}, }, } - // Pre-deploy EIP-4788 system contract - genesis.Alloc[params.BeaconRootsAddress] = types.Account{Code: params.BeaconRootsCode} - if faucet != nil { genesis.Alloc[*faucet] = types.Account{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))} } From 07ffbc0e9d4bfcd38680331c7d585df173619e02 Mon Sep 17 00:00:00 2001 From: 0xbeny <55846654+0xbeny@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:05:06 +0000 Subject: [PATCH 3/7] fix: read BeaconRootsCode by fromHex --- core/chain_makers_test.go | 2 +- params/protocol_params.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index a2ec9e6507d4..bfd8a145fe77 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -43,7 +43,7 @@ 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") + asm4788 = params.BeaconRootsCode gspec = &Genesis{ Config: &config, Alloc: types.GenesisAlloc{ diff --git a/params/protocol_params.go b/params/protocol_params.go index 55661c3750f9..9c3b49910c8c 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -188,7 +188,7 @@ var ( BeaconRootsAddress = common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02") // BeaconRootsCode is the code where historical beacon roots are stored as per EIP-4788 - BeaconRootsCode = []byte("3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500") + BeaconRootsCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500") // SystemAddress is where the system-transaction is sent from as per EIP-4788 SystemAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") From bd7834d5ee52e397aa89247e172d860f27ba1dfd Mon Sep 17 00:00:00 2001 From: 0xbeny <55846654+0xbeny@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:36:12 +0000 Subject: [PATCH 4/7] lint: remove white-space --- params/protocol_params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/protocol_params.go b/params/protocol_params.go index 9c3b49910c8c..0617f47001c7 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -189,7 +189,7 @@ var ( // 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") ) From 1400be4eb859044cc91db7be9b72d988993493a7 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 14 May 2024 14:35:53 +0200 Subject: [PATCH 5/7] Update chain_makers_test.go --- core/chain_makers_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index bfd8a145fe77..0bf9a10dafc8 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 = params.BeaconRootsCode gspec = &Genesis{ Config: &config, Alloc: types.GenesisAlloc{ address: {Balance: funds}, - params.BeaconRootsAddress: {Balance: common.Big0, Code: asm4788}, + params.BeaconRootsAddress: {Balance: common.Big0, Code: params.BeaconRootsCode}, }, BaseFee: big.NewInt(params.InitialBaseFee), Difficulty: common.Big1, From 8fc0781477b0316372b00b6adef9e74d2c872cfa Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 14 May 2024 14:36:40 +0200 Subject: [PATCH 6/7] Update chain_makers_test.go --- core/chain_makers_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index 0bf9a10dafc8..6241f3fb6960 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -47,7 +47,7 @@ func TestGeneratePOSChain(t *testing.T) { Config: &config, Alloc: types.GenesisAlloc{ address: {Balance: funds}, - params.BeaconRootsAddress: {Balance: common.Big0, Code: params.BeaconRootsCode}, + params.BeaconRootsAddress: {Code: params.BeaconRootsCode}, }, BaseFee: big.NewInt(params.InitialBaseFee), Difficulty: common.Big1, From 5b770d2b68ce484b1b5411df34d8cd88f03aff53 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 14 May 2024 14:37:25 +0200 Subject: [PATCH 7/7] Update genesis.go --- core/genesis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/genesis.go b/core/genesis.go index 2184393b3d83..b4cd92171e99 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -594,7 +594,7 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis { 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{Code: params.BeaconRootsCode}, + params.BeaconRootsAddress: types.Account{Nonce: 1, Code: params.BeaconRootsCode}, }, } if faucet != nil {