Skip to content

Commit

Permalink
feat: add support of BEP-440
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Oct 2, 2024
1 parent ea05ebd commit 1a4420b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions consensus/misc/eip2935.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 9 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 1a4420b

Please sign in to comment.