1
- use alloc:: vec:: Vec ;
2
-
3
1
use group:: ff:: Field ;
4
2
use halo2curves_axiom:: bls12_381:: {
5
3
Fq , Fq12 , Fq2 , Fq6 , G1Affine , G2Affine , G2Prepared , MillerLoopResult , FROBENIUS_COEFF_FQ12_C1 ,
@@ -10,59 +8,20 @@ use rand::{rngs::StdRng, SeedableRng};
10
8
11
9
use super :: { Fp , Fp12 , Fp2 } ;
12
10
use crate :: {
13
- bls12_381:: { Bls12_381 , G2Affine as OpenVmG2Affine } ,
11
+ bls12_381:: {
12
+ utils:: {
13
+ convert_bls12381_fp12_to_halo2_fq12, convert_bls12381_halo2_fq12_to_fp12,
14
+ convert_bls12381_halo2_fq2_to_fp2, convert_bls12381_halo2_fq_to_fp,
15
+ convert_g2_affine_halo2_to_openvm,
16
+ } ,
17
+ Bls12_381 , G2Affine as OpenVmG2Affine ,
18
+ } ,
14
19
pairing:: {
15
- fp2_invert_assign, fp6_invert_assign, fp6_square_assign, MultiMillerLoop , PairingIntrinsics ,
20
+ fp2_invert_assign, fp6_invert_assign, fp6_square_assign, FinalExp , MultiMillerLoop ,
21
+ PairingCheck , PairingIntrinsics ,
16
22
} ,
17
23
} ;
18
24
19
- fn convert_bls12381_halo2_fq_to_fp ( x : Fq ) -> Fp {
20
- let bytes = x. to_bytes ( ) ;
21
- Fp :: from_le_bytes ( & bytes)
22
- }
23
-
24
- fn convert_bls12381_halo2_fq2_to_fp2 ( x : Fq2 ) -> Fp2 {
25
- Fp2 :: new (
26
- convert_bls12381_halo2_fq_to_fp ( x. c0 ) ,
27
- convert_bls12381_halo2_fq_to_fp ( x. c1 ) ,
28
- )
29
- }
30
-
31
- fn convert_bls12381_halo2_fq12_to_fp12 ( x : Fq12 ) -> Fp12 {
32
- Fp12 {
33
- c : x. to_coeffs ( ) . map ( convert_bls12381_halo2_fq2_to_fp2) ,
34
- }
35
- }
36
-
37
- fn convert_bls12381_fp_to_halo2_fq ( x : Fp ) -> Fq {
38
- let bytes =
39
- x. 0 . chunks ( 8 )
40
- . map ( |b| u64:: from_le_bytes ( b. try_into ( ) . unwrap ( ) ) )
41
- . collect :: < Vec < _ > > ( )
42
- . try_into ( )
43
- . unwrap ( ) ;
44
- Fq :: from_raw_unchecked ( bytes)
45
- }
46
-
47
- fn convert_bls12381_fp2_to_halo2_fq2 ( x : Fp2 ) -> Fq2 {
48
- Fq2 {
49
- c0 : convert_bls12381_fp_to_halo2_fq ( x. c0 . clone ( ) ) ,
50
- c1 : convert_bls12381_fp_to_halo2_fq ( x. c1 . clone ( ) ) ,
51
- }
52
- }
53
-
54
- fn convert_bls12381_fp12_to_halo2_fq12 ( x : Fp12 ) -> Fq12 {
55
- let c = x. to_coeffs ( ) ;
56
- Fq12 :: from_coeffs ( c. map ( convert_bls12381_fp2_to_halo2_fq2) )
57
- }
58
-
59
- fn convert_g2_affine_halo2_to_openvm ( p : G2Affine ) -> OpenVmG2Affine {
60
- OpenVmG2Affine :: from_xy_unchecked (
61
- convert_bls12381_halo2_fq2_to_fp2 ( p. x ) ,
62
- convert_bls12381_halo2_fq2_to_fp2 ( p. y ) ,
63
- )
64
- }
65
-
66
25
#[ test]
67
26
fn test_bls12381_frobenius_coeffs ( ) {
68
27
#[ allow( clippy:: needless_range_loop) ]
@@ -300,3 +259,39 @@ fn test_bls12381_g2_affine() {
300
259
}
301
260
}
302
261
}
262
+
263
+ #[ test]
264
+ fn test_bls12381_pairing_check_hint_host ( ) {
265
+ let mut rng = StdRng :: seed_from_u64 ( 83 ) ;
266
+ let h2c_p = G1Affine :: random ( & mut rng) ;
267
+ let h2c_q = G2Affine :: random ( & mut rng) ;
268
+
269
+ let p = AffinePoint {
270
+ x : convert_bls12381_halo2_fq_to_fp ( h2c_p. x ) ,
271
+ y : convert_bls12381_halo2_fq_to_fp ( h2c_p. y ) ,
272
+ } ;
273
+ let q = AffinePoint {
274
+ x : convert_bls12381_halo2_fq2_to_fp2 ( h2c_q. x ) ,
275
+ y : convert_bls12381_halo2_fq2_to_fp2 ( h2c_q. y ) ,
276
+ } ;
277
+
278
+ let ( c, s) = Bls12_381 :: pairing_check_hint ( & [ p] , & [ q] ) ;
279
+
280
+ let p_cmp = AffinePoint {
281
+ x : h2c_p. x ,
282
+ y : h2c_p. y ,
283
+ } ;
284
+ let q_cmp = AffinePoint {
285
+ x : h2c_q. x ,
286
+ y : h2c_q. y ,
287
+ } ;
288
+
289
+ let f_cmp =
290
+ crate :: halo2curves_shims:: bls12_381:: Bls12_381 :: multi_miller_loop ( & [ p_cmp] , & [ q_cmp] ) ;
291
+ let ( c_cmp, s_cmp) = crate :: halo2curves_shims:: bls12_381:: Bls12_381 :: final_exp_hint ( & f_cmp) ;
292
+ let c_cmp = convert_bls12381_halo2_fq12_to_fp12 ( c_cmp) ;
293
+ let s_cmp = convert_bls12381_halo2_fq12_to_fp12 ( s_cmp) ;
294
+
295
+ assert_eq ! ( c, c_cmp) ;
296
+ assert_eq ! ( s, s_cmp) ;
297
+ }
0 commit comments