kzg4844

package
v1.17.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: GPL-3.0, LGPL-3.0 Imports: 9 Imported by: 408

Documentation

Overview

Package kzg4844 implements the KZG crypto for EIP-4844.

Index

Constants

View Source
const (
	CellProofsPerBlob = 128
	CellsPerBlob      = 128
	DataPerBlob       = 64
)

Variables

This section is empty.

Functions

func CalcBlobHashV1 added in v1.13.11

func CalcBlobHashV1(hasher hash.Hash, commit *Commitment) (vh [32]byte)

CalcBlobHashV1 calculates the 'versioned blob hash' of a commitment. The given hasher must be a sha256 hash instance, otherwise the result will be invalid!

func ComputeProof

func ComputeProof(blob *Blob, point Point) (Proof, Claim, error)

ComputeProof computes the KZG proof at the given point for the polynomial represented by the blob.

func IsValidVersionedHash added in v1.13.11

func IsValidVersionedHash(h []byte) bool

IsValidVersionedHash checks that h is a structurally-valid versioned blob hash.

func UseCKZG

func UseCKZG(use bool) error

UseCKZG can be called to switch the default Go implementation of KZG to the C library if for some reason the user wishes to do so (e.g. consensus bug in one or the other).

func VerifyBlobProof

func VerifyBlobProof(blob *Blob, commitment Commitment, proof Proof) error

VerifyBlobProof verifies that the blob data corresponds to the provided commitment.

func VerifyCellProofs added in v1.16.0

func VerifyCellProofs(blobs []Blob, commitments []Commitment, proofs []Proof) error

VerifyCellProofs verifies a batch of proofs corresponding to the blobs and commitments. Expects length of blobs and commitments to be equal. Expects length of proofs be 128 * length of blobs.

func VerifyCells added in v1.17.3

func VerifyCells(cells []Cell, commitments []Commitment, proofs []Proof, cellIndices []uint64) error

VerifyCells verifies a batch of proofs corresponding to the cells and blob commitments.

For this function, it is sufficient to only provide some of the cells.

The `cellIndices` specify which of the 128 cells of each blob are given. Indices must be given in ascending order.

Note the list of indices is shared among all blobs, i.e. for a given list of indices [1, 2, 13], the cells slice must contain cells [1, 2, 13] of each blob. Thus, `len(cells)` must be a multiple of `len(cellIndices)`.

One proof must be given for each cell. As such, `len(proofs)` must equal `len(cells)`.

func VerifyProof

func VerifyProof(commitment Commitment, point Point, claim Claim, proof Proof) error

VerifyProof verifies the KZG proof that the polynomial represented by the blob evaluated at the given point is the claimed value.

Types

type Blob

type Blob [131072]byte

Blob represents a 4844 data blob.

func RecoverBlobs added in v1.17.3

func RecoverBlobs(cells []Cell, cellIndices []uint64) ([]Blob, error)

RecoverBlobs recovers blobs from the given cells and cell indices. In order to successfully recover, at least DataPerBlob (64) cells must be provided.

For the layout of cells and cellIndices, please see VerifyCells.

func (*Blob) MarshalText added in v1.13.12

func (b *Blob) MarshalText() ([]byte, error)

MarshalText returns the hex representation of b.

func (*Blob) UnmarshalJSON added in v1.13.12

func (b *Blob) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a blob in hex syntax.

type Cell added in v1.17.3

type Cell [2048]byte

Cell represents a single cell in a blob.

func ComputeCells added in v1.17.3

func ComputeCells(blobs []Blob) ([]Cell, error)

ComputeCells computes the cells from the given blobs.

func (*Cell) MarshalText added in v1.17.3

func (c *Cell) MarshalText() ([]byte, error)

MarshalText returns the hex representation of c.

func (*Cell) UnmarshalJSON added in v1.17.3

func (c *Cell) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a cell in hex syntax.

type Claim

type Claim [32]byte

Claim is a claimed evaluation value in a specific point.

type Commitment

type Commitment [48]byte

Commitment is a serialized commitment to a polynomial.

func BlobToCommitment

func BlobToCommitment(blob *Blob) (Commitment, error)

BlobToCommitment creates a small commitment out of a data blob.

func (Commitment) MarshalText added in v1.13.12

func (c Commitment) MarshalText() ([]byte, error)

MarshalText returns the hex representation of c.

func (*Commitment) UnmarshalJSON added in v1.13.12

func (c *Commitment) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a commitment in hex syntax.

type Point

type Point [32]byte

Point is a BLS field element.

type Proof

type Proof [48]byte

Proof is a serialized commitment to the quotient polynomial.

func ComputeBlobProof

func ComputeBlobProof(blob *Blob, commitment Commitment) (Proof, error)

ComputeBlobProof returns the KZG proof that is used to verify the blob against the commitment.

This method does not verify that the commitment is correct with respect to blob.

func ComputeCellProofs added in v1.15.11

func ComputeCellProofs(blob *Blob) ([]Proof, error)

ComputeCellProofs returns the KZG cell proofs that are used to verify the blob against the commitment.

This method does not verify that the commitment is correct with respect to blob.

func (Proof) MarshalText added in v1.13.12

func (p Proof) MarshalText() ([]byte, error)

MarshalText returns the hex representation of p.

func (*Proof) UnmarshalJSON added in v1.13.12

func (p *Proof) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a proof in hex syntax.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL