From 4b4980d949d33c2efa60866dd715ade32d89469c Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Thu, 17 Jul 2025 17:54:23 +0800 Subject: [PATCH] core/vm: set basefee to 0 internally on eth_call #28470 (#1238) --- core/state_transition.go | 4 +++- core/vm/evm.go | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 3c829f7983..854ce14cec 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -271,10 +271,12 @@ func (st *StateTransition) preCheck() error { msg.From().Hex(), codeHash) } } + // Make sure that transaction gasFeeCap is greater than the baseFee (post london) if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) { // Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call) - if !st.evm.Config.NoBaseFee || st.gasFeeCap.BitLen() > 0 || st.gasTipCap.BitLen() > 0 { + skipCheck := st.evm.Config.NoBaseFee && st.gasFeeCap.BitLen() == 0 && st.gasTipCap.BitLen() == 0 + if !skipCheck { if l := st.gasFeeCap.BitLen(); l > 256 { return fmt.Errorf("%w: address %v, maxFeePerGas bit length: %d", ErrFeeCapVeryHigh, msg.From().Hex(), l) diff --git a/core/vm/evm.go b/core/vm/evm.go index e5461e7b8e..1b1283dba0 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -74,7 +74,7 @@ type BlockContext struct { BlockNumber *big.Int // Provides information for NUMBER Time *big.Int // Provides information for TIME Difficulty *big.Int // Provides information for DIFFICULTY - BaseFee *big.Int // Provides information for BASEFEE + BaseFee *big.Int // Provides information for BASEFEE (0 if vm runs with NoBaseFee flag and 0 gas price) Random *common.Hash // Provides information for PREVRANDAO } @@ -83,7 +83,7 @@ type BlockContext struct { type TxContext struct { // Message information Origin common.Address // Provides information for ORIGIN - GasPrice *big.Int // Provides information for GASPRICE + GasPrice *big.Int // Provides information for GASPRICE (and is used to zero the basefee if NoBaseFee is set) } // EVM is the Ethereum Virtual Machine base object and provides @@ -128,6 +128,14 @@ type EVM struct { // NewEVM returns a new EVM. The returned EVM is not thread safe and should // only ever be used *once*. func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, tradingStateDB *tradingstate.TradingStateDB, chainConfig *params.ChainConfig, config Config) *EVM { + // If basefee tracking is disabled (eth_call, eth_estimateGas, etc), and no + // gas prices were specified, lower the basefee to 0 to avoid breaking EVM + // invariants (basefee < feecap) + if config.NoBaseFee { + if txCtx.GasPrice.BitLen() == 0 { + blockCtx.BaseFee = new(big.Int) + } + } evm := &EVM{ Context: blockCtx, TxContext: txCtx, @@ -165,12 +173,6 @@ func (evm *EVM) Interpreter() *EVMInterpreter { return evm.interpreter } -// SetBlockContext updates the block context of the EVM. -func (evm *EVM) SetBlockContext(blockCtx BlockContext) { - evm.Context = blockCtx - evm.chainRules = evm.chainConfig.Rules(blockCtx.BlockNumber) -} - // Call executes the contract associated with the addr with the given input as // parameters. It also handles any necessary value transfer required and takes // the necessary steps to create accounts and reverses the state in case of an