From 2fcf653277f80a638a88e24d4fcf49deaec72c82 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:46:45 +0200 Subject: [PATCH] Fix gas fee calculation for debug calls (#10880) Cherry pick PR #10825 into the release branch Co-authored-by: Minhyuk Kim --- core/state_transition.go | 5 +++-- core/vm/evm.go | 6 ++++++ turbo/adapter/ethapi/api.go | 2 +- turbo/jsonrpc/eth_call.go | 2 -- turbo/transactions/tracing.go | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 58fa60b596c..81af68a75c7 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -305,7 +305,8 @@ func (st *StateTransition) preCheck(gasBailout bool) error { // Make sure the transaction gasFeeCap is greater than the block's baseFee. if st.evm.ChainRules().IsLondon { // Skip the checks if gas fields are zero and baseFee was explicitly disabled (eth_call) - if !st.evm.Config().NoBaseFee || !st.gasFeeCap.IsZero() || !st.tip.IsZero() { + skipCheck := st.evm.Config().NoBaseFee && st.gasFeeCap.IsZero() && st.tip.IsZero() + if !skipCheck { if err := CheckEip1559TxGasFeeCap(st.msg.From(), st.gasFeeCap, st.tip, st.evm.Context.BaseFee, st.msg.IsFree()); err != nil { return err } @@ -320,7 +321,7 @@ func (st *StateTransition) preCheck(gasBailout bool) error { return err } maxFeePerBlobGas := st.msg.MaxFeePerBlobGas() - if blobGasPrice.Cmp(maxFeePerBlobGas) > 0 { + if !st.evm.Config().NoBaseFee && blobGasPrice.Cmp(maxFeePerBlobGas) > 0 { return fmt.Errorf("%w: address %v, maxFeePerBlobGas: %v blobGasPrice: %v, excessBlobGas: %v", ErrMaxFeePerBlobGas, st.msg.From().Hex(), st.msg.MaxFeePerBlobGas(), blobGasPrice, st.evm.Context.ExcessBlobGas) diff --git a/core/vm/evm.go b/core/vm/evm.go index da1734e3f4f..2b84c9414c0 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -99,6 +99,12 @@ 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 evmtypes.BlockContext, txCtx evmtypes.TxContext, state evmtypes.IntraBlockState, chainConfig *chain.Config, vmConfig Config) *EVM { + if vmConfig.NoBaseFee { + if txCtx.GasPrice.IsZero() { + blockCtx.BaseFee = new(uint256.Int) + } + } + evm := &EVM{ Context: blockCtx, TxContext: txCtx, diff --git a/turbo/adapter/ethapi/api.go b/turbo/adapter/ethapi/api.go index 9e179234e3e..be3b38197eb 100644 --- a/turbo/adapter/ethapi/api.go +++ b/turbo/adapter/ethapi/api.go @@ -112,7 +112,7 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type gasFeeCap, gasTipCap = gasPrice, gasPrice } else { // User specified 1559 gas fields (or none), use those - gasFeeCap = uint256.MustFromBig(baseFee.ToBig()) + gasFeeCap = new(uint256.Int) if args.MaxFeePerGas != nil { overflow := gasFeeCap.SetFromBig(args.MaxFeePerGas.ToInt()) if overflow { diff --git a/turbo/jsonrpc/eth_call.go b/turbo/jsonrpc/eth_call.go index a76393bb697..d88be770a0b 100644 --- a/turbo/jsonrpc/eth_call.go +++ b/turbo/jsonrpc/eth_call.go @@ -180,8 +180,6 @@ func (api *APIImpl) EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs feeCap = args.GasPrice.ToInt() } else if args.MaxFeePerGas != nil { feeCap = args.MaxFeePerGas.ToInt() - } else if header.BaseFee != nil { - feeCap = new(big.Int).Set(header.BaseFee) } else { feeCap = libcommon.Big0 } diff --git a/turbo/transactions/tracing.go b/turbo/transactions/tracing.go index c24926a6807..b532b118335 100644 --- a/turbo/transactions/tracing.go +++ b/turbo/transactions/tracing.go @@ -209,7 +209,7 @@ func ExecuteTraceTx( execCb func(evm *vm.EVM, refunds bool) (*core.ExecutionResult, error), ) error { // Run the transaction with tracing enabled. - evm := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vm.Config{Debug: true, Tracer: tracer}) + evm := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vm.Config{Debug: true, Tracer: tracer, NoBaseFee: true}) var refunds = true if config != nil && config.NoRefunds != nil && *config.NoRefunds {