Skip to content

Commit

Permalink
cmd/hivechain: add 4788 contract to genesis and set beacon root post-…
Browse files Browse the repository at this point in the history
…cancun

Co-authored-by: Felix Lange <fjl@twurst.com>
  • Loading branch information
2 people authored and Eikix committed Mar 1, 2024
1 parent e5a1df0 commit 71e0529
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/hivechain/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"math/big"
"math/rand"
"strings"

"github.com/ethereum/go-ethereum/accounts"
Expand Down Expand Up @@ -61,6 +62,7 @@ type generator struct {
genesis *core.Genesis
td *big.Int
accounts []genAccount
rand *rand.Rand

modlist []*modifierInstance
modOffset int
Expand All @@ -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),
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/hivechain/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 71e0529

Please sign in to comment.