ckzg4844

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Go bindings

This package implements Go bindings (using Cgo) for the exported functions in C-KZG-4844.

Installation

go get github.com/ethereum/c-kzg-4844/v2

Go version

This package requires 1.19rc1 or later. Version 1.19beta1 and before will not work. These versions have a linking issue and are unable to see blst functions.

Tests

Run the tests with this command:

go test

Benchmarks

Run the benchmarks with this command:

go test -bench=Benchmark

Note

The go.mod and go.sum files are in the project's root directory because the bindings need access to the c-kzg-4844 source, but Go cannot reference files outside its module/package. The best way to deal with this is to make the whole project available, that way everything is accessible.

Documentation

Index

Constants

View Source
const (
	BytesPerBlob         = C.BYTES_PER_BLOB
	BytesPerCell         = C.BYTES_PER_CELL
	BytesPerCommitment   = C.BYTES_PER_COMMITMENT
	BytesPerFieldElement = C.BYTES_PER_FIELD_ELEMENT
	BytesPerProof        = C.BYTES_PER_PROOF
	CellsPerExtBlob      = C.CELLS_PER_EXT_BLOB
	FieldElementsPerBlob = C.FIELD_ELEMENTS_PER_BLOB
	FieldElementsPerCell = C.FIELD_ELEMENTS_PER_CELL
)

Variables

View Source
var (
	ErrBadArgs = errors.New("bad arguments")
	ErrError   = errors.New("unexpected error")
	ErrMalloc  = errors.New("malloc failed")
)

Functions

func ComputeCellsAndKZGProofs

func ComputeCellsAndKZGProofs(blob *Blob) ([CellsPerExtBlob]Cell, [CellsPerExtBlob]KZGProof, error)

ComputeCellsAndKZGProofs is the binding for:

C_KZG_RET compute_cells_and_kzg_proofs(
    Cell *cells,
    KZGProof *proofs,
    const Blob *blob,
    const KZGSettings *s);

func ComputeKZGProof

func ComputeKZGProof(blob *Blob, zBytes Bytes32) (KZGProof, Bytes32, error)

ComputeKZGProof is the binding for:

C_KZG_RET compute_kzg_proof(
    KZGProof *proof_out,
    Bytes32 *y_out,
    const Blob *blob,
    const Bytes32 *z_bytes,
    const KZGSettings *s);

func FreeTrustedSetup

func FreeTrustedSetup()

FreeTrustedSetup is the binding for:

void free_trusted_setup(
    KZGSettings *s);

func LoadTrustedSetup

func LoadTrustedSetup(g1MonomialBytes, g1LagrangeBytes, g2MonomialBytes []byte, precompute uint) error

LoadTrustedSetup is the binding for:

C_KZG_RET load_trusted_setup(
    KZGSettings *out,
    const uint8_t *g1_monomial_bytes,
    uint64_t num_g1_monomial_bytes,
    const uint8_t *g1_lagrange_bytes,
    uint64_t num_g1_lagrange_bytes,
    const uint8_t *g2_monomial_bytes,
    uint64_t num_g2_monomial_bytes,
    uint64_t precompute);

func LoadTrustedSetupFile

func LoadTrustedSetupFile(trustedSetupFile string, precompute uint) error

LoadTrustedSetupFile is the binding for:

C_KZG_RET load_trusted_setup_file(
    KZGSettings *out,
    FILE *in,
    uint64_t precompute);

func RecoverCellsAndKZGProofs

func RecoverCellsAndKZGProofs(cellIndices []uint64, cells []Cell) ([CellsPerExtBlob]Cell, [CellsPerExtBlob]KZGProof, error)

RecoverCellsAndKZGProofs is the binding for:

C_KZG_RET recover_cells_and_kzg_proofs(
    Cell *recovered_cells,
    KZGProof *recovered_proofs,
    const uint64_t *cell_indices,
    const Cell *cells,
    uint64_t num_cells,
    const KZGSettings *s);

func VerifyBlobKZGProof

func VerifyBlobKZGProof(blob *Blob, commitmentBytes, proofBytes Bytes48) (bool, error)

VerifyBlobKZGProof is the binding for:

C_KZG_RET verify_blob_kzg_proof(
    bool *out,
    const Blob *blob,
    const Bytes48 *commitment_bytes,
    const Bytes48 *proof_bytes,
    const KZGSettings *s);

func VerifyBlobKZGProofBatch

func VerifyBlobKZGProofBatch(blobs []Blob, commitmentsBytes, proofsBytes []Bytes48) (bool, error)

VerifyBlobKZGProofBatch is the binding for:

C_KZG_RET verify_blob_kzg_proof_batch(
    bool *out,
    const Blob *blobs,
    const Bytes48 *commitments_bytes,
    const Bytes48 *proofs_bytes,
    const KZGSettings *s);

func VerifyCellKZGProofBatch

func VerifyCellKZGProofBatch(commitmentsBytes []Bytes48, cellIndices []uint64, cells []Cell, proofsBytes []Bytes48) (bool, error)

VerifyCellKZGProofBatch is the binding for:

C_KZG_RET verify_cell_kzg_proof_batch(
    bool *ok,
    const Bytes48 *commitments_bytes,
    const uint64_t *cell_indices,
    const Cell *cells,
    const Bytes48 *proofs_bytes,
    uint64_t num_cells,
    const KZGSettings *s);

func VerifyKZGProof

func VerifyKZGProof(commitmentBytes Bytes48, zBytes, yBytes Bytes32, proofBytes Bytes48) (bool, error)

VerifyKZGProof is the binding for:

C_KZG_RET verify_kzg_proof(
    bool *out,
    const Bytes48 *commitment_bytes,
    const Bytes32 *z_bytes,
    const Bytes32 *y_bytes,
    const Bytes48 *proof_bytes,
    const KZGSettings *s);

Types

type Blob

type Blob [BytesPerBlob]byte

func (*Blob) UnmarshalText

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

type Bytes32

type Bytes32 [32]byte

func (*Bytes32) UnmarshalText

func (b *Bytes32) UnmarshalText(input []byte) error

type Bytes48

type Bytes48 [48]byte

func (*Bytes48) UnmarshalText

func (b *Bytes48) UnmarshalText(input []byte) error

type Cell

type Cell [BytesPerCell]byte

func (*Cell) UnmarshalText

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

type KZGCommitment

type KZGCommitment Bytes48

func BlobToKZGCommitment

func BlobToKZGCommitment(blob *Blob) (KZGCommitment, error)

BlobToKZGCommitment is the binding for:

C_KZG_RET blob_to_kzg_commitment(
    KZGCommitment *out,
    const Blob *blob,
    const KZGSettings *s);

type KZGProof

type KZGProof Bytes48

func ComputeBlobKZGProof

func ComputeBlobKZGProof(blob *Blob, commitmentBytes Bytes48) (KZGProof, error)

ComputeBlobKZGProof is the binding for:

C_KZG_RET compute_blob_kzg_proof(
    KZGProof *out,
    const Blob *blob,
    const Bytes48 *commitment_bytes,
    const KZGSettings *s);

Jump to

Keyboard shortcuts

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