From 31b2e2478ddc3d02204057af2dd4d739057bdcac Mon Sep 17 00:00:00 2001 From: ahmetyalp Date: Wed, 7 Feb 2024 13:46:27 +0300 Subject: [PATCH] refactor: make pedersen vk fields public --- ecc/bls12-377/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bls12-377/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bls12-378/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bls12-378/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bls12-381/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bls12-381/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bls24-315/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bls24-315/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bls24-317/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bls24-317/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bn254/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bn254/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bw6-633/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bw6-633/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bw6-756/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bw6-756/fr/pedersen/pedersen_test.go | 4 ++-- ecc/bw6-761/fr/pedersen/pedersen.go | 18 ++++++++--------- ecc/bw6-761/fr/pedersen/pedersen_test.go | 4 ++-- .../pedersen/template/pedersen.go.tmpl | 20 +++++++++---------- .../pedersen/template/pedersen.test.go.tmpl | 6 +++--- 20 files changed, 112 insertions(+), 112 deletions(-) diff --git a/ecc/bls12-377/fr/pedersen/pedersen.go b/ecc/bls12-377/fr/pedersen/pedersen.go index 31130283a0..b09acbd223 100644 --- a/ecc/bls12-377/fr/pedersen/pedersen.go +++ b/ecc/bls12-377/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bls12-377/fr/pedersen/pedersen_test.go b/ecc/bls12-377/fr/pedersen/pedersen_test.go index 126101e1f1..75c11fdae0 100644 --- a/ecc/bls12-377/fr/pedersen/pedersen_test.go +++ b/ecc/bls12-377/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bls12-378/fr/pedersen/pedersen.go b/ecc/bls12-378/fr/pedersen/pedersen.go index 96c963e3af..be32bdca46 100644 --- a/ecc/bls12-378/fr/pedersen/pedersen.go +++ b/ecc/bls12-378/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bls12-378/fr/pedersen/pedersen_test.go b/ecc/bls12-378/fr/pedersen/pedersen_test.go index 1a4cf496d9..d94ac20ef6 100644 --- a/ecc/bls12-378/fr/pedersen/pedersen_test.go +++ b/ecc/bls12-378/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bls12-381/fr/pedersen/pedersen.go b/ecc/bls12-381/fr/pedersen/pedersen.go index 204c6f13b6..6e0f51c3e2 100644 --- a/ecc/bls12-381/fr/pedersen/pedersen.go +++ b/ecc/bls12-381/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bls12-381/fr/pedersen/pedersen_test.go b/ecc/bls12-381/fr/pedersen/pedersen_test.go index ad88e67127..5356f190ea 100644 --- a/ecc/bls12-381/fr/pedersen/pedersen_test.go +++ b/ecc/bls12-381/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bls24-315/fr/pedersen/pedersen.go b/ecc/bls24-315/fr/pedersen/pedersen.go index 9616162110..30fcc11d12 100644 --- a/ecc/bls24-315/fr/pedersen/pedersen.go +++ b/ecc/bls24-315/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bls24-315/fr/pedersen/pedersen_test.go b/ecc/bls24-315/fr/pedersen/pedersen_test.go index 8d774dcfbd..5dda2da1a3 100644 --- a/ecc/bls24-315/fr/pedersen/pedersen_test.go +++ b/ecc/bls24-315/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bls24-317/fr/pedersen/pedersen.go b/ecc/bls24-317/fr/pedersen/pedersen.go index 684498ef1a..86fcc5f37c 100644 --- a/ecc/bls24-317/fr/pedersen/pedersen.go +++ b/ecc/bls24-317/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bls24-317/fr/pedersen/pedersen_test.go b/ecc/bls24-317/fr/pedersen/pedersen_test.go index 60808db344..c0625afa6b 100644 --- a/ecc/bls24-317/fr/pedersen/pedersen_test.go +++ b/ecc/bls24-317/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bn254/fr/pedersen/pedersen.go b/ecc/bn254/fr/pedersen/pedersen.go index 7c6bf8c2cd..d836eeaecb 100644 --- a/ecc/bn254/fr/pedersen/pedersen.go +++ b/ecc/bn254/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bn254/fr/pedersen/pedersen_test.go b/ecc/bn254/fr/pedersen/pedersen_test.go index a22cd9ac94..53109adfba 100644 --- a/ecc/bn254/fr/pedersen/pedersen_test.go +++ b/ecc/bn254/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bw6-633/fr/pedersen/pedersen.go b/ecc/bw6-633/fr/pedersen/pedersen.go index 0dd39010d3..60964a610e 100644 --- a/ecc/bw6-633/fr/pedersen/pedersen.go +++ b/ecc/bw6-633/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bw6-633/fr/pedersen/pedersen_test.go b/ecc/bw6-633/fr/pedersen/pedersen_test.go index 0d9fae77b0..c644bebd3e 100644 --- a/ecc/bw6-633/fr/pedersen/pedersen_test.go +++ b/ecc/bw6-633/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bw6-756/fr/pedersen/pedersen.go b/ecc/bw6-756/fr/pedersen/pedersen.go index 2d757b8ecd..e33f50d43f 100644 --- a/ecc/bw6-756/fr/pedersen/pedersen.go +++ b/ecc/bw6-756/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bw6-756/fr/pedersen/pedersen_test.go b/ecc/bw6-756/fr/pedersen/pedersen_test.go index f3c71a905c..c91e012b14 100644 --- a/ecc/bw6-756/fr/pedersen/pedersen_test.go +++ b/ecc/bw6-756/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/ecc/bw6-761/fr/pedersen/pedersen.go b/ecc/bw6-761/fr/pedersen/pedersen.go index c1ca758aa1..b77c0724b0 100644 --- a/ecc/bw6-761/fr/pedersen/pedersen.go +++ b/ecc/bw6-761/fr/pedersen/pedersen.go @@ -35,8 +35,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -55,7 +55,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -70,7 +70,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -215,7 +215,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -290,10 +290,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -309,9 +309,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err } diff --git a/ecc/bw6-761/fr/pedersen/pedersen_test.go b/ecc/bw6-761/fr/pedersen/pedersen_test.go index b1b4ee0fdc..32f53f99d1 100644 --- a/ecc/bw6-761/fr/pedersen/pedersen_test.go +++ b/ecc/bw6-761/fr/pedersen/pedersen_test.go @@ -173,9 +173,9 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) diff --git a/internal/generator/pedersen/template/pedersen.go.tmpl b/internal/generator/pedersen/template/pedersen.go.tmpl index c84d175597..af1cdc8a58 100644 --- a/internal/generator/pedersen/template/pedersen.go.tmpl +++ b/internal/generator/pedersen/template/pedersen.go.tmpl @@ -17,8 +17,8 @@ type ProvingKey struct { } type VerifyingKey struct { - g curve.G2Affine // TODO @tabaie: does this really have to be randomized? - gRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} + G curve.G2Affine // TODO @tabaie: does this really have to be randomized? + GRootSigmaNeg curve.G2Affine //gRootSigmaNeg = g^{-1/σ} } func randomFrSizedBytes() ([]byte, error) { @@ -37,7 +37,7 @@ func randomOnG2() (curve.G2Affine, error) { // TODO: Add to G2.go? func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err error) { - if vk.g, err = randomOnG2(); err != nil { + if vk.G, err = randomOnG2(); err != nil { return } @@ -52,7 +52,7 @@ func Setup(bases ...[]curve.G1Affine) (pk []ProvingKey, vk VerifyingKey, err err var sigmaInvNeg big.Int sigmaInvNeg.ModInverse(sigma, fr.Modulus()) sigmaInvNeg.Sub(fr.Modulus(), &sigmaInvNeg) - vk.gRootSigmaNeg.ScalarMultiplication(&vk.g, &sigmaInvNeg) + vk.GRootSigmaNeg.ScalarMultiplication(&vk.G, &sigmaInvNeg) pk = make([]ProvingKey, len(bases)) for i := range bases { @@ -197,7 +197,7 @@ func (vk *VerifyingKey) Verify(commitment curve.G1Affine, knowledgeProof curve.G return fmt.Errorf("subgroup check failed") } - if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.g, vk.gRootSigmaNeg}); err != nil { + if isOne, err := curve.PairingCheck([]curve.G1Affine{commitment, knowledgeProof}, []curve.G2Affine{vk.G, vk.GRootSigmaNeg}); err != nil { return err } else if !isOne { return fmt.Errorf("proof rejected") @@ -272,10 +272,10 @@ func (vk *VerifyingKey) WriteRawTo(w io.Writer) (int64, error) { func (vk *VerifyingKey) writeTo(enc *curve.Encoder) (int64, error) { var err error - if err = enc.Encode(&vk.g); err != nil { + if err = enc.Encode(&vk.G); err != nil { return enc.BytesWritten(), err } - err = enc.Encode(&vk.gRootSigmaNeg) + err = enc.Encode(&vk.GRootSigmaNeg) return enc.BytesWritten(), err } @@ -291,9 +291,9 @@ func (vk *VerifyingKey) readFrom(r io.Reader, decOptions ...func(*curve.Decoder) dec := curve.NewDecoder(r, decOptions...) var err error - if err = dec.Decode(&vk.g); err != nil { + if err = dec.Decode(&vk.G); err != nil { return dec.BytesRead(), err } - err = dec.Decode(&vk.gRootSigmaNeg) + err = dec.Decode(&vk.GRootSigmaNeg) return dec.BytesRead(), err -} \ No newline at end of file +} diff --git a/internal/generator/pedersen/template/pedersen.test.go.tmpl b/internal/generator/pedersen/template/pedersen.test.go.tmpl index 73ec978732..f8556b811a 100644 --- a/internal/generator/pedersen/template/pedersen.test.go.tmpl +++ b/internal/generator/pedersen/template/pedersen.test.go.tmpl @@ -155,13 +155,13 @@ func TestMarshal(t *testing.T) { vk VerifyingKey err error ) - vk.g, err = randomOnG2() + vk.G, err = randomOnG2() assert.NoError(t, err) - vk.gRootSigmaNeg, err = randomOnG2() + vk.GRootSigmaNeg, err = randomOnG2() assert.NoError(t, err) t.Run("ProvingKey -> Bytes -> ProvingKey must remain identical.", utils.SerializationRoundTrip(&pk)) t.Run("ProvingKey -> Bytes (raw) -> ProvingKey must remain identical.", utils.SerializationRoundTripRaw(&pk)) t.Run("VerifyingKey -> Bytes -> VerifyingKey must remain identical.", utils.SerializationRoundTrip(&vk)) t.Run("VerifyingKey -> Bytes (raw) -> ProvingKey must remain identical.", utils.SerializationRoundTripRaw(&vk)) -} \ No newline at end of file +}