Repository: ethereum/go-ethereum (Go)

Issue:
Geth on Linea network crashes with `debug_traceCall` request
#### System information

Geth version: `geth version`
v1.16.5

CL client & version: e.g. lighthouse/nimbus/prysm@v1.0.0
maru-bcfdb43

OS & Version: Windows/Linux/OSX
ubuntu 22.04
Commit hash : (if `develop`)

#### Expected behaviour

Valid response

#### Actual behaviour
`
{"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"method handler crashed"}}`

#### Steps to reproduce the behaviour
method
```
curl -X POST https://<endpoint> \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "debug_traceCall",
    "params": [
      {
        "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb5",
        "to": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
        "gas": "0x30d40",
        "gasPrice": "0x3b9aca00",
        "value": "0x0",
        "data": "0x70a08231000000000000000000000000742d35cc6634c0532925a3b844bc9e7595f0beb5"
      },
      "latest",
      {
      "tracer": "callTracer",
      "tracerConfig": {
        "onlyTopCall": false,
        "withLog": true
      },
      "blockOverrides": {
        "baseFee": "0x0",
        "gasLimit": "0xffffffffffffffff"
      }
    }    ],
    "id": 1
  }'
```

#### Backtrace

````
[backtrace]

Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: ERROR[10-24|11:02:04.389] RPC method debug_traceCall crashed: runtime error: invalid memory address or nil pointer dereference
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: goroutine 18527191 [running]:
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*callback).call.func1()
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/service.go:199 +0x85
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: panic({0x19a15a0?, 0x30d3610?})
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         runtime/panic.go:783 +0x132
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: math/big.(*Int).Uint64(...)
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         math/big/int.go:440
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/eth/tracers.(*API).TraceCall(0xc0c073cd00, {0x226def8, _}, {0xc1843fa690, 0x0, 0xc143f13da0, 0xc0c8eddbc0, 0x0, 0x0, 0x0, ...}, ...)
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/eth/tracers/api.go:962 +0x4d9
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: reflect.Value.call({0xc0c2c0d570?, 0xc0c20e5c80?, 0xc126db1ba8?}, {0x1c6dd1e, 0x4}, {0xc0a8507c80, 0x5, 0x8?})
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         reflect/value.go:581 +0xcc6
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: reflect.Value.Call({0xc0c2c0d570?, 0xc0c20e5c80?, 0x20?}, {0xc0a8507c80?, 0xc13501ec30?, 0xc0f9655f68?})
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         reflect/value.go:365 +0xb9
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*callback).call(0xc0c33131a0, {0x226def8, 0xc13501ebe0}, {0xc143f13d60, 0xf}, {0xc13501ec30, 0x3, 0x4fb3d3?})
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/service.go:205 +0x2fd
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*handler).runMethod(0xc07d0aa580?, {0x226def8?, 0xc13501ebe0?}, 0xc152889500, 0x3?, {0xc13501ec30?, 0x17?, 0x18f1f20?})
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/handler.go:577 +0x3c
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*handler).handleCall(0xc142dfa000, 0xc12cb90600, 0xc152889500)
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/handler.go:519 +0x357
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*handler).handleCallMsg(0xc142dfa000, 0xc12cb90600, 0xc152889500)
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/handler.go:473 +0x22d
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*handler).handleNonBatchCall(0xc142dfa000, 0xc12cb90600, 0xc152889500)
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/handler.go:299 +0x185
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*handler).handleMsg.func1.1(0x226def8?)
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/handler.go:272 +0x25
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: github.com/ethereum/go-ethereum/rpc.(*handler).startCallProc.func1()
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/handler.go:390 +0xbb
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]: created by github.com/ethereum/go-ethereum/rpc.(*handler).startCallProc in goroutine 18523914
Oct 24 11:02:04 juju-c5fc64-0 geth[956155]:         github.com/ethereum/go-ethereum/rpc/handler.go:386 +0x76

````

When submitting logs: please submit them as text and not screenshots.



Discussion:

Patch:
diff --git a/eth/tracers/api.go b/eth/tracers/api.go
index aebeb484635..5cfbc24b8e3 100644
--- a/eth/tracers/api.go
+++ b/eth/tracers/api.go
@@ -959,7 +959,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
 
 	// Apply the customization rules if required.
 	if config != nil {
-		if config.BlockOverrides != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 {
+		if config.BlockOverrides != nil && config.BlockOverrides.Number != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 {
 			// Overriding the block number to n+1 is a common way for wallets to
 			// simulate transactions, however without the following fix, a contract
 			// can assert it is being simulated by checking if blockhash(n) == 0x0 and


Test patch:
diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go
index 4173d2a7915..609c3f4d8b3 100644
--- a/eth/tracers/api_test.go
+++ b/eth/tracers/api_test.go
@@ -471,6 +471,20 @@ func TestTraceCall(t *testing.T) {
 		{"pc":0,"op":"NUMBER","gas":24946984,"gasCost":2,"depth":1,"stack":[]},
 		{"pc":1,"op":"STOP","gas":24946982,"gasCost":0,"depth":1,"stack":["0x1337"]}]}`,
 		},
+		// Tests issue #33014 where accessing nil block number override panics.
+		{
+			blockNumber: rpc.BlockNumber(0),
+			call: ethapi.TransactionArgs{
+				From:  &accounts[0].addr,
+				To:    &accounts[1].addr,
+				Value: (*hexutil.Big)(big.NewInt(1000)),
+			},
+			config: &TraceCallConfig{
+				BlockOverrides: &override.BlockOverrides{},
+			},
+			expectErr: nil,
+			expect:    `{"gas":21000,"failed":false,"returnValue":"0x","structLogs":[]}`,
+		},
 	}
 	for i, testspec := range testSuite {
 		result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config)