@@ -18,7 +18,6 @@ package native
1818
1919import (
2020 "encoding/json"
21- "errors"
2221 "math/big"
2322 "strconv"
2423 "strings"
@@ -60,21 +59,21 @@ type callTracer struct {
6059func newCallTracer (ctx * tracers.Context ) tracers.Tracer {
6160 // First callframe contains tx context info
6261 // and is populated on start and end.
63- t := & callTracer {callstack : make ([]callFrame , 1 )}
62+ t := & callTracer {callstack : make ([]callFrame , 0 , 1 )}
6463 return t
6564}
6665
6766// CaptureStart implements the EVMLogger interface to initialize the tracing operation.
6867func (t * callTracer ) CaptureStart (env * vm.EVM , from common.Address , to common.Address , create bool , input []byte , gas uint64 , value * big.Int , authorizationResults []types.AuthorizationResult ) {
6968 t .env = env
70- t .callstack [ 0 ] = callFrame {
69+ t .callstack = append ( t . callstack , callFrame {
7170 Type : "CALL" ,
7271 From : addrToHex (from ),
7372 To : addrToHex (to ),
7473 Input : bytesToHex (input ),
7574 Gas : uintToHex (gas ),
7675 Value : bigToHex (value ),
77- }
76+ })
7877 if create {
7978 t .callstack [0 ].Type = "CREATE"
8079 }
@@ -152,7 +151,10 @@ func (t *callTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
152151// error arising from the encoding or forceful termination (via `Stop`).
153152func (t * callTracer ) GetResult () (json.RawMessage , error ) {
154153 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
156158 }
157159 res , err := json .Marshal (t .callstack [0 ])
158160 if err != nil {
0 commit comments