# `EEVM.Precompiles.BN256`
[🔗](https://github.com/mw2000/eevm/blob/v0.1.0/lib/eevm/precompiles/bn256.ex#L1)

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

| Operation | Byzantium (EIP-196/197)        | Istanbul on (EIP-1108)        |
|-----------|--------------------------------|-------------------------------|
| ecAdd     | 500                            | 150                           |
| ecMul     | 40,000                         | 6,000                         |
| ecPairing | 100,000 + 80,000 × pair count  | 45,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)`.

# `execute_add`

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

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

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

---

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