core/vm: polish

This commit is contained in:
Gary Rong 2026-07-03 16:33:18 +08:00
parent 361c909667
commit a25d64a837

View file

@ -400,7 +400,7 @@ func makeCallVariantGasCallEIP7702(intrinsicFunc intrinsicGasFunc, coldCost uint
// Terminate the gas measurement if the leftover gas is not sufficient,
// it can effectively prevent accessing the states in the following steps.
// It's an essential safeguard before any stateful check.
if contract.Gas.RegularGas < intrinsicCost {
if !contract.chargeRegular(intrinsicCost, evm.Config.Tracer, tracing.GasChangeIgnored) {
return GasCosts{}, ErrOutOfGas
}
@ -415,9 +415,6 @@ func makeCallVariantGasCallEIP7702(intrinsicFunc intrinsicGasFunc, coldCost uint
if !contract.chargeRegular(eip7702Cost, evm.Config.Tracer, tracing.GasChangeCallStorageColdAccess) {
return GasCosts{}, ErrOutOfGas
}
if contract.Gas.RegularGas < intrinsicCost {
return GasCosts{}, ErrOutOfGas
}
// The delegated address has passed its gas check; record it in the
// block access list now, before the call's sender-balance and
// call-stack-depth checks.
@ -425,7 +422,7 @@ func makeCallVariantGasCallEIP7702(intrinsicFunc intrinsicGasFunc, coldCost uint
}
// Calculate the gas budget for the nested call. The costs defined by
// EIP-2929 and EIP-7702 have already been applied.
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas.RegularGas, intrinsicCost, stack.back(0))
evm.callGasTemp, err = callGas(evm.chainRules.IsEIP150, contract.Gas.RegularGas, 0, stack.back(0))
if err != nil {
return GasCosts{}, err
}
@ -433,11 +430,13 @@ func makeCallVariantGasCallEIP7702(intrinsicFunc intrinsicGasFunc, coldCost uint
// adding it to the return, it will be charged outside of this function, as
// part of the dynamic gas. This will ensure it is correctly reported to
// tracers.
contract.Gas.RegularGas += eip2929Cost + eip7702Cost
contract.Gas.RegularGas += eip2929Cost + eip7702Cost + intrinsicCost
// Undo the RegularGasUsed increments from the direct UseGas charges,
// since this gas will be re-charged via the returned cost.
contract.Gas.UsedRegularGas -= eip2929Cost
contract.Gas.UsedRegularGas -= eip7702Cost
contract.Gas.UsedRegularGas -= intrinsicCost
// Aggregate the gas costs from all components, including EIP-2929, EIP-7702,
// the CALL opcode itself, and the cost incurred by nested calls.