Skip to content

Commit

Permalink
add beacon block hash to the witness
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Mar 27, 2024
1 parent d69fbc2 commit d4019ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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{
Expand All @@ -202,8 +202,14 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat
To: &params.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)
}
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d4019ed

Please sign in to comment.