EEVM.Gas.Intrinsic (eevm v0.1.0)

Copy Markdown View Source

Intrinsic gas costs for transactions — costs that apply before execution begins.

Two main components:

  • Base cost: 21,000 gas for a regular transaction.
  • Calldata cost: per-byte fee on the transaction's data field — 4 gas per zero byte, 16 gas per non-zero byte (post-Istanbul / EIP-2028; pre-Istanbul, non-zero bytes cost 68 gas).

Summary

Functions

Computes the total intrinsic calldata gas cost for the given binary.

Computes the Prague calldata floor gas cost for the given calldata.

Counts EIP-7623 calldata floor tokens (zero=1, non-zero=4).

Returns the Prague calldata floor gas charged per token.

Returns the intrinsic gas cost for non-zero-byte calldata.

Returns the intrinsic gas cost for zero-byte calldata.

Functions

calldata_cost(data, hardfork)

@spec calldata_cost(binary(), EEVM.HardforkConfig.t()) :: non_neg_integer()

Computes the total intrinsic calldata gas cost for the given binary.

Iterates each byte: zero bytes cost 4 gas, non-zero bytes cost 16 gas from Istanbul (EIP-2028) and 68 before.

Examples

iex> EEVM.Gas.Intrinsic.calldata_cost(<<>>, EEVM.HardforkConfig.new(:cancun))
0

iex> EEVM.Gas.Intrinsic.calldata_cost(<<0x00, 0xFF>>, EEVM.HardforkConfig.new(:istanbul))
20

iex> EEVM.Gas.Intrinsic.calldata_cost(<<0x00, 0xFF>>, EEVM.HardforkConfig.new(:constantinople))
72

calldata_floor_cost(data)

@spec calldata_floor_cost(binary()) :: non_neg_integer()

Computes the Prague calldata floor gas cost for the given calldata.

calldata_floor_tokens(data)

@spec calldata_floor_tokens(binary()) :: non_neg_integer()

Counts EIP-7623 calldata floor tokens (zero=1, non-zero=4).

tx_calldata_floor_token_cost()

@spec tx_calldata_floor_token_cost() :: non_neg_integer()

Returns the Prague calldata floor gas charged per token.

tx_data_non_zero_gas()

@spec tx_data_non_zero_gas() :: non_neg_integer()

Returns the intrinsic gas cost for non-zero-byte calldata.

Per EIP-2028 (Istanbul): 16 gas per non-zero byte (was 68 pre-Istanbul).

tx_data_zero_gas()

@spec tx_data_zero_gas() :: non_neg_integer()

Returns the intrinsic gas cost for zero-byte calldata.

Per EIP-2028: 4 gas per zero byte.