Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

KZG Proofs

Generate and verify cryptographic proofs that a polynomial evaluates to a specific value at a given point.

Overview

KZG proofs enable proving p(z) = y where:
  • p(x) is the polynomial representing the blob
  • z is the evaluation point (32 bytes)
  • y is the claimed value (32 bytes)
  • Proof is 48 bytes

Compute Proof

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

Kzg.loadTrustedSetup();

const blob = Blob(131072);
const z = Bytes32(); // Evaluation point

// Compute proof
const { proof, y } = Kzg.Proof(blob, z);
// proof: Uint8Array (48 bytes)
// y: Uint8Array (32 bytes) - polynomial evaluation at z

Verify Proof

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

const commitment = Kzg.Commitment(blob);
const z = Bytes32();
const { proof, y } = Kzg.Proof(blob, z);

// Verify proof
const valid = Kzg.verify(commitment, z, y, proof);
// Returns: boolean (true if valid, false otherwise)

Blob Proof Verification

Optimized verification for blob-commitment pairs:
import { Kzg, Blob, Bytes32 } from '@tevm/voltaire';

const blob = Blob(131072);
const commitment = Kzg.Commitment(blob);
const z = Bytes32();
const { proof } = Kzg.Proof(blob, z);

// Verify blob proof (optimized)
const valid = Kzg.verifyBlob(blob, commitment, proof);

Batch Verification

Verify multiple proofs efficiently:
import { Kzg } from '@tevm/voltaire';

const blobs = [blob1, blob2, blob3];
const commitments = blobs.map(b => Kzg.Commitment(b));
const proofs = [proof1, proof2, proof3];

// Batch verify (more efficient than individual verification)
const allValid = Kzg.verifyBatch(blobs, commitments, proofs);
// Returns: boolean (true if ALL proofs valid, false otherwise)

Error Handling

try {
  const { proof, y } = Kzg.Proof(blob, z);
} catch (error) {
  if (error instanceof KzgNotInitializedError) {
    // Trusted setup not loaded
  } else if (error instanceof KzgInvalidBlobError) {
    // Invalid blob format
  } else if (error instanceof KzgError) {
    // Computation failed
    console.error('Code:', error.code);
    console.error('Message:', error.message);
  }
}