Skip to content

Commit 4b4980d

Browse files
authored
core/vm: set basefee to 0 internally on eth_call ethereum#28470 (#1238)
1 parent dc01dba commit 4b4980d

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

core/state_transition.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,12 @@ func (st *StateTransition) preCheck() error {
271271
msg.From().Hex(), codeHash)
272272
}
273273
}
274+
274275
// Make sure that transaction gasFeeCap is greater than the baseFee (post london)
275276
if st.evm.ChainConfig().IsEIP1559(st.evm.Context.BlockNumber) {
276277
// Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call)
277-
if !st.evm.Config.NoBaseFee || st.gasFeeCap.BitLen() > 0 || st.gasTipCap.BitLen() > 0 {
278+
skipCheck := st.evm.Config.NoBaseFee && st.gasFeeCap.BitLen() == 0 && st.gasTipCap.BitLen() == 0
279+
if !skipCheck {
278280
if l := st.gasFeeCap.BitLen(); l > 256 {
279281
return fmt.Errorf("%w: address %v, maxFeePerGas bit length: %d", ErrFeeCapVeryHigh,
280282
msg.From().Hex(), l)

core/vm/evm.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type BlockContext struct {
7474
BlockNumber *big.Int // Provides information for NUMBER
7575
Time *big.Int // Provides information for TIME
7676
Difficulty *big.Int // Provides information for DIFFICULTY
77-
BaseFee *big.Int // Provides information for BASEFEE
77+
BaseFee *big.Int // Provides information for BASEFEE (0 if vm runs with NoBaseFee flag and 0 gas price)
7878
Random *common.Hash // Provides information for PREVRANDAO
7979
}
8080

@@ -83,7 +83,7 @@ type BlockContext struct {
8383
type TxContext struct {
8484
// Message information
8585
Origin common.Address // Provides information for ORIGIN
86-
GasPrice *big.Int // Provides information for GASPRICE
86+
GasPrice *big.Int // Provides information for GASPRICE (and is used to zero the basefee if NoBaseFee is set)
8787
}
8888

8989
// EVM is the Ethereum Virtual Machine base object and provides
@@ -128,6 +128,14 @@ type EVM struct {
128128
// NewEVM returns a new EVM. The returned EVM is not thread safe and should
129129
// only ever be used *once*.
130130
func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, tradingStateDB *tradingstate.TradingStateDB, chainConfig *params.ChainConfig, config Config) *EVM {
131+
// If basefee tracking is disabled (eth_call, eth_estimateGas, etc), and no
132+
// gas prices were specified, lower the basefee to 0 to avoid breaking EVM
133+
// invariants (basefee < feecap)
134+
if config.NoBaseFee {
135+
if txCtx.GasPrice.BitLen() == 0 {
136+
blockCtx.BaseFee = new(big.Int)
137+
}
138+
}
131139
evm := &EVM{
132140
Context: blockCtx,
133141
TxContext: txCtx,
@@ -165,12 +173,6 @@ func (evm *EVM) Interpreter() *EVMInterpreter {
165173
return evm.interpreter
166174
}
167175

168-
// SetBlockContext updates the block context of the EVM.
169-
func (evm *EVM) SetBlockContext(blockCtx BlockContext) {
170-
evm.Context = blockCtx
171-
evm.chainRules = evm.chainConfig.Rules(blockCtx.BlockNumber)
172-
}
173-
174176
// Call executes the contract associated with the addr with the given input as
175177
// parameters. It also handles any necessary value transfer required and takes
176178
// the necessary steps to create accounts and reverses the state in case of an

0 commit comments

Comments
 (0)