@@ -81,6 +81,24 @@ mod test {
81
81
/// Public key League of Entropy Mainnet (curl -sS https://drand.cloudflare.com/info)
82
82
const PK_LEO_MAINNET : [ u8 ; 48 ] = hex ! ( "868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31" ) ;
83
83
84
+ /// The identity of G1 (the point at infinity).
85
+ ///
86
+ /// See https://docs.rs/bls12_381/latest/bls12_381/notes/serialization/index.html for encoding info.
87
+ const G1_IDENTITY : [ u8 ; 48 ] = [
88
+ 0b11000000 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
89
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
90
+ ] ;
91
+
92
+ /// The identity of G2 (the point at infinity).
93
+ ///
94
+ /// See https://docs.rs/bls12_381/latest/bls12_381/notes/serialization/index.html for encoding info.
95
+ const G2_IDENTITY : [ u8 ; 96 ] = [
96
+ 0b11000000 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
97
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
98
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
99
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
100
+ ] ;
101
+
84
102
fn build_message ( round : u64 , previous_signature : & [ u8 ] ) -> digest:: Output < Sha256 > {
85
103
Sha256 :: new ( )
86
104
. chain_update ( previous_signature)
@@ -153,6 +171,36 @@ mod test {
153
171
. unwrap( ) ) ;
154
172
}
155
173
174
+ /// This tests 1 == e(a, b) as there is no term on the left-hand side.
175
+ /// This is true for `a` or `b` being the point at infinity. See
176
+ /// https://eips.ethereum.org/EIPS/eip-2537#test-cases
177
+ #[ test]
178
+ fn pairing_equality_works_for_empty_lhs ( ) {
179
+ // a and b not point at infinity (Non-degeneracy)
180
+ let a = PK_LEO_MAINNET ;
181
+ let b = bls12_381_hash_to_g2 ( HashFunction :: Sha256 , b"blub" , DOMAIN_HASH_TO_G2 ) ;
182
+ let equal = bls12_381_pairing_equality ( & [ ] , & [ ] , & a, & b) . unwrap ( ) ;
183
+ assert ! ( !equal) ;
184
+
185
+ // a point at infinity
186
+ let a = G1_IDENTITY ;
187
+ let b = bls12_381_hash_to_g2 ( HashFunction :: Sha256 , b"blub" , DOMAIN_HASH_TO_G2 ) ;
188
+ let equal = bls12_381_pairing_equality ( & [ ] , & [ ] , & a, & b) . unwrap ( ) ;
189
+ assert ! ( equal) ;
190
+
191
+ // b point at infinity
192
+ let a = PK_LEO_MAINNET ;
193
+ let b = G2_IDENTITY ;
194
+ let equal = bls12_381_pairing_equality ( & [ ] , & [ ] , & a, & b) . unwrap ( ) ;
195
+ assert ! ( equal) ;
196
+
197
+ // a and b point at infinity
198
+ let a = G1_IDENTITY ;
199
+ let b = G2_IDENTITY ;
200
+ let equal = bls12_381_pairing_equality ( & [ ] , & [ ] , & a, & b) . unwrap ( ) ;
201
+ assert ! ( equal) ;
202
+ }
203
+
156
204
#[ test]
157
205
fn pairing_equality_error_cases_work ( ) {
158
206
let result = bls12_381_pairing_equality ( & [ 12 ] , & [ 0 ; 96 ] , & [ 12 ] , & [ 12 ] ) ;
0 commit comments