Skip to content

Commit 53c85da

Browse files
eth/tracers: fix crasher in TraceCall with BlockOverrides (#33015)
fix #33014 --------- Co-authored-by: lightclient <[email protected]>
1 parent 0413af4 commit 53c85da

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

eth/tracers/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
959959

960960
// Apply the customization rules if required.
961961
if config != nil {
962-
if config.BlockOverrides != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 {
962+
if config.BlockOverrides != nil && config.BlockOverrides.Number != nil && config.BlockOverrides.Number.ToInt().Uint64() == h.Number.Uint64()+1 {
963963
// Overriding the block number to n+1 is a common way for wallets to
964964
// simulate transactions, however without the following fix, a contract
965965
// can assert it is being simulated by checking if blockhash(n) == 0x0 and

eth/tracers/api_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,20 @@ func TestTraceCall(t *testing.T) {
471471
{"pc":0,"op":"NUMBER","gas":24946984,"gasCost":2,"depth":1,"stack":[]},
472472
{"pc":1,"op":"STOP","gas":24946982,"gasCost":0,"depth":1,"stack":["0x1337"]}]}`,
473473
},
474+
// Tests issue #33014 where accessing nil block number override panics.
475+
{
476+
blockNumber: rpc.BlockNumber(0),
477+
call: ethapi.TransactionArgs{
478+
From: &accounts[0].addr,
479+
To: &accounts[1].addr,
480+
Value: (*hexutil.Big)(big.NewInt(1000)),
481+
},
482+
config: &TraceCallConfig{
483+
BlockOverrides: &override.BlockOverrides{},
484+
},
485+
expectErr: nil,
486+
expect: `{"gas":21000,"failed":false,"returnValue":"0x","structLogs":[]}`,
487+
},
474488
}
475489
for i, testspec := range testSuite {
476490
result, err := api.TraceCall(context.Background(), testspec.call, rpc.BlockNumberOrHash{BlockNumber: &testspec.blockNumber}, testspec.config)

0 commit comments

Comments
 (0)