setupKzg
Sets up and returns a KZG interface with trusted setup loading
Loading...
Sets up and returns a KZG interface with trusted setup loading
Sets up and returns a KZG interface. It loads the trusted setup from the specified path before returning.
import "github.com/ChefBingbong/viem-go/utils/kzg"import "github.com/ChefBingbong/viem-go/utils/kzg"import "github.com/ethereum/c-kzg-4844/bindings/go"
kzgImpl, err := kzg.SetupKzg(kzg.SetupKzgParams{ BlobToKzgCommitment: func(blob []byte) ([]byte, error) { var b ckzg.Blob copy(b[:], blob) commitment, err := ckzg.BlobToKZGCommitment(&b) if err != nil { return nil, err } return commitment[:], nil }, ComputeBlobKzgProof: func(blob, commitment []byte) ([]byte, error) { var b ckzg.Blob var c ckzg.Bytes48 copy(b[:], blob) copy(c[:], commitment) proof, err := ckzg.ComputeBlobKZGProof(&b, c) if err != nil { return nil, err } return proof[:], nil }, LoadTrustedSetup: func(path string) error { return ckzg.LoadTrustedSetupFile(path) },}, "/path/to/trusted_setup.txt")if err != nil { log.Fatal(err)}(kzg.Kzg, error)A KZG implementation that can be used for blob operations.
kzg.SetupKzgParamsParameters for setting up KZG.
params := kzg.SetupKzgParams{ BlobToKzgCommitment: func(blob []byte) ([]byte, error) { // Implementation }, ComputeBlobKzgProof: func(blob, commitment []byte) ([]byte, error) { // Implementation }, LoadTrustedSetup: func(path string) error { // Implementation },}
kzgImpl, _ := kzg.SetupKzg(params, "/path/to/trusted_setup.txt")func(blob []byte) ([]byte, error)Function that converts a blob to a KZG commitment.
BlobToKzgCommitment: func(blob []byte) ([]byte, error) { var b ckzg.Blob copy(b[:], blob) commitment, err := ckzg.BlobToKZGCommitment(&b) if err != nil { return nil, err } return commitment[:], nil}func(blob []byte, commitment []byte) ([]byte, error)Function that computes the KZG proof for a blob.
ComputeBlobKzgProof: func(blob, commitment []byte) ([]byte, error) { var b ckzg.Blob var c ckzg.Bytes48 copy(b[:], blob) copy(c[:], commitment) proof, err := ckzg.ComputeBlobKZGProof(&b, c) if err != nil { return nil, err } return proof[:], nil}func(path string) errorFunction that loads the trusted setup from a file path. If the trusted setup is already loaded, errors are ignored.
LoadTrustedSetup: func(path string) error { return ckzg.LoadTrustedSetupFile(path)}stringThe path to the trusted setup file.
kzgImpl, _ := kzg.SetupKzg(params, "/path/to/trusted_setup.txt")Sets up KZG with trusted setup loading:
kzgImpl, _ := kzg.SetupKzg(params, "/path/to/trusted_setup.txt")
Sets up KZG using a KzgWithSetup implementation:
kzgImpl, _ := kzg.SetupKzgWithLoader(kzgWithSetup, "/path/to/trusted_setup.txt")