Try it Live
Run BN254 examples in the interactive playground
BN254 (alt_bn128)
BN254 (also known as alt_bn128) is a pairing-friendly elliptic curve at the 128-bit security level, optimized for zkSNARK verification in zero-knowledge proof systems. L2-critical algorithm - Used extensively in Polygon, Optimism, Arbitrum, and zkEVMs for zero-knowledge proof verification. Available as EVM precompiles (0x06-0x08) for efficient on-chain verification.Overview
BN254 (also BN128, alt_bn128) is THE pairing curve for Ethereum zkSNARKs. Activated in Byzantium fork (2017), it enables privacy protocols, L2 proofs, and zero-knowledge applications.Why BN254 on Ethereum?
Gas-Efficient: Precompiled contracts make zkSNARK verification affordable Ecosystem: Groth16, PlonK, and most zk-proof systems support BN254 Adoption: Tornado Cash, zkSync, Aztec, Polygon zkEVM all use BN254 Tooling: Mature libraries (snarkjs, circom, libsnark) Security Note: 128-bit security level (equivalent to BLS12-381). Some estimates suggest ~100-bit practical security due to faster discrete log attacks on BN curves, but sufficient for current use.Mathematical Foundation
Curve Equations
G1 (base field Fp):Field Parameters
Base Field Modulus (p): 254-bit primeImplementation Status
Voltaire provides multiple BN254 implementations optimized for different environments:Pure Zig Implementation
Location:src/crypto/bn254.zig (~32KB)
Complete implementation including:
- G1/G2 point operations (add, double, negate, multiply)
- Projective coordinates with Montgomery form field arithmetic
- NAF (Non-Adjacent Form) scalar multiplication
- Optimal ate pairing (Miller loop + final exponentiation)
- Field arithmetic (Fp, Fp2, Fp6, Fp12)
Arkworks Rust (PRODUCTION)
Location:src/crypto/bn254_arkworks.zig (FFI wrapper)
Production-grade implementation via arkworks-algebra:
- Audited and battle-tested
- ~2x faster than pure Zig
- Used for EVM precompile implementation
- Full G1/G2/GT operations and pairing
WASM Status
Location:src/crypto/bn254.wasm.ts
Status: Not yet implemented - WASM loader infrastructure required.
All WASM methods currently throw:
- G1/G2 point operations
- Field arithmetic
- Pairing operations
- Tree-shakeable individual modules
Quick Start
Key Operations
G1 Point Operations
G1 operates on the base curve over field Fp:- Addition: Point addition on elliptic curve
- Scalar multiplication: Multiply point by scalar (NAF algorithm)
- Double: Efficient point doubling
- Negate: Compute additive inverse
G2 Point Operations
G2 operates on the twisted curve over extension field Fp2:- Addition/Multiplication: Same operations as G1, over Fp2
- Subgroup check: Critical for security (prevent invalid curve attacks)
- Frobenius endomorphism: Fast scalar multiplication
Pairing Check
The core operation for zkSNARK verification: Input: Pairs of points (P1, Q1), (P2, Q2), …, (Pn, Qn) where Pi ∈ G1, Qi ∈ G2 Output: Boolean - whether e(P1, Q1) · e(P2, Q2) · … · e(Pn, Qn) = 1 Implementation:- Miller loop: Compute line functions for each pair
- Final exponentiation: Raise result to (p^12 - 1) / r
Field Arithmetic
- Fp: Base field (254-bit prime modulus)
- Fp2: Quadratic extension (a + bi)
- Fp6: Sextic extension (3 Fp2 elements)
- Fp12: Dodecic extension (2 Fp6 elements) - pairing target group
zkSNARK Usage
BN254 is the standard curve for Ethereum zkSNARK systems:Groth16 Verification
Most common zkSNARK construction. Verification requires:- 3 G1 points (proof.A, proof.C, public inputs contribution)
- 1 G2 point (proof.B)
- 1 precomputed G2 verification key
- 1 pairing check with 3 pairs
PLONK Verification
More flexible than Groth16, supports universal setup:- Multiple G1 points (commitments, evaluations)
- Fewer G2 points (usually 1-2)
- Pairing check with fewer pairs
Documentation
Core Concepts
- Pairing - Optimal ate pairing, Miller loop, final exponentiation
- Precompiles - EIP-196/197 precompiled contracts (0x06-0x08)
- zkSNARK Usage - Groth16, PLONK, proof verification patterns
Operations
- G1 Operations - Point addition, scalar mul, serialization
- G2 Operations - Extension field operations, subgroup checks
Reference
- Test Vectors - Official EIP-196/197 test vectors
- Performance - Benchmarks, gas costs, optimizations
- Usage Patterns - Privacy protocols, L2 proofs, DeFi
Precompile Addresses
EIP-196 (Byzantium):0x06: ECADD - G1 point addition0x07: ECMUL - G1 scalar multiplication
0x08: ECPAIRING - Pairing check
Point Formats
G1 Points (64 bytes)
G2 Points (128 bytes)
Gas Costs
EIP-196 (after Istanbul):- ECADD: 150 gas
- ECMUL: 6,000 gas
- ECPAIRING base: 45,000 gas
- ECPAIRING per pair: 34,000 gas
Security
Security Level: 128-bit (nominal) BN254 provides 128-bit security level equivalent to BLS12-381. However, practical attacks on the discrete logarithm problem for BN curves are faster than originally estimated: Practical Considerations:- Some estimates suggest ~100-bit practical security due to faster DLP attacks
- Kim-Barbulescu attack (2016) improved NFS complexity for BN curves
- Still sufficient for current protocols and usage
- BLS12-381: 128-bit security (more conservative curve choice)
- BN254: 128-bit nominal, ~100-bit practical (faster operations, wider adoption)
Use Cases
Privacy: Tornado Cash, Aztec, zkBob L2 Scaling: zkSync, Polygon zkEVM, Scroll Identity: zk-proofs for authentication DeFi: Private trading, dark pools Voting: On-chain governance with privacyPerformance
Native (arkworks):- G1 add: ~5 μs
- G1 mul: ~40 μs
- G2 add: ~10 μs
- G2 mul: ~120 μs
- Pairing (single): ~600 μs
- Pairing check (3 pairs): ~2 ms
- ~2x faster pairing
- Less secure (100-bit vs 128-bit)
Related
- BLS12-381 - More secure pairing curve
- KZG Commitments - Uses BLS12-381 (not BN254)
- Precompiles: BN254 - Implementation details

