EIP-1962 Precompiles for runtime-specified EC operations and pairings (EC arithmetic and pairings with runtime definitions)

No call decision · Security & privacy · EIP status Stagnant · created 2019-04-22

EIP-1962 proposes adding general-purpose precompiles that let the type and parameters of an elliptic curve be specified at call time, supporting point operations and pairings on a variety of curves.

Why it is needed

Today Ethereum only provides point addition, point multiplication, and pairing check precompiles (0x06, 0x07, 0x08) for a single curve, BN254. Privacy protocols and zero-knowledge proof (zk-SNARK) based scaling solutions want to use other curves such as BLS12-381, BLS12-377, and MNT4/6, but using a new curve currently requires a hard fork to add a new precompile each time. EIP-1962 aims to create general-purpose operations that take curve parameters such as the base field, A and B coefficients, and extension tower structure as call data, so that desired curves can be experimented with and used without a fork. However, there is a constraint that a precompile's gas cost must be computable exactly from the input before execution.

What changes

Today

After EIP-1962

Who is affected

In depth

Structure of the 10 precompiles

There are 10 total: point addition, point multiplication, and multi-exponentiation over N (scalar, point) pairs on a base-field curve (3 operations); the same three operations on a curve over a quadratic or cubic extension of the base field (3 operations); and pairing operations for each of the four families BLS12, BN, MNT4, and MNT6 (4 operations). Every operation receives curve parameters such as the base field, scalar field, A and B coefficients, and extension tower structure at runtime via the call.

Scalar field operations and gas estimation

This precompile does not itself provide arithmetic operations on the scalar field, the size of the curve's main group, but scalar field information is still needed for gas estimation. Multi-exponentiation was split out as a separate operation because it can substantially cut cost. Point decompression was not included because the cost of the square root operation cannot be estimated in general. Because the cost in some favorable cases differs so much, pricing based on the worst case was judged inefficient, and adding yet more complexity to an already complex gas-pricing formula was judged not worth it.

Relationship with EIP-1109

EIP-1109 is not strictly required for EIP-1962's own functionality, but there is an example showing why it is needed. On the BLS12-381 curve, which uses a 381-bit modulus and a 255-bit scalar field, point addition takes about 5000ns and point multiplication about 150000ns. Converted at the ECRecover precompile's benchmark rate of 15M gas per second, that is roughly 75 gas for point addition and 2250 gas for point multiplication, but STATICCALL itself costs as much as 700 gas, so for low-cost operations like point addition the STATICCALL cost dwarfs the actual computation cost.

Ways to narrow the scope

Because implementation, debugging, and gas cost evaluation are complex, one proposal is to limit the list of supported curves at adoption time and expand it later. Suggested minimal lists include Ethereum's current BN254, a BN curve with a 2^32 root of unity from DIZK, BLS12-381, ZEXE's BLS12-377, the MNT4/6 cycle from the original paper, Coda's MNT4/6 cycle if performance allows, and a Cocks-Pinch-generated curve embedding BLS12-377. Alternatively, an updatable whitelist contract that does not require a consensus change (fork) is mentioned as an option if technically feasible.

Backward compatibility

This change is not backward compatible and requires a hard fork to activate. The new precompiles themselves do not affect existing Ethereum or EVM functionality, but they could fully replace the existing ECADD, ECMUL, and pairing check precompiles (0x06, 0x07, 0x08).

Implementation progress and benchmarks

Implementation is underway in the matter-labs/eip1829 repository. Non-pairing operations have been implemented and tested, the BLS12 family has been completed and tested on the BLS12-381 and BLS12-377 curves, and the BN family has been completed and tested on the BN254 curve. ZEXE's k=6 Cocks-Pinch curve has also been tested. Preliminary benchmarks on a Core i7 2.9GHz show the BLS12-381 pairing taking about 2,348,317ns, the cp6 pairing about 86,328,825ns, and BN254 multiplication about 81,744ns.

Current status

This EIP's status is Stagnant, meaning it is no longer being actively discussed. No fork-inclusion decision for adoption has been made yet, and the specification and scope (such as the list of supported curves) could still change or be abandoned.

Original EIP · ← EIPs