@@ -18,6 +18,7 @@ import (
18
18
"go.dedis.ch/kyber/v4/internal/test"
19
19
"go.dedis.ch/kyber/v4/pairing"
20
20
circl "go.dedis.ch/kyber/v4/pairing/bls12381/circl"
21
+ "go.dedis.ch/kyber/v4/pairing/bls12381/gnark"
21
22
kilic "go.dedis.ch/kyber/v4/pairing/bls12381/kilic"
22
23
"go.dedis.ch/kyber/v4/sign/bdn"
23
24
"go.dedis.ch/kyber/v4/sign/bls"
@@ -39,6 +40,7 @@ func TestScalarEndianess(t *testing.T) {
39
40
suites := []pairing.Suite {
40
41
kilic .NewBLS12381Suite (),
41
42
circl .NewSuiteBLS12381 (),
43
+ gnark .NewSuiteBLS12381 (),
42
44
}
43
45
44
46
seed := "TestScalarEndianess"
@@ -110,6 +112,16 @@ func TestZKCryptoVectorsG1Compressed(t *testing.T) {
110
112
if err != nil && testCaseValid {
111
113
panic ("Circl: err should be nil" )
112
114
}
115
+
116
+ // Test gnark
117
+ g3 := gnark.G1Elt {}
118
+ err = g3 .UnmarshalBinary (byts )
119
+ if err == nil && ! testCaseValid {
120
+ panic ("Gnark: err should not be nil" )
121
+ }
122
+ if err != nil && testCaseValid {
123
+ panic ("Gnark: err should be nil" )
124
+ }
113
125
})
114
126
}
115
127
}
@@ -157,6 +169,16 @@ func TestZKCryptoVectorsG2Compressed(t *testing.T) {
157
169
if err != nil && testCaseValid {
158
170
panic ("Circl: err should be nil" )
159
171
}
172
+
173
+ // Test gnark
174
+ g3 := gnark.G2Elt {}
175
+ err = g3 .UnmarshalBinary (byts )
176
+ if err == nil && ! testCaseValid {
177
+ panic ("Gnark: err should not be nil" )
178
+ }
179
+ if err != nil && testCaseValid {
180
+ panic ("Gnark: err should be nil" )
181
+ }
160
182
})
161
183
}
162
184
}
@@ -401,6 +423,7 @@ func TestKyberG1(t *testing.T) {
401
423
suites := []pairing.Suite {
402
424
kilic .NewBLS12381Suite (),
403
425
circl .NewSuiteBLS12381 (),
426
+ gnark .NewSuiteBLS12381 (),
404
427
}
405
428
406
429
for _ , suite := range suites {
@@ -412,6 +435,7 @@ func TestKyberG2(t *testing.T) {
412
435
suites := []pairing.Suite {
413
436
kilic .NewBLS12381Suite (),
414
437
circl .NewSuiteBLS12381 (),
438
+ gnark .NewSuiteBLS12381 (),
415
439
}
416
440
417
441
for _ , suite := range suites {
@@ -423,6 +447,7 @@ func TestKyberPairingG2(t *testing.T) {
423
447
suites := []pairing.Suite {
424
448
kilic .NewBLS12381Suite (),
425
449
circl .NewSuiteBLS12381 (),
450
+ gnark .NewSuiteBLS12381 (),
426
451
}
427
452
428
453
for _ , s := range suites {
@@ -450,6 +475,7 @@ func TestRacePairings(_ *testing.T) {
450
475
suites := []pairing.Suite {
451
476
kilic .NewBLS12381Suite (),
452
477
circl .NewSuiteBLS12381 (),
478
+ gnark .NewSuiteBLS12381 (),
453
479
}
454
480
455
481
for _ , s := range suites {
@@ -474,6 +500,7 @@ func TestKyberBLSG2(t *testing.T) {
474
500
suites := []pairing.Suite {
475
501
kilic .NewBLS12381Suite (),
476
502
circl .NewSuiteBLS12381 (),
503
+ gnark .NewSuiteBLS12381 (),
477
504
}
478
505
479
506
for _ , suite := range suites {
@@ -486,6 +513,7 @@ func TestKyberBLSG1(t *testing.T) {
486
513
suites := []pairing.Suite {
487
514
kilic .NewBLS12381Suite (),
488
515
circl .NewSuiteBLS12381 (),
516
+ gnark .NewSuiteBLS12381 (),
489
517
}
490
518
491
519
for _ , suite := range suites {
@@ -498,6 +526,7 @@ func TestKyberThresholdG2(t *testing.T) {
498
526
suites := []pairing.Suite {
499
527
kilic .NewBLS12381Suite (),
500
528
circl .NewSuiteBLS12381 (),
529
+ gnark .NewSuiteBLS12381 (),
501
530
}
502
531
503
532
for _ , suite := range suites {
@@ -510,6 +539,7 @@ func TestKyberThresholdG1(t *testing.T) {
510
539
suites := []pairing.Suite {
511
540
kilic .NewBLS12381Suite (),
512
541
circl .NewSuiteBLS12381 (),
542
+ gnark .NewSuiteBLS12381 (),
513
543
}
514
544
515
545
for _ , suite := range suites {
@@ -522,6 +552,7 @@ func TestIsValidGroup(t *testing.T) {
522
552
suites := []pairing.Suite {
523
553
kilic .NewBLS12381Suite (),
524
554
circl .NewSuiteBLS12381 (),
555
+ gnark .NewSuiteBLS12381 (),
525
556
}
526
557
527
558
for _ , suite := range suites {
@@ -550,6 +581,7 @@ func TestBasicPairing(t *testing.T) {
550
581
suites := []pairing.Suite {
551
582
kilic .NewBLS12381Suite (),
552
583
circl .NewSuiteBLS12381 (),
584
+ gnark .NewSuiteBLS12381 (),
553
585
}
554
586
555
587
for _ , suite := range suites {
@@ -602,6 +634,7 @@ func BenchmarkPairingSeparate(bb *testing.B) {
602
634
var suites = []pairing.Suite {
603
635
kilic .NewBLS12381Suite (),
604
636
circl .NewSuiteBLS12381 (),
637
+ gnark .NewSuiteBLS12381 (),
605
638
}
606
639
607
640
for _ , s := range suites {
@@ -631,6 +664,7 @@ func BenchmarkPairingInv(bb *testing.B) {
631
664
var suites = []pairing.Suite {
632
665
kilic .NewBLS12381Suite (),
633
666
circl .NewSuiteBLS12381 (),
667
+ gnark .NewSuiteBLS12381 (),
634
668
}
635
669
636
670
for _ , s := range suites {
@@ -658,7 +692,7 @@ func BenchmarkPairingInv(bb *testing.B) {
658
692
var (
659
693
dataSize = 32
660
694
numSigs = []int {1 , 10 , 100 , 1000 , 10000 }
661
- curveOptions = []string {"kilic" , "circl" }
695
+ curveOptions = []string {"kilic" , "circl" , "gnark" }
662
696
)
663
697
664
698
// Used to avoid compiler optimizations
@@ -672,9 +706,12 @@ func BenchmarkKilic(b *testing.B) {
672
706
func BenchmarkCircl (b * testing.B ) {
673
707
BDNBenchmark (b , "circl" )
674
708
}
709
+ func BenchmarkGnark (b * testing.B ) {
710
+ BDNBenchmark (b , "gnark" )
711
+ }
712
+
713
+ func BDNBenchmark (b * testing.B , curveOption string ) { //nolint: gocyclo,cyclop // breaking this down doesn't make sense
675
714
676
- //nolint: gocyclo,cyclop // breaking this down doesn't make sense
677
- func BDNBenchmark (b * testing.B , curveOption string ) {
678
715
b .Logf ("----------------------" )
679
716
b .Logf ("Payload to sign: %d bytes\n " , dataSize )
680
717
b .Logf ("Numbers of signatures: %v\n " , numSigs )
@@ -698,6 +735,8 @@ func BDNBenchmark(b *testing.B, curveOption string) {
698
735
suite = kilic .NewBLS12381Suite ()
699
736
case "circl" :
700
737
suite = circl .NewSuiteBLS12381 ()
738
+ case "gnark" :
739
+ suite = gnark .NewSuiteBLS12381 ()
701
740
default :
702
741
panic (fmt .Errorf ("invalid curve option: %s" , curveOption ))
703
742
}
0 commit comments