@@ -58,6 +58,18 @@ func NewBaseGasDimensionTracer(chainConfig *params.ChainConfig) BaseGasDimension
58
58
refundAccumulated : 0 ,
59
59
prevAccessListAddresses : map [common.Address ]int {},
60
60
prevAccessListSlots : []map [common.Hash ]struct {}{},
61
+ env : nil ,
62
+ txHash : common.Hash {},
63
+ gasUsed : 0 ,
64
+ gasUsedForL1 : 0 ,
65
+ gasUsedForL2 : 0 ,
66
+ intrinsicGas : 0 ,
67
+ callStack : CallGasDimensionStack {},
68
+ executionGasAccumulated : 0 ,
69
+ refundAdjusted : 0 ,
70
+ err : nil ,
71
+ interrupt : atomic.Bool {},
72
+ reason : nil ,
61
73
}
62
74
}
63
75
@@ -96,7 +108,7 @@ func (t *BaseGasDimensionTracer) onOpcodeStart(
96
108
opcode vm.OpCode ,
97
109
) {
98
110
if t .interrupt .Load () {
99
- return true , GasesByDimension {} , nil , vm .OpCode (op )
111
+ return true , zeroGasesByDimension () , nil , vm .OpCode (op )
100
112
}
101
113
if depth != t .depth && depth != t .depth - 1 {
102
114
t .interrupt .Store (true )
@@ -107,7 +119,7 @@ func (t *BaseGasDimensionTracer) onOpcodeStart(
107
119
depth ,
108
120
t .callStack ,
109
121
)
110
- return true , GasesByDimension {} , nil , vm .OpCode (op )
122
+ return true , zeroGasesByDimension () , nil , vm .OpCode (op )
111
123
}
112
124
if t .depth != len (t .callStack )+ 1 {
113
125
t .interrupt .Store (true )
@@ -118,18 +130,18 @@ func (t *BaseGasDimensionTracer) onOpcodeStart(
118
130
len (t .callStack ),
119
131
t .callStack ,
120
132
)
121
- return true , GasesByDimension {} , nil , vm .OpCode (op )
133
+ return true , zeroGasesByDimension () , nil , vm .OpCode (op )
122
134
}
123
135
124
136
// get the gas dimension function
125
137
// if it's not a call, directly calculate the gas dimensions for the opcode
126
138
f := GetCalcGasDimensionFunc (vm .OpCode (op ))
127
- var fErr error = nil
139
+ var fErr error
128
140
gasesByDimension , callStackInfo , fErr = f (t , pc , op , gas , cost , scope , rData , depth , err )
129
141
if fErr != nil {
130
142
t .interrupt .Store (true )
131
143
t .reason = fErr
132
- return true , GasesByDimension {} , nil , vm .OpCode (op )
144
+ return true , zeroGasesByDimension () , nil , vm .OpCode (op )
133
145
}
134
146
opcode = vm .OpCode (op )
135
147
@@ -141,7 +153,7 @@ func (t *BaseGasDimensionTracer) onOpcodeStart(
141
153
opcode .String (),
142
154
callStackInfo ,
143
155
)
144
- return true , GasesByDimension {} , nil , vm .OpCode (op )
156
+ return true , zeroGasesByDimension () , nil , vm .OpCode (op )
145
157
}
146
158
return false , gasesByDimension , callStackInfo , opcode
147
159
}
@@ -181,7 +193,7 @@ func (t *BaseGasDimensionTracer) callFinishFunction(
181
193
if ! ok {
182
194
t .interrupt .Store (true )
183
195
t .reason = fmt .Errorf ("call stack is unexpectedly empty %d %d %d" , pc , depth , t .depth )
184
- return true , 0 , CallGasDimensionStackInfo {}, GasesByDimension {}
196
+ return true , 0 , zeroCallGasDimensionStackInfo (), zeroGasesByDimension ()
185
197
}
186
198
finishFunction := GetFinishCalcGasDimensionFunc (stackInfo .GasDimensionInfo .Op )
187
199
if finishFunction == nil {
@@ -191,18 +203,18 @@ func (t *BaseGasDimensionTracer) callFinishFunction(
191
203
stackInfo .GasDimensionInfo .Op .String (),
192
204
pc ,
193
205
)
194
- return true , 0 , CallGasDimensionStackInfo {}, GasesByDimension {}
206
+ return true , 0 , zeroCallGasDimensionStackInfo (), zeroGasesByDimension ()
195
207
}
196
208
// IMPORTANT NOTE: for some reason the only reliable way to actually get the gas cost of the call
197
209
// is to subtract gas at time of call from gas at opcode AFTER return
198
210
// you can't trust the `gas` field on the call itself. I wonder if the gas field is an estimation
199
211
gasUsedByCall = stackInfo .GasDimensionInfo .GasCounterAtTimeOfCall - gas
200
- var finishErr error = nil
212
+ var finishErr error
201
213
finishGasesByDimension , finishErr = finishFunction (gasUsedByCall , stackInfo .ExecutionCost , stackInfo .GasDimensionInfo )
202
214
if finishErr != nil {
203
215
t .interrupt .Store (true )
204
216
t .reason = finishErr
205
- return true , 0 , CallGasDimensionStackInfo {}, GasesByDimension {}
217
+ return true , 0 , zeroCallGasDimensionStackInfo (), zeroGasesByDimension ()
206
218
}
207
219
return false , gasUsedByCall , stackInfo , finishGasesByDimension
208
220
}
@@ -211,7 +223,7 @@ func (t *BaseGasDimensionTracer) callFinishFunction(
211
223
// then we need to track the execution gas
212
224
// of our own code so that when the call returns,
213
225
// we can write the gas dimensions for the call opcode itself
214
- func (t * BaseGasDimensionTracer ) updateExecutionCost (cost uint64 ) {
226
+ func (t * BaseGasDimensionTracer ) updateCallChildExecutionCost (cost uint64 ) {
215
227
if len (t .callStack ) > 0 {
216
228
t .callStack .UpdateExecutionCost (cost )
217
229
}
@@ -326,6 +338,43 @@ func (t *BaseGasDimensionTracer) adjustRefund(gasUsedByL2BeforeRefunds, refund u
326
338
return refundAdjusted
327
339
}
328
340
341
+ // zeroGasesByDimension returns a GasesByDimension struct with all fields set to zero
342
+ func zeroGasesByDimension () GasesByDimension {
343
+ return GasesByDimension {
344
+ OneDimensionalGasCost : 0 ,
345
+ Computation : 0 ,
346
+ StateAccess : 0 ,
347
+ StateGrowth : 0 ,
348
+ HistoryGrowth : 0 ,
349
+ StateGrowthRefund : 0 ,
350
+ ChildExecutionCost : 0 ,
351
+ }
352
+ }
353
+
354
+ // zeroCallGasDimensionInfo returns a CallGasDimensionInfo struct with all fields set to zero
355
+ func zeroCallGasDimensionInfo () CallGasDimensionInfo {
356
+ return CallGasDimensionInfo {
357
+ Pc : 0 ,
358
+ Op : 0 ,
359
+ GasCounterAtTimeOfCall : 0 ,
360
+ MemoryExpansionCost : 0 ,
361
+ AccessListComputationCost : 0 ,
362
+ AccessListStateAccessCost : 0 ,
363
+ IsValueSentWithCall : false ,
364
+ InitCodeCost : 0 ,
365
+ HashCost : 0 ,
366
+ }
367
+ }
368
+
369
+ // zeroCallGasDimensionStackInfo returns a CallGasDimensionStackInfo struct with all fields set to zero
370
+ func zeroCallGasDimensionStackInfo () CallGasDimensionStackInfo {
371
+ return CallGasDimensionStackInfo {
372
+ GasDimensionInfo : zeroCallGasDimensionInfo (),
373
+ ExecutionCost : 0 ,
374
+ DimensionLogPosition : 0 ,
375
+ }
376
+ }
377
+
329
378
// ############################################################################
330
379
// OUTPUTS
331
380
// ############################################################################
0 commit comments