Skip to main content

KZG Commitments

Convert 128 KB blobs into succinct 48-byte commitments using polynomial commitments.

Overview

KZG commitments represent a blob as a polynomial commitment on the BLS12-381 curve. The commitment is binding (cannot change blob after commitment) and enables efficient verification.

API

import { Kzg, Blob } from '@tevm/voltaire';

// Load trusted setup (required once)
Kzg.loadTrustedSetup();

// Create blob
const blob = Blob(131072); // 131,072 bytes
// ... fill with data

// Generate commitment
const commitment = Kzg.Commitment(blob);
// Returns: Uint8Array (48 bytes)

Blob Format

Size: 131,072 bytes (128 KB exactly) Structure: 4,096 field elements × 32 bytes Constraint: Each field element must have top byte = 0 (< BLS12-381 modulus)
// Valid blob
const blob = Blob(131072);
for (let i = 0; i < 4096; i++) {
  blob[i * 32] = 0; // Top byte must be 0
  // ... fill remaining 31 bytes
}

Error Handling

try {
  const commitment = Kzg.Commitment(blob);
} catch (error) {
  if (error instanceof KzgNotInitializedError) {
    // Trusted setup not loaded
    Kzg.loadTrustedSetup();
  } else if (error instanceof KzgInvalidBlobError) {
    // Invalid blob format
    console.error('Blob validation failed:', error.message);
  } else if (error instanceof KzgError) {
    // Commitment computation failed
    console.error('KZG error:', error.message);
  }
}