From 1a4420b88900fda59e5b03175f1c3c0b30112cb6 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Wed, 2 Oct 2024 16:29:41 +0200 Subject: [PATCH] feat: add support of BEP-440 --- consensus/misc/eip2935.go | 7 +++++++ core/blockchain.go | 10 +++++++++- params/protocol_params.go | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/consensus/misc/eip2935.go b/consensus/misc/eip2935.go index 460c95f4b39..cbf7fe6a22c 100644 --- a/consensus/misc/eip2935.go +++ b/consensus/misc/eip2935.go @@ -47,3 +47,10 @@ func storeHash(num uint64, hash libcommon.Hash, state *state.IntraBlockState) { parentHashInt := uint256.NewInt(0).SetBytes32(hash.Bytes()) state.SetState(params.HistoryStorageAddress, &storageSlot, *parentHashInt) } + +func InitializeBlockHashesEip2935(state *state.IntraBlockState) { + if state.GetCodeSize(params.HistoryStorageAddress) != 0 { + return + } + state.SetCode(params.HistoryStorageAddress, params.HistoryStorageCode) +} diff --git a/core/blockchain.go b/core/blockchain.go index b2c991cf8a5..a9f9d94b97a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -24,11 +24,12 @@ import ( "cmp" "encoding/json" "fmt" - "github.com/erigontech/erigon/core/systemcontracts" "reflect" "slices" "time" + "github.com/erigontech/erigon/core/systemcontracts" + "golang.org/x/crypto/sha3" "github.com/erigontech/erigon-lib/chain" @@ -39,6 +40,7 @@ import ( "github.com/erigontech/erigon/common/math" "github.com/erigontech/erigon/common/u256" "github.com/erigontech/erigon/consensus" + "github.com/erigontech/erigon/consensus/misc" "github.com/erigontech/erigon/core/state" "github.com/erigontech/erigon/core/tracing" "github.com/erigontech/erigon/core/types" @@ -510,6 +512,12 @@ func InitializeBlockExecution(engine consensus.Engine, chain consensus.ChainHead systemcontracts.UpgradeBuildInSystemContract(cc, header.Number, parent.Time, header.Time, ibs, logger) } + if cc.IsPrague(header.Time) { + //TODO: find better way to init? + misc.InitializeBlockHashesEip2935(ibs) + misc.StoreBlockHashesEip2935(header, ibs, cc, chain) + } + noop := state.NewNoopWriter() ibs.FinalizeTx(cc.Rules(header.Number.Uint64(), header.Time), noop) return nil diff --git a/params/protocol_params.go b/params/protocol_params.go index 8731bdde1e4..5f005d5f01d 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -221,6 +221,9 @@ var BeaconRootsAddress = common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522 // EIP-2935: Historical block hashes in state var HistoryStorageAddress = common.HexToAddress("0x0aae40965e6800cd9b1f4b05ff21581047e3f91e") +// HistoryStorageCode is the code with getters for historical block hashes. +var HistoryStorageCode = common.FromHex("3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500") + // EIP-7002: Execution layer triggerable withdrawals var WithdrawalRequestAddress = common.HexToAddress("0x00A3ca265EBcb825B45F985A16CEFB49958cE017")