EIP-1829 Elliptic curve linear combination precompile (Precompile for Elliptic Curve Linear Combinations)
No call decision · EVM & execution · EIP status Stagnant · created 2019-03-06
Adds a general-purpose precompile to the EVM. It computes, in a single call, the linear combination of multiple points and scalars on any short Weierstrass elliptic curve whose modulus is smaller than 2^256.
Why it is needed
Today the EVM can only use secp256k1 in a limited way, via ecrecover, and altbn128 is supported only through the two precompiles ecadd and ecmul from EIP-196. To use other curves, especially new curves used in zero-knowledge proofs (ZK), one must compute them slowly directly in EVM code. Also, EIP-196's ecmul only handles scalar multiplication of a single point at a time, so when there are two or more points it is inefficient enough that computing directly in EVM code is actually cheaper (as demonstrated by Weierstrudel). Operations that need a linear combination of the form s0·A0+s1·A1, such as ECDSA verification, lose out under this structure. This EIP creates a general-purpose precompile that takes the curve and field as parameters, aiming to support multiple curves at once instead of adding a new precompile for every specific curve.
What changes
Today
- secp256k1 is only supported in a limited way via ecrecover
- altbn128 is the only curve supported, via EIP-196's ecadd and ecmul
- EIP-196's ecmul only handles scalar multiplication of a single point, so with multiple points it is cheaper to compute directly in the EVM
- To use a new curve (such as one used for ZK), a separate precompile must be newly created each time
After EIP-1829
- Supports any short Weierstrass prime-field curve with a modulus below 2^256 through a single precompile
- Computes the linear combination (multi-scalar multiplication) of multiple points and scalars in a single call
- Makes ECDSA-like operations efficient through optimizations dedicated to linear combinations, such as Shamir's trick
- Handles coordinate recovery, on-curve point checking, addition, doubling, scalar multiplication, and modular square roots all as special cases of the same precompile
Who is affected
- Smart contract developers: Signature verification based on new curves and ZK proof computations can be implemented directly on-chain.
- Client teams: A general-purpose curve-operation precompile and its gas cost model need to be newly implemented.
- Validators / full node operators: DoS resistance depends on whether the variable-time computation and gas pricing are adequately handled.
- ZK protocol developers: This opens a path to cheaply using ZK-friendly curve operations, such as BLS12-381, on the EVM.
In depth
Core operation: linear combination
The original text specifies computing C = s0·A0 + s1·A1 + ... + sn·An on an elliptic curve y² = x³ + α·x + β mod m, given integers m, α, β, scalars s_i, and curve points A_i. This is called a linear combination, inner product, multi-multiplication, or multi-exponentiation. The call form is (Cx, Cy) := ecmul(m, α, β, s0,Ax0,As0, s1,Ax1,As1, ...). The key point is processing multiple point-scalar pairs at once, rather than a simple scalar multiplication of a single point.
Gas cost model
Gas is computed as BASE_GAS plus ADD_GAS for each term where s_i equals 1 and MUL_GAS for each term where s_i is greater than 1. Terms where s_i is 0 are free. The original text does not give actual values for BASE_GAS, ADD_GAS, and MUL_GAS, leaving them as placeholders (...), so the concrete values have not yet been determined.
Compressed coordinate encoding of points
A point is encoded as (x, y'), where y' is a sign byte indicating which of y or -y to take. It follows SEC 1 v1.9 2.3.4, but does not support uncompressed coordinates (y'=0x04). y'=0x00 means the point at infinity, 0x02 means the solution where y is even, and 0x03 means the solution where y is odd. Converting from affine to compressed coordinates is simply y' = 0x02 | (y & 0x01).
Multiple operations implemented as special cases
A single linear combination operation can implement several functions. Setting s0=1 gives coordinate recovery of A0, and comparing the y-coordinate after recovery allows on-curve checking. s0=s1=1 gives addition A0+A1; s0=2 gives doubling 2·A0 (though the original text points out that under the current gas model this could be more expensive than adding a point to itself); setting only s0 and A0 gives ordinary scalar multiplication. Setting α=s0=A=0 turns it into a modular square root operation where the result's Cy² satisfies β mod m.
Edge cases noted in the original text
The original text lists the following edge cases without yet settling on how to handle them: a modulus that is not prime or too small, a field element larger than the modulus, a singular curve where 4α³+27β²=0, an invalid sign byte, an x-coordinate not on the curve, and cases that return the point at infinity. The original text itself notes "please add more if you find them," making clear the list is not exhaustive.
Design rationale: why a general-purpose field and curve were chosen
Designing generically, rather than restricting to a specific field or curve, lets field- and curve-independent optimizations be applied uniformly. However, this generality means certain specific optimizations are missed, such as reductions specialized to binary-field structure, precomputed Montgomery factors, precomputed multiples of popular points like generators, and point addition/doubling formulas specialized for parameters such as α=-3, α=-1, α=0, or β=0. The original text leaves as a TODO whether it is worth implementing special cases for α, β to give a gas discount.
Limits of the covered scope
This EIP only covers large-characteristic prime fields, not non-prime-characteristic fields such as binary fields. The modulus is restricted to below 2^256 so that every parameter fits in a single EVM word; a 512-bit (double-word) version is left as a TODO. Curves with larger moduli, such as NIST P-384 or ZCash Sapling's BLS12-381, are the target of that future work. It also only supports curves in short Weierstrass form; curves of other forms can be converted to short Weierstrass form via a change of variables, but doing so loses the performance advantages specific to that form.
Current status and overlap in scope
This EIP's status is Stagnant and it is not actively progressing. The original text itself states that its scope overlaps with EIP-196 (altbn128 ecadd, ecmul), EIP-665 (ECDSA verification for ED25519), and EIP-1108 (gas optimization for altbn128 ecadd/ecmul), making it difficult for it to be adopted separately without first resolving its relationship to these. This material contains no core dev call record addressing fork inclusion.