From 2667b3fb0c5a534b3f4e9ac9c6cb90063f8d79c8 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 22 Jan 2026 13:53:48 +0800 Subject: [PATCH] core/vm: fix lint, check leftover gas before stateful check --- core/vm/gas_table.go | 7 ++++++- core/vm/operations_acl.go | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index a067f38e6a..88490c76c5 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -19,6 +19,7 @@ package vm import ( "errors" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/params" @@ -420,7 +421,11 @@ func gasCallIntrinsic(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m if gas, overflow = math.SafeAdd(memoryGas, transferGas); overflow { return 0, ErrGasUintOverflow } - + // Terminate the gas measurement if the leftover gas is not sufficient, + // it can effectively prevent accessing the states in the following steps. + if contract.Gas < gas { + return 0, ErrOutOfGas + } // Stateful check var stateGas uint64 if evm.chainRules.IsEIP158 { diff --git a/core/vm/operations_acl.go b/core/vm/operations_acl.go index 0bd8ec2d9d..addd2b162f 100644 --- a/core/vm/operations_acl.go +++ b/core/vm/operations_acl.go @@ -308,7 +308,8 @@ func makeCallVariantGasCallEIP7702(intrinsicFunc gasFunc) gasFunc { return 0, err } // Terminate the gas measurement if the leftover gas is not sufficient, - // it can effectively prevent accessing the states in the following steps + // it can effectively prevent accessing the states in the following steps. + // It's an essential safeguard before any stateful check. if contract.Gas < intrinsicCost { return 0, ErrOutOfGas } @@ -325,7 +326,8 @@ func makeCallVariantGasCallEIP7702(intrinsicFunc gasFunc) gasFunc { return 0, ErrOutOfGas } } - + // 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, intrinsicCost, stack.Back(0)) if err != nil { return 0, err