EEVM.Gas.Blob (eevm v0.1.0)

Copy Markdown View Source

Blob gas pricing (EIP-4844) and its later adjustments.

The blob schedule (target and max blobs per block, base-fee update fraction) follows the active hardfork: EIP-4844 values in Cancun and the EIP-7691 increase from Prague. From Osaka, EIP-7918 bounds the blob base fee below by execution cost: while GAS_PER_BLOB * blob_base_fee is below BLOB_BASE_COST * base_fee_per_gas, excess blob gas stops shrinking.

Summary

Types

The parent-header fields calc_excess_blob_gas/2 reads.

Functions

Returns the blob base fee for a block carrying excess_blob_gas.

Returns the excess_blob_gas a child of parent must carry under hardfork.

Approximates factor * e ** (numerator / denominator) with integer math, as specified by EIP-4844.

Returns the blob gas consumed by one blob (2^17).

Returns the most blob gas one block may use: max blobs per block times gas_per_blob/0 (6 blobs in Cancun, 9 from Prague per EIP-7691).

Types

parent()

@type parent() :: %{
  :excess_blob_gas => non_neg_integer() | nil,
  :blob_gas_used => non_neg_integer() | nil,
  :base_fee_per_gas => non_neg_integer(),
  optional(atom()) => term()
}

The parent-header fields calc_excess_blob_gas/2 reads.

Functions

base_fee_per_blob_gas(excess_blob_gas, hardfork)

@spec base_fee_per_blob_gas(non_neg_integer(), EEVM.HardforkConfig.t()) ::
  pos_integer()

Returns the blob base fee for a block carrying excess_blob_gas.

Examples

iex> EEVM.Gas.Blob.base_fee_per_blob_gas(0, EEVM.HardforkConfig.new(:cancun))
1

iex> EEVM.Gas.Blob.base_fee_per_blob_gas(10_000_000, EEVM.HardforkConfig.new(:cancun))
19

calc_excess_blob_gas(parent, hardfork)

@spec calc_excess_blob_gas(parent(), EEVM.HardforkConfig.t()) :: non_neg_integer()

Returns the excess_blob_gas a child of parent must carry under hardfork.

A nil blob field on the parent (a pre-Cancun header) counts as zero.

fake_exponential(factor, numerator, denominator)

@spec fake_exponential(non_neg_integer(), non_neg_integer(), pos_integer()) ::
  non_neg_integer()

Approximates factor * e ** (numerator / denominator) with integer math, as specified by EIP-4844.

Example

iex> EEVM.Gas.Blob.fake_exponential(1, 0, 3_338_477)
1

gas_per_blob()

@spec gas_per_blob() :: pos_integer()

Returns the blob gas consumed by one blob (2^17).

max_blob_gas_per_block(hardfork)

@spec max_blob_gas_per_block(EEVM.HardforkConfig.t()) :: pos_integer()

Returns the most blob gas one block may use: max blobs per block times gas_per_blob/0 (6 blobs in Cancun, 9 from Prague per EIP-7691).

Example

iex> EEVM.Gas.Blob.max_blob_gas_per_block(EEVM.HardforkConfig.new(:cancun))
786_432