EIP-1108 · Final · Core · 2018-05-21
EIP-1108: Reduce alt_bn128 precompile gas costs
Cut the gas price of the alt_bn128 elliptic-curve precompiles (add, multiply, pairing) by roughly 3–7×, making on-chain zk-SNARK verification and privacy protocols far cheaper.
What problem does it solve?
EIP-196 and EIP-197 added precompiled contracts for arithmetic on the alt_bn128 (BN254) curve. They are the building blocks for verifying zk-SNARK proofs (for example Groth16) inside a smart contract. Their gas prices were set in 2017 based on the client code of the time.
During 2018–2019 both Geth (which switched to Cloudflare's bn256 library) and Parity (optimised bn crate) became much faster at these operations, roughly an order of magnitude for Geth. The gas prices no longer matched the real cost, so privacy tools, rollups and other SNARK-based systems were paying far more than the computation deserved. EIP-1108 brings the prices back in line. It shipped in the Istanbul upgrade.
How it works
Only the gas schedule changes; the precompiles' inputs, outputs and behaviour stay exactly the same.
| Precompile | Address | Before | After |
|---|---|---|---|
ECADD |
0x06 |
500 | 150 |
ECMUL |
0x07 |
40,000 | 6,000 |
| Pairing check | 0x08 |
80,000·k + 100,000 | 34,000·k + 45,000 |
k is the number of point pairs passed to the pairing check.
The new numbers were derived from benchmarks of the slower client (Parity). The authors took ecrecover (3,000 gas, ~116 µs) as a "fair" reference, giving about 25.86 gas per microsecond, then split measured pairing time into a fixed part and a per-pairing part.
A typical Groth16 verification uses 4 pairings, so the pairing step alone drops from 420,000 gas to 181,000 gas, plus the much cheaper ECMUL/ECADD calls used to build the public-input point.
Sample code
Calling ECADD directly from Solidity. Most projects use a generated verifier (snarkjs, gnark, etc.) that wraps these calls, but they all compile down to staticcalls like this:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
library BN254 {
struct G1 { uint256 x; uint256 y; }
/// Point addition via the 0x06 precompile (150 gas since EIP-1108).
function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {
uint256[4] memory input = [p.x, p.y, q.x, q.y];
bool ok;
assembly {
ok := staticcall(gas(), 0x06, input, 0x80, r, 0x40)
}
require(ok, "ecAdd failed");
}
/// Scalar multiplication via the 0x07 precompile (6,000 gas since EIP-1108).
function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {
uint256[3] memory input = [p.x, p.y, s];
bool ok;
assembly {
ok := staticcall(gas(), 0x07, input, 0x60, r, 0x40)
}
require(ok, "ecMul failed");
}
}
Estimating the pairing cost before and after:
const pairingGas = (k: number, istanbul = true) =>
istanbul ? 34_000 * k + 45_000 : 80_000 * k + 100_000;
console.log(pairingGas(4)); // 181000
console.log(pairingGas(4, false)); // 420000
Things to know
- The rationale text quotes a rounded "~35,000·k + 45,000"; the normative table, and what clients implement, is 34,000·k + 45,000.
- Nothing about the cryptography changed, so existing verifier contracts kept working and simply became cheaper.
- BN254 offers roughly 100 bits of security by current estimates, below its original 128-bit target. Newer designs often prefer BLS12-381, which got its own precompiles in EIP-2537.
- The proposal was framed as a stop-gap alongside the more general curve precompile EIP-1829, which never advanced.