diff --git a/hydra/garaga/definitions.py b/hydra/garaga/definitions.py index e62a4c0a..87bdb9d4 100644 --- a/hydra/garaga/definitions.py +++ b/hydra/garaga/definitions.py @@ -448,73 +448,6 @@ def bit(value, index): ), } -ISOGENY_MAP_G2 = { - BLS12_381_ID: { - "x_map_num": [ - [ - 889424345604814976315064405719089812568196182208668418962679585805340366775741747653930584250892369786198727235542, - 889424345604814976315064405719089812568196182208668418962679585805340366775741747653930584250892369786198727235542, - ], - [ - 0, - 2668273036814444928945193217157269437704588546626005256888038757416021100327225242961791752752677109358596181706522, - ], - [ - 2668273036814444928945193217157269437704588546626005256888038757416021100327225242961791752752677109358596181706526, - 1334136518407222464472596608578634718852294273313002628444019378708010550163612621480895876376338554679298090853261, - ], - [ - 3557697382419259905260257622876359250272784728834673675850718343221361467102966990615722337003569479144794908942033, - 0, - ], - ], - "x_map_den": [ - [ - 0, - 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559715, - ], - [ - 12, - 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559775, - ], - [1, 0], - ], - "y_map_num": [ - [ - 3261222600550988246488569487636662646083386001431784202863158481286248011511053074731078808919938689216061999863558, - 3261222600550988246488569487636662646083386001431784202863158481286248011511053074731078808919938689216061999863558, - ], - [ - 0, - 889424345604814976315064405719089812568196182208668418962679585805340366775741747653930584250892369786198727235518, - ], - [ - 2668273036814444928945193217157269437704588546626005256888038757416021100327225242961791752752677109358596181706524, - 1334136518407222464472596608578634718852294273313002628444019378708010550163612621480895876376338554679298090853263, - ], - [ - 2816510427748580758331037284777117739799287910327449993381818688383577828123182200904113516794492504322962636245776, - 0, - ], - ], - "y_map_den": [ - [ - 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559355, - 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559355, - ], - [ - 0, - 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559571, - ], - [ - 18, - 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559769, - ], - [1, 0], - ], - }, -} - def is_generator(g: int, p: int) -> bool: """ diff --git a/hydra/garaga/modulo_circuit.py b/hydra/garaga/modulo_circuit.py index 7a34abc0..ec6b28c5 100644 --- a/hydra/garaga/modulo_circuit.py +++ b/hydra/garaga/modulo_circuit.py @@ -864,27 +864,6 @@ def fp2_sub(self, X: list[ModuloCircuitElement], Y: list[ModuloCircuitElement]): self.sub(X[1], Y[1], comment="Fp2 sub imag part"), ] - def fp2_inv( - self, element: list[ModuloCircuitElement] - ) -> list[ModuloCircuitElement]: - assert len(element) == 2 and all( - isinstance(x, ModuloCircuitElement) for x in element - ) - # For element a + bi, compute (a - bi)/(a² + b²) - a, b = element[0], element[1] - # Compute conjugate (a - bi) - conj = [a, self.neg(b)] - # Compute norm (a² + b²) - a_squared = self.mul(a, a) - b_squared = self.mul(b, b) - norm = self.add(a_squared, b_squared) - - # Compute 1/norm - norm_inv = self.inv(norm) - - # Multiply conjugate by inverse of norm - return [self.mul(conj[0], norm_inv), self.mul(conj[1], norm_inv)] - def fp2_parity( self, element: list[ModuloCircuitElement] ) -> list[ModuloCircuitElement]: diff --git a/src/src/circuits/ec.cairo b/src/src/circuits/ec.cairo index 57df9049..db2703ee 100644 --- a/src/src/circuits/ec.cairo +++ b/src/src/circuits/ec.cairo @@ -171,18 +171,18 @@ pub fn run_ADD_EC_POINTS_G2_circuit(p: G2Point, q: G2Point, curve_index: usize) let t1 = circuit_sub(in4, in8); // Fp2 sub coeff 1/1 let t2 = circuit_sub(in1, in5); // Fp2 sub coeff 0/1 let t3 = circuit_sub(in2, in6); // Fp2 sub coeff 1/1 - let t4 = circuit_sub(in0, t3); - let t5 = circuit_mul(t2, t2); - let t6 = circuit_mul(t3, t3); - let t7 = circuit_add(t5, t6); - let t8 = circuit_inverse(t7); - let t9 = circuit_mul(t2, t8); - let t10 = circuit_mul(t4, t8); - let t11 = circuit_mul(t0, t9); // Fp2 mul start + let t4 = circuit_mul(t2, t2); // Fp2 Inv start + let t5 = circuit_mul(t3, t3); + let t6 = circuit_add(t4, t5); + let t7 = circuit_inverse(t6); + let t8 = circuit_mul(t2, t7); // Fp2 Inv real part end + let t9 = circuit_mul(t3, t7); + let t10 = circuit_sub(in0, t9); // Fp2 Inv imag part end + let t11 = circuit_mul(t0, t8); // Fp2 mul start let t12 = circuit_mul(t1, t10); let t13 = circuit_sub(t11, t12); // Fp2 mul real part end let t14 = circuit_mul(t0, t10); - let t15 = circuit_mul(t1, t9); + let t15 = circuit_mul(t1, t8); let t16 = circuit_add(t14, t15); // Fp2 mul imag part end let t17 = circuit_add(t13, t16); let t18 = circuit_sub(t13, t16); @@ -277,18 +277,18 @@ pub fn run_DOUBLE_EC_POINT_G2_A_EQ_0_circuit(p: G2Point, curve_index: usize) -> let t6 = circuit_mul(t4, in0); // Fp2 scalar mul coeff 1/1 let t7 = circuit_add(in4, in4); // Fp2 add coeff 0/1 let t8 = circuit_add(in5, in5); // Fp2 add coeff 1/1 - let t9 = circuit_sub(in1, t8); - let t10 = circuit_mul(t7, t7); - let t11 = circuit_mul(t8, t8); - let t12 = circuit_add(t10, t11); - let t13 = circuit_inverse(t12); - let t14 = circuit_mul(t7, t13); - let t15 = circuit_mul(t9, t13); - let t16 = circuit_mul(t5, t14); // Fp2 mul start + let t9 = circuit_mul(t7, t7); // Fp2 Inv start + let t10 = circuit_mul(t8, t8); + let t11 = circuit_add(t9, t10); + let t12 = circuit_inverse(t11); + let t13 = circuit_mul(t7, t12); // Fp2 Inv real part end + let t14 = circuit_mul(t8, t12); + let t15 = circuit_sub(in1, t14); // Fp2 Inv imag part end + let t16 = circuit_mul(t5, t13); // Fp2 mul start let t17 = circuit_mul(t6, t15); let t18 = circuit_sub(t16, t17); // Fp2 mul real part end let t19 = circuit_mul(t5, t15); - let t20 = circuit_mul(t6, t14); + let t20 = circuit_mul(t6, t13); let t21 = circuit_add(t19, t20); // Fp2 mul imag part end let t22 = circuit_add(t18, t21); let t23 = circuit_sub(t18, t21); diff --git a/src/src/circuits/extf_mul.cairo b/src/src/circuits/extf_mul.cairo index 5d92b8bb..0a78a224 100644 --- a/src/src/circuits/extf_mul.cairo +++ b/src/src/circuits/extf_mul.cairo @@ -44,17 +44,7 @@ pub fn run_BLS12_381_EVAL_E12D_circuit(f: E12D, z: u384) -> (u384,) { let t20 = circuit_mul(t19, in12); // Eval X Horner step: multiply by z let t21 = circuit_add(in0, t20); // Eval X Horner step: add coefficient_0 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t21,).new_inputs(); // Prefill constants: @@ -183,17 +173,7 @@ pub fn run_BLS12_381_FP12_MUL_ASSERT_ONE_circuit( let t80 = circuit_sub(t78, t79); // (X(z) * Y(z)) - (Q(z) * P(z)) let t81 = circuit_sub(t80, in2); // (X(z) * Y(z) - Q(z) * P(z)) - 1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t81,).new_inputs(); // Prefill constants: @@ -279,10 +259,7 @@ pub fn run_BN254_EVAL_E12D_circuit(f: E12D, z: u384) -> (u384,) { let t20 = circuit_mul(t19, in12); // Eval X Horner step: multiply by z let t21 = circuit_add(in0, t20); // Eval X Horner step: add coefficient_0 - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t21,).new_inputs(); // Prefill constants: @@ -411,10 +388,7 @@ pub fn run_BN254_FP12_MUL_ASSERT_ONE_circuit( let t80 = circuit_sub(t78, t79); // (X(z) * Y(z)) - (Q(z) * P(z)) let t81 = circuit_sub(t80, in2); // (X(z) * Y(z) - Q(z) * P(z)) - 1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t81,).new_inputs(); // Prefill constants: diff --git a/src/src/circuits/isogeny.cairo b/src/src/circuits/isogeny.cairo index 285c6129..4ece4ca8 100644 --- a/src/src/circuits/isogeny.cairo +++ b/src/src/circuits/isogeny.cairo @@ -287,17 +287,7 @@ pub fn run_BLS12_381_APPLY_ISOGENY_BLS12_381_circuit(pt: G1Point) -> (G1Point,) let t105 = circuit_mul(t73, t104); let t106 = circuit_mul(t105, in55); - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t43, t106).new_inputs(); // Prefill constants: diff --git a/src/src/circuits/multi_pairing_check.cairo b/src/src/circuits/multi_pairing_check.cairo index f911d5f4..1570baee 100644 --- a/src/src/circuits/multi_pairing_check.cairo +++ b/src/src/circuits/multi_pairing_check.cairo @@ -108,15 +108,7 @@ pub fn run_BLS12_381_MP_CHECK_BIT00_2P_2F_circuit( let t64 = circuit_mul(t4, t63); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t65 = circuit_add(in20, t64); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t65, t4).new_inputs(); // Prefill constants: @@ -231,18 +223,18 @@ pub fn run_BLS12_381_MP_CHECK_BIT00_3P_2F_circuit( let t39 = circuit_mul(t37, in1); // Doubling slope numerator end let t40 = circuit_add(in27, in27); // Fp2 add coeff 0/1 let t41 = circuit_add(in28, in28); // Fp2 add coeff 1/1 - let t42 = circuit_sub(in2, t41); - let t43 = circuit_mul(t40, t40); - let t44 = circuit_mul(t41, t41); - let t45 = circuit_add(t43, t44); - let t46 = circuit_inverse(t45); - let t47 = circuit_mul(t40, t46); - let t48 = circuit_mul(t42, t46); - let t49 = circuit_mul(t38, t47); // Fp2 mul start + let t42 = circuit_mul(t40, t40); // Fp2 Inv start + let t43 = circuit_mul(t41, t41); + let t44 = circuit_add(t42, t43); + let t45 = circuit_inverse(t44); + let t46 = circuit_mul(t40, t45); // Fp2 Inv real part end + let t47 = circuit_mul(t41, t45); + let t48 = circuit_sub(in2, t47); // Fp2 Inv imag part end + let t49 = circuit_mul(t38, t46); // Fp2 mul start let t50 = circuit_mul(t39, t48); let t51 = circuit_sub(t49, t50); // Fp2 mul real part end let t52 = circuit_mul(t38, t48); - let t53 = circuit_mul(t39, t47); + let t53 = circuit_mul(t39, t46); let t54 = circuit_add(t52, t53); // Fp2 mul imag part end let t55 = circuit_add(t51, t54); let t56 = circuit_sub(t51, t54); @@ -324,18 +316,18 @@ pub fn run_BLS12_381_MP_CHECK_BIT00_3P_2F_circuit( let t130 = circuit_mul(t128, in1); // Doubling slope numerator end let t131 = circuit_add(t72, t72); // Fp2 add coeff 0/1 let t132 = circuit_add(t73, t73); // Fp2 add coeff 1/1 - let t133 = circuit_sub(in2, t132); - let t134 = circuit_mul(t131, t131); - let t135 = circuit_mul(t132, t132); - let t136 = circuit_add(t134, t135); - let t137 = circuit_inverse(t136); - let t138 = circuit_mul(t131, t137); - let t139 = circuit_mul(t133, t137); - let t140 = circuit_mul(t129, t138); // Fp2 mul start + let t133 = circuit_mul(t131, t131); // Fp2 Inv start + let t134 = circuit_mul(t132, t132); + let t135 = circuit_add(t133, t134); + let t136 = circuit_inverse(t135); + let t137 = circuit_mul(t131, t136); // Fp2 Inv real part end + let t138 = circuit_mul(t132, t136); + let t139 = circuit_sub(in2, t138); // Fp2 Inv imag part end + let t140 = circuit_mul(t129, t137); // Fp2 mul start let t141 = circuit_mul(t130, t139); let t142 = circuit_sub(t140, t141); // Fp2 mul real part end let t143 = circuit_mul(t129, t139); - let t144 = circuit_mul(t130, t138); + let t144 = circuit_mul(t130, t137); let t145 = circuit_add(t143, t144); // Fp2 mul imag part end let t146 = circuit_add(t142, t145); let t147 = circuit_sub(t142, t145); @@ -382,15 +374,7 @@ pub fn run_BLS12_381_MP_CHECK_BIT00_3P_2F_circuit( let t188 = circuit_mul(t4, t187); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t189 = circuit_add(in29, t188); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t153, t154, t163, t164, t189, t4).new_inputs(); // Prefill constants: @@ -500,15 +484,7 @@ pub fn run_BLS12_381_MP_CHECK_BIT0_2P_2F_circuit( let t35 = circuit_mul(t4, t34); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t36 = circuit_add(in12, t35); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t36, t4).new_inputs(); // Prefill constants: @@ -610,18 +586,18 @@ pub fn run_BLS12_381_MP_CHECK_BIT0_3P_2F_circuit( let t39 = circuit_mul(t37, in1); // Doubling slope numerator end let t40 = circuit_add(in19, in19); // Fp2 add coeff 0/1 let t41 = circuit_add(in20, in20); // Fp2 add coeff 1/1 - let t42 = circuit_sub(in2, t41); - let t43 = circuit_mul(t40, t40); - let t44 = circuit_mul(t41, t41); - let t45 = circuit_add(t43, t44); - let t46 = circuit_inverse(t45); - let t47 = circuit_mul(t40, t46); - let t48 = circuit_mul(t42, t46); - let t49 = circuit_mul(t38, t47); // Fp2 mul start + let t42 = circuit_mul(t40, t40); // Fp2 Inv start + let t43 = circuit_mul(t41, t41); + let t44 = circuit_add(t42, t43); + let t45 = circuit_inverse(t44); + let t46 = circuit_mul(t40, t45); // Fp2 Inv real part end + let t47 = circuit_mul(t41, t45); + let t48 = circuit_sub(in2, t47); // Fp2 Inv imag part end + let t49 = circuit_mul(t38, t46); // Fp2 mul start let t50 = circuit_mul(t39, t48); let t51 = circuit_sub(t49, t50); // Fp2 mul real part end let t52 = circuit_mul(t38, t48); - let t53 = circuit_mul(t39, t47); + let t53 = circuit_mul(t39, t46); let t54 = circuit_add(t52, t53); // Fp2 mul imag part end let t55 = circuit_add(t51, t54); let t56 = circuit_sub(t51, t54); @@ -668,15 +644,7 @@ pub fn run_BLS12_381_MP_CHECK_BIT0_3P_2F_circuit( let t97 = circuit_mul(t4, t96); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t98 = circuit_add(in21, t97); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t62, t63, t72, t73, t98, t4).new_inputs(); // Prefill constants: @@ -813,15 +781,7 @@ pub fn run_BLS12_381_MP_CHECK_BIT1_2P_2F_circuit( let t64 = circuit_mul(t4, t63); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t65 = circuit_add(in20, t64); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t65, t4).new_inputs(); // Prefill constants: @@ -962,18 +922,18 @@ pub fn run_BLS12_381_MP_CHECK_BIT1_3P_2F_circuit( let t63 = circuit_sub(in26, in30); // Fp2 sub coeff 1/1 let t64 = circuit_sub(in23, in27); // Fp2 sub coeff 0/1 let t65 = circuit_sub(in24, in28); // Fp2 sub coeff 1/1 - let t66 = circuit_sub(in0, t65); - let t67 = circuit_mul(t64, t64); - let t68 = circuit_mul(t65, t65); - let t69 = circuit_add(t67, t68); - let t70 = circuit_inverse(t69); - let t71 = circuit_mul(t64, t70); - let t72 = circuit_mul(t66, t70); - let t73 = circuit_mul(t62, t71); // Fp2 mul start + let t66 = circuit_mul(t64, t64); // Fp2 Inv start + let t67 = circuit_mul(t65, t65); + let t68 = circuit_add(t66, t67); + let t69 = circuit_inverse(t68); + let t70 = circuit_mul(t64, t69); // Fp2 Inv real part end + let t71 = circuit_mul(t65, t69); + let t72 = circuit_sub(in0, t71); // Fp2 Inv imag part end + let t73 = circuit_mul(t62, t70); // Fp2 mul start let t74 = circuit_mul(t63, t72); let t75 = circuit_sub(t73, t74); // Fp2 mul real part end let t76 = circuit_mul(t62, t72); - let t77 = circuit_mul(t63, t71); + let t77 = circuit_mul(t63, t70); let t78 = circuit_add(t76, t77); // Fp2 mul imag part end let t79 = circuit_add(t75, t78); let t80 = circuit_sub(t75, t78); @@ -996,18 +956,18 @@ pub fn run_BLS12_381_MP_CHECK_BIT1_3P_2F_circuit( let t97 = circuit_add(in26, in26); // Fp2 add coeff 1/1 let t98 = circuit_sub(t86, in23); // Fp2 sub coeff 0/1 let t99 = circuit_sub(t87, in24); // Fp2 sub coeff 1/1 - let t100 = circuit_sub(in0, t99); - let t101 = circuit_mul(t98, t98); - let t102 = circuit_mul(t99, t99); - let t103 = circuit_add(t101, t102); - let t104 = circuit_inverse(t103); - let t105 = circuit_mul(t98, t104); - let t106 = circuit_mul(t100, t104); - let t107 = circuit_mul(t96, t105); // Fp2 mul start + let t100 = circuit_mul(t98, t98); // Fp2 Inv start + let t101 = circuit_mul(t99, t99); + let t102 = circuit_add(t100, t101); + let t103 = circuit_inverse(t102); + let t104 = circuit_mul(t98, t103); // Fp2 Inv real part end + let t105 = circuit_mul(t99, t103); + let t106 = circuit_sub(in0, t105); // Fp2 Inv imag part end + let t107 = circuit_mul(t96, t104); // Fp2 mul start let t108 = circuit_mul(t97, t106); let t109 = circuit_sub(t107, t108); // Fp2 mul real part end let t110 = circuit_mul(t96, t106); - let t111 = circuit_mul(t97, t105); + let t111 = circuit_mul(t97, t104); let t112 = circuit_add(t110, t111); // Fp2 mul imag part end let t113 = circuit_add(t75, t109); // Fp2 add coeff 0/1 let t114 = circuit_add(t78, t112); // Fp2 add coeff 1/1 @@ -1073,15 +1033,7 @@ pub fn run_BLS12_381_MP_CHECK_BIT1_3P_2F_circuit( let t174 = circuit_mul(t4, t173); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t175 = circuit_add(in31, t174); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t124, t125, t134, t135, t175, t4).new_inputs(); // Prefill constants: @@ -1389,15 +1341,7 @@ pub fn run_BLS12_381_MP_CHECK_FINALIZE_BLS_2P_circuit( let t202 = circuit_mul(t201, t41); // Q(z) * P(z) let t203 = circuit_sub(t38, t202); // final_lhs - Q(z) * P(z) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t203,).new_inputs(); // Prefill constants: @@ -1748,15 +1692,7 @@ pub fn run_BLS12_381_MP_CHECK_FINALIZE_BLS_3P_circuit( let t250 = circuit_mul(t249, t41); // Q(z) * P(z) let t251 = circuit_sub(t38, t250); // final_lhs - Q(z) * P(z) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t251,).new_inputs(); // Prefill constants: @@ -1886,15 +1822,7 @@ pub fn run_BLS12_381_MP_CHECK_INIT_BIT_2P_2F_circuit( let t62 = circuit_sub(t61, in20); let t63 = circuit_mul(in21, t62); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t63,).new_inputs(); // Prefill constants: @@ -2033,18 +1961,18 @@ pub fn run_BLS12_381_MP_CHECK_INIT_BIT_3P_2F_circuit( let t67 = circuit_mul(t65, in1); let t68 = circuit_add(in27, in27); // Fp2 add coeff 0/1 let t69 = circuit_add(in28, in28); // Fp2 add coeff 1/1 - let t70 = circuit_sub(in2, t69); - let t71 = circuit_mul(t68, t68); - let t72 = circuit_mul(t69, t69); - let t73 = circuit_add(t71, t72); - let t74 = circuit_inverse(t73); - let t75 = circuit_mul(t68, t74); - let t76 = circuit_mul(t70, t74); - let t77 = circuit_mul(t66, t75); // Fp2 mul start + let t70 = circuit_mul(t68, t68); // Fp2 Inv start + let t71 = circuit_mul(t69, t69); + let t72 = circuit_add(t70, t71); + let t73 = circuit_inverse(t72); + let t74 = circuit_mul(t68, t73); // Fp2 Inv real part end + let t75 = circuit_mul(t69, t73); + let t76 = circuit_sub(in2, t75); // Fp2 Inv imag part end + let t77 = circuit_mul(t66, t74); // Fp2 mul start let t78 = circuit_mul(t67, t76); let t79 = circuit_sub(t77, t78); // Fp2 mul real part end let t80 = circuit_mul(t66, t76); - let t81 = circuit_mul(t67, t75); + let t81 = circuit_mul(t67, t74); let t82 = circuit_add(t80, t81); // Fp2 mul imag part end let t83 = circuit_mul(t79, in25); // Fp2 mul start let t84 = circuit_mul(t82, in26); @@ -2065,18 +1993,18 @@ pub fn run_BLS12_381_MP_CHECK_INIT_BIT_3P_2F_circuit( let t99 = circuit_sub(t95, t97); // Fp2 sub coeff 1/1 let t100 = circuit_sub(in25, t98); // Fp2 sub coeff 0/1 let t101 = circuit_sub(in26, t99); // Fp2 sub coeff 1/1 - let t102 = circuit_sub(in2, t101); - let t103 = circuit_mul(t100, t100); - let t104 = circuit_mul(t101, t101); - let t105 = circuit_add(t103, t104); - let t106 = circuit_inverse(t105); - let t107 = circuit_mul(t100, t106); - let t108 = circuit_mul(t102, t106); - let t109 = circuit_mul(t68, t107); // Fp2 mul start + let t102 = circuit_mul(t100, t100); // Fp2 Inv start + let t103 = circuit_mul(t101, t101); + let t104 = circuit_add(t102, t103); + let t105 = circuit_inverse(t104); + let t106 = circuit_mul(t100, t105); // Fp2 Inv real part end + let t107 = circuit_mul(t101, t105); + let t108 = circuit_sub(in2, t107); // Fp2 Inv imag part end + let t109 = circuit_mul(t68, t106); // Fp2 mul start let t110 = circuit_mul(t69, t108); let t111 = circuit_sub(t109, t110); // Fp2 mul real part end let t112 = circuit_mul(t68, t108); - let t113 = circuit_mul(t69, t107); + let t113 = circuit_mul(t69, t106); let t114 = circuit_add(t112, t113); // Fp2 mul imag part end let t115 = circuit_sub(t111, t79); // Fp2 sub coeff 0/1 let t116 = circuit_sub(t114, t82); // Fp2 sub coeff 1/1 @@ -2138,15 +2066,7 @@ pub fn run_BLS12_381_MP_CHECK_INIT_BIT_3P_2F_circuit( let t172 = circuit_sub(t171, in29); let t173 = circuit_mul(in30, t172); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t132, t133, t142, t143, t173).new_inputs(); // Prefill constants: @@ -2347,15 +2267,7 @@ pub fn run_BLS12_381_MP_CHECK_PREPARE_LAMBDA_ROOT_circuit( let t93 = circuit_mul(t72, t9); // Eval C_inv_frob_1 step coeff_11 * z^11 let t94 = circuit_add(t92, t93); // Eval C_inv_frob_1 step + (coeff_11 * z^11) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t37, t47, t94).new_inputs(); // Prefill constants: @@ -2489,15 +2401,7 @@ pub fn run_BLS12_381_MP_CHECK_PREPARE_PAIRS_1P_circuit(p_0: G1Point) -> (BLSProc let t1 = circuit_mul(in1, t0); let t2 = circuit_sub(in0, t1); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t0, t2).new_inputs(); // Prefill constants: @@ -2529,15 +2433,7 @@ pub fn run_BLS12_381_MP_CHECK_PREPARE_PAIRS_2P_circuit( let t4 = circuit_mul(in3, t3); let t5 = circuit_sub(in0, t4); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t0, t2, t3, t5).new_inputs(); // Prefill constants: @@ -2577,15 +2473,7 @@ pub fn run_BLS12_381_MP_CHECK_PREPARE_PAIRS_3P_circuit( let t7 = circuit_mul(in5, t6); let t8 = circuit_sub(in0, t7); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, 0x6730d2a0f6b0f6241eabfffe, 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6, - ], - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t0, t2, t3, t5, t6, t8).new_inputs(); // Prefill constants: @@ -2722,10 +2610,7 @@ pub fn run_BN254_MP_CHECK_BIT00_2P_2F_circuit( let t77 = circuit_mul(t5, t76); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t78 = circuit_add(in22, t77); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t78, t5).new_inputs(); // Prefill constants: @@ -2853,18 +2738,18 @@ pub fn run_BN254_MP_CHECK_BIT00_3P_2F_circuit( let t46 = circuit_mul(t44, in3); // Doubling slope numerator end let t47 = circuit_add(in29, in29); // Fp2 add coeff 0/1 let t48 = circuit_add(in30, in30); // Fp2 add coeff 1/1 - let t49 = circuit_sub(in4, t48); - let t50 = circuit_mul(t47, t47); - let t51 = circuit_mul(t48, t48); - let t52 = circuit_add(t50, t51); - let t53 = circuit_inverse(t52); - let t54 = circuit_mul(t47, t53); - let t55 = circuit_mul(t49, t53); - let t56 = circuit_mul(t45, t54); // Fp2 mul start + let t49 = circuit_mul(t47, t47); // Fp2 Inv start + let t50 = circuit_mul(t48, t48); + let t51 = circuit_add(t49, t50); + let t52 = circuit_inverse(t51); + let t53 = circuit_mul(t47, t52); // Fp2 Inv real part end + let t54 = circuit_mul(t48, t52); + let t55 = circuit_sub(in4, t54); // Fp2 Inv imag part end + let t56 = circuit_mul(t45, t53); // Fp2 mul start let t57 = circuit_mul(t46, t55); let t58 = circuit_sub(t56, t57); // Fp2 mul real part end let t59 = circuit_mul(t45, t55); - let t60 = circuit_mul(t46, t54); + let t60 = circuit_mul(t46, t53); let t61 = circuit_add(t59, t60); // Fp2 mul imag part end let t62 = circuit_add(t58, t61); let t63 = circuit_sub(t58, t61); @@ -2955,18 +2840,18 @@ pub fn run_BN254_MP_CHECK_BIT00_3P_2F_circuit( let t146 = circuit_mul(t144, in3); // Doubling slope numerator end let t147 = circuit_add(t79, t79); // Fp2 add coeff 0/1 let t148 = circuit_add(t80, t80); // Fp2 add coeff 1/1 - let t149 = circuit_sub(in4, t148); - let t150 = circuit_mul(t147, t147); - let t151 = circuit_mul(t148, t148); - let t152 = circuit_add(t150, t151); - let t153 = circuit_inverse(t152); - let t154 = circuit_mul(t147, t153); - let t155 = circuit_mul(t149, t153); - let t156 = circuit_mul(t145, t154); // Fp2 mul start + let t149 = circuit_mul(t147, t147); // Fp2 Inv start + let t150 = circuit_mul(t148, t148); + let t151 = circuit_add(t149, t150); + let t152 = circuit_inverse(t151); + let t153 = circuit_mul(t147, t152); // Fp2 Inv real part end + let t154 = circuit_mul(t148, t152); + let t155 = circuit_sub(in4, t154); // Fp2 Inv imag part end + let t156 = circuit_mul(t145, t153); // Fp2 mul start let t157 = circuit_mul(t146, t155); let t158 = circuit_sub(t156, t157); // Fp2 mul real part end let t159 = circuit_mul(t145, t155); - let t160 = circuit_mul(t146, t154); + let t160 = circuit_mul(t146, t153); let t161 = circuit_add(t159, t160); // Fp2 mul imag part end let t162 = circuit_add(t158, t161); let t163 = circuit_sub(t158, t161); @@ -3016,10 +2901,7 @@ pub fn run_BN254_MP_CHECK_BIT00_3P_2F_circuit( let t207 = circuit_mul(t5, t206); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t208 = circuit_add(in31, t207); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t169, t170, t179, t180, t208, t5).new_inputs(); // Prefill constants: @@ -3228,10 +3110,7 @@ pub fn run_BN254_MP_CHECK_BIT01_2P_2F_circuit( let t112 = circuit_mul(t5, t111); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t113 = circuit_add(in30, t112); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t113, t5).new_inputs(); // Prefill constants: @@ -3387,7 +3266,7 @@ pub fn run_BN254_MP_CHECK_BIT01_3P_2F_circuit( let t57 = circuit_mul(t46, t55); let t58 = circuit_sub(t56, t57); // Fp2 mul real part end let t59 = circuit_mul(t45, t55); - let t60 = circuit_mul(t46, t54); + let t60 = circuit_mul(t46, t53); let t61 = circuit_add(t59, t60); // Fp2 mul imag part end let t62 = circuit_add(t58, t61); let t63 = circuit_sub(t58, t61); @@ -3625,10 +3504,7 @@ pub fn run_BN254_MP_CHECK_BIT01_3P_2F_circuit( let t293 = circuit_mul(t5, t292); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t294 = circuit_add(in43, t293); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t237, t238, t247, t248, t294, t5).new_inputs(); // Prefill constants: @@ -3851,10 +3727,7 @@ pub fn run_BN254_MP_CHECK_BIT10_2P_2F_circuit( let t113 = circuit_mul(t5, t112); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t114 = circuit_add(in30, t113); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t114, t5).new_inputs(); // Prefill constants: @@ -4040,7 +3913,7 @@ pub fn run_BN254_MP_CHECK_BIT10_3P_2F_circuit( let t87 = circuit_mul(t76, t85); let t88 = circuit_sub(t86, t87); // Fp2 mul real part end let t89 = circuit_mul(t75, t85); - let t90 = circuit_mul(t76, t84); + let t90 = circuit_mul(t76, t83); let t91 = circuit_add(t89, t90); // Fp2 mul imag part end let t92 = circuit_add(t88, t91); let t93 = circuit_sub(t88, t91); @@ -4074,7 +3947,7 @@ pub fn run_BN254_MP_CHECK_BIT10_3P_2F_circuit( let t121 = circuit_mul(t110, t119); let t122 = circuit_sub(t120, t121); // Fp2 mul real part end let t123 = circuit_mul(t109, t119); - let t124 = circuit_mul(t110, t118); + let t124 = circuit_mul(t110, t117); let t125 = circuit_add(t123, t124); // Fp2 mul imag part end let t126 = circuit_add(t88, t122); // Fp2 add coeff 0/1 let t127 = circuit_add(t91, t125); // Fp2 add coeff 1/1 @@ -4249,10 +4122,7 @@ pub fn run_BN254_MP_CHECK_BIT10_3P_2F_circuit( let t294 = circuit_mul(t5, t293); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t295 = circuit_add(in43, t294); // LHS = LHS + ci * ((Π(i,k) (Pk(z)) - Ri(z)) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t254, t255, t264, t265, t295, t5).new_inputs(); // Prefill constants: @@ -4845,10 +4715,7 @@ pub fn run_BN254_MP_CHECK_FINALIZE_BN_2P_2F_circuit( let t426 = circuit_mul(t422, t425); let t427 = circuit_sub(t134, t426); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t427,).new_inputs(); // Prefill constants: @@ -5127,18 +4994,18 @@ pub fn run_BN254_MP_CHECK_FINALIZE_BN_3P_2F_circuit( let t76 = circuit_sub(in39, t70); // Fp2 sub coeff 1/1 let t77 = circuit_sub(in36, t61); // Fp2 sub coeff 0/1 let t78 = circuit_sub(in37, t64); // Fp2 sub coeff 1/1 - let t79 = circuit_sub(in6, t78); - let t80 = circuit_mul(t77, t77); - let t81 = circuit_mul(t78, t78); - let t82 = circuit_add(t80, t81); - let t83 = circuit_inverse(t82); - let t84 = circuit_mul(t77, t83); - let t85 = circuit_mul(t79, t83); - let t86 = circuit_mul(t75, t84); // Fp2 mul start + let t79 = circuit_mul(t77, t77); // Fp2 Inv start + let t80 = circuit_mul(t78, t78); + let t81 = circuit_add(t79, t80); + let t82 = circuit_inverse(t81); + let t83 = circuit_mul(t77, t82); // Fp2 Inv real part end + let t84 = circuit_mul(t78, t82); + let t85 = circuit_sub(in6, t84); // Fp2 Inv imag part end + let t86 = circuit_mul(t75, t83); // Fp2 mul start let t87 = circuit_mul(t76, t85); let t88 = circuit_sub(t86, t87); // Fp2 mul real part end let t89 = circuit_mul(t75, t85); - let t90 = circuit_mul(t76, t84); + let t90 = circuit_mul(t76, t83); let t91 = circuit_add(t89, t90); // Fp2 mul imag part end let t92 = circuit_add(t88, t91); let t93 = circuit_sub(t88, t91); @@ -5171,18 +5038,18 @@ pub fn run_BN254_MP_CHECK_FINALIZE_BN_3P_2F_circuit( let t120 = circuit_sub(t110, t74); // Fp2 sub coeff 1/1 let t121 = circuit_sub(t99, t71); // Fp2 sub coeff 0/1 let t122 = circuit_sub(t100, t72); // Fp2 sub coeff 1/1 - let t123 = circuit_sub(in6, t122); - let t124 = circuit_mul(t121, t121); - let t125 = circuit_mul(t122, t122); - let t126 = circuit_add(t124, t125); - let t127 = circuit_inverse(t126); - let t128 = circuit_mul(t121, t127); - let t129 = circuit_mul(t123, t127); - let t130 = circuit_mul(t119, t128); // Fp2 mul start + let t123 = circuit_mul(t121, t121); // Fp2 Inv start + let t124 = circuit_mul(t122, t122); + let t125 = circuit_add(t123, t124); + let t126 = circuit_inverse(t125); + let t127 = circuit_mul(t121, t126); // Fp2 Inv real part end + let t128 = circuit_mul(t122, t126); + let t129 = circuit_sub(in6, t128); // Fp2 Inv imag part end + let t130 = circuit_mul(t119, t127); // Fp2 mul start let t131 = circuit_mul(t120, t129); let t132 = circuit_sub(t130, t131); // Fp2 mul real part end let t133 = circuit_mul(t119, t129); - let t134 = circuit_mul(t120, t128); + let t134 = circuit_mul(t120, t127); let t135 = circuit_add(t133, t134); // Fp2 mul imag part end let t136 = circuit_mul(t132, t99); // Fp2 mul start let t137 = circuit_mul(t135, t100); @@ -5688,10 +5555,7 @@ pub fn run_BN254_MP_CHECK_FINALIZE_BN_3P_2F_circuit( let t637 = circuit_mul(t633, t636); let t638 = circuit_sub(t255, t637); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t638,).new_inputs(); // Prefill constants: @@ -5889,10 +5753,7 @@ pub fn run_BN254_MP_CHECK_INIT_BIT_2P_2F_circuit( let t42 = circuit_mul(t6, t41); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t43 = circuit_add(t42, in18); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t43, t6).new_inputs(); // Prefill constants: @@ -6007,18 +5868,18 @@ pub fn run_BN254_MP_CHECK_INIT_BIT_3P_2F_circuit( let t46 = circuit_mul(t44, in3); // Doubling slope numerator end let t47 = circuit_add(in21, in21); // Fp2 add coeff 0/1 let t48 = circuit_add(in22, in22); // Fp2 add coeff 1/1 - let t49 = circuit_sub(in4, t48); - let t50 = circuit_mul(t47, t47); - let t51 = circuit_mul(t48, t48); - let t52 = circuit_add(t50, t51); - let t53 = circuit_inverse(t52); - let t54 = circuit_mul(t47, t53); - let t55 = circuit_mul(t49, t53); - let t56 = circuit_mul(t45, t54); // Fp2 mul start + let t49 = circuit_mul(t47, t47); // Fp2 Inv start + let t50 = circuit_mul(t48, t48); + let t51 = circuit_add(t49, t50); + let t52 = circuit_inverse(t51); + let t53 = circuit_mul(t47, t52); // Fp2 Inv real part end + let t54 = circuit_mul(t48, t52); + let t55 = circuit_sub(in4, t54); // Fp2 Inv imag part end + let t56 = circuit_mul(t45, t53); // Fp2 mul start let t57 = circuit_mul(t46, t55); let t58 = circuit_sub(t56, t57); // Fp2 mul real part end let t59 = circuit_mul(t45, t55); - let t60 = circuit_mul(t46, t54); + let t60 = circuit_mul(t46, t53); let t61 = circuit_add(t59, t60); // Fp2 mul imag part end let t62 = circuit_add(t58, t61); let t63 = circuit_sub(t58, t61); @@ -6068,10 +5929,7 @@ pub fn run_BN254_MP_CHECK_INIT_BIT_3P_2F_circuit( let t107 = circuit_mul(t6, t106); // ci * ((Π(i,k) (Pk(z)) - Ri(z)) let t108 = circuit_add(t107, in27); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t69, t70, t79, t80, t108, t6).new_inputs(); // Prefill constants: @@ -6442,10 +6300,7 @@ pub fn run_BN254_MP_CHECK_PREPARE_LAMBDA_ROOT_circuit( let t207 = circuit_mul(t142, t9); // Eval C_inv_frob_3 step coeff_11 * z^11 let t208 = circuit_add(t206, t207); // Eval C_inv_frob_3 step + (coeff_11 * z^11) - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t31, t41, t63, t66, t164, t186, t208).new_inputs(); // Prefill constants: @@ -6783,10 +6638,7 @@ pub fn run_BN254_MP_CHECK_PREPARE_PAIRS_1P_circuit( let t3 = circuit_sub(in0, in3); let t4 = circuit_sub(in0, in4); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t0, t2, t3, t4).new_inputs(); // Prefill constants: @@ -6828,10 +6680,7 @@ pub fn run_BN254_MP_CHECK_PREPARE_PAIRS_2P_circuit( let t8 = circuit_sub(in0, in7); let t9 = circuit_sub(in0, in8); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t0, t2, t3, t4, t5, t7, t8, t9).new_inputs(); // Prefill constants: @@ -6897,10 +6746,7 @@ pub fn run_BN254_MP_CHECK_PREPARE_PAIRS_3P_circuit( let t13 = circuit_sub(in0, in11); let t14 = circuit_sub(in0, in12); - let modulus = TryInto::< - _, CircuitModulus, - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t0, t2, t3, t4, t5, t7, t8, t9, t10, t12, t13, t14).new_inputs(); // Prefill constants: diff --git a/src/src/circuits/tower_circuits.cairo b/src/src/circuits/tower_circuits.cairo index 34b15c38..c190f60c 100644 --- a/src/src/circuits/tower_circuits.cairo +++ b/src/src/circuits/tower_circuits.cairo @@ -146,17 +146,7 @@ pub fn run_BLS12_381_E12T_CYCLOTOMIC_SQUARE_circuit(M: E12T) -> (E12T,) { let t123 = circuit_add(t121, t40); // Fp2 add coeff 0/1 let t124 = circuit_add(t122, t41); // Fp2 add coeff 1/1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t93, t94, t99, t100, t105, t106, t111, t112, t117, t118, t123, t124) .new_inputs(); @@ -294,17 +284,7 @@ pub fn run_BLS12_381_E12T_CYCLO_SQUARE_COMPRESSED_circuit( let t83 = circuit_add(t77, t81); // Fp2 add coeff 0/1 let t84 = circuit_add(t78, t82); // Fp2 add coeff 1/1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t73, t74, t60, t61, t42, t43, t83, t84).new_inputs(); // Prefill constants: @@ -354,18 +334,18 @@ pub fn run_BLS12_381_E12T_DECOMP_KARABINA_II_circuit( let (in5, in6, in7) = (CE::> {}, CE::> {}, CE::> {}); let (in8, in9, in10) = (CE::> {}, CE::> {}, CE::> {}); let (in11, in12, in13) = (CE::> {}, CE::> {}, CE::> {}); - let t0 = circuit_sub(in0, in5); - let t1 = circuit_mul(in4, in4); - let t2 = circuit_mul(in5, in5); - let t3 = circuit_add(t1, t2); - let t4 = circuit_inverse(t3); - let t5 = circuit_mul(in4, t4); - let t6 = circuit_mul(t0, t4); - let t7 = circuit_mul(in2, t5); // Fp2 mul start + let t0 = circuit_mul(in4, in4); // Fp2 Inv start + let t1 = circuit_mul(in5, in5); + let t2 = circuit_add(t0, t1); + let t3 = circuit_inverse(t2); + let t4 = circuit_mul(in4, t3); // Fp2 Inv real part end + let t5 = circuit_mul(in5, t3); + let t6 = circuit_sub(in0, t5); // Fp2 Inv imag part end + let t7 = circuit_mul(in2, t4); // Fp2 mul start let t8 = circuit_mul(in3, t6); let t9 = circuit_sub(t7, t8); // Fp2 mul real part end let t10 = circuit_mul(in2, t6); - let t11 = circuit_mul(in3, t5); + let t11 = circuit_mul(in3, t4); let t12 = circuit_add(t10, t11); // Fp2 mul imag part end let t13 = circuit_mul(in8, in6); // Fp2 mul start let t14 = circuit_mul(in9, in7); @@ -399,17 +379,7 @@ pub fn run_BLS12_381_E12T_DECOMP_KARABINA_II_circuit( let t42 = circuit_sub(t41, t37); let t43 = circuit_add(t40, in1); - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t43, t42, t9, t12).new_inputs(); // Prefill constants: @@ -479,17 +449,7 @@ pub fn run_BLS12_381_E12T_DECOMP_KARABINA_I_NZ_circuit( let t25 = circuit_add(t23, t23); // Fp2 add coeff 0/1 let t26 = circuit_add(t24, t24); // Fp2 add coeff 1/1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t21, t22, t25, t26).new_inputs(); // Prefill constants: @@ -527,17 +487,7 @@ pub fn run_BLS12_381_E12T_DECOMP_KARABINA_I_Z_circuit( let t6 = circuit_add(t2, t2); // Fp2 add coeff 0/1 let t7 = circuit_add(t5, t5); // Fp2 add coeff 1/1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t6, t7).new_inputs(); // Prefill constants: @@ -605,17 +555,7 @@ pub fn run_BLS12_381_E12T_FROBENIUS_CUBE_circuit(M: E12T) -> (E12T,) { let t31 = circuit_mul(in3, in15); let t32 = circuit_add(t30, t31); // Fp2 mul imag part end - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t1, t0, t9, t12, t13, t14, t17, t20, t23, t26, t29, t32).new_inputs(); // Prefill constants: @@ -709,17 +649,7 @@ pub fn run_BLS12_381_E12T_FROBENIUS_SQUARE_circuit(M: E12T) -> (E12T,) { let t10 = circuit_mul(in5, in16); let t11 = circuit_mul(in5, in17); - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11).new_inputs(); // Prefill constants: @@ -855,17 +785,7 @@ pub fn run_BLS12_381_E12T_FROBENIUS_circuit(M: E12T) -> (E12T,) { let t31 = circuit_mul(in7, in18); let t32 = circuit_add(t30, t31); // Fp2 mul imag part end - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = (t1, t0, t9, t12, t13, t14, t17, t20, t23, t26, t29, t32).new_inputs(); // Prefill constants: @@ -1162,30 +1082,30 @@ pub fn run_BLS12_381_E12T_INVERSE_circuit(M: E12T) -> (E12T,) { let t200 = circuit_sub(t199, t195); let t201 = circuit_add(t178, t198); // Fp2 add coeff 0/1 let t202 = circuit_add(t181, t200); // Fp2 add coeff 1/1 - let t203 = circuit_sub(in0, t202); - let t204 = circuit_mul(t201, t201); - let t205 = circuit_mul(t202, t202); - let t206 = circuit_add(t204, t205); - let t207 = circuit_inverse(t206); - let t208 = circuit_mul(t201, t207); - let t209 = circuit_mul(t203, t207); - let t210 = circuit_mul(t165, t208); // Fp2 mul start + let t203 = circuit_mul(t201, t201); // Fp2 Inv start + let t204 = circuit_mul(t202, t202); + let t205 = circuit_add(t203, t204); + let t206 = circuit_inverse(t205); + let t207 = circuit_mul(t201, t206); // Fp2 Inv real part end + let t208 = circuit_mul(t202, t206); + let t209 = circuit_sub(in0, t208); // Fp2 Inv imag part end + let t210 = circuit_mul(t165, t207); // Fp2 mul start let t211 = circuit_mul(t166, t209); let t212 = circuit_sub(t210, t211); // Fp2 mul real part end let t213 = circuit_mul(t165, t209); - let t214 = circuit_mul(t166, t208); + let t214 = circuit_mul(t166, t207); let t215 = circuit_add(t213, t214); // Fp2 mul imag part end - let t216 = circuit_mul(t172, t208); // Fp2 mul start + let t216 = circuit_mul(t172, t207); // Fp2 mul start let t217 = circuit_mul(t173, t209); let t218 = circuit_sub(t216, t217); // Fp2 mul real part end let t219 = circuit_mul(t172, t209); - let t220 = circuit_mul(t173, t208); + let t220 = circuit_mul(t173, t207); let t221 = circuit_add(t219, t220); // Fp2 mul imag part end - let t222 = circuit_mul(t174, t208); // Fp2 mul start + let t222 = circuit_mul(t174, t207); // Fp2 mul start let t223 = circuit_mul(t175, t209); let t224 = circuit_sub(t222, t223); // Fp2 mul real part end let t225 = circuit_mul(t174, t209); - let t226 = circuit_mul(t175, t208); + let t226 = circuit_mul(t175, t207); let t227 = circuit_add(t225, t226); // Fp2 mul imag part end let t228 = circuit_mul(in1, t212); // Fp2 mul start let t229 = circuit_mul(in2, t215); @@ -1346,17 +1266,7 @@ pub fn run_BLS12_381_E12T_INVERSE_circuit(M: E12T) -> (E12T,) { let t384 = circuit_sub(in0, t378); // Fp6 neg coeff 4/5 let t385 = circuit_sub(in0, t379); // Fp6 neg coeff 5/5 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = ( t265, t266, t286, t287, t302, t303, t380, t381, t382, t383, t384, t385, @@ -1670,17 +1580,7 @@ pub fn run_BLS12_381_E12T_MUL_circuit(X: E12T, Y: E12T) -> (E12T,) { let t261 = circuit_add(t222, t162); // Fp6 add coeff 4/5 let t262 = circuit_add(t223, t163); // Fp6 add coeff 5/5 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = ( t257, t258, t259, t260, t261, t262, t246, t247, t248, t249, t250, t251, @@ -1954,18 +1854,18 @@ pub fn run_BLS12_381_TOWER_MILLER_BIT0_1P_circuit( let t203 = circuit_mul(t201, in2); // Doubling slope numerator end let t204 = circuit_add(in8, in8); // Fp2 add coeff 0/1 let t205 = circuit_add(in9, in9); // Fp2 add coeff 1/1 - let t206 = circuit_sub(in0, t205); - let t207 = circuit_mul(t204, t204); - let t208 = circuit_mul(t205, t205); - let t209 = circuit_add(t207, t208); - let t210 = circuit_inverse(t209); - let t211 = circuit_mul(t204, t210); - let t212 = circuit_mul(t206, t210); - let t213 = circuit_mul(t202, t211); // Fp2 mul start + let t206 = circuit_mul(t204, t204); // Fp2 Inv start + let t207 = circuit_mul(t205, t205); + let t208 = circuit_add(t206, t207); + let t209 = circuit_inverse(t208); + let t210 = circuit_mul(t204, t209); // Fp2 Inv real part end + let t211 = circuit_mul(t205, t209); + let t212 = circuit_sub(in0, t211); // Fp2 Inv imag part end + let t213 = circuit_mul(t202, t210); // Fp2 mul start let t214 = circuit_mul(t203, t212); let t215 = circuit_sub(t213, t214); // Fp2 mul real part end let t216 = circuit_mul(t202, t212); - let t217 = circuit_mul(t203, t211); + let t217 = circuit_mul(t203, t210); let t218 = circuit_add(t216, t217); // Fp2 mul imag part end let t219 = circuit_add(t215, t218); let t220 = circuit_sub(t215, t218); @@ -2147,17 +2047,7 @@ pub fn run_BLS12_381_TOWER_MILLER_BIT0_1P_circuit( let t396 = circuit_add(t395, t236); let t397 = circuit_add(t396, t237); - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = ( t397, t389, t390, t391, t392, t393, t394, t378, t379, t380, t381, t382, t383, @@ -2430,18 +2320,18 @@ pub fn run_BLS12_381_TOWER_MILLER_BIT1_1P_circuit( let t199 = circuit_sub(in7, in11); // Fp2 sub coeff 1/1 let t200 = circuit_sub(in4, in8); // Fp2 sub coeff 0/1 let t201 = circuit_sub(in5, in9); // Fp2 sub coeff 1/1 - let t202 = circuit_sub(in0, t201); - let t203 = circuit_mul(t200, t200); - let t204 = circuit_mul(t201, t201); - let t205 = circuit_add(t203, t204); - let t206 = circuit_inverse(t205); - let t207 = circuit_mul(t200, t206); - let t208 = circuit_mul(t202, t206); - let t209 = circuit_mul(t198, t207); // Fp2 mul start + let t202 = circuit_mul(t200, t200); // Fp2 Inv start + let t203 = circuit_mul(t201, t201); + let t204 = circuit_add(t202, t203); + let t205 = circuit_inverse(t204); + let t206 = circuit_mul(t200, t205); // Fp2 Inv real part end + let t207 = circuit_mul(t201, t205); + let t208 = circuit_sub(in0, t207); // Fp2 Inv imag part end + let t209 = circuit_mul(t198, t206); // Fp2 mul start let t210 = circuit_mul(t199, t208); let t211 = circuit_sub(t209, t210); // Fp2 mul real part end let t212 = circuit_mul(t198, t208); - let t213 = circuit_mul(t199, t207); + let t213 = circuit_mul(t199, t206); let t214 = circuit_add(t212, t213); // Fp2 mul imag part end let t215 = circuit_add(t211, t214); let t216 = circuit_sub(t211, t214); @@ -2464,18 +2354,18 @@ pub fn run_BLS12_381_TOWER_MILLER_BIT1_1P_circuit( let t233 = circuit_add(in7, in7); // Fp2 add coeff 1/1 let t234 = circuit_sub(t222, in4); // Fp2 sub coeff 0/1 let t235 = circuit_sub(t223, in5); // Fp2 sub coeff 1/1 - let t236 = circuit_sub(in0, t235); - let t237 = circuit_mul(t234, t234); - let t238 = circuit_mul(t235, t235); - let t239 = circuit_add(t237, t238); - let t240 = circuit_inverse(t239); - let t241 = circuit_mul(t234, t240); - let t242 = circuit_mul(t236, t240); - let t243 = circuit_mul(t232, t241); // Fp2 mul start + let t236 = circuit_mul(t234, t234); // Fp2 Inv start + let t237 = circuit_mul(t235, t235); + let t238 = circuit_add(t236, t237); + let t239 = circuit_inverse(t238); + let t240 = circuit_mul(t234, t239); // Fp2 Inv real part end + let t241 = circuit_mul(t235, t239); + let t242 = circuit_sub(in0, t241); // Fp2 Inv imag part end + let t243 = circuit_mul(t232, t240); // Fp2 mul start let t244 = circuit_mul(t233, t242); let t245 = circuit_sub(t243, t244); // Fp2 mul real part end let t246 = circuit_mul(t232, t242); - let t247 = circuit_mul(t233, t241); + let t247 = circuit_mul(t233, t240); let t248 = circuit_add(t246, t247); // Fp2 mul imag part end let t249 = circuit_add(t211, t245); // Fp2 add coeff 0/1 let t250 = circuit_add(t214, t248); // Fp2 add coeff 1/1 @@ -2810,17 +2700,7 @@ pub fn run_BLS12_381_TOWER_MILLER_BIT1_1P_circuit( let t579 = circuit_add(t578, t270); let t580 = circuit_add(t579, t271); - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = ( t580, t572, t573, t574, t575, t576, t577, t561, t562, t563, t564, t565, t566, @@ -2897,18 +2777,18 @@ pub fn run_BLS12_381_TOWER_MILLER_INIT_BIT_1P_circuit( let t5 = circuit_mul(t3, in1); let t6 = circuit_add(in8, in8); // Fp2 add coeff 0/1 let t7 = circuit_add(in9, in9); // Fp2 add coeff 1/1 - let t8 = circuit_sub(in2, t7); - let t9 = circuit_mul(t6, t6); - let t10 = circuit_mul(t7, t7); - let t11 = circuit_add(t9, t10); - let t12 = circuit_inverse(t11); - let t13 = circuit_mul(t6, t12); - let t14 = circuit_mul(t8, t12); - let t15 = circuit_mul(t4, t13); // Fp2 mul start + let t8 = circuit_mul(t6, t6); // Fp2 Inv start + let t9 = circuit_mul(t7, t7); + let t10 = circuit_add(t8, t9); + let t11 = circuit_inverse(t10); + let t12 = circuit_mul(t6, t11); // Fp2 Inv real part end + let t13 = circuit_mul(t7, t11); + let t14 = circuit_sub(in2, t13); // Fp2 Inv imag part end + let t15 = circuit_mul(t4, t12); // Fp2 mul start let t16 = circuit_mul(t5, t14); let t17 = circuit_sub(t15, t16); // Fp2 mul real part end let t18 = circuit_mul(t4, t14); - let t19 = circuit_mul(t5, t13); + let t19 = circuit_mul(t5, t12); let t20 = circuit_add(t18, t19); // Fp2 mul imag part end let t21 = circuit_mul(t17, in6); // Fp2 mul start let t22 = circuit_mul(t20, in7); @@ -2929,18 +2809,18 @@ pub fn run_BLS12_381_TOWER_MILLER_INIT_BIT_1P_circuit( let t37 = circuit_sub(t33, t35); // Fp2 sub coeff 1/1 let t38 = circuit_sub(in6, t36); // Fp2 sub coeff 0/1 let t39 = circuit_sub(in7, t37); // Fp2 sub coeff 1/1 - let t40 = circuit_sub(in2, t39); - let t41 = circuit_mul(t38, t38); - let t42 = circuit_mul(t39, t39); - let t43 = circuit_add(t41, t42); - let t44 = circuit_inverse(t43); - let t45 = circuit_mul(t38, t44); - let t46 = circuit_mul(t40, t44); - let t47 = circuit_mul(t6, t45); // Fp2 mul start + let t40 = circuit_mul(t38, t38); // Fp2 Inv start + let t41 = circuit_mul(t39, t39); + let t42 = circuit_add(t40, t41); + let t43 = circuit_inverse(t42); + let t44 = circuit_mul(t38, t43); // Fp2 Inv real part end + let t45 = circuit_mul(t39, t43); + let t46 = circuit_sub(in2, t45); // Fp2 Inv imag part end + let t47 = circuit_mul(t6, t44); // Fp2 mul start let t48 = circuit_mul(t7, t46); let t49 = circuit_sub(t47, t48); // Fp2 mul real part end let t50 = circuit_mul(t6, t46); - let t51 = circuit_mul(t7, t45); + let t51 = circuit_mul(t7, t44); let t52 = circuit_add(t50, t51); // Fp2 mul imag part end let t53 = circuit_sub(t49, t17); // Fp2 sub coeff 0/1 let t54 = circuit_sub(t52, t20); // Fp2 sub coeff 1/1 @@ -3017,17 +2897,7 @@ pub fn run_BLS12_381_TOWER_MILLER_INIT_BIT_1P_circuit( let t125 = circuit_add(t122, t92); // Fp2 add coeff 0/1 let t126 = circuit_add(t124, t95); // Fp2 add coeff 1/1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into( - [ - 0xb153ffffb9feffffffffaaab, - 0x6730d2a0f6b0f6241eabfffe, - 0x434bacd764774b84f38512bf, - 0x1a0111ea397fe69a4b1ba7b6 - ] - ) - .unwrap(); // BLS12_381 prime field modulus + let modulus = get_BLS12_381_modulus(); // BLS12_381 prime field modulus let mut circuit_inputs = ( t70, t71, t80, t81, t125, t126, t116, t117, t98, t101, t102, t103, t118, t119, @@ -3206,10 +3076,7 @@ pub fn run_BN254_E12T_CYCLOTOMIC_SQUARE_circuit(M: E12T) -> (E12T,) { let t127 = circuit_add(t125, t40); // Fp2 add coeff 0/1 let t128 = circuit_add(t126, t41); // Fp2 add coeff 1/1 - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t97, t98, t103, t104, t109, t110, t115, t116, t121, t122, t127, t128) .new_inputs(); @@ -3307,10 +3174,7 @@ pub fn run_BN254_E12T_FROBENIUS_CUBE_circuit(M: E12T) -> (E12T,) { let t35 = circuit_mul(in10, in21); let t36 = circuit_add(t34, t35); // Fp2 mul imag part end - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t1, t0, t9, t12, t15, t18, t21, t24, t27, t30, t33, t36).new_inputs(); // Prefill constants: @@ -3440,10 +3304,7 @@ pub fn run_BN254_E12T_FROBENIUS_SQUARE_circuit(M: E12T) -> (E12T,) { let t10 = circuit_mul(in5, in16); let t11 = circuit_mul(in5, in17); - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11).new_inputs(); // Prefill constants: @@ -3555,10 +3416,7 @@ pub fn run_BN254_E12T_FROBENIUS_circuit(M: E12T) -> (E12T,) { let t35 = circuit_mul(in10, in21); let t36 = circuit_add(t34, t35); // Fp2 mul imag part end - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = (t1, t0, t9, t12, t15, t18, t21, t24, t27, t30, t33, t36).new_inputs(); // Prefill constants: @@ -3882,30 +3740,30 @@ pub fn run_BN254_E12T_INVERSE_circuit(M: E12T) -> (E12T,) { let t208 = circuit_sub(t207, t202); let t209 = circuit_add(t185, t206); // Fp2 add coeff 0/1 let t210 = circuit_add(t188, t208); // Fp2 add coeff 1/1 - let t211 = circuit_sub(in2, t210); - let t212 = circuit_mul(t209, t209); - let t213 = circuit_mul(t210, t210); - let t214 = circuit_add(t212, t213); - let t215 = circuit_inverse(t214); - let t216 = circuit_mul(t209, t215); - let t217 = circuit_mul(t211, t215); - let t218 = circuit_mul(t171, t216); // Fp2 mul start + let t211 = circuit_mul(t209, t209); // Fp2 Inv start + let t212 = circuit_mul(t210, t210); + let t213 = circuit_add(t211, t212); + let t214 = circuit_inverse(t213); + let t215 = circuit_mul(t209, t214); // Fp2 Inv real part end + let t216 = circuit_mul(t210, t214); + let t217 = circuit_sub(in2, t216); // Fp2 Inv imag part end + let t218 = circuit_mul(t171, t215); // Fp2 mul start let t219 = circuit_mul(t172, t217); let t220 = circuit_sub(t218, t219); // Fp2 mul real part end let t221 = circuit_mul(t171, t217); - let t222 = circuit_mul(t172, t216); + let t222 = circuit_mul(t172, t215); let t223 = circuit_add(t221, t222); // Fp2 mul imag part end - let t224 = circuit_mul(t179, t216); // Fp2 mul start + let t224 = circuit_mul(t179, t215); // Fp2 mul start let t225 = circuit_mul(t180, t217); let t226 = circuit_sub(t224, t225); // Fp2 mul real part end let t227 = circuit_mul(t179, t217); - let t228 = circuit_mul(t180, t216); + let t228 = circuit_mul(t180, t215); let t229 = circuit_add(t227, t228); // Fp2 mul imag part end - let t230 = circuit_mul(t181, t216); // Fp2 mul start + let t230 = circuit_mul(t181, t215); // Fp2 mul start let t231 = circuit_mul(t182, t217); let t232 = circuit_sub(t230, t231); // Fp2 mul real part end let t233 = circuit_mul(t181, t217); - let t234 = circuit_mul(t182, t216); + let t234 = circuit_mul(t182, t215); let t235 = circuit_add(t233, t234); // Fp2 mul imag part end let t236 = circuit_mul(in3, t220); // Fp2 mul start let t237 = circuit_mul(in4, t223); @@ -4070,10 +3928,7 @@ pub fn run_BN254_E12T_INVERSE_circuit(M: E12T) -> (E12T,) { let t396 = circuit_sub(in2, t390); // Fp6 neg coeff 4/5 let t397 = circuit_sub(in2, t391); // Fp6 neg coeff 5/5 - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = ( t274, t275, t296, t297, t312, t313, t392, t393, t394, t395, t396, t397, @@ -4400,10 +4255,7 @@ pub fn run_BN254_E12T_MUL_circuit(X: E12T, Y: E12T) -> (E12T,) { let t268 = circuit_add(t228, t166); // Fp6 add coeff 4/5 let t269 = circuit_add(t229, t167); // Fp6 add coeff 5/5 - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = ( t264, t265, t266, t267, t268, t269, t252, t253, t254, t255, t256, t257, @@ -4686,18 +4538,18 @@ pub fn run_BN254_TOWER_MILLER_BIT0_1P_circuit( let t209 = circuit_mul(t207, in4); // Doubling slope numerator end let t210 = circuit_add(in10, in10); // Fp2 add coeff 0/1 let t211 = circuit_add(in11, in11); // Fp2 add coeff 1/1 - let t212 = circuit_sub(in2, t211); - let t213 = circuit_mul(t210, t210); - let t214 = circuit_mul(t211, t211); - let t215 = circuit_add(t213, t214); - let t216 = circuit_inverse(t215); - let t217 = circuit_mul(t210, t216); - let t218 = circuit_mul(t212, t216); - let t219 = circuit_mul(t208, t217); // Fp2 mul start + let t212 = circuit_mul(t210, t210); // Fp2 Inv start + let t213 = circuit_mul(t211, t211); + let t214 = circuit_add(t212, t213); + let t215 = circuit_inverse(t214); + let t216 = circuit_mul(t210, t215); // Fp2 Inv real part end + let t217 = circuit_mul(t211, t215); + let t218 = circuit_sub(in2, t217); // Fp2 Inv imag part end + let t219 = circuit_mul(t208, t216); // Fp2 mul start let t220 = circuit_mul(t209, t218); let t221 = circuit_sub(t219, t220); // Fp2 mul real part end let t222 = circuit_mul(t208, t218); - let t223 = circuit_mul(t209, t217); + let t223 = circuit_mul(t209, t216); let t224 = circuit_add(t222, t223); // Fp2 mul imag part end let t225 = circuit_add(t221, t224); let t226 = circuit_sub(t221, t224); @@ -4884,10 +4736,7 @@ pub fn run_BN254_TOWER_MILLER_BIT0_1P_circuit( let t407 = circuit_add(t406, t242); let t408 = circuit_add(t407, t243); - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = ( t408, t400, t401, t402, t403, t404, t405, t388, t389, t390, t391, t392, t393, @@ -5170,18 +5019,18 @@ pub fn run_BN254_TOWER_MILLER_BIT1_1P_circuit( let t205 = circuit_sub(in9, in13); // Fp2 sub coeff 1/1 let t206 = circuit_sub(in6, in10); // Fp2 sub coeff 0/1 let t207 = circuit_sub(in7, in11); // Fp2 sub coeff 1/1 - let t208 = circuit_sub(in2, t207); - let t209 = circuit_mul(t206, t206); - let t210 = circuit_mul(t207, t207); - let t211 = circuit_add(t209, t210); - let t212 = circuit_inverse(t211); - let t213 = circuit_mul(t206, t212); - let t214 = circuit_mul(t208, t212); - let t215 = circuit_mul(t204, t213); // Fp2 mul start + let t208 = circuit_mul(t206, t206); // Fp2 Inv start + let t209 = circuit_mul(t207, t207); + let t210 = circuit_add(t208, t209); + let t211 = circuit_inverse(t210); + let t212 = circuit_mul(t206, t211); // Fp2 Inv real part end + let t213 = circuit_mul(t207, t211); + let t214 = circuit_sub(in2, t213); // Fp2 Inv imag part end + let t215 = circuit_mul(t204, t212); // Fp2 mul start let t216 = circuit_mul(t205, t214); let t217 = circuit_sub(t215, t216); // Fp2 mul real part end let t218 = circuit_mul(t204, t214); - let t219 = circuit_mul(t205, t213); + let t219 = circuit_mul(t205, t212); let t220 = circuit_add(t218, t219); // Fp2 mul imag part end let t221 = circuit_add(t217, t220); let t222 = circuit_sub(t217, t220); @@ -5204,18 +5053,18 @@ pub fn run_BN254_TOWER_MILLER_BIT1_1P_circuit( let t239 = circuit_add(in9, in9); // Fp2 add coeff 1/1 let t240 = circuit_sub(t228, in6); // Fp2 sub coeff 0/1 let t241 = circuit_sub(t229, in7); // Fp2 sub coeff 1/1 - let t242 = circuit_sub(in2, t241); - let t243 = circuit_mul(t240, t240); - let t244 = circuit_mul(t241, t241); - let t245 = circuit_add(t243, t244); - let t246 = circuit_inverse(t245); - let t247 = circuit_mul(t240, t246); - let t248 = circuit_mul(t242, t246); - let t249 = circuit_mul(t238, t247); // Fp2 mul start + let t242 = circuit_mul(t240, t240); // Fp2 Inv start + let t243 = circuit_mul(t241, t241); + let t244 = circuit_add(t242, t243); + let t245 = circuit_inverse(t244); + let t246 = circuit_mul(t240, t245); // Fp2 Inv real part end + let t247 = circuit_mul(t241, t245); + let t248 = circuit_sub(in2, t247); // Fp2 Inv imag part end + let t249 = circuit_mul(t238, t246); // Fp2 mul start let t250 = circuit_mul(t239, t248); let t251 = circuit_sub(t249, t250); // Fp2 mul real part end let t252 = circuit_mul(t238, t248); - let t253 = circuit_mul(t239, t247); + let t253 = circuit_mul(t239, t246); let t254 = circuit_add(t252, t253); // Fp2 mul imag part end let t255 = circuit_add(t217, t251); // Fp2 add coeff 0/1 let t256 = circuit_add(t220, t254); // Fp2 add coeff 1/1 @@ -5560,10 +5409,7 @@ pub fn run_BN254_TOWER_MILLER_BIT1_1P_circuit( let t595 = circuit_add(t594, t276); let t596 = circuit_add(t595, t277); - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = ( t596, t588, t589, t590, t591, t592, t593, t576, t577, t578, t579, t580, t581, @@ -5667,18 +5513,18 @@ pub fn run_BN254_TOWER_MILLER_FINALIZE_BN_1P_circuit( let t19 = circuit_sub(in18, t13); // Fp2 sub coeff 1/1 let t20 = circuit_sub(in15, t4); // Fp2 sub coeff 0/1 let t21 = circuit_sub(in16, t7); // Fp2 sub coeff 1/1 - let t22 = circuit_sub(in6, t21); - let t23 = circuit_mul(t20, t20); - let t24 = circuit_mul(t21, t21); - let t25 = circuit_add(t23, t24); - let t26 = circuit_inverse(t25); - let t27 = circuit_mul(t20, t26); - let t28 = circuit_mul(t22, t26); - let t29 = circuit_mul(t18, t27); // Fp2 mul start + let t22 = circuit_mul(t20, t20); // Fp2 Inv start + let t23 = circuit_mul(t21, t21); + let t24 = circuit_add(t22, t23); + let t25 = circuit_inverse(t24); + let t26 = circuit_mul(t20, t25); // Fp2 Inv real part end + let t27 = circuit_mul(t21, t25); + let t28 = circuit_sub(in6, t27); // Fp2 Inv imag part end + let t29 = circuit_mul(t18, t26); // Fp2 mul start let t30 = circuit_mul(t19, t28); let t31 = circuit_sub(t29, t30); // Fp2 mul real part end let t32 = circuit_mul(t18, t28); - let t33 = circuit_mul(t19, t27); + let t33 = circuit_mul(t19, t26); let t34 = circuit_add(t32, t33); // Fp2 mul imag part end let t35 = circuit_add(t31, t34); let t36 = circuit_sub(t31, t34); @@ -5711,18 +5557,18 @@ pub fn run_BN254_TOWER_MILLER_FINALIZE_BN_1P_circuit( let t63 = circuit_sub(t53, t17); // Fp2 sub coeff 1/1 let t64 = circuit_sub(t42, t14); // Fp2 sub coeff 0/1 let t65 = circuit_sub(t43, t15); // Fp2 sub coeff 1/1 - let t66 = circuit_sub(in6, t65); - let t67 = circuit_mul(t64, t64); - let t68 = circuit_mul(t65, t65); - let t69 = circuit_add(t67, t68); - let t70 = circuit_inverse(t69); - let t71 = circuit_mul(t64, t70); - let t72 = circuit_mul(t66, t70); - let t73 = circuit_mul(t62, t71); // Fp2 mul start + let t66 = circuit_mul(t64, t64); // Fp2 Inv start + let t67 = circuit_mul(t65, t65); + let t68 = circuit_add(t66, t67); + let t69 = circuit_inverse(t68); + let t70 = circuit_mul(t64, t69); // Fp2 Inv real part end + let t71 = circuit_mul(t65, t69); + let t72 = circuit_sub(in6, t71); // Fp2 Inv imag part end + let t73 = circuit_mul(t62, t70); // Fp2 mul start let t74 = circuit_mul(t63, t72); let t75 = circuit_sub(t73, t74); // Fp2 mul real part end let t76 = circuit_mul(t62, t72); - let t77 = circuit_mul(t63, t71); + let t77 = circuit_mul(t63, t70); let t78 = circuit_add(t76, t77); // Fp2 mul imag part end let t79 = circuit_mul(t75, t42); // Fp2 mul start let t80 = circuit_mul(t78, t43); @@ -6048,10 +5894,7 @@ pub fn run_BN254_TOWER_MILLER_FINALIZE_BN_1P_circuit( let t400 = circuit_add(t360, t298); // Fp6 add coeff 4/5 let t401 = circuit_add(t361, t299); // Fp6 add coeff 5/5 - let modulus = TryInto::< - _, CircuitModulus - >::try_into([0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0]) - .unwrap(); // BN254 prime field modulus + let modulus = get_BN254_modulus(); // BN254 prime field modulus let mut circuit_inputs = ( t396, t397, t398, t399, t400, t401, t384, t385, t386, t387, t388, t389,