@@ -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 {
8383type 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*.
130130func 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