From a0e75ee7d771b35b4980285846d20ac10155b369 Mon Sep 17 00:00:00 2001 From: Charles Billette Date: Wed, 15 May 2024 10:28:34 -0400 Subject: [PATCH] fix ProcessBeaconBlockRoot tracing --- core/state_processor.go | 7 +++++++ core/tracing/hooks.go | 31 +++++++++++++++++++++++++------ eth/tracers/firehose.go | 16 +++++++++------- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index 46820d3681de..7c7b34189f13 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -211,6 +211,13 @@ 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) { + if vmenv.Config.Tracer != nil && vmenv.Config.Tracer.OnSystemCallStart != nil { + vmenv.Config.Tracer.OnSystemCallStart() + } + if vmenv.Config.Tracer != nil && vmenv.Config.Tracer.OnSystemCallEnd != nil { + defer vmenv.Config.Tracer.OnSystemCallEnd() + } + // If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with // the new root msg := &Message{ diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 31a21e20b7e5..4902ff8644b1 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -125,6 +125,22 @@ type ( // GenesisBlockHook is called when the genesis block is being processed. GenesisBlockHook = func(genesis *types.Block, alloc types.GenesisAlloc) + // OnSystemCallStartHook is called when a system call is about to be executed. Today, + // this hook is invoked when the EIP-4788 system call is about to be executed to set the + // beacon block root. + // + // After this hook, the EVM call tracing will happened as usual so you will receive a `OnEnter/OnExit` + // as well as state hooks between this hook and the `OnSystemCallEndHook`. + // + // Note that system call happens outside normal transaction execution, so the `OnTxStart/OnTxEnd` hooks + // will not be invoked. + OnSystemCallStartHook = func() + + // OnSystemCallEndHook is called when a system call has finished executing. Today, + // this hook is invoked when the EIP-4788 system call is about to be executed to set the + // beacon block root. + OnSystemCallEndHook = func() + /* - State events - */ @@ -155,12 +171,15 @@ type Hooks struct { OnFault FaultHook OnGasChange GasChangeHook // Chain events - OnBlockchainInit BlockchainInitHook - OnClose CloseHook - OnBlockStart BlockStartHook - OnBlockEnd BlockEndHook - OnSkippedBlock SkippedBlockHook - OnGenesisBlock GenesisBlockHook + OnBlockchainInit BlockchainInitHook + OnClose CloseHook + OnBlockStart BlockStartHook + OnBlockEnd BlockEndHook + OnSkippedBlock SkippedBlockHook + OnGenesisBlock GenesisBlockHook + OnSystemCallStart OnSystemCallStartHook + OnSystemCallEnd OnSystemCallEndHook + // State events OnBalanceChange BalanceChangeHook OnNonceChange NonceChangeHook diff --git a/eth/tracers/firehose.go b/eth/tracers/firehose.go index 86798b2beaab..a4e92bf591c5 100644 --- a/eth/tracers/firehose.go +++ b/eth/tracers/firehose.go @@ -97,12 +97,14 @@ func NewTracingHooksFromFirehose(tracer *Firehose) *tracing.Hooks { OnOpcode: tracer.OnOpcode, OnFault: tracer.OnOpcodeFault, - OnBalanceChange: tracer.OnBalanceChange, - OnNonceChange: tracer.OnNonceChange, - OnCodeChange: tracer.OnCodeChange, - OnStorageChange: tracer.OnStorageChange, - OnGasChange: tracer.OnGasChange, - OnLog: tracer.OnLog, + OnBalanceChange: tracer.OnBalanceChange, + OnNonceChange: tracer.OnNonceChange, + OnCodeChange: tracer.OnCodeChange, + OnStorageChange: tracer.OnStorageChange, + OnGasChange: tracer.OnGasChange, + OnLog: tracer.OnLog, + OnSystemCallStart: tracer.OnBeaconBlockRootStart, + OnSystemCallEnd: tracer.OnBeaconBlockRootEnd, // This should actually be conditional but it's not possible to do it in the hooks // directly because the chain ID will be known only after the `OnBlockchainInit` call. @@ -514,7 +516,7 @@ func (f *Firehose) reorderCallOrdinals(call *pbeth.Call, ordinalBase uint64) (or return call.EndOrdinal } -func (f *Firehose) OnBeaconBlockRootStart(root common.Hash) { +func (f *Firehose) OnBeaconBlockRootStart() { firehoseInfo("system call start (for=%s)", "beacon_block_root") f.ensureInBlockAndNotInTrx()