diff --git a/cmd/hivechain/generate.go b/cmd/hivechain/generate.go index ea1860eabe..27989ecb58 100644 --- a/cmd/hivechain/generate.go +++ b/cmd/hivechain/generate.go @@ -5,6 +5,7 @@ import ( "fmt" "math" "math/big" + "math/rand" "strings" "github.com/ethereum/go-ethereum/accounts" @@ -61,6 +62,7 @@ type generator struct { genesis *core.Genesis td *big.Int accounts []genAccount + rand *rand.Rand modlist []*modifierInstance modOffset int @@ -84,6 +86,7 @@ func newGenerator(cfg generatorConfig) *generator { return &generator{ cfg: cfg, genesis: genesis, + rand: rand.New(rand.NewSource(10)), td: new(big.Int).Set(genesis.Difficulty), modlist: cfg.createBlockModifiers(), accounts: slices.Clone(knownAccounts), @@ -166,6 +169,7 @@ func (g *generator) modifyBlock(i int, gen *core.BlockGen) { g.setClique(i, gen) } g.setDifficulty(i, gen) + g.setParentBeaconRoot(i, gen) g.runModifiers(i, gen) } @@ -200,6 +204,14 @@ func (g *generator) setDifficulty(i int, gen *core.BlockGen) { } } +func (g *generator) setParentBeaconRoot(i int, gen *core.BlockGen) { + if g.genesis.Config.IsCancun(gen.Number(), gen.Timestamp()) { + var h common.Hash + g.rand.Read(h[:]) + gen.SetParentBeaconRoot(h) + } +} + // runModifiers executes the chain modifiers. func (g *generator) runModifiers(i int, gen *core.BlockGen) { if len(g.modlist) == 0 || g.cfg.txInterval == 0 || i%g.cfg.txInterval != 0 { diff --git a/cmd/hivechain/genesis.go b/cmd/hivechain/genesis.go index c482280268..a036125eb1 100644 --- a/cmd/hivechain/genesis.go +++ b/cmd/hivechain/genesis.go @@ -6,6 +6,7 @@ import ( "math/big" "strings" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/params" @@ -163,6 +164,10 @@ func (cfg *generatorConfig) createGenesis() *core.Genesis { // dcc := hexutil.MustDecode("0x" + depositCode) // g.Alloc[dca] = core.GenesisAccount{Code: dcc} + // Deploy beacon roots storage contract (EIP-4788). + asm4788 := common.FromHex("0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500") + g.Alloc[params.BeaconRootsStorageAddress] = core.GenesisAccount{Code: asm4788, Balance: big.NewInt(42)} + return &g }