Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support of BEP-440 #530

Open
wants to merge 3 commits into
base: prague-pascal
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need IsOnPrague. Suggest move the code logic to system contract upgrade. Just like other systemcontracts.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no IsOnPrague, but this is doing same - IsPrague returns whether time is either equal to the Prague fork time or greater. https://github.com/node-real/bsc-erigon/blob/bep-440/erigon-lib/chain/chain_config.go#L292

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