c-kzg-4844/bindings/go
Justin Traglia 71dd9574d6
Add go bindings (#77)
* Add go bindings

* Use Bytes32 type

* Update blst package

* Add binding for compute_kzg_proof

* Use bytes-only input (will fail)

* Fix go bindings tests

* Use better blobs for benchmarks

* Move rand* funcs to helpers & add comment

* Add headers check
2023-01-26 17:04:24 +00:00
..
blst_headers Add go bindings (#77) 2023-01-26 17:04:24 +00:00
README.md Add go bindings (#77) 2023-01-26 17:04:24 +00:00
go.mod Add go bindings (#77) 2023-01-26 17:04:24 +00:00
go.sum Add go bindings (#77) 2023-01-26 17:04:24 +00:00
main.go Add go bindings (#77) 2023-01-26 17:04:24 +00:00
main_test.go Add go bindings (#77) 2023-01-26 17:04:24 +00:00

README.md

cgo-kzg-4844

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

Installation

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

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.

Example

For example, a module with this source file:

package main

import "fmt"
import "encoding/hex"
import ckzg "github.com/ethereum/c-kzg-4844/bindings/go"

func main() {
	ret := ckzg.LoadTrustedSetupFile("trusted_setup.txt")
	if ret != ckzg.C_KZG_OK {
		panic("failed to load trusted setup")
	}
	defer ckzg.FreeTrustedSetup()

	blob := ckzg.Blob{1, 2, 3}
	commitment, ret := ckzg.BlobToKZGCommitment(blob)
	if ret != ckzg.C_KZG_OK {
		panic("failed to get commitment for blob")
	}
	fmt.Println(hex.EncodeToString(commitment[:]))
}

Will produce this output:

$ go run .
88f1aea383b825371cb98acfbae6c81cce601a2e3129461c3c2b816409af8f3e5080db165fd327db687b3ed632153a62

The trusted setup file in the example can be downloaded here:

Tests

Run the tests with this command:

go test

Benchmarks

Run the benchmarks with this command:

go test -bench=Benchmark