@@ -18,7 +18,6 @@ package native
18
18
19
19
import (
20
20
"encoding/json"
21
- "errors"
22
21
"math/big"
23
22
"strconv"
24
23
"strings"
@@ -60,21 +59,21 @@ type callTracer struct {
60
59
func newCallTracer (ctx * tracers.Context ) tracers.Tracer {
61
60
// First callframe contains tx context info
62
61
// and is populated on start and end.
63
- t := & callTracer {callstack : make ([]callFrame , 1 )}
62
+ t := & callTracer {callstack : make ([]callFrame , 0 , 1 )}
64
63
return t
65
64
}
66
65
67
66
// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
68
67
func (t * callTracer ) CaptureStart (env * vm.EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int , authorizationResults []types.AuthorizationResult ) {
69
68
t .env = env
70
- t .callstack [ 0 ] = callFrame {
69
+ t .callstack = append ( t . callstack , callFrame {
71
70
Type : "CALL" ,
72
71
From : addrToHex (from ),
73
72
To : addrToHex (to ),
74
73
Input : bytesToHex (input ),
75
74
Gas : uintToHex (gas ),
76
75
Value : bigToHex (value ),
77
- }
76
+ })
78
77
if create {
79
78
t .callstack [0 ].Type = "CREATE"
80
79
}
@@ -152,7 +151,10 @@ func (t *callTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
152
151
// error arising from the encoding or forceful termination (via `Stop`).
153
152
func (t * callTracer ) GetResult () (json.RawMessage , error ) {
154
153
if len (t .callstack ) != 1 {
155
- return nil , errors .New ("incorrect number of top-level calls" )
154
+ // If the callstack is empty, return an empty JSON object instead of erroring
155
+ // Callstack can be empty due to an edge case where an L1 message is reverted even
156
+ // before entering the first call.
157
+ return json .RawMessage ("{}" ), nil
156
158
}
157
159
res , err := json .Marshal (t .callstack [0 ])
158
160
if err != nil {
0 commit comments