@@ -36,6 +36,11 @@ type BaseGasDimensionTracer struct {
36
36
prevAccessListSlots []map [common.Hash ]struct {}
37
37
// the amount of refund accumulated at the current step of execution
38
38
refundAccumulated uint64
39
+ // in order to calculate the refund adjusted, we need to know the total execution gas
40
+ // of just the opcodes of the transaction with no refunds
41
+ executionGasAccumulated uint64
42
+ // the amount of refund allowed at the end of the transaction, adjusted by EIP-3529
43
+ refundAdjusted uint64
39
44
// whether the transaction had an error, like out of gas
40
45
err error
41
46
// whether the tracer itself was interrupted
@@ -254,6 +259,7 @@ func (t *BaseGasDimensionTracer) OnTxEnd(receipt *types.Receipt, err error) {
254
259
t .gasUsedForL1 = receipt .GasUsedForL1
255
260
t .gasUsedForL2 = receipt .GasUsedForL2 ()
256
261
t .txHash = receipt .TxHash
262
+ t .refundAdjusted = t .adjustRefund (t .executionGasAccumulated + t .intrinsicGas , t .GetRefundAccumulated ())
257
263
}
258
264
259
265
// Stop signals the tracer to stop tracing
@@ -300,6 +306,26 @@ func (t *BaseGasDimensionTracer) GetPrevAccessList() (addresses map[common.Addre
300
306
// Error returns the VM error captured by the trace
301
307
func (t * BaseGasDimensionTracer ) Error () error { return t .err }
302
308
309
+ // Add to the execution gas accumulated, for tracking adjusted refund
310
+ func (t * BaseGasDimensionTracer ) AddToExecutionGasAccumulated (gas uint64 ) {
311
+ t .executionGasAccumulated += gas
312
+ }
313
+
314
+ // this function implements the EIP-3529 refund adjustment
315
+ // this is a copy of the logic in the state transition function
316
+ func (t * BaseGasDimensionTracer ) adjustRefund (gasUsedByL2BeforeRefunds , refund uint64 ) uint64 {
317
+ var refundAdjusted uint64
318
+ if ! t .chainConfig .IsLondon (t .env .BlockNumber ) {
319
+ refundAdjusted = gasUsedByL2BeforeRefunds / params .RefundQuotient
320
+ } else {
321
+ refundAdjusted = gasUsedByL2BeforeRefunds / params .RefundQuotientEIP3529
322
+ }
323
+ if refundAdjusted > refund {
324
+ return refund
325
+ }
326
+ return refundAdjusted
327
+ }
328
+
303
329
// ############################################################################
304
330
// OUTPUTS
305
331
// ############################################################################
@@ -310,6 +336,7 @@ type BaseExecutionResult struct {
310
336
GasUsedForL1 uint64 `json:"gasUsedForL1"`
311
337
GasUsedForL2 uint64 `json:"gasUsedForL2"`
312
338
IntrinsicGas uint64 `json:"intrinsicGas"`
339
+ AdjustedRefund uint64 `json:"adjustedRefund"`
313
340
Failed bool `json:"failed"`
314
341
TxHash string `json:"txHash"`
315
342
BlockTimestamp uint64 `json:"blockTimestamp"`
@@ -329,6 +356,7 @@ func (t *BaseGasDimensionTracer) GetBaseExecutionResult() (BaseExecutionResult,
329
356
GasUsedForL1 : t .gasUsedForL1 ,
330
357
GasUsedForL2 : t .gasUsedForL2 ,
331
358
IntrinsicGas : t .intrinsicGas ,
359
+ AdjustedRefund : t .refundAdjusted ,
332
360
Failed : failed ,
333
361
TxHash : t .txHash .Hex (),
334
362
BlockTimestamp : t .env .Time ,
0 commit comments