Gas and Fees Fundamentals
Gas is a unit measuring computational intensity of a transaction - the work required to execute it. Complex, multi-step transactions require more gas than simple transfers. Fees are the cost paid for gas:Fee Handling
Cosmos SDK Fees
Users specify two fields:GasLimit- upper bound on execution gas (GasWanted)- One of
FeesorGasPriceto specify or calculate transaction fees
GasLimit is insufficient, the transaction fails and rolls back without refunding fees.
Validators specify their min-gas-prices for transaction selection. Transactions with insufficient fees encounter delays or fail.
Ethereum Fees (EIP-1559)
With EIP-1559 (London Hard Fork),GasPrice split into two components:
- BaseFee: Calculated automatically based on block size (burned on Ethereum, distributed on Cosmos EVM)
- PriorityFee: Tip to proposer for transaction inclusion
max_fee_per_gas: TotalGasPricemaximummax_priority_fee_per_gas: MaximumPriorityFeegas_limit: Gas consumption limit
Cosmos EVM Implementation
Fundamentally, Cosmos EVM is a Cosmos SDK chain enabling EVM compatibility via a module. All EVM transactions are encoded as Cosmos SDK transactions and update Cosmos SDK-managed state.Fee Market Module
Supports EIP-1559 gas calculation on the EVM layer:- Tracks gas supplied per block to calculate base fee for future transactions
- For EVM transactions, bypasses local
min-gas-pricesand applies EIP-1559 fee logic - Gas price must exceed both global
min-gas-priceand block’sBaseFee
BaseFeeis distributed to validators/delegators (not burned)BaseFeeis lower-bounded by globalmin-gas-price(currently zero, adjustable via governance)
EVM Gas Refunds
Cosmos EVM refunds a fraction (at least 50% by default) of unused gas for EVM transactions to approximate Ethereum behavior. This is adjustable.Block Processing Timeline
- EndBlock: FeeMarket module tracks total
TransientGasWantedfrom block transactions for next block’sBaseFee - Transaction Reception: Nodes receive and gossip transactions, prioritized by fee price
- BeginBlock:
- FeeMarket calculates
BaseFee(code) using previous block’sGasWanted - Distribution module distributes previous block’s fee rewards
- FeeMarket calculates
- Transaction Processing:
AnteHandlervalidates transaction, verifies fees > minimum values andBaseFee, deducts fees tofee_collectormodule- For Cosmos transactions: Execute and consume gas
- For Ethereum transactions: Execute with gas isolation, calculate gas used, refund surplus
- EndBlock: Store block’s
GasWantedfor next block
Gas Mechanics
Cosmos Gas Metering
GasMeter: Tracks gas consumed during state transitions (reset per transaction)BlockGasMeter: Tracks gas consumed in block, enforces predefined limit (set via governance)
Matching EVM Gas Consumption
The EVM uses a gas table for each OPCODE, whereas Cosmos uses aGasConfig with flat and per-byte costs for database operations.
To match EVM gas consumption, Cosmos EVM:
- Ignores SDK gas consumption logic
- Calculates gas consumed by subtracting EVM leftover gas + refund from gas limit
- Resets transaction
GasMeterto 0 and manually sets it togasUsedvalue from EVM execution
x/vm/keeper/state_transition.go
AnteHandler
Performs basic checks before transaction execution:- Signature verification, transaction field validation, transaction fees
- Verifies user has sufficient balance for tx cost (amount + fees)
- Checks gas limit >= computed intrinsic gas
Gas Estimation
Ethereum’seth_estimateGas is implemented via EstimateGas query API. It:
- Applies transaction against current block/state
- Performs binary search to find optimal gas value
- Uses cache context to avoid persisting state changes
x/vm/keeper/grpc_query.go
For Cosmos transactions, use transaction simulation.
Zero-Fee Transactions
In Cosmos, minimum gas price is not enforced byAnteHandler - validators specify their own min-gas-prices. This allows 0-fee transactions for non-EVM transactions if validators accept them.
EVM transactions cannot have 0 fees as gas is inherently required by the EVM (validated in ValidateBasic and custom AnteHandler).
Cross-Chain Gas and Fees
For cross-chain scenarios (e.g., IBC transfer from Chain A to Cosmos EVM without native tokens), Cosmos SDKTips allow users to:
- Sign transaction with tip and no fees
- Send to fee relayer who covers fees in native currency
- Receive tip in payment (intermediary exchange behavior)
Related Documentation
- EIP-1559 Fee Market - Detailed fee market mechanics
- Performance Optimization - Gas estimation optimizations
- x/feemarket Module - Fee market implementation