Skip to main content

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
Key Properties:
  • Succinct: Constant-size commitments (48 bytes) for large data (128 KB)
  • Binding: Computationally infeasible to open to different polynomial
  • Evaluation proofs: Prove p(z) = y without revealing polynomial
  • Batch verification: Verify multiple proofs efficiently

Quick Start

KZG Polynomial Commitments

What are Polynomial Commitments?

Polynomial commitment: Cryptographic binding to polynomial p(x) enabling:
  1. Commitment: C = Commit(p) - Publish short commitment
  2. Evaluation: Prove p(z) = y for any z without revealing p
  3. Verification: Anyone can verify proof against commitment
KZG Construction:
  • Represent data as polynomial coefficients: p(x) = a_0 + a_1*x + ... + a_n*x^n
  • Commitment: C = [p(τ)]_1 where τ 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)
Why Useful?:
  • 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

Trusted Setup: Ceremony-generated parameters (τ powers) for secure KZG.
  • 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
Format:

Check Initialization

Free Trusted Setup

Blob Operations

Create Empty Blob

Blob Format:
  • 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

Use case: Testing, benchmarking

Validate Blob

Validation Checks:
  • 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

Computation:
  1. Interpret blob as 4096 field element coefficients: p(x) = a_0 + a_1*x + ... + a_4095*x^4095
  2. Evaluate polynomial at secret point τ: p(τ)
  3. Return G1 point: [p(τ)]_1
Properties:
  • 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

Computation:
  1. Evaluate polynomial: y = p(z)
  2. Compute quotient: q(x) = (p(x) - y) / (x - z)
  3. Return proof: π = [q(τ)]_1
Use case: Data availability sampling - prove blob evaluation at random point

Proof Verification

Verify KZG Proof

Verification Equation:
Explanation:
  • 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

Use case: Validators verify blob transaction data matches commitment Computation:
  1. Compute expected commitment from blob
  2. Verify commitment matches provided commitment
  3. Verify evaluation proof at challenge point

Batch Verify Blob KZG Proofs

Optimization: Batch verification uses fewer pairing operations than individual checks. Performance:
  • 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)
Why c-kzg-4844?
  • 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/ (.js files)
  • 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
WASM builds:
  • KZG functions stubbed (throw errors)
  • Use native builds for EIP-4844 functionality
Workaround: Use native builds or server-side KZG for blob transactions.

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)
Blob Validation:
Proof Verification:
Field Element Validation:
  • Each 32-byte field element must be < BLS12-381 modulus
  • Top byte must be 0
  • Handled automatically by validation functions
Replay Attacks:
  • 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)
Optimization Tips:
  • 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)
Cost Comparison (approximate):
  • 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
Blob Gas Calculation:

References