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

Function verify_pairing

bitvm/src/chunk/g16_runner_core.rs:582–728  ·  view source on GitHub ↗

rust version of pairing verification check with normalized (1 + a. J) representation

(
        ps: Vec<ark_bn254::G1Affine>,
        qs: Vec<ark_bn254::G2Affine>,
        gc: ark_bn254::Fq12,
        _s: ark_bn254::Fq12,
        p1q1: ark_bn254::Fq6,
    )

Source from the content-addressed store, hash-verified

580
581 // rust version of pairing verification check with normalized (1 + a. J) representation
582 fn verify_pairing(
583 ps: Vec<ark_bn254::G1Affine>,
584 qs: Vec<ark_bn254::G2Affine>,
585 gc: ark_bn254::Fq12,
586 _s: ark_bn254::Fq12,
587 p1q1: ark_bn254::Fq6,
588 ) {
589 let mut cinv = gc.inverse().unwrap();
590 cinv = ark_bn254::Fq12::new(ark_bn254::Fq6::ONE, cinv.c1 / cinv.c0);
591 let mut c = gc;
592 c = ark_bn254::Fq12::new(ark_bn254::Fq6::ONE, c.c1 / c.c0);
593
594 let mut f = cinv;
595
596 let mut ts = qs.clone();
597 let ps: Vec<ark_bn254::G1Affine> = ps
598 .iter()
599 .map(|p1| ark_bn254::G1Affine::new_unchecked(-p1.x / p1.y, p1.y.inverse().unwrap()))
600 .collect();
601 let num_pairings = ps.len();
602 for itr in (1..ark_bn254::Config::ATE_LOOP_COUNT.len()).rev() {
603 let ate_bit = ark_bn254::Config::ATE_LOOP_COUNT[itr - 1];
604 // square
605 f = f * f;
606 f = ark_bn254::Fq12::new(ark_bn254::Fq6::ONE, f.c1 / f.c0);
607
608 // double and eval
609 for i in 0..num_pairings {
610 let t = ts[i];
611 let p = ps[i];
612 let alpha = (t.x.square() + t.x.square() + t.x.square()) / (t.y + t.y);
613 let neg_bias = alpha * t.x - t.y;
614 let mut le0 = alpha;
615 le0.mul_assign_by_fp(&p.x);
616 let mut le1 = neg_bias;
617 le1.mul_assign_by_fp(&p.y);
618 let mut le = ark_bn254::Fq12::ZERO;
619 le.c0.c0 = ark_bn254::fq2::Fq2::ONE;
620 le.c1.c0 = le0;
621 le.c1.c1 = le1;
622
623 f *= le;
624 f = ark_bn254::Fq12::new(ark_bn254::Fq6::ONE, f.c1 / f.c0);
625
626 ts[i] = (t + t).into_affine();
627 }
628
629 if ate_bit == 1 || ate_bit == -1 {
630 let c_or_cinv = if ate_bit == -1 { c } else { cinv };
631 f *= c_or_cinv;
632 f = ark_bn254::Fq12::new(ark_bn254::Fq6::ONE, f.c1 / f.c0);
633
634 for i in 0..num_pairings {
635 let t = ts[i];
636 let mut q = qs[i];
637 let p = ps[i];
638
639 if ate_bit == -1 {

Callers 1

test_verify_pairingFunction · 0.85

Calls 4

frob_q_powerFunction · 0.85
cloneMethod · 0.80
lenMethod · 0.80
negMethod · 0.45

Tested by 1

test_verify_pairingFunction · 0.68