Skip to content

TransformErrors

Set of possible error when transforming the setup file to KZG4844.

FileOpenError || FileReadError || Allocator.Error || ParseError(Scanner)

BytesToBlobError

Set of possible errors when converting bytes to a Blob.

Allocator.Error || error{ InvalidBlobSize, EmptyBytes, DivisionByZero, Overflow }

ToSidecarErrors

Set of possible errors when converting, blobs, proofs and commitments to a Sidecar.

BytesToBlobError || error{
    ExpectedBlobData,
    ExpectedZBytes,
    SetupMustBeInitialized,
    FailedToConvertBlobToCommitment,
    FailedToComputeKZGProof,
}

Blob

Blob type representation.

[c.BYTES_PER_BLOB]u8

KZGProof

KZGProof type representation.

[c.BYTES_PER_PROOF]u8

KZGCommitment

KZGCommitment type representation.

[c.BYTES_PER_COMMITMENT]u8

KZGSettings

KZGSettings type representation.

c.KZGSettings

KZGProofResult

Result when generating a KZGProof.

Properties

struct {
  proof: KZGProof
  y: [c.BYTES_PER_FIELD_ELEMENT]u8
}

JsonTrustedSetup

Expected result from parsing the json file

Properties

struct {
  g1_monomial: []const []const u8
  g2_monomial: []const []const u8
}

Sidecar

Sidecar type representation.

Properties

struct {
  blob: Blob
  commitment: KZGCommitment
  proof: KZGProof
}

SideCarOpts

Set of options when converting toSidecars.

Properties

struct {
  data: ?[]const u8 = null
  blobs: ?[]const Blob = null
  commitments: ?[]const KZGCommitment = null
  proofs: ?[]const KZGProof = null
  z_bytes: ?[]const [32]u8 = null
}

Sidecars

[]const Sidecar

InitTrustedSetup

Inits the trusted setup from a 2d array of g1 and g2 bytes.

Signature

pub fn initTrustedSetup(
    self: *KZG4844,
    g1: [][48]u8,
    g2: [][96]u8,
) error{ SetupAlreadyLoaded, InvalidG1Length, InvalidG2Length, FailedToLoadSetup }!void

InitTrustedSetupFromJsonFile

Inits the trusted setup from a json file

Signature

pub fn initTrustedSetupFromJsonFile(
    self: *KZG4844,
    allocator: Allocator,
    path: []const u8,
) (TransformErrors || FileWriteError || error{ ExpectJsonFile, SetupAlreadyLoaded, FailedToLoadSetup })!void

InitTrustedSetupFromFile

Inits the trusted setup from a trusted setup file.

Signature

pub fn initTrustedSetupFromFile(
    self: *KZG4844,
    file_path: [*:0]const u8,
) error{ SetupAlreadyLoaded, FailedToLoadSetup }!void

DeinitTrustSetupFile

Frees the trusted setup. Will panic if the setup was never loaded.

Signature

pub fn deinitTrustSetupFile(self: *KZG4844) void

BlobToKZGCommitment

Converts a blob to a KZGCommitment.

Signature

pub fn blobToKZGCommitment(
    self: *KZG4844,
    blob: Blob,
) error{ SetupMustBeInitialized, FailedToConvertBlobToCommitment }!KZGCommitment

BlobToKZGProof

Computes blob proof.

Signature

pub fn blobToKZGProof(
    self: *KZG4844,
    blob: Blob,
    commitment: KZGCommitment,
) error{ SetupMustBeInitialized, FailedToComputeBlobKZGProof }!KZGProof

BlobsToKZGCommitment

Converts blobs to KZGCommitments. Caller owns the allocated memory.

Signature

pub fn blobsToKZGCommitment(
    self: *KZG4844,
    allocator: Allocator,
    blobs: []const Blob,
) (Allocator.Error || error{ SetupMustBeInitialized, FailedToConvertBlobToCommitment })![]const KZGCommitment

BlobsToKZGProofs

Computes blobs proof bytes

Signature

pub fn blobsToKZGProofs(
    self: *KZG4844,
    allocator: Allocator,
    blobs: []const Blob,
    commitments: []const KZGCommitment,
) (Allocator.Error || error{ SetupMustBeInitialized, FailedToComputeBlobKZGProof })![]const KZGProof

BytesToBlob

Converts an array of blob sized bytes into a Blob

Signature

pub fn bytesToBlob(
    self: *KZG4844,
    data: [c.BYTES_PER_BLOB]u8,
) Blob

BytesToBlobs

Converts slices to blobs. Caller owns the allocated memory.

Signature

pub fn bytesToBlobs(
    self: *KZG4844,
    allocator: Allocator,
    bytes: []const u8,
) BytesToBlobError![]const Blob

CommitmentToVersionedHash

Hashes a KZGCommitment.

Signature

pub fn commitmentToVersionedHash(
    commitment: KZGCommitment,
    version: ?u8,
) [Sha256.digest_length]u8

CommitmentsToVersionedHash

Hashes a slice of KZGCommitments to their version hashes

Signature

pub fn commitmentsToVersionedHash(
    allocator: Allocator,
    commitments: []const KZGCommitment,
    version: ?u8,
) Allocator.Error![]const [Sha256.digest_length]u8

ComputeKZGProof

Computes a given KZGProof from a blob

Signature

pub fn computeKZGProof(
    self: *KZG4844,
    blob: Blob,
    bytes: [32]u8,
) error{ SetupMustBeInitialized, FailedToComputeKZGProof }!KZGProofResult

ComputeKZGProofs

Computes the KZG Proofs based on the provided blobs. Caller owns the allocated memory.

Signature

pub fn computeKZGProofs(
    self: *KZG4844,
    allocator: Allocator,
    blobs: []const Blob,
    z_bytes: []const [32]u8,
) (Allocator.Error || error{ SetupMustBeInitialized, FailedToComputeKZGProof })![]const [48]u8

SidecarsToVersionedHash

Generates the commitments hashes based on the sidecar commitments.

Signature

pub fn sidecarsToVersionedHash(
    allocator: Allocator,
    sidecars: Sidecars,
    versions: []const ?u8,
) Allocator.Error![]const [Sha256.digest_length]u8

ToSidecars

Bundles together the blobs, commitments and proofs into a sidecar.

Signature

pub fn toSidecars(
    self: *KZG4844,
    allocator: Allocator,
    opts: SideCarOpts,
) ToSidecarErrors!Sidecars

TransformJsonFileFromHex

Transform the g1_monomial and g2_monomial into their g1 and g2 points representation so that they can be used by the initTrustedSetup method

Signature

pub fn transformJsonFileFromHex(
    allocator: Allocator,
    path: []const u8,
) TransformErrors![]const u8

TransformJsonFileToBytes

Transform the g1_monomial and g2_monomial into their g1 and g2 points representation so that they can be used by the initTrustedSetup method

Signature

pub fn transformJsonFileToBytes(
    allocator: Allocator,
    path: []const u8,
) (TransformErrors || error{ NoSpaceLeft, InvalidLength, InvalidCharacter })!struct { [][48]u8, [][96]u8 }

VerifyBlobKZGProof

Verifies a Blob KZG Proof from a commitment.

Signature

pub fn verifyBlobKZGProof(
    self: *KZG4844,
    blob: Blob,
    commitment_bytes: KZGCommitment,
    proof_bytes: KZGProof,
) error{ SetupMustBeInitialized, InvalidProof }!bool

VerifyBlobKZGProofBatch

Verifies a batch of blob KZG proofs from an array commitments and blobs.

Signature

pub fn verifyBlobKZGProofBatch(
    self: *KZG4844,
    blobs: []c.Blob,
    commitment_bytes: []c.KZGCommitment,
    proof_bytes: []c.KZGProof,
) error{ SetupMustBeInitialized, InvalidSize, InvalidProof }!bool

VerifyKZGProof

Verifies a KZGProof from a commitment.

Signature

pub fn verifyKZGProof(
    self: *KZG4844,
    commitment_bytes: KZGCommitment,
    z_bytes: [32]u8,
    y_bytes: [32]u8,
    proof_bytes: KZGProof,
) error{ SetupMustBeInitialized, InvalidProof }!bool