Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: batched KZG #908

Merged
merged 22 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions std/commitments/kzg/native_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,29 @@ func Example_native() {
panic("commitment witness failed: " + err.Error())
}

// create a witness element of the opening proof and the evaluation point
wProof, err := kzg.ValueOfOpeningProof[sw_bls12377.ScalarField, sw_bls12377.G1Affine](point, proof)
// create a witness element of the opening proof
wProof, err := kzg.ValueOfOpeningProof[sw_bls12377.ScalarField, sw_bls12377.G1Affine](proof)
if err != nil {
panic("opening proof witness failed: " + err.Error())
}

// create a witness element of the SRS
wVk, err := kzg.ValueOfVerifyingKey[sw_bls12377.G2Affine](srs.Vk)
wVk, err := kzg.ValueOfVerifyingKey[sw_bls12377.G1Affine, sw_bls12377.G2Affine](srs.Vk)
if err != nil {
panic("verifying key witness failed: " + err.Error())
}

// create a witness element of the evaluation point
wPt, err := kzg.ValueOfScalar[sw_bls12377.ScalarField](point)
if err != nil {
panic("point witness failed: " + err.Error())
}

assignment := KZGVerificationCircuit[sw_bls12377.ScalarField, sw_bls12377.G1Affine, sw_bls12377.G2Affine, sw_bls12377.GT]{
VerifyingKey: wVk,
Commitment: wCmt,
OpeningProof: wProof,
Point: wPt,
}
circuit := KZGVerificationCircuit[sw_bls12377.ScalarField, sw_bls12377.G1Affine, sw_bls12377.G2Affine, sw_bls12377.GT]{}

Expand Down
28 changes: 16 additions & 12 deletions std/commitments/kzg/nonnative_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ import (
)

type KZGVerificationCircuit[FR emulated.FieldParams, G1El algebra.G1ElementT, G2El algebra.G2ElementT, GTEl algebra.GtElementT] struct {
kzg.VerifyingKey[G2El]
kzg.VerifyingKey[G1El, G2El]
kzg.Commitment[G1El]
kzg.OpeningProof[FR, G1El]
Point emulated.Element[FR]
}

func (c *KZGVerificationCircuit[FR, G1El, G2El, GTEl]) Define(api frontend.API) error {
curve, err := algebra.GetCurve[FR, G1El](api)
verifier, err := kzg.NewVerifier[FR, G1El, G2El, GTEl](api)
if err != nil {
return fmt.Errorf("get curve: %w", err)
return fmt.Errorf("new verifier: %w", err)
}
pairing, err := algebra.GetPairing[G1El, G2El, GTEl](api)
if err != nil {
return fmt.Errorf("get pairing: %w", err)
}
verifier := kzg.NewVerifier(c.VerifyingKey, curve, pairing)
if err := verifier.AssertProof(c.Commitment, c.OpeningProof); err != nil {
if err := verifier.CheckOpeningProof(c.Commitment, c.OpeningProof, c.Point, c.VerifyingKey); err != nil {
return fmt.Errorf("assert proof: %w", err)
}
return nil
Expand Down Expand Up @@ -94,21 +90,29 @@ func Example_emulated() {
panic("commitment witness failed: " + err.Error())
}

// create a witness element of the opening proof and the evaluation point
wProof, err := kzg.ValueOfOpeningProof[sw_bn254.ScalarField, sw_bn254.G1Affine](point, proof)
// create a witness element of the opening proof
wProof, err := kzg.ValueOfOpeningProof[sw_bn254.ScalarField, sw_bn254.G1Affine](proof)
if err != nil {
panic("opening proof witness failed: " + err.Error())
}

// create a witness element of the SRS
wVk, err := kzg.ValueOfVerifyingKey[sw_bn254.G2Affine](srs.Vk)
wVk, err := kzg.ValueOfVerifyingKey[sw_bn254.G1Affine, sw_bn254.G2Affine](srs.Vk)
if err != nil {
panic("verifying key witness failed: " + err.Error())
}

// create a witness element of the evaluation point
wPt, err := kzg.ValueOfScalar[sw_bn254.ScalarField](point)
if err != nil {
panic("point witness failed: " + err.Error())
}

assignment := KZGVerificationCircuit[sw_bn254.ScalarField, sw_bn254.G1Affine, sw_bn254.G2Affine, sw_bn254.GTEl]{
VerifyingKey: wVk,
Commitment: wCmt,
OpeningProof: wProof,
Point: wPt,
}
circuit := KZGVerificationCircuit[sw_bn254.ScalarField, sw_bn254.G1Affine, sw_bn254.G2Affine, sw_bn254.GTEl]{}

Expand Down
Loading
Loading