Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gas fee calculation in debug calls #189

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/txpool/txpoolcfg"
types2 "github.com/ledgerwatch/erigon-lib/types"

cmath "github.com/ledgerwatch/erigon/common/math"
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/consensus/misc"
Expand Down Expand Up @@ -352,7 +352,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.BitLen() == 0 && st.tip.BitLen() == 0
if !skipCheck {
if err := CheckEip1559TxGasFeeCap(st.msg.From(), st.gasFeeCap, st.tip, st.evm.Context.BaseFee, st.msg.IsFree()); err != nil {
return err
}
Expand All @@ -367,7 +368,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)
Expand Down
6 changes: 6 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,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,
Expand Down
2 changes: 1 addition & 1 deletion turbo/adapter/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions turbo/jsonrpc/eth_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,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
}
Expand Down
2 changes: 1 addition & 1 deletion turbo/transactions/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,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 {
Expand Down
Loading