EIPs Explained

ERC-2494 · Stagnant · ERC · 2020-01-29

ERC-2494: Baby Jubjub Elliptic Curve

Defines Baby Jubjub, a twisted Edwards curve built over the BN254 scalar field so that signatures and Pedersen hashes can be computed cheaply inside zk-SNARK circuits verified on Ethereum.

What problem does it solve?

Ethereum verifies zk-SNARK proofs over the alt_bn128 (BN254) curve, using the precompiles from EIP-196 and EIP-197. A circuit proven on BN254 works with numbers modulo BN254's prime group order r. That is fine for arithmetic, but if you want the circuit itself to do elliptic-curve cryptography (check an EdDSA signature, compute a Pedersen hash, derive a public key) you need a second curve whose coordinates live in that same field F_r. BN254 itself doesn't qualify.

Baby Jubjub is that curve. Because its points are pairs of F_r elements, curve operations become native field arithmetic inside the circuit, which keeps constraint counts small.

How it works

  • Field: F_r with r = 21888242871839275222246405745257275088548364400416034343698204186575808495617, the order of BN254.
  • Curve: twisted Edwards form a·x² + y² = 1 + d·x²·y² with a = 168700, d = 168696.
  • Order: n = 8 · l, where the cofactor is 8 and l is a 251-bit prime.
  • Points: a generator G of the whole group and a base point B = 8·G that generates the prime-order subgroup. Protocols should work in the subgroup generated by B.
  • Addition: a single complete formula handles both addition and doubling, which is very efficient in circuits:
x3 = (x1*y2 + y1*x2) / (1 + d*x1*x2*y1*y2)
y3 = (y1*y2 - a*x1*x2) / (1 - d*x1*x2*y1*y2)

The curve was generated deterministically (following RFC 7748's method) from the Montgomery form y² = x³ + 168698·x² + x, and the authors state it passes the SafeCurves criteria. The spec also gives the equivalent Montgomery and "reduced twisted Edwards" (a' = -1) forms and formulas to convert points between them; implementations often use the reduced form, so check which one a library expects.

Sample code

Point addition in TypeScript using native BigInt (no library):

const r = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
const A = 168700n, D = 168696n;

const mod = (x: bigint) => ((x % r) + r) % r;
const inv = (x: bigint) => {           // modular inverse via Fermat
  let res = 1n, b = mod(x), e = r - 2n;
  while (e > 0n) { if (e & 1n) res = mod(res * b); b = mod(b * b); e >>= 1n; }
  return res;
};

type Point = [bigint, bigint];

export function add([x1, y1]: Point, [x2, y2]: Point): Point {
  const t = mod(D * x1 * x2 * y1 * y2);
  const x3 = mod((x1 * y2 + y1 * x2) * inv(1n + t));
  const y3 = mod((y1 * y2 - A * x1 * x2) * inv(1n - t));
  return [x3, y3];
}

export const isOnCurve = ([x, y]: Point) =>
  mod(A * x * x + y * y) === mod(1n + D * x * x * y * y);

Things to know

  • Status: Stagnant. The proposal was never finalized as a standard, but the curve itself is widely used in zk tooling (for example circom/circomlib's EdDSA and Pedersen hash gadgets).
  • It is an ERC only in the sense of a shared definition: there is no precompile or contract interface. Baby Jubjub operations normally happen inside circuits, not in Solidity.
  • Mind the cofactor of 8: validate that points are in the prime-order subgroup before using them in signatures, or small-subgroup issues can arise.
  • Different libraries may use the twisted Edwards or reduced form with different coordinates for the same point; mixing them silently produces wrong results.

#cryptography #elliptic-curve #zk-snark #eddsa #zero-knowledge

Details

Authors
Barry WhiteHat (@barryWhiteHat), Marta Bellés (@bellesmarta), Jordi Baylina (@jbaylina)
Status
Stagnant
Type
Standards Track / ERC
Created
2020-01-29

Machine-readable: Markdown · JSON