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

Use a generic group abstraction supporting G1 and GT #1

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5def044
hacky Group and Element abstraction
jsign Sep 12, 2023
6352d93
add gt group impl skeleton
jsign Sep 12, 2023
45e69f7
add gt backend
jsign Sep 12, 2023
0965c1e
naive time measurement
jsign Sep 12, 2023
a16d27e
be sure to sample only element in G_T
asanso Sep 21, 2023
760c571
adding ExpGLV
asanso Sep 21, 2023
1ff0542
Merge pull request #2 from asanso/jsign-gt
jsign Sep 21, 2023
fa40fb8
group: add constraint that order is r
jsign Sep 21, 2023
d392506
Merge pull request #3 from jsign/jsign-backtofr
jsign Sep 21, 2023
1ae4f67
generalize innerproductargument for g1
jsign Sep 22, 2023
b8d7f5f
innerproductargument: add support for Gt
jsign Sep 22, 2023
ec7fb7f
innerproductargument: add group durations
jsign Sep 22, 2023
6f2bd4a
Merge pull request #4 from jsign/jsign-migrate-ipa
jsign Sep 23, 2023
a86b74a
tmp progress
jsign Sep 23, 2023
1acab36
samemultiscalarargument: use generic group backend
jsign Sep 23, 2023
00726ea
Merge branch 'jsign-gt-grandproductargument' into jsign-gt-samemultis…
jsign Sep 23, 2023
b66501f
remove debug code
jsign Sep 23, 2023
220deaa
grandproductargument: fixes
jsign Sep 23, 2023
207067c
samepermutationargument: migrate to generic backend
jsign Sep 23, 2023
829c179
curdleproofs: make progress in generic backend
jsign Sep 23, 2023
61fc0c4
bench: support abstract group
jsign Sep 23, 2023
9f96dcd
curdleproofs: migrate soundess tests to generic gorup
jsign Sep 24, 2023
61e1bba
mod: add my patch for faster equality check
jsign Sep 24, 2023
685d722
cleanups
jsign Sep 24, 2023
89152b8
Merge pull request #5 from jsign/jsign-gt-morearguments
jsign Sep 25, 2023
502ef8f
make the linter happy
jsign Sep 25, 2023
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
Prev Previous commit
Next Next commit
curdleproofs: migrate soundess tests to generic gorup
Signed-off-by: Ignacio Hagopian <[email protected]>
jsign committed Sep 24, 2023

Verified

This commit was signed with the committer’s verified signature.
jsign Ignacio Hagopian
commit 9f96dcd356dcf74c79cba0693dade0af4e0b028c
314 changes: 179 additions & 135 deletions curdleproof_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package curdleproof

import (
"bytes"
"fmt"
"testing"

@@ -84,141 +85,184 @@ func TestCompleteness(t *testing.T) {
}
}

// func TestSoundness(t *testing.T) {
// t.Parallel()

// n := 128

// rand, err := common.NewRand(0)
// require.NoError(t, err)

// crs, err := GenerateCRS(n-common.N_BLINDERS, rand)
// require.NoError(t, err)

// perm := make([]uint32, n-common.N_BLINDERS)
// for i := range perm {
// perm[i] = uint32(i)
// }
// srand := mrand.New(mrand.NewSource(42))
// srand.Shuffle(len(perm), func(i, j int) { perm[i], perm[j] = perm[j], perm[i] })

// k, err := rand.GetFr()
// require.NoError(t, err)

// Rs, err := rand.GetG1Affines(n - common.N_BLINDERS)
// require.NoError(t, err)
// Ss, err := rand.GetG1Affines(n - common.N_BLINDERS)
// require.NoError(t, err)

// Ts, Us, M, rs_m, err := common.ShufflePermuteCommit(crs.Gs, crs.Hs, Rs, Ss, perm, k, rand)
// require.NoError(t, err)

// // Prove.
// rand, err = common.NewRand(0)
// require.NoError(t, err)
// proof, err := Prove(
// crs,
// Rs,
// Ss,
// Ts,
// Us,
// M,
// perm,
// k,
// rs_m,
// rand,
// )
// require.NoError(t, err)

// anotherPerm := make([]uint32, n-common.N_BLINDERS)
// for i := range anotherPerm {
// anotherPerm[i] = uint32(i)
// }
// srand.Shuffle(len(anotherPerm), func(i, j int) { anotherPerm[i], anotherPerm[j] = anotherPerm[j], anotherPerm[i] })

// t.Run("flips Ss and Rs", func(t *testing.T) {
// ok, err := Verify(proof, crs, Ss, Rs, Ts, Us, M, rand)
// require.NoError(t, err)
// require.False(t, ok)
// })

// t.Run("apply a different permutation than the one proved", func(t *testing.T) {
// ok, err := Verify(
// proof,
// crs,
// Rs,
// Ss,
// common.Permute(Ts, anotherPerm),
// common.Permute(Us, anotherPerm),
// M,
// rand,
// )
// require.NoError(t, err)
// require.False(t, ok)
// })

// t.Run("provide wrong perm commitment", func(t *testing.T) {
// biK := common.FrToBigInt(&k)
// var touchedM bls12381.G1Jac
// touchedM.ScalarMultiplication(&M, biK)
// ok, err := Verify(
// proof,
// crs,
// Rs,
// Ss,
// Ts,
// Us,
// touchedM,
// rand,
// )
// require.NoError(t, err)
// require.False(t, ok)

// })

// t.Run("instance outputs use a different randomizer", func(t *testing.T) {
// anotherK, err := rand.GetFr()
// require.NoError(t, err)
// biAnotherK := common.FrToBigInt(&anotherK)

// anotherTs := make([]bls12381.G1Affine, len(Rs))
// for i := range Ts {
// anotherTs[i].ScalarMultiplication(&Ts[i], biAnotherK)
// }

// anotherUs := make([]bls12381.G1Affine, len(Us))
// for i := range Us {
// anotherUs[i].ScalarMultiplication(&Us[i], biAnotherK)
// }
// ok, err := Verify(
// proof,
// crs,
// Rs,
// Ss,
// anotherTs,
// anotherUs,
// M,
// rand,
// )
// require.NoError(t, err)
// require.False(t, ok)

// })

// t.Run("encode/decode", func(t *testing.T) {
// buf := bytes.NewBuffer(nil)
// require.NoError(t, proof.Serialize(buf))
// expected := buf.Bytes()

// var proof2 Proof
// require.NoError(t, proof2.FromReader(buf))

// buf2 := bytes.NewBuffer(nil)
// require.NoError(t, proof2.Serialize(buf2))

// require.Equal(t, expected, buf2.Bytes())
// })
// }
func TestSoundness(t *testing.T) {
t.Parallel()

n := 128

configs := []testConfig{
{
name: "G1",
group: &group.GroupG1{},
genRandomGroupElement: func(rand *common.Rand) (group.Element, error) {
randG1Aff, err := rand.GetG1Affine()
if err != nil {
return nil, err
}
var randG1Jac bls12381.G1Jac
randG1Jac.FromAffine(&randG1Aff)
return group.FromG1Jac(randG1Jac), nil
},
},
{
name: "Gt",
group: &group.GroupGt{},
genRandomGroupElement: func(rand *common.Rand) (group.Element, error) {
randGt, err := rand.GetGt()
if err != nil {
return nil, err
}
return group.FromGt(randGt), nil
},
},
}

for _, config := range configs {
t.Run(config.name, func(t *testing.T) {

rand, err := common.NewRand(0)
require.NoError(t, err)

crs, err := GenerateCRS(n-common.N_BLINDERS, config.group, func() (group.Element, error) { return config.genRandomGroupElement(rand) })
require.NoError(t, err)

perm := make([]uint32, n-common.N_BLINDERS)
for i := range perm {
perm[i] = uint32(i)
}
srand := mrand.New(mrand.NewSource(42))
srand.Shuffle(len(perm), func(i, j int) { perm[i], perm[j] = perm[j], perm[i] })

k, err := rand.GetFr()
require.NoError(t, err)

Rs := make([]group.Element, n-common.N_BLINDERS)
for i := range Rs {
Rs[i], err = config.genRandomGroupElement(rand)
require.NoError(t, err)
}

Ss := make([]group.Element, n-common.N_BLINDERS)
for i := range Ss {
Ss[i], err = config.genRandomGroupElement(rand)
require.NoError(t, err)
}

Ts, Us, M, rs_m, err := utils.ShufflePermuteCommit(config.group, crs.Gs, crs.Hs, Rs, Ss, perm, k, rand)
require.NoError(t, err)

// Prove.
rand, err = common.NewRand(0)
require.NoError(t, err)
proof, err := Prove(
config.group,
crs,
Rs,
Ss,
Ts,
Us,
M,
perm,
k,
rs_m,
rand,
)
require.NoError(t, err)

anotherPerm := make([]uint32, n-common.N_BLINDERS)
for i := range anotherPerm {
anotherPerm[i] = uint32(i)
}
srand.Shuffle(len(anotherPerm), func(i, j int) { anotherPerm[i], anotherPerm[j] = anotherPerm[j], anotherPerm[i] })

t.Run("flips Ss and Rs", func(t *testing.T) {
ok, err := Verify(config.group, proof, crs, Ss, Rs, Ts, Us, M, rand)
require.NoError(t, err)
require.False(t, ok)
})

t.Run("apply a different permutation than the one proved", func(t *testing.T) {
ok, err := Verify(
config.group,
proof,
crs,
Rs,
Ss,
common.Permute(Ts, anotherPerm),
common.Permute(Us, anotherPerm),
M,
rand,
)
require.NoError(t, err)
require.False(t, ok)
})

t.Run("provide wrong perm commitment", func(t *testing.T) {
touchedM := config.group.CreateElement()
touchedM.ScalarMultiplication(M, k)
ok, err := Verify(
config.group,
proof,
crs,
Rs,
Ss,
Ts,
Us,
touchedM,
rand,
)
require.NoError(t, err)
require.False(t, ok)

})

t.Run("instance outputs use a different randomizer", func(t *testing.T) {
anotherK, err := rand.GetFr()
require.NoError(t, err)

anotherTs := make([]group.Element, len(Rs))
for i := range Ts {
anotherTs[i] = config.group.CreateElement()
anotherTs[i].ScalarMultiplication(Ts[i], anotherK)
}

anotherUs := make([]group.Element, len(Us))
for i := range Us {
anotherUs[i] = config.group.CreateElement()
anotherUs[i].ScalarMultiplication(Us[i], anotherK)
}
ok, err := Verify(
config.group,
proof,
crs,
Rs,
Ss,
anotherTs,
anotherUs,
M,
rand,
)
require.NoError(t, err)
require.False(t, ok)

})

t.Run("encode/decode", func(t *testing.T) {
buf := bytes.NewBuffer(nil)
require.NoError(t, proof.Serialize(buf))
expected := buf.Bytes()

var proof2 Proof
require.NoError(t, proof2.FromReader(buf))

buf2 := bytes.NewBuffer(nil)
require.NoError(t, proof2.Serialize(buf2))

require.Equal(t, expected, buf2.Bytes())
})
})
}
}

func BenchmarkProver(b *testing.B) {
configs := []testConfig{