1
1
package bdn
2
2
3
3
import (
4
+ "encoding"
5
+ "encoding/hex"
4
6
"fmt"
5
7
"testing"
6
8
7
9
"github.com/stretchr/testify/require"
8
10
"go.dedis.ch/kyber/v4"
11
+ "go.dedis.ch/kyber/v4/pairing/bls12381/kilic"
9
12
"go.dedis.ch/kyber/v4/pairing/bn256"
10
- "go.dedis.ch/kyber/v4/sign"
11
13
"go.dedis.ch/kyber/v4/sign/bls"
12
14
"go.dedis.ch/kyber/v4/util/random"
13
15
)
@@ -30,7 +32,7 @@ func TestBDN_HashPointToR_BN256(t *testing.T) {
30
32
require .Equal (t , "933f6013eb3f654f9489d6d45ad04eaf" , coefs [2 ].String ())
31
33
require .Equal (t , 16 , coefs [0 ].MarshalSize ())
32
34
33
- mask , _ := sign . NewMask ([]kyber.Point {p1 , p2 , p3 }, nil )
35
+ mask , _ := NewMask ([]kyber.Point {p1 , p2 , p3 }, nil )
34
36
mask .SetBit (0 , true )
35
37
mask .SetBit (1 , true )
36
38
mask .SetBit (2 , true )
@@ -54,7 +56,7 @@ func TestBDN_AggregateSignatures(t *testing.T) {
54
56
sig2 , err := Sign (suite , private2 , msg )
55
57
require .NoError (t , err )
56
58
57
- mask , _ := sign . NewMask ([]kyber.Point {public1 , public2 }, nil )
59
+ mask , _ := NewMask ([]kyber.Point {public1 , public2 }, nil )
58
60
mask .SetBit (0 , true )
59
61
mask .SetBit (1 , true )
60
62
@@ -92,7 +94,7 @@ func TestBDN_SubsetSignature(t *testing.T) {
92
94
sig2 , err := Sign (suite , private2 , msg )
93
95
require .NoError (t , err )
94
96
95
- mask , _ := sign . NewMask ([]kyber.Point {public1 , public3 , public2 }, nil )
97
+ mask , _ := NewMask ([]kyber.Point {public1 , public3 , public2 }, nil )
96
98
mask .SetBit (0 , true )
97
99
mask .SetBit (2 , true )
98
100
@@ -131,7 +133,7 @@ func TestBDN_RogueAttack(t *testing.T) {
131
133
require .NoError (t , scheme .Verify (agg , msg , sig ))
132
134
133
135
// New scheme that should detect
134
- mask , _ := sign . NewMask (pubs , nil )
136
+ mask , _ := NewMask (pubs , nil )
135
137
mask .SetBit (0 , true )
136
138
mask .SetBit (1 , true )
137
139
agg , err = AggregatePublicKeys (suite , mask )
@@ -149,7 +151,7 @@ func Benchmark_BDN_AggregateSigs(b *testing.B) {
149
151
sig2 , err := Sign (suite , private2 , msg )
150
152
require .Nil (b , err )
151
153
152
- mask , _ := sign . NewMask ([]kyber.Point {public1 , public2 }, nil )
154
+ mask , _ := NewMask ([]kyber.Point {public1 , public2 }, nil )
153
155
mask .SetBit (0 , true )
154
156
mask .SetBit (1 , false )
155
157
@@ -158,3 +160,99 @@ func Benchmark_BDN_AggregateSigs(b *testing.B) {
158
160
AggregateSignatures (suite , [][]byte {sig1 , sig2 }, mask )
159
161
}
160
162
}
163
+
164
+ func Benchmark_BDN_BLS12381_AggregateVerify (b * testing.B ) {
165
+ suite := kilic .NewBLS12381Suite ()
166
+ schemeOnG2 := NewSchemeOnG2 (suite )
167
+
168
+ rng := random .New ()
169
+ pubKeys := make ([]kyber.Point , 3000 )
170
+ privKeys := make ([]kyber.Scalar , 3000 )
171
+ for i := range pubKeys {
172
+ privKeys [i ], pubKeys [i ] = schemeOnG2 .NewKeyPair (rng )
173
+ }
174
+
175
+ mask , err := NewMask (pubKeys , nil )
176
+ require .NoError (b , err )
177
+ for i := range pubKeys {
178
+ require .NoError (b , mask .SetBit (i , true ))
179
+ }
180
+
181
+ msg := []byte ("Hello many times Boneh-Lynn-Shacham" )
182
+ sigs := make ([][]byte , len (privKeys ))
183
+ for i , k := range privKeys {
184
+ s , err := schemeOnG2 .Sign (k , msg )
185
+ require .NoError (b , err )
186
+ sigs [i ] = s
187
+ }
188
+
189
+ sig , err := schemeOnG2 .AggregateSignatures (sigs , mask )
190
+ require .NoError (b , err )
191
+ sigb , err := sig .MarshalBinary ()
192
+ require .NoError (b , err )
193
+
194
+ b .ResetTimer ()
195
+ for i := 0 ; i < b .N ; i ++ {
196
+ pk , err := schemeOnG2 .AggregatePublicKeys (mask )
197
+ require .NoError (b , err )
198
+ require .NoError (b , schemeOnG2 .Verify (pk , msg , sigb ))
199
+ }
200
+ }
201
+
202
+ func unmarshalHex [T encoding.BinaryUnmarshaler ](t * testing.T , into T , s string ) T {
203
+ t .Helper ()
204
+ b , err := hex .DecodeString (s )
205
+ require .NoError (t , err )
206
+ require .NoError (t , into .UnmarshalBinary (b ))
207
+ return into
208
+ }
209
+
210
+ // This tests exists to make sure we don't accidentally make breaking changes to signature
211
+ // aggregation by using checking against known aggregated signatures and keys.
212
+ func TestBDNFixtures (t * testing.T ) {
213
+ suite := bn256 .NewSuite ()
214
+ schemeOnG1 := NewSchemeOnG1 (suite )
215
+
216
+ public1 := unmarshalHex (t , suite .G2 ().Point (), "1a30714035c7a161e286e54c191b8c68345bd8239c74925a26290e8e1ae97ed6657958a17dca12c943fadceb11b824402389ff427179e0f10194da3c1b771c6083797d2b5915ea78123cbdb99ea6389d6d6b67dcb512a2b552c373094ee5693524e3ebb4a176f7efa7285c25c80081d8cb598745978f1a63b886c09a316b1493" )
217
+ private1 := unmarshalHex (t , suite .G2 ().Scalar (), "49cfe5e9f4532670137184d43c0299f8b635bcacf6b0af7cab262494602d9f38" )
218
+ public2 := unmarshalHex (t , suite .G2 ().Point (), "603bc61466ec8762ec6de2ba9a80b9d302d08f580d1685ac45a8e404a6ed549719dc0faf94d896a9983ff23423772720e3de5d800bc200de6f7d7e146162d3183b8880c5c0d8b71ca4b3b40f30c12d8cc0679c81a47c239c6aa7e9cc2edab4a927fe865cd413c1c17e3df8f74108e784cd77dd3e161bdaf30019a55826a32a1f" )
219
+ private2 := unmarshalHex (t , suite .G2 ().Scalar (), "493abea4bb35b74c78ad9245f9d37883aeb6ee91f7fb0d8a8e11abf7aa2be581" )
220
+ public3 := unmarshalHex (t , suite .G2 ().Point (), "56118769a1f0b6286abacaa32109c1497ab0819c5d21f27317e184b6681c283007aa981cb4760de044946febdd6503ab77a4586bc29c04159e53a6fa5dcb9c0261ccd1cb2e28db5204ca829ac9f6be95f957a626544adc34ba3bc542533b6e2f5cbd0567e343641a61a42b63f26c3625f74b66f6f46d17b3bf1688fae4d455ec" )
221
+ private3 := unmarshalHex (t , suite .G2 ().Scalar (), "7fb0ebc317e161502208c3c16a4af890dedc3c7b275e8a04e99c0528aa6a19aa" )
222
+
223
+ sig1Exp , err := hex .DecodeString ("0913b76987be19f943be23b636cab9a2484507717326bd8bbdcdbbb6b8d5eb9253cfb3597c3fa550ee4972a398813650825a871f8e0b242ae5ddbce1b7c0e2a8" )
224
+ require .NoError (t , err )
225
+ sig2Exp , err := hex .DecodeString ("21195d29b1863bca1559e24375211d1411d8a28a8f4c772870b07f4ccda2fd5e337c1315c210475c683e3aa8b87d3aed3f7255b3087daa30d1e1432dd61d7484" )
226
+ require .NoError (t , err )
227
+ sig3Exp , err := hex .DecodeString ("3c1ac80345c1733630dbdc8106925c867544b521c259f9fa9678d477e6e5d3d212b09bc0d95137c3dbc0af2241415156c56e757d5577a609293584d045593195" )
228
+ require .NoError (t , err )
229
+
230
+ aggSigExp := unmarshalHex (t , suite .G1 ().Point (), "43c1d2ad5a7d71a08f3cd7495db6b3c81a4547af1b76438b2f215e85ec178fea048f93f6ffed65a69ea757b47761e7178103bb347fd79689652e55b6e0054af2" )
231
+ aggKeyExp := unmarshalHex (t , suite .G2 ().Point (), "43b5161ede207b9a69fc93114b0c5022b76cc22e813ba739c7e622d826b132333cd637505399963b94e393ec7f5d4875f82391620b34be1fde1f232204fa4f723935d4dbfb725f059456bcf2557f846c03190969f7b800e904d25b0b5bcbdd421c9877d443f0313c3425dfc1e7e646b665d27b9e649faadef1129f95670d70e1" )
232
+
233
+ msg := []byte ("Hello many times Boneh-Lynn-Shacham" )
234
+ sig1 , err := schemeOnG1 .Sign (private1 , msg )
235
+ require .Nil (t , err )
236
+ require .Equal (t , sig1Exp , sig1 )
237
+
238
+ sig2 , err := schemeOnG1 .Sign (private2 , msg )
239
+ require .Nil (t , err )
240
+ require .Equal (t , sig2Exp , sig2 )
241
+
242
+ sig3 , err := schemeOnG1 .Sign (private3 , msg )
243
+ require .Nil (t , err )
244
+ require .Equal (t , sig3Exp , sig3 )
245
+
246
+ mask , _ := NewMask ([]kyber.Point {public1 , public2 , public3 }, nil )
247
+ mask .SetBit (0 , true )
248
+ mask .SetBit (1 , false )
249
+ mask .SetBit (2 , true )
250
+
251
+ aggSig , err := schemeOnG1 .AggregateSignatures ([][]byte {sig1 , sig3 }, mask )
252
+ require .NoError (t , err )
253
+ require .True (t , aggSigExp .Equal (aggSig ))
254
+
255
+ aggKey , err := schemeOnG1 .AggregatePublicKeys (mask )
256
+ require .NoError (t , err )
257
+ require .True (t , aggKeyExp .Equal (aggKey ))
258
+ }
0 commit comments