Update Compute*KZGProof in go bindings (#181)
This commit is contained in:
parent
ccf1a4fdf0
commit
b71746df74
|
@ -141,22 +141,25 @@ func BlobToKZGCommitment(blob Blob) (KZGCommitment, CKzgRet) {
|
||||||
ComputeKZGProof is the binding for:
|
ComputeKZGProof is the binding for:
|
||||||
|
|
||||||
C_KZG_RET compute_kzg_proof(
|
C_KZG_RET compute_kzg_proof(
|
||||||
KZGProof *out,
|
KZGProof *proof_out,
|
||||||
|
Bytes32 *y_out,
|
||||||
const Blob *blob,
|
const Blob *blob,
|
||||||
const Bytes32 *z_bytes,
|
const Bytes32 *z_bytes,
|
||||||
const KZGSettings *s);
|
const KZGSettings *s);
|
||||||
*/
|
*/
|
||||||
func ComputeKZGProof(blob Blob, zBytes Bytes32) (KZGProof, CKzgRet) {
|
func ComputeKZGProof(blob Blob, zBytes Bytes32) (KZGProof, Bytes32, CKzgRet) {
|
||||||
if !loaded {
|
if !loaded {
|
||||||
panic("trusted setup isn't loaded")
|
panic("trusted setup isn't loaded")
|
||||||
}
|
}
|
||||||
proof := KZGProof{}
|
proof := KZGProof{}
|
||||||
|
y := Bytes32{}
|
||||||
ret := C.compute_kzg_proof(
|
ret := C.compute_kzg_proof(
|
||||||
(*C.KZGProof)(unsafe.Pointer(&proof)),
|
(*C.KZGProof)(unsafe.Pointer(&proof)),
|
||||||
|
(*C.Bytes32)(unsafe.Pointer(&y)),
|
||||||
(*C.Blob)(unsafe.Pointer(&blob)),
|
(*C.Blob)(unsafe.Pointer(&blob)),
|
||||||
(*C.Bytes32)(unsafe.Pointer(&zBytes)),
|
(*C.Bytes32)(unsafe.Pointer(&zBytes)),
|
||||||
&settings)
|
&settings)
|
||||||
return proof, CKzgRet(ret)
|
return proof, y, CKzgRet(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -165,9 +168,10 @@ ComputeBlobKZGProof is the binding for:
|
||||||
C_KZG_RET compute_blob_kzg_proof(
|
C_KZG_RET compute_blob_kzg_proof(
|
||||||
KZGProof *out,
|
KZGProof *out,
|
||||||
const Blob *blob,
|
const Blob *blob,
|
||||||
|
const Bytes48 *commitment_bytes,
|
||||||
const KZGSettings *s);
|
const KZGSettings *s);
|
||||||
*/
|
*/
|
||||||
func ComputeBlobKZGProof(blob Blob) (KZGProof, CKzgRet) {
|
func ComputeBlobKZGProof(blob Blob, commitmentBytes Bytes48) (KZGProof, CKzgRet) {
|
||||||
if !loaded {
|
if !loaded {
|
||||||
panic("trusted setup isn't loaded")
|
panic("trusted setup isn't loaded")
|
||||||
}
|
}
|
||||||
|
@ -175,6 +179,7 @@ func ComputeBlobKZGProof(blob Blob) (KZGProof, CKzgRet) {
|
||||||
ret := C.compute_blob_kzg_proof(
|
ret := C.compute_blob_kzg_proof(
|
||||||
(*C.KZGProof)(unsafe.Pointer(&proof)),
|
(*C.KZGProof)(unsafe.Pointer(&proof)),
|
||||||
(*C.Blob)(unsafe.Pointer(&blob)),
|
(*C.Blob)(unsafe.Pointer(&blob)),
|
||||||
|
(*C.Bytes48)(unsafe.Pointer(&commitmentBytes)),
|
||||||
&settings)
|
&settings)
|
||||||
return proof, CKzgRet(ret)
|
return proof, CKzgRet(ret)
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ func TestComputeKZGProof(t *testing.T) {
|
||||||
Blob Blob `yaml:"blob"`
|
Blob Blob `yaml:"blob"`
|
||||||
Z Bytes32 `yaml:"z"`
|
Z Bytes32 `yaml:"z"`
|
||||||
}
|
}
|
||||||
Output *Bytes48 `yaml:"output"`
|
Output *[]string `yaml:"output"`
|
||||||
}
|
}
|
||||||
|
|
||||||
tests, err := filepath.Glob(computeKZGProofTests)
|
tests, err := filepath.Glob(computeKZGProofTests)
|
||||||
|
@ -167,10 +167,17 @@ func TestComputeKZGProof(t *testing.T) {
|
||||||
require.NoError(t, testFile.Close())
|
require.NoError(t, testFile.Close())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proof, ret := ComputeKZGProof(test.Input.Blob, test.Input.Z)
|
proof, y, ret := ComputeKZGProof(test.Input.Blob, test.Input.Z)
|
||||||
if ret == C_KZG_OK {
|
if ret == C_KZG_OK {
|
||||||
require.NotNil(t, test.Output)
|
require.NotNil(t, test.Output)
|
||||||
require.Equal(t, test.Output[:], proof[:])
|
var expectedProof Bytes48
|
||||||
|
err = expectedProof.UnmarshalText([]byte((*test.Output)[0]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, expectedProof[:], proof[:])
|
||||||
|
var expectedY Bytes32
|
||||||
|
err = expectedY.UnmarshalText([]byte((*test.Output)[1]))
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, expectedY[:], y[:])
|
||||||
} else {
|
} else {
|
||||||
require.Nil(t, test.Output)
|
require.Nil(t, test.Output)
|
||||||
}
|
}
|
||||||
|
@ -180,7 +187,8 @@ func TestComputeKZGProof(t *testing.T) {
|
||||||
func TestComputeBlobKZGProof(t *testing.T) {
|
func TestComputeBlobKZGProof(t *testing.T) {
|
||||||
type Test struct {
|
type Test struct {
|
||||||
Input struct {
|
Input struct {
|
||||||
Blob Blob `yaml:"blob"`
|
Blob Blob `yaml:"blob"`
|
||||||
|
Commitment Bytes48 `yaml:"commitment"`
|
||||||
}
|
}
|
||||||
Output *Bytes48 `yaml:"output"`
|
Output *Bytes48 `yaml:"output"`
|
||||||
}
|
}
|
||||||
|
@ -196,7 +204,7 @@ func TestComputeBlobKZGProof(t *testing.T) {
|
||||||
require.NoError(t, testFile.Close())
|
require.NoError(t, testFile.Close())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
proof, ret := ComputeBlobKZGProof(test.Input.Blob)
|
proof, ret := ComputeBlobKZGProof(test.Input.Blob, test.Input.Commitment)
|
||||||
if ret == C_KZG_OK {
|
if ret == C_KZG_OK {
|
||||||
require.NotNil(t, test.Output)
|
require.NotNil(t, test.Output)
|
||||||
require.Equal(t, test.Output[:], proof[:])
|
require.Equal(t, test.Output[:], proof[:])
|
||||||
|
@ -324,7 +332,7 @@ func Benchmark(b *testing.B) {
|
||||||
blob := GetRandBlob(int64(i))
|
blob := GetRandBlob(int64(i))
|
||||||
commitment, ret := BlobToKZGCommitment(blob)
|
commitment, ret := BlobToKZGCommitment(blob)
|
||||||
require.Equal(b, ret, C_KZG_OK)
|
require.Equal(b, ret, C_KZG_OK)
|
||||||
proof, ret := ComputeBlobKZGProof(blob)
|
proof, ret := ComputeBlobKZGProof(blob, Bytes48(commitment))
|
||||||
require.Equal(b, ret, C_KZG_OK)
|
require.Equal(b, ret, C_KZG_OK)
|
||||||
|
|
||||||
blobs[i] = blob
|
blobs[i] = blob
|
||||||
|
@ -351,7 +359,7 @@ func Benchmark(b *testing.B) {
|
||||||
|
|
||||||
b.Run("ComputeBlobKZGProof", func(b *testing.B) {
|
b.Run("ComputeBlobKZGProof", func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
ComputeBlobKZGProof(blobs[0])
|
ComputeBlobKZGProof(blobs[0], commitments[0])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue