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 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)
import { Kzg, Blob } from '@tevm/voltaire';
import * as ckzg from 'c-kzg';
// Load trusted setup
Kzg.loadTrustedSetup();
// Create factory with c-kzg dependency injection
const Commitment = Kzg.CommitmentFactory({
blobToKzgCommitment: ckzg.blobToKzgCommitment
});
// Use factory
const blob = Blob(131072);
const commitment = Commitment(blob);
// Returns: Uint8Array (48 bytes)
Benefits: Tree-shakeable, testable with mock c-kzg implementations
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);
}
}