From a21c021b51bf7e238d01f52240512d564946c9da Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:09:51 +0100 Subject: [PATCH] add beacon block hash to the witness --- core/chain_makers.go | 2 +- core/state_processor.go | 14 ++++++++++---- miner/worker.go | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/chain_makers.go b/core/chain_makers.go index 13d7cb86c0..1656984558 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -102,7 +102,7 @@ func (b *BlockGen) SetParentBeaconRoot(root common.Hash) { blockContext = NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase) vmenv = vm.NewEVM(blockContext, vm.TxContext{}, b.statedb, b.cm.config, vm.Config{}) ) - ProcessBeaconBlockRoot(root, vmenv, b.statedb) + ProcessBeaconBlockRoot(root, vmenv, b.statedb, b.Number(), b.Timestamp()) } // addTx adds a transaction to the generated block. If no coinbase has diff --git a/core/state_processor.go b/core/state_processor.go index 7d69718c03..15b8703b6e 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -78,7 +78,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg signer = types.MakeSigner(p.config, header.Number, header.Time) ) if beaconRoot := block.BeaconRoot(); beaconRoot != nil { - ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb) + ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb, header.Number, header.Time) } // Iterate over and process the individual transactions for i, tx := range block.Transactions() { @@ -190,7 +190,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo // ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root // contract. This method is exported to be used in tests. -func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *state.StateDB) { +func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *state.StateDB, num *big.Int, time uint64) { // If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with // the new root msg := &Message{ @@ -202,8 +202,14 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat To: ¶ms.BeaconRootsAddress, Data: beaconRoot[:], } - vmenv.Reset(NewEVMTxContext(msg), statedb) - statedb.AddAddressToAccessList(params.BeaconRootsAddress) + txctx := NewEVMTxContext(msg) + vmenv.Reset(txctx, statedb) + if vmenv.ChainConfig().Rules(num, true, time).IsEIP2929 { + statedb.AddAddressToAccessList(params.BeaconRootsAddress) + } _, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560) + if vmenv.ChainConfig().Rules(num, true, time).IsEIP4762 { + statedb.Witness().Merge(txctx.Accesses) + } statedb.Finalise(true) } diff --git a/miner/worker.go b/miner/worker.go index 5dc3e2056b..a9c53ae7c1 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -198,7 +198,7 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error) if header.ParentBeaconRoot != nil { context := core.NewEVMBlockContext(header, miner.chain, nil) vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, miner.chainConfig, vm.Config{}) - core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state) + core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state, env.header.Number, env.header.Time) } return env, nil }