MCPcopy Create free account
hub / github.com/BitVM/BitVM / hinted_quad_miller_loop_with_c_wi

Method hinted_quad_miller_loop_with_c_wi

bitvm/src/bn254/pairing.rs:30–722  ·  view source on GitHub ↗

refer algorithm 9 of https://eprint.iacr.org/2024/640.pdf four pairings in total, where three of them is fixed on G2, only one is non-fixed on G2 (specially for groth16 verifier for now) input on stack: [beta_12, beta_13, beta_22, P1', P2', P3', P4', Q4, c, c_inv, wi, T4] P1', P2', P3', P4' are variants of points P1, P2, P3, P4 individually, such as P1' = (-P1.x / P1.y, 1 / P1.y) Q1, Q2 and Q3 ar

(
        constants: Vec<G2Prepared>,
        c: ark_bn254::Fq12,
        c_inv: ark_bn254::Fq12,
        wi: ark_bn254::Fq12,
        p_lst: Vec<ark_bn254::G1Affine>,
        q4: ark_bn254::G2Affine,

Source from the content-addressed store, hash-verified

28 // input of parameters:
29 // [L(Q1), L(Q2), L(Q3), L(Q4)] (line coefficients in affine mode)
30 pub fn hinted_quad_miller_loop_with_c_wi(
31 constants: Vec<G2Prepared>,
32 c: ark_bn254::Fq12,
33 c_inv: ark_bn254::Fq12,
34 wi: ark_bn254::Fq12,
35 p_lst: Vec<ark_bn254::G1Affine>,
36 q4: ark_bn254::G2Affine,
37 ) -> (Script, Vec<Hint>) {
38 assert_eq!(constants.len(), 4);
39 let num_line_groups = constants.len();
40 let num_constant = 3;
41
42 let line_coeffs = collect_line_coeffs(constants);
43 let num_lines = line_coeffs.len();
44
45 let mut hints = Vec::new();
46 let mut scripts = Vec::new();
47
48 let mut f = c_inv;
49 let mut t4 = q4;
50
51 for i in (1..ark_bn254::Config::ATE_LOOP_COUNT.len()).rev() {
52 let fx = f.square();
53 let (hinted_script, hint) = Fq12::hinted_square(f);
54 scripts.push(hinted_script);
55 hints.extend(hint);
56 f = fx;
57
58 if ark_bn254::Config::ATE_LOOP_COUNT[i - 1] == 1 {
59 let fx = f * c_inv;
60 let (hinted_script, hint) = Fq12::hinted_mul(12, f, 0, c_inv);
61 scripts.push(hinted_script);
62 hints.extend(hint);
63 f = fx;
64 } else if ark_bn254::Config::ATE_LOOP_COUNT[i - 1] == -1 {
65 let fx = f * c;
66 let (hinted_script, hint) = Fq12::hinted_mul(12, f, 0, c);
67 scripts.push(hinted_script);
68 hints.extend(hint);
69 f = fx;
70 }
71
72 for (j, p) in p_lst.iter().enumerate().take(num_line_groups) {
73 if j == 2 {
74 continue;
75 }
76 let coeffs = &line_coeffs[num_lines - (i + 2)][j][0];
77 assert_eq!(coeffs.0, ark_bn254::Fq2::ONE);
78 let mut fx = f;
79 let mut c1new = coeffs.1;
80 c1new.mul_assign_by_fp(&(-p.x / p.y));
81 let mut c2new = coeffs.2;
82 c2new.mul_assign_by_fp(&(p.y.inverse().unwrap()));
83 fx.mul_by_034(&coeffs.0, &c1new, &c2new);
84
85 let (hinted_script, hint) = hinted_ell_by_constant_affine_and_sparse_mul(
86 f,
87 -p.x / p.y,

Callers

nothing calls this directly

Calls 11

collect_line_coeffsFunction · 0.85
hinted_check_chord_lineFunction · 0.85
hinted_affine_add_lineFunction · 0.85
lenMethod · 0.80
cloneMethod · 0.80
pushMethod · 0.45
doubleMethod · 0.45
negMethod · 0.45

Tested by

no test coverage detected