From 4b0278bd69b31db9ad1f548b7babea06331e13c5 Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Sun, 5 Jul 2026 10:32:54 +0800 Subject: [PATCH] core/vm/runtime: cap regular gas budget at MaxTxGas for Amsterdam Apply the Amsterdam gas budget split in runtime.Execute so regular gas is limited to MaxTxGas and the remainder is charged as inflation gas. --- core/vm/runtime/runtime.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 9a15f7ac96..8dfa0fb740 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -143,12 +143,16 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) { cfg.State.CreateAccount(address) // set the receiver's (the executing contract) code for execution. cfg.State.SetCode(address, code, tracing.CodeChangeUnspecified) + limit := cfg.GasLimit + if rules.IsAmsterdam { + limit = min(cfg.GasLimit, params.MaxTxGas) + } // Call the code with the given configuration. ret, result, err := vmenv.Call( cfg.Origin, common.BytesToAddress([]byte("contract")), input, - vm.NewGasBudget(cfg.GasLimit, 0), + vm.NewGasBudget(limit, cfg.GasLimit-limit), uint256.MustFromBig(cfg.Value), ) if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil { @@ -178,11 +182,15 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) { // - prepare accessList(post-berlin) // - reset transient storage(eip 1153) cfg.State.Prepare(rules, cfg.Origin, cfg.Coinbase, nil, vm.ActivePrecompiles(rules), nil) + limit := cfg.GasLimit + if rules.IsAmsterdam { + limit = min(cfg.GasLimit, params.MaxTxGas) + } // Call the code with the given configuration. code, address, result, _, err := vmenv.Create( cfg.Origin, input, - vm.NewGasBudget(cfg.GasLimit, 0), + vm.NewGasBudget(limit, cfg.GasLimit-limit), uint256.MustFromBig(cfg.Value), ) if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil { @@ -212,12 +220,16 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er // - reset transient storage(eip 1153) statedb.Prepare(rules, cfg.Origin, cfg.Coinbase, &address, vm.ActivePrecompiles(rules), nil) + limit := cfg.GasLimit + if rules.IsAmsterdam { + limit = min(cfg.GasLimit, params.MaxTxGas) + } // Call the code with the given configuration. ret, result, err := vmenv.Call( cfg.Origin, address, input, - vm.NewGasBudget(cfg.GasLimit, 0), + vm.NewGasBudget(limit, cfg.GasLimit-limit), uint256.MustFromBig(cfg.Value), ) if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil {