EIPs Explained

EIP-1962 · Stagnant · Core · 2019-04-22

EIP-1962: EC arithmetic and pairings with runtime definitions

Proposed one generic set of EVM precompiles for elliptic-curve arithmetic and pairings where the curve parameters are supplied at call time, so new curves would not need a hard fork.

What problem does it solve?

Privacy and scaling protocols rely on elliptic-curve operations and pairings, but the EVM only had precompiles for one curve, BN254 (addresses 0x06–0x08). Every additional curve, such as BLS12-381 or curves suited to recursive proofs, would need its own EIP and hard fork.

EIP-1962 proposed precompiles where the curve is a runtime input: the caller passes the field modulus, coefficients and extension structure along with the points. Developers could then use, and experiment with, new curves without waiting for a network upgrade. It extends EIP-1829 by adding pairings.

How it works

The spec defines ten operations:

  • On curves over the base field: point addition, scalar multiplication, and multi-exponentiation over N (scalar, point) pairs.
  • The same three operations on curves over quadratic or cubic extension fields (needed for G2).
  • Pairings for four curve families: BLS12, BN, MNT4 and MNT6.

Key design choices:

  • Gas is estimated from the supplied parameters (modulus size, operation type, number of pairs) as early as possible, so nodes can reject over-priced calls quickly.
  • Multi-exponentiation is its own operation because it is much cheaper than repeated multiplications.
  • No point decompression, because square-root cost is hard to price generically.
  • It requires EIP-1109 (PRECOMPILEDCALL), since the 700-gas STATICCALL cost at the time would dominate cheap operations such as point addition.

As fallbacks the spec suggests starting with a fixed whitelist of curves (BN254, BLS12-381, BLS12-377 and others).

Sample code

Calling a generic precompile from Solidity. The address and byte layout are placeholders: the spec delegates the ABI and gas schedule to an external document and left addresses unassigned:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract GenericCurveCaller {
    address constant EC_PRECOMPILE = address(0); // not assigned by EIP-1962

    function call(bytes calldata curveParamsAndInput) external view returns (bytes memory) {
        // input = operation id || field modulus || A || B || group order || points/scalars ...
        (bool ok, bytes memory out) = EC_PRECOMPILE.staticcall(curveParamsAndInput);
        require(ok, "EC op failed");
        return out;
    }
}

Things to know

  • Status: Stagnant. It was not included in any upgrade.
  • The detailed binary interface and gas schedule live outside the EIP, in the implementation's documentation, so the EIP alone is not a complete spec.
  • Ethereum instead adopted fixed-curve precompiles for BLS12-381 via EIP-2537, trading flexibility for simpler implementation and pricing.
  • The spec itself flags the difficulty of implementing, debugging and pricing such generic operations, and suggests limiting the initial set of curves.

#precompile #cryptography #elliptic-curves #pairings #core

Details

Authors
Alex Vlasov (@shamatar)
Status
Stagnant
Type
Standards Track / Core
Created
2019-04-22
Requires

Machine-readable: Markdown · JSON