KZG Commitments
Polynomial commitment scheme implementation for EIP-4844 blob transactions enabling Proto-Danksharding data availability.Overview
KZG (Kate-Zaverucha-Goldberg) commitments are cryptographic commitments to polynomials using BLS12-381 pairing-based cryptography. They enable Ethereum’s Proto-Danksharding upgrade (EIP-4844), dramatically reducing Layer 2 transaction costs through efficient data availability sampling. Ethereum Use Cases:- EIP-4844: Blob-carrying transactions for rollup data
- Proto-Danksharding: First step toward full Danksharding
- Data Availability Sampling: Light client verification without full data download
- Layer 2 Scaling: 10-100x cost reduction for rollups
- Succinct: Constant-size commitments (48 bytes) for large data (128 KB)
- Binding: Computationally infeasible to open to different polynomial
- Evaluation proofs: Prove
p(z) = ywithout revealing polynomial - Batch verification: Verify multiple proofs efficiently
Quick Start
KZG Polynomial Commitments
What are Polynomial Commitments?
Polynomial commitment: Cryptographic binding to polynomialp(x) enabling:
- Commitment:
C = Commit(p)- Publish short commitment - Evaluation: Prove
p(z) = yfor anyzwithout revealingp - Verification: Anyone can verify proof against commitment
- Represent data as polynomial coefficients:
p(x) = a_0 + a_1*x + ... + a_n*x^n - Commitment:
C = [p(τ)]_1whereτis trusted setup secret - Proof:
π = [(p(τ) - p(z))/(τ - z)]_1(quotient polynomial) - Verify: Check pairing equation
e(C - [y]_1, [1]_2) = e(π, [τ]_2 - [z]_2)
- Rollups post 128 KB blob commitments (48 bytes) to L1
- Anyone can sample blob points and verify correctness
- Validators don’t store full blob data (pruned after 18 days)
- Light clients verify availability without downloading data
API Reference
Initialization
Load Trusted Setup
- Ethereum used multi-party computation ceremony (10,000+ participants)
- Setup file: ~1 MB, contains powers of secret
τin both G1 and G2 - Must be loaded before any KZG operations
Check Initialization
Free Trusted Setup
Blob Operations
Create Empty Blob
- Size: 131,072 bytes (128 KB)
- Structure: 4096 field elements × 32 bytes each
- Each field element: Must be < BLS12-381 scalar field modulus
- Top byte: Must be 0 (ensures valid field element)
Generate Random Blob
Validate Blob
- Length is exactly 131,072 bytes
- Each 32-byte field element < BLS12-381 modulus
- Top byte of each element is 0
Commitment Generation
Blob to KZG Commitment
- Interpret blob as 4096 field element coefficients:
p(x) = a_0 + a_1*x + ... + a_4095*x^4095 - Evaluate polynomial at secret point τ:
p(τ) - Return G1 point:
[p(τ)]_1
- Deterministic: Same blob always produces same commitment
- Binding: Computationally infeasible to find different blob with same commitment
- Succinct: 48 bytes regardless of blob size
Proof Generation
Compute KZG Proof
- Evaluate polynomial:
y = p(z) - Compute quotient:
q(x) = (p(x) - y) / (x - z) - Return proof:
π = [q(τ)]_1
Proof Verification
Verify KZG Proof
- Left:
e([p(τ) - y]_1, [1]_2) = e([p(τ) - p(z)]_1, [1]_2) - Right:
e([q(τ)]_1, [τ - z]_2) = e([(p(τ) - p(z))/(τ - z)]_1, [τ - z]_2) - Equality holds iff
q(x) = (p(x) - y)/(x - z)(quotient polynomial)
Verify Blob KZG Proof
- Compute expected commitment from blob
- Verify commitment matches provided commitment
- Verify evaluation proof at challenge point
Batch Verify Blob KZG Proofs
- Individual: n pairings (n blobs)
- Batch: 2 pairings total (constant)
- Speedup: ~n/2 for large n
EIP-4844 Integration
Blob Transaction Structure
Computing Versioned Hash
Full Blob Transaction Flow
Use Cases
Rollup Data Availability
Data Availability Sampling
Implementation Details
C Library (c-kzg-4844 - Production)
- Library: c-kzg-4844 (Ethereum official)
- Location:
lib/c-kzg-4844/(git submodule) - Status: Production-ready, specification-compliant
- Backend: BLST library for BLS12-381 operations
- Features:
- Trusted setup loading
- Polynomial commitment
- Evaluation proof generation/verification
- Batch verification
- Embedded trusted setup (mainnet)
- Official Ethereum implementation
- Used in all consensus clients (Prysm, Lighthouse, Teku, Nimbus)
- Battle-tested in production
- Specification-compliant with EIP-4844
Zig FFI Wrapper
- Location:
src/crypto/c_kzg.zig - Purpose: Safe Zig bindings to c-kzg-4844
- Features:
- Memory-safe wrappers
- Error handling
- Automatic cleanup
TypeScript API
- Location:
src/crypto/KZG/(.jsfiles) - Runtime: FFI to native c-kzg-4844
- Platform: Node.js, Bun (native)
WASM Limitations
KZG NOT SUPPORTED IN WASM c-kzg-4844 requires:- BLST native library (BLS12-381 operations)
- Large trusted setup data (~1 MB)
- Native memory management
- KZG functions stubbed (throw errors)
- Use native builds for EIP-4844 functionality
Security Considerations
Trusted Setup Security:- Use official Ethereum ceremony setup
- Verify setup file hash before loading
- Setup ceremony had 10,000+ participants (only 1 needs to be honest)
- Each 32-byte field element must be < BLS12-381 modulus
- Top byte must be 0
- Handled automatically by validation functions
- Versioned hashes include commitment binding
- Challenge points derived from commitments (Fiat-Shamir)
- Prevents proof reuse across different blobs
Performance
Native (c-kzg-4844 with BLST):- Blob to commitment: ~50ms
- Compute proof: ~50ms
- Verify proof: ~2ms
- Verify blob proof: ~52ms (commitment + verification)
- Batch verify (4 blobs): ~80ms (vs ~208ms individual)
- Precompute commitments during block production
- Use batch verification for multiple blobs
- Cache trusted setup in memory (load once)
- Validate blobs before expensive operations
Constants
EIP-4844 Economics
Blob Gas:- Separate gas market from execution gas
- Dynamic pricing (EIP-1559 style)
- Target: 3 blobs per block (393 KB)
- Max: 6 blobs per block (786 KB)
- Calldata (pre-4844): ~16 gas/byte → ~$100 for 128 KB
- Blob data (post-4844): ~1 gas/byte → ~$1-10 for 128 KB
- 10-100x reduction in L2 costs
Related
- Precompiles: Point Evaluation - EIP-4844 precompile (0x0a)
- Primitives: Blob - Blob primitive wrapper
- BLS12-381 - Underlying pairing curve
- Transaction: EIP-4844 - Blob transactions

