EEVM.Precompiles.BN256 (eevm v0.1.0)

Copy Markdown View Source

BN256 (alt_bn128) curve precompiles — addresses 0x06, 0x07, 0x08 (EIP-196, EIP-197).

Three operations are exposed:

  • ecAdd (0x06) — adds two G1 points on the curve.
  • ecMul (0x07) — performs scalar multiplication on a G1 point.
  • ecPairing (0x08) — evaluates an optimal ate pairing check over a list of (G1, G2) point pairs.

The curve arithmetic for all three is in EEVM.Precompiles.BN256.Curve.

Gas schedule

OperationByzantium (EIP-196/197)Istanbul on (EIP-1108)
ecAdd500150
ecMul40,0006,000
ecPairing100,000 + 80,000 × pair count45,000 + 34,000 × pair count

Each operation takes the hardfork as an optional third argument (default: Cancun) to pick its prices.

Input formats

  • ecAdd: 128 bytes — two G1 points, each 64 bytes (x, y as big-endian uint256). Short input is right-padded with zeros.
  • ecMul: 96 bytes — one G1 point (64 bytes) + scalar (32 bytes). Short input is right-padded with zeros.
  • ecPairing: k × 192 bytes — list of (G1, G2) pairs. Each G1 point is 64 bytes; each G2 point is 128 bytes encoded as x_imaginary(32) || x_real(32) || y_imaginary(32) || y_real(32). Input length must be divisible by 192.

The identity/infinity point is encoded as (0, 0).

Summary

Functions

execute_add(input, gas_limit, hardfork \\ %{__struct__: EEVM.HardforkConfig, spec_id: :cancun})

@spec execute_add(binary(), non_neg_integer(), EEVM.HardforkConfig.t()) ::
  {:ok, binary(), non_neg_integer()} | {:error, :out_of_gas | :invalid_point}

Adds two G1 points (ecAdd, 0x06).

execute_mul(input, gas_limit, hardfork \\ %{__struct__: EEVM.HardforkConfig, spec_id: :cancun})

@spec execute_mul(binary(), non_neg_integer(), EEVM.HardforkConfig.t()) ::
  {:ok, binary(), non_neg_integer()} | {:error, :out_of_gas | :invalid_point}

Multiplies a G1 point by a scalar (ecMul, 0x07).

execute_pairing(input, gas_limit, hardfork \\ %{__struct__: EEVM.HardforkConfig, spec_id: :cancun})

@spec execute_pairing(binary(), non_neg_integer(), EEVM.HardforkConfig.t()) ::
  {:ok, binary(), non_neg_integer()}
  | {:error, :out_of_gas | :invalid_input | :invalid_point}

Checks a product of pairings over (G1, G2) pairs (ecPairing, 0x08).