EIP-1829 · Stagnant · Core · 2019-03-06
EIP-1829: Precompile for Elliptic Curve Linear Combinations
A draft idea for one precompile that computes a linear combination of points on any short Weierstrass elliptic curve given as parameters, instead of adding a new precompile per curve.
What problem does it solve?
The EVM only supports a few curves natively: secp256k1 indirectly through ecrecover, and alt_bn128 (BN254) through the precompiles from EIP-196 and EIP-197. Many other curves are useful, for interoperating with other systems or for zero-knowledge proofs, and adding a dedicated precompile for each one is slow and piecemeal.
EIP-1829 proposes a single generic precompile where the caller supplies the curve itself. It also argues that a linear combination is the right primitive: EIP-196 multiplication handles only one point at a time, and the author notes that for two or more points it was cheaper to do the math in EVM code than to call it repeatedly.
How it works
The caller passes a modulus m, curve coefficients α and β, and a list of scalar/point pairs. The precompile works on the curve
y² = x³ + α·x + β (mod m)
and returns
C = s₀·A₀ + s₁·A₁ + … + sₙ·Aₙ
Points are passed in compressed form (x, y') following SEC 1: 0x00 for the point at infinity, 0x02 for even y, 0x03 for odd y. Uncompressed points are not supported. Converting from affine coordinates is y' = 0x02 | (y & 1).
The same call covers many operations as special cases: addition (s₀ = s₁ = 1), scalar multiplication (one pair), coordinate recovery (s₀ = 1, also usable as an on-curve check), and even a modular square root. Gas would be a base cost plus a per-term cost, with terms where s = 1 charged as additions and larger scalars charged as multiplications; s = 0 is free.
Scope is limited to prime fields with moduli below 2²⁵⁶, so every parameter fits in one EVM word.
Sample code
Illustrative pseudocode of the call. The spec does not define a byte-level input layout or a precompile address:
# ECDSA-style verification needs u1·G + u2·Q, a two-term combination
(Cx, Cy) = ecmul(
m, alpha, beta,
u1, Gx, G_sign, # s0, A0 (x, sign byte)
u2, Qx, Q_sign, # s1, A1
)
valid = (Cx % n) == r
def sign_byte(y):
return 0x02 | (y & 1)
Things to know
- Status: Stagnant. The text is incomplete: gas constants (
BASE_GAS,ADD_GAS,MUL_GAS) are left blank, the motivation, test-case and backwards-compatibility sections are empty, and the edge-case list invites additions. - Error handling for non-prime or tiny moduli, singular curves, invalid sign bytes and off-curve
xvalues is listed but not specified. - A generic approach gives up curve-specific optimizations; the spec lists several it would miss.
- Ethereum instead added specific curves: BLS12-381 via EIP-2537 and secp256r1 via EIP-7951. EIP-1962 was a related, also stagnant, attempt at runtime-defined curve arithmetic.