@@ -33,7 +33,8 @@ import (
3333// ExecutionResult includes all output after executing given evm
3434// message no matter the execution itself is successful or not.
3535type ExecutionResult struct {
36- UsedGas uint64 // Total used gas but include the refunded gas
36+ UsedGas uint64 // Total used gas, refunded gas is deducted
37+ MaxUsedGas uint64 // Maximum gas consumed during execution, excluding gas refunds.
3738 Err error // Any error encountered during the execution(listed in core/vm/errors.go)
3839 ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
3940}
@@ -478,9 +479,13 @@ func (st *stateTransition) execute(owner common.Address) (*ExecutionResult, erro
478479 ret , st .gasRemaining , vmerr = st .evm .Call (msg .From , st .to (), msg .Data , st .gasRemaining , value )
479480 }
480481
482+ // Record the gas used excluding gas refunds. This value represents the actual
483+ // gas allowance required to complete execution.
484+ peakGasUsed := st .gasUsed ()
485+
481486 // Compute refund counter, capped to a refund quotient.
482- gasRefund : = st .calcRefund ()
483- st . gasRemaining += gasRefund
487+ st . gasRemaining + = st .calcRefund ()
488+
484489 if rules .IsPrague {
485490 // After EIP-7623: Data-heavy transactions pay the floor gas.
486491 if st .gasUsed () < floorDataGas {
@@ -490,6 +495,9 @@ func (st *stateTransition) execute(owner common.Address) (*ExecutionResult, erro
490495 t .OnGasChange (prev , st .gasRemaining , tracing .GasChangeTxDataFloor )
491496 }
492497 }
498+ if peakGasUsed < floorDataGas {
499+ peakGasUsed = floorDataGas
500+ }
493501 }
494502 st .returnGas ()
495503
@@ -514,6 +522,7 @@ func (st *stateTransition) execute(owner common.Address) (*ExecutionResult, erro
514522
515523 return & ExecutionResult {
516524 UsedGas : st .gasUsed (),
525+ MaxUsedGas : peakGasUsed ,
517526 Err : vmerr ,
518527 ReturnData : ret ,
519528 }, nil
0 commit comments