# `EEVM.Gas.Blob`
[🔗](https://github.com/mw2000/eevm/blob/main/lib/eevm/gas/blob.ex#L1)

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

- `base_fee_per_blob_gas/2` derives the blob base fee exposed by
  BLOBBASEFEE from a header's `excess_blob_gas`.
- `calc_excess_blob_gas/2` computes the `excess_blob_gas` a child header
  must carry, given its parent.

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.

# `parent`

```elixir
@type parent() :: %{
  :excess_blob_gas =&gt; non_neg_integer() | nil,
  :blob_gas_used =&gt; non_neg_integer() | nil,
  :base_fee_per_gas =&gt; non_neg_integer(),
  optional(atom()) =&gt; term()
}
```

The parent-header fields `calc_excess_blob_gas/2` reads.

# `base_fee_per_blob_gas`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@spec gas_per_blob() :: pos_integer()
```

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

# `max_blob_gas_per_block`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
