Skip to content

[Bug]: BenchmarkAnteHandler fails - invalid gas cap & fee rounding error #338

@heijiLee

Description

@heijiLee

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Running 'BenchmarkAnteHandler' on current main fails with an invalid gas cap error and a fee rounding isssue. (ref)

Background
This benchmark measures how fast the AnteHandler runs in cosmos/evm. It only times the checks (fees, balance, signature, etc.), not the full message execution. BenchmarkAnteHandler benchmarks 4 test cases here.

  • tx_type_evm_transfer_sim : EVM transfer run in simulate mode. estimates gas/validity only; no state changes are committed.
  • tx_type_evm_transfer : EVM transfer in execution mode. fees are deducted, nonce increases, and changes are committed.
  • tx_type_bank_msg_send_sim : Cosmos MsgSend in simulate mode. fee/balance checks only, no state changes.
  • tx_type_bank_msg_send : Cosmos MsgSend in execution mode. fees and nonce are applied, state is updated.

Here's how to run the benchmark and see the error.

Command

cd evmd/ante
go test -benchmem -run=^$ -bench ^BenchmarkAnteHandler$ github.com/cosmos/evm/evmd/ante

Actual Result

goos: darwin
goarch: arm64
pkg: github.com/cosmos/evm/evmd/ante
cpu: Apple M1 Pro
BenchmarkAnteHandler/tx_type_evm_transfer_sim-10                --- FAIL: BenchmarkAnteHandler/tx_type_evm_transfer_sim-10
    evm_antehandler_benchmark_test.go:101: failed to generate tx type: failed to validate transaction: max priority fee per gas higher than max fee per gas (1 > 0): invalid gas cap [/Users/heiji/Develop/HeijiLee/evm/x/vm/types/dynamic_fee_tx.go:225]
BenchmarkAnteHandler/tx_type_evm_transfer-10                    --- FAIL: BenchmarkAnteHandler/tx_type_evm_transfer-10
    evm_antehandler_benchmark_test.go:101: failed to generate tx type: failed to validate transaction: max priority fee per gas higher than max fee per gas (1 > 0): invalid gas cap [/Users/heiji/Develop/HeijiLee/evm/x/vm/types/dynamic_fee_tx.go:225]
BenchmarkAnteHandler/tx_type_bank_msg_send_sim-10                  24591             45902 ns/op           26576 B/op        369 allocs/op
BenchmarkAnteHandler/tx_type_bank_msg_send-10                   --- FAIL: BenchmarkAnteHandler/tx_type_bank_msg_send-10
    evm_antehandler_benchmark_test.go:108: failed to run ante handler: gas prices too low, got: 586181640.624994978239035821aatom required: 586181640.625000000000000000aatom. Please retry using a higher gas price or a higher fee: insufficient fee [/Users/heiji/Develop/HeijiLee/evm/ante/evm/fee_checker.go:100]
--- FAIL: BenchmarkAnteHandler
FAIL
exit status 1
FAIL    github.com/cosmos/evm/evmd/ante 41.065s
FAIL

Expected Results
Benchmarks should run completion(PASS) without configuration errors.
evm_transfer cases should auto-generate valid EIP-1559 fee fields (maxFeePerGas >= maPriorityFeePerGas)
bank_msg_send should not fail due to a tiny floating-point difference in fee calculation.

Suspected Cause
evm_transfer
In the factory (see factory.go#L146–157), GasTipCap correctly defaults to 1 wei and GasFeeCap is supposed to default to GetEVMBaseFee(). However, for some reason, GasFeeCap is being set to 0.

bank_msg_send
Fee calculation truncates instead of rounding up, causing "gas prices too low" by an extremly small margin. (It relevant to PR#255)
The helper in testutil/integration/base/factory/helper.go , computes the required fee with floating-point math then calls TruncateInt(), dropping any fractional wei.

Cosmos EVM Version

main

How to reproduce?

No modifications are needed on the main branch.

cd evmd/ante
go test -benchmem -run=^$ -bench ^BenchmarkAnteHandler$ github.com/cosmos/evm/evmd/ante

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions