Repository: ethereum/go-ethereum (language: go)

Issue:
`insertChain` panics when struct tracer is set
When a tracer is set while calling "insertChain", the client panics. Doesn't seem like `OnTxStart` is called before `process`.

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x38 pc=0x10155f144]

goroutine 1 [running]:
github.com/ethereum/go-ethereum/eth/tracers/logger.(*StructLogger).OnOpcode(0x14000273290, 0x0, 0x33, 0x1c9c380, 0x2, {0x101ba1de0, 0x14000329b18}, {0x0, 0x0, 0x101506be4?}, ...)
        /Users/matt/dev/go-ethereum/eth/tracers/logger/logger.go:214 +0x644
github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run(0x140005d5440, 0x140000e69c0, {0x14000038340, 0x20, 0x20}, 0x0)
        /Users/matt/dev/go-ethereum/core/vm/interpreter.go:304 +0x8f0
github.com/ethereum/go-ethereum/core/vm.(*EVM).Call(0x140000f7900, {0x101b93640, 0x140004d8d68}, {0x0, 0xf, 0x3d, 0xf6, 0xd7, 0x32, 0x80, ...}, ...)
        /Users/matt/dev/go-ethereum/core/vm/evm.go:227 +0x780
github.com/ethereum/go-ethereum/core.ProcessBeaconBlockRoot({0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...}, ...)
        /Users/matt/dev/go-ethereum/core/state_processor.go:240 +0x240
github.com/ethereum/go-ethereum/core.(*StateProcessor).Process(0x140004d49e0, 0x1400040f680, 0x14000246f00, {0x140004e6a00, 0x0, 0x0, {0x0, 0x0, 0x0}, 0x0})
        /Users/matt/dev/go-ethereum/core/state_processor.go:80 +0x49c
github.com/ethereum/go-ethereum/core.(*BlockChain).processBlock(0x140000fa408, 0x1400040f680, 0x14000246f00, {0x0?, 0x101ba2438?, 0x1022ebd60?}, 0x1)
        /Users/matt/dev/go-ethereum/core/blockchain.go:1899 +0x220
github.com/ethereum/go-ethereum/core.(*BlockChain).insertChain(0x140000fa408, {0x1400038a9f8, 0x1, 0x1}, 0x1, 0x0)
        /Users/matt/dev/go-ethereum/core/blockchain.go:1818 +0x16ac
github.com/ethereum/go-ethereum/core.(*BlockChain).InsertChain(0x140000fa408, {0x1400038a9f8, 0x1, 0x1})
        /Users/matt/dev/go-ethereum/core/blockchain.go:1601 +0x908
github.com/ethereum/go-ethereum/tests.(*BlockTest).insertBlocks(0x101ba94a8?, 0x140000fa408)
        /Users/matt/dev/go-ethereum/tests/block_test_util.go:238 +0x21c
github.com/ethereum/go-ethereum/tests.(*BlockTest).Run(0x1400037c608, 0x0, {0x1016bf309, 0x4}, 0x0, 0x140004e6a00, 0x140004d1978)
        /Users/matt/dev/go-ethereum/tests/block_test_util.go:162 +0x478
main.blockTestCmd(0x140001fa900)
        /Users/matt/dev/go-ethereum/cmd/evm/blockrunner.go:84 +0x514
github.com/ethereum/go-ethereum/internal/flags.MigrateGlobalFlags.func2.1(0x140001fa900)
        /Users/matt/dev/go-ethereum/internal/flags/helpers.go:99 +0x38
github.com/urfave/cli/v2.(*Command).Run(0x10227f7a0, 0x140001fa900, {0x14000396320, 0x5, 0x5})
        /Users/matt/dev/go-workspace/pkg/mod/github.com/urfave/cli/v2@v2.25.7/command.go:274 +0x5e0
github.com/urfave/cli/v2.(*Command).Run(0x140003482c0, 0x140001fa300, {0x14000152000, 0x7, 0x7})
        /Users/matt/dev/go-workspace/pkg/mod/github.com/urfave/cli/v2@v2.25.7/command.go:267 +0x81c
github.com/urfave/cli/v2.(*App).RunContext(0x140001fc000, {0x101b9c6c0, 0x10231b3e0}, {0x14000152000, 0x7, 0x7})
        /Users/matt/dev/go-workspace/pkg/mod/github.com/urfave/cli/v2@v2.25.7/app.go:332 +0x4f8
github.com/urfave/cli/v2.(*App).Run(...)
        /Users/matt/dev/go-workspace/pkg/mod/github.com/urfave/cli/v2@v2.25.7/app.go:309
main.main()
        /Users/matt/dev/go-ethereum/cmd/evm/main.go:141 +0x4c
exit status 2
```


Discussion / hints:
cc @s1na 
Yeah the the pre-block processors get the non-wrapped statedb. here is the fix for that: https://github.com/ethereum/go-ethereum/pull/30441/commits/fbd1d19cdb136c9510fd5cf80302560b650e3e1c#diff-7ee5f952a6b64b5c8a5db54348910f6e901dcafce4afa172720c40713fe2e78bR80-R88

Fix patch:
diff --git a/core/state_processor.go b/core/state_processor.go
index ec499f892875..c04049e98645 100644
--- a/core/state_processor.go
+++ b/core/state_processor.go
@@ -77,11 +77,15 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
 	context = NewEVMBlockContext(header, p.chain, nil)
 
 	vmenv := vm.NewEVM(context, vm.TxContext{}, statedb, p.config, cfg)
+	var tracingStateDB = vm.StateDB(statedb)
+	if hooks := cfg.Tracer; hooks != nil {
+		tracingStateDB = state.NewHookedState(statedb, hooks)
+	}
 	if beaconRoot := block.BeaconRoot(); beaconRoot != nil {
-		ProcessBeaconBlockRoot(*beaconRoot, vmenv, statedb)
+		ProcessBeaconBlockRoot(*beaconRoot, vmenv, tracingStateDB)
 	}
 	if p.config.IsPrague(block.Number(), block.Time()) {
-		ProcessParentBlockHash(block.ParentHash(), vmenv, statedb)
+		ProcessParentBlockHash(block.ParentHash(), vmenv, tracingStateDB)
 	}
 
 	// Iterate over and process the individual transactions
@@ -99,10 +103,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
 		receipts = append(receipts, receipt)
 		allLogs = append(allLogs, receipt.Logs...)
 	}
-	var tracingStateDB = vm.StateDB(statedb)
-	if hooks := cfg.Tracer; hooks != nil {
-		tracingStateDB = state.NewHookedState(statedb, hooks)
-	}
 	// Read requests if Prague is enabled.
 	var requests [][]byte
 	if p.config.IsPrague(block.Number(), block.Time()) {


Test patch: