You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

721 lines
22 KiB

  1. use ark_bls12_381::Bls12_381;
  2. use ark_ec::PairingEngine;
  3. use ark_ff::{BigInteger, PrimeField};
  4. use ark_mnt4_298::MNT4_298;
  5. use ark_mnt4_753::MNT4_753;
  6. use ark_mnt6_298::MNT6_298;
  7. use ark_mnt6_753::MNT6_753;
  8. use ark_r1cs_std::{
  9. alloc::AllocVar,
  10. eq::EqGadget,
  11. fields::{
  12. nonnative::{AllocatedNonNativeFieldVar, NonNativeFieldVar},
  13. FieldVar,
  14. },
  15. R1CSVar,
  16. };
  17. use ark_relations::r1cs::{ConstraintSystem, ConstraintSystemRef};
  18. use ark_std::rand::RngCore;
  19. #[cfg(not(ci))]
  20. const NUM_REPETITIONS: usize = 100;
  21. #[cfg(ci)]
  22. const NUM_REPETITIONS: usize = 1;
  23. #[cfg(not(ci))]
  24. const TEST_COUNT: usize = 100;
  25. #[cfg(ci)]
  26. const TEST_COUNT: usize = 1;
  27. fn allocation_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  28. cs: ConstraintSystemRef<BaseField>,
  29. rng: &mut R,
  30. ) {
  31. let a_native = TargetField::rand(rng);
  32. let a = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  33. ark_relations::ns!(cs, "alloc a"),
  34. || Ok(a_native),
  35. )
  36. .unwrap();
  37. let a_actual = a.value().unwrap();
  38. let a_expected = a_native;
  39. assert!(
  40. a_actual.eq(&a_expected),
  41. "allocated value does not equal the expected value"
  42. );
  43. let (_a, a_bits) =
  44. AllocatedNonNativeFieldVar::<TargetField, BaseField>::new_witness_with_le_bits(
  45. ark_relations::ns!(cs, "alloc a2"),
  46. || Ok(a_native),
  47. )
  48. .unwrap();
  49. let a_bits_actual: Vec<bool> = a_bits.into_iter().map(|b| b.value().unwrap()).collect();
  50. let mut a_bits_expected = a_native.into_bigint().to_bits_le();
  51. a_bits_expected.truncate(TargetField::MODULUS_BIT_SIZE as usize);
  52. assert_eq!(
  53. a_bits_actual, a_bits_expected,
  54. "allocated bits does not equal the expected bits"
  55. );
  56. }
  57. fn addition_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  58. cs: ConstraintSystemRef<BaseField>,
  59. rng: &mut R,
  60. ) {
  61. let a_native = TargetField::rand(rng);
  62. let a = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  63. ark_relations::ns!(cs, "alloc a"),
  64. || Ok(a_native),
  65. )
  66. .unwrap();
  67. let b_native = TargetField::rand(rng);
  68. let b = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  69. ark_relations::ns!(cs, "alloc b"),
  70. || Ok(b_native),
  71. )
  72. .unwrap();
  73. let a_plus_b = a + &b;
  74. let a_plus_b_actual = a_plus_b.value().unwrap();
  75. let a_plus_b_expected = a_native + &b_native;
  76. assert!(a_plus_b_actual.eq(&a_plus_b_expected), "a + b failed");
  77. }
  78. fn multiplication_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  79. cs: ConstraintSystemRef<BaseField>,
  80. rng: &mut R,
  81. ) {
  82. let a_native = TargetField::rand(rng);
  83. let a = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  84. ark_relations::ns!(cs, "alloc a"),
  85. || Ok(a_native),
  86. )
  87. .unwrap();
  88. let b_native = TargetField::rand(rng);
  89. let b = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  90. ark_relations::ns!(cs, "alloc b"),
  91. || Ok(b_native),
  92. )
  93. .unwrap();
  94. let a_times_b = a * &b;
  95. let a_times_b_actual = a_times_b.value().unwrap();
  96. let a_times_b_expected = a_native * &b_native;
  97. assert!(
  98. a_times_b_actual.eq(&a_times_b_expected),
  99. "a_times_b = {:?}, a_times_b_actual = {:?}, a_times_b_expected = {:?}",
  100. a_times_b,
  101. a_times_b_actual.into_bigint().as_ref(),
  102. a_times_b_expected.into_bigint().as_ref()
  103. );
  104. }
  105. fn equality_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  106. cs: ConstraintSystemRef<BaseField>,
  107. rng: &mut R,
  108. ) {
  109. let a_native = TargetField::rand(rng);
  110. let a = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  111. ark_relations::ns!(cs, "alloc a"),
  112. || Ok(a_native),
  113. )
  114. .unwrap();
  115. let b_native = TargetField::rand(rng);
  116. let b = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  117. ark_relations::ns!(cs, "alloc b"),
  118. || Ok(b_native),
  119. )
  120. .unwrap();
  121. let a_times_b = a * &b;
  122. let a_times_b_expected = a_native * &b_native;
  123. let a_times_b_expected_gadget = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  124. ark_relations::ns!(cs, "alloc a * b"),
  125. || Ok(a_times_b_expected),
  126. )
  127. .unwrap();
  128. a_times_b.enforce_equal(&a_times_b_expected_gadget).unwrap();
  129. }
  130. fn edge_cases_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  131. cs: ConstraintSystemRef<BaseField>,
  132. rng: &mut R,
  133. ) {
  134. let zero_native = TargetField::zero();
  135. let zero = NonNativeFieldVar::<TargetField, BaseField>::zero();
  136. let one = NonNativeFieldVar::<TargetField, BaseField>::one();
  137. let a_native = TargetField::rand(rng);
  138. let minus_a_native = TargetField::zero() - &a_native;
  139. let a = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  140. ark_relations::ns!(cs, "alloc a"),
  141. || Ok(a_native),
  142. )
  143. .unwrap();
  144. let a_plus_zero = &a + &zero;
  145. let a_minus_zero = &a - &zero;
  146. let zero_minus_a = &zero - &a;
  147. let a_times_zero = &a * &zero;
  148. let zero_plus_a = &zero + &a;
  149. let zero_times_a = &zero * &a;
  150. let a_times_one = &a * &one;
  151. let one_times_a = &one * &a;
  152. let a_plus_zero_native = a_plus_zero.value().unwrap();
  153. let a_minus_zero_native = a_minus_zero.value().unwrap();
  154. let zero_minus_a_native = zero_minus_a.value().unwrap();
  155. let a_times_zero_native = a_times_zero.value().unwrap();
  156. let zero_plus_a_native = zero_plus_a.value().unwrap();
  157. let zero_times_a_native = zero_times_a.value().unwrap();
  158. let a_times_one_native = a_times_one.value().unwrap();
  159. let one_times_a_native = one_times_a.value().unwrap();
  160. assert!(
  161. a_plus_zero_native.eq(&a_native),
  162. "a_plus_zero = {:?}, a = {:?}",
  163. a_plus_zero_native.into_bigint().as_ref(),
  164. a_native.into_bigint().as_ref()
  165. );
  166. assert!(
  167. a_minus_zero_native.eq(&a_native),
  168. "a_minus_zero = {:?}, a = {:?}",
  169. a_minus_zero_native.into_bigint().as_ref(),
  170. a_native.into_bigint().as_ref()
  171. );
  172. assert!(
  173. zero_minus_a_native.eq(&minus_a_native),
  174. "zero_minus_a = {:?}, minus_a = {:?}",
  175. zero_minus_a_native.into_bigint().as_ref(),
  176. minus_a_native.into_bigint().as_ref()
  177. );
  178. assert!(
  179. a_times_zero_native.eq(&zero_native),
  180. "a_times_zero = {:?}, zero = {:?}",
  181. a_times_zero_native.into_bigint().as_ref(),
  182. zero_native.into_bigint().as_ref()
  183. );
  184. assert!(
  185. zero_plus_a_native.eq(&a_native),
  186. "zero_plus_a = {:?}, a = {:?}",
  187. zero_plus_a_native.into_bigint().as_ref(),
  188. a_native.into_bigint().as_ref()
  189. );
  190. assert!(
  191. zero_times_a_native.eq(&zero_native),
  192. "zero_times_a = {:?}, zero = {:?}",
  193. zero_times_a_native.into_bigint().as_ref(),
  194. zero_native.into_bigint().as_ref()
  195. );
  196. assert!(
  197. a_times_one_native.eq(&a_native),
  198. "a_times_one = {:?}, a = {:?}",
  199. a_times_one_native.into_bigint().as_ref(),
  200. a_native.into_bigint().as_ref()
  201. );
  202. assert!(
  203. one_times_a_native.eq(&a_native),
  204. "one_times_a = {:?}, a = {:?}",
  205. one_times_a_native.into_bigint().as_ref(),
  206. a_native.into_bigint().as_ref()
  207. );
  208. }
  209. fn distribution_law_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  210. cs: ConstraintSystemRef<BaseField>,
  211. rng: &mut R,
  212. ) {
  213. let a_native = TargetField::rand(rng);
  214. let b_native = TargetField::rand(rng);
  215. let c_native = TargetField::rand(rng);
  216. let a_plus_b_native = a_native.clone() + &b_native;
  217. let a_times_c_native = a_native.clone() * &c_native;
  218. let b_times_c_native = b_native.clone() * &c_native;
  219. let a_plus_b_times_c_native = a_plus_b_native.clone() * &c_native;
  220. let a_times_c_plus_b_times_c_native = a_times_c_native + &b_times_c_native;
  221. assert!(
  222. a_plus_b_times_c_native.eq(&a_times_c_plus_b_times_c_native),
  223. "(a + b) * c doesn't equal (a * c) + (b * c)"
  224. );
  225. let a = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  226. ark_relations::ns!(cs, "a"),
  227. || Ok(a_native),
  228. )
  229. .unwrap();
  230. let b = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  231. ark_relations::ns!(cs, "b"),
  232. || Ok(b_native),
  233. )
  234. .unwrap();
  235. let c = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  236. ark_relations::ns!(cs, "c"),
  237. || Ok(c_native),
  238. )
  239. .unwrap();
  240. let a_plus_b = &a + &b;
  241. let a_times_c = &a * &c;
  242. let b_times_c = &b * &c;
  243. let a_plus_b_times_c = &a_plus_b * &c;
  244. let a_times_c_plus_b_times_c = &a_times_c + &b_times_c;
  245. assert!(
  246. a_plus_b.value().unwrap().eq(&a_plus_b_native),
  247. "a + b doesn't match"
  248. );
  249. assert!(
  250. a_times_c.value().unwrap().eq(&a_times_c_native),
  251. "a * c doesn't match"
  252. );
  253. assert!(
  254. b_times_c.value().unwrap().eq(&b_times_c_native),
  255. "b * c doesn't match"
  256. );
  257. assert!(
  258. a_plus_b_times_c
  259. .value()
  260. .unwrap()
  261. .eq(&a_plus_b_times_c_native),
  262. "(a + b) * c doesn't match"
  263. );
  264. assert!(
  265. a_times_c_plus_b_times_c
  266. .value()
  267. .unwrap()
  268. .eq(&a_times_c_plus_b_times_c_native),
  269. "(a * c) + (b * c) doesn't match"
  270. );
  271. assert!(
  272. a_plus_b_times_c_native.eq(&a_times_c_plus_b_times_c_native),
  273. "(a + b) * c != (a * c) + (b * c)"
  274. );
  275. }
  276. fn randomized_arithmetic_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  277. cs: ConstraintSystemRef<BaseField>,
  278. rng: &mut R,
  279. ) {
  280. let mut operations: Vec<u32> = Vec::new();
  281. for _ in 0..TEST_COUNT {
  282. operations.push(rng.next_u32() % 3);
  283. }
  284. let mut num_native = TargetField::rand(rng);
  285. let mut num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  286. ark_relations::ns!(cs, "initial num"),
  287. || Ok(num_native),
  288. )
  289. .unwrap();
  290. for op in operations.iter() {
  291. let next_native = TargetField::rand(rng);
  292. let next = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  293. ark_relations::ns!(cs, "next num for repetition"),
  294. || Ok(next_native),
  295. )
  296. .unwrap();
  297. match op {
  298. 0 => {
  299. num_native += &next_native;
  300. num += &next;
  301. },
  302. 1 => {
  303. num_native *= &next_native;
  304. num *= &next;
  305. },
  306. 2 => {
  307. num_native -= &next_native;
  308. num -= &next;
  309. },
  310. _ => (),
  311. };
  312. assert!(
  313. num.value().unwrap().eq(&num_native),
  314. "randomized arithmetic failed:"
  315. );
  316. }
  317. }
  318. fn addition_stress_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  319. cs: ConstraintSystemRef<BaseField>,
  320. rng: &mut R,
  321. ) {
  322. let mut num_native = TargetField::rand(rng);
  323. let mut num =
  324. NonNativeFieldVar::new_witness(ark_relations::ns!(cs, "initial num"), || Ok(num_native))
  325. .unwrap();
  326. for _ in 0..TEST_COUNT {
  327. let next_native = TargetField::rand(rng);
  328. let next = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  329. ark_relations::ns!(cs, "next num for repetition"),
  330. || Ok(next_native),
  331. )
  332. .unwrap();
  333. num_native += &next_native;
  334. num += &next;
  335. assert!(num.value().unwrap().eq(&num_native));
  336. }
  337. }
  338. fn multiplication_stress_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  339. cs: ConstraintSystemRef<BaseField>,
  340. rng: &mut R,
  341. ) {
  342. let mut num_native = TargetField::rand(rng);
  343. let mut num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  344. ark_relations::ns!(cs, "initial num"),
  345. || Ok(num_native),
  346. )
  347. .unwrap();
  348. for _ in 0..TEST_COUNT {
  349. let next_native = TargetField::rand(rng);
  350. let next = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  351. ark_relations::ns!(cs, "next num for repetition"),
  352. || Ok(next_native),
  353. )
  354. .unwrap();
  355. num_native *= &next_native;
  356. num *= &next;
  357. assert!(num.value().unwrap().eq(&num_native));
  358. }
  359. }
  360. fn mul_and_add_stress_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  361. cs: ConstraintSystemRef<BaseField>,
  362. rng: &mut R,
  363. ) {
  364. let mut num_native = TargetField::rand(rng);
  365. let mut num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  366. ark_relations::ns!(cs, "initial num"),
  367. || Ok(num_native),
  368. )
  369. .unwrap();
  370. for _ in 0..TEST_COUNT {
  371. let next_add_native = TargetField::rand(rng);
  372. let next_add = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  373. ark_relations::ns!(cs, "next to add num for repetition"),
  374. || Ok(next_add_native),
  375. )
  376. .unwrap();
  377. let next_mul_native = TargetField::rand(rng);
  378. let next_mul = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  379. ark_relations::ns!(cs, "next to mul num for repetition"),
  380. || Ok(next_mul_native),
  381. )
  382. .unwrap();
  383. num_native = num_native * &next_mul_native + &next_add_native;
  384. num = num * &next_mul + &next_add;
  385. assert!(num.value().unwrap().eq(&num_native));
  386. }
  387. }
  388. fn square_mul_add_stress_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  389. cs: ConstraintSystemRef<BaseField>,
  390. rng: &mut R,
  391. ) {
  392. let mut num_native = TargetField::rand(rng);
  393. let mut num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  394. ark_relations::ns!(cs, "initial num"),
  395. || Ok(num_native),
  396. )
  397. .unwrap();
  398. for _ in 0..TEST_COUNT {
  399. let next_add_native = TargetField::rand(rng);
  400. let next_add = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  401. ark_relations::ns!(cs, "next to add num for repetition"),
  402. || Ok(next_add_native),
  403. )
  404. .unwrap();
  405. let next_mul_native = TargetField::rand(rng);
  406. let next_mul = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  407. ark_relations::ns!(cs, "next to mul num for repetition"),
  408. || Ok(next_mul_native),
  409. )
  410. .unwrap();
  411. num_native = num_native * &num_native * &next_mul_native + &next_add_native;
  412. num = &num * &num * &next_mul + &next_add;
  413. assert!(num.value().unwrap().eq(&num_native));
  414. }
  415. }
  416. fn double_stress_test_1<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  417. cs: ConstraintSystemRef<BaseField>,
  418. rng: &mut R,
  419. ) {
  420. let mut num_native = TargetField::rand(rng);
  421. let mut num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  422. ark_relations::ns!(cs, "initial num"),
  423. || Ok(num_native),
  424. )
  425. .unwrap();
  426. // Add to at least BaseField::size_in_bits() to ensure that we teat the
  427. // overflowing
  428. for _ in 0..TEST_COUNT + BaseField::MODULUS_BIT_SIZE as usize {
  429. // double
  430. num_native = num_native + &num_native;
  431. num = &num + &num;
  432. assert!(num.value().unwrap().eq(&num_native), "result incorrect");
  433. }
  434. }
  435. fn double_stress_test_2<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  436. cs: ConstraintSystemRef<BaseField>,
  437. rng: &mut R,
  438. ) {
  439. let mut num_native = TargetField::rand(rng);
  440. let mut num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  441. ark_relations::ns!(cs, "initial num"),
  442. || Ok(num_native),
  443. )
  444. .unwrap();
  445. for _ in 0..TEST_COUNT {
  446. // double
  447. num_native = num_native + &num_native;
  448. num = &num + &num;
  449. assert!(num.value().unwrap().eq(&num_native));
  450. // square
  451. let num_square_native = num_native * &num_native;
  452. let num_square = &num * &num;
  453. assert!(num_square.value().unwrap().eq(&num_square_native));
  454. }
  455. }
  456. fn double_stress_test_3<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  457. cs: ConstraintSystemRef<BaseField>,
  458. rng: &mut R,
  459. ) {
  460. let mut num_native = TargetField::rand(rng);
  461. let mut num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  462. ark_relations::ns!(cs, "initial num"),
  463. || Ok(num_native),
  464. )
  465. .unwrap();
  466. for _ in 0..TEST_COUNT {
  467. // double
  468. num_native = num_native + &num_native;
  469. num = &num + &num;
  470. assert!(num.value().unwrap().eq(&num_native));
  471. // square
  472. let num_square_native = num_native * &num_native;
  473. let num_square = &num * &num;
  474. let num_square_native_gadget = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  475. ark_relations::ns!(cs, "repetition: alloc_native num"),
  476. || Ok(num_square_native),
  477. )
  478. .unwrap();
  479. num_square.enforce_equal(&num_square_native_gadget).unwrap();
  480. }
  481. }
  482. fn inverse_stress_test<TargetField: PrimeField, BaseField: PrimeField, R: RngCore>(
  483. cs: ConstraintSystemRef<BaseField>,
  484. rng: &mut R,
  485. ) {
  486. for _ in 0..TEST_COUNT {
  487. let num_native = TargetField::rand(rng);
  488. let num = NonNativeFieldVar::<TargetField, BaseField>::new_witness(
  489. ark_relations::ns!(cs, "num"),
  490. || Ok(num_native),
  491. )
  492. .unwrap();
  493. if num_native == TargetField::zero() {
  494. continue;
  495. }
  496. let num_native_inverse = num_native.inverse().unwrap();
  497. let num_inverse = num.inverse().unwrap();
  498. assert!(num_inverse.value().unwrap().eq(&num_native_inverse));
  499. }
  500. }
  501. macro_rules! nonnative_test_individual {
  502. ($test_method:ident, $test_name:ident, $test_target_field:ty, $test_base_field:ty) => {
  503. paste::item! {
  504. #[test]
  505. fn [<$test_method _ $test_name:lower>]() {
  506. let rng = &mut ark_std::test_rng();
  507. for _ in 0..NUM_REPETITIONS {
  508. let cs = ConstraintSystem::<$test_base_field>::new_ref();
  509. $test_method::<$test_target_field, $test_base_field, _>(cs.clone(), rng);
  510. assert!(cs.is_satisfied().unwrap());
  511. }
  512. }
  513. }
  514. };
  515. }
  516. macro_rules! nonnative_test {
  517. ($test_name:ident, $test_target_field:ty, $test_base_field:ty) => {
  518. nonnative_test_individual!(
  519. allocation_test,
  520. $test_name,
  521. $test_target_field,
  522. $test_base_field
  523. );
  524. nonnative_test_individual!(
  525. addition_test,
  526. $test_name,
  527. $test_target_field,
  528. $test_base_field
  529. );
  530. nonnative_test_individual!(
  531. multiplication_test,
  532. $test_name,
  533. $test_target_field,
  534. $test_base_field
  535. );
  536. nonnative_test_individual!(
  537. equality_test,
  538. $test_name,
  539. $test_target_field,
  540. $test_base_field
  541. );
  542. nonnative_test_individual!(
  543. edge_cases_test,
  544. $test_name,
  545. $test_target_field,
  546. $test_base_field
  547. );
  548. nonnative_test_individual!(
  549. distribution_law_test,
  550. $test_name,
  551. $test_target_field,
  552. $test_base_field
  553. );
  554. nonnative_test_individual!(
  555. addition_stress_test,
  556. $test_name,
  557. $test_target_field,
  558. $test_base_field
  559. );
  560. nonnative_test_individual!(
  561. double_stress_test_1,
  562. $test_name,
  563. $test_target_field,
  564. $test_base_field
  565. );
  566. nonnative_test_individual!(
  567. double_stress_test_2,
  568. $test_name,
  569. $test_target_field,
  570. $test_base_field
  571. );
  572. nonnative_test_individual!(
  573. double_stress_test_3,
  574. $test_name,
  575. $test_target_field,
  576. $test_base_field
  577. );
  578. nonnative_test_individual!(
  579. randomized_arithmetic_test,
  580. $test_name,
  581. $test_target_field,
  582. $test_base_field
  583. );
  584. nonnative_test_individual!(
  585. multiplication_stress_test,
  586. $test_name,
  587. $test_target_field,
  588. $test_base_field
  589. );
  590. nonnative_test_individual!(
  591. mul_and_add_stress_test,
  592. $test_name,
  593. $test_target_field,
  594. $test_base_field
  595. );
  596. nonnative_test_individual!(
  597. square_mul_add_stress_test,
  598. $test_name,
  599. $test_target_field,
  600. $test_base_field
  601. );
  602. nonnative_test_individual!(
  603. inverse_stress_test,
  604. $test_name,
  605. $test_target_field,
  606. $test_base_field
  607. );
  608. };
  609. }
  610. nonnative_test!(
  611. MNT46Small,
  612. <MNT4_298 as PairingEngine>::Fr,
  613. <MNT6_298 as PairingEngine>::Fr
  614. );
  615. nonnative_test!(
  616. MNT64Small,
  617. <MNT6_298 as PairingEngine>::Fr,
  618. <MNT4_298 as PairingEngine>::Fr
  619. );
  620. nonnative_test!(
  621. MNT46Big,
  622. <MNT4_753 as PairingEngine>::Fr,
  623. <MNT6_753 as PairingEngine>::Fr
  624. );
  625. nonnative_test!(
  626. MNT64Big,
  627. <MNT6_753 as PairingEngine>::Fr,
  628. <MNT4_753 as PairingEngine>::Fr
  629. );
  630. nonnative_test!(
  631. BLS12MNT4Small,
  632. <Bls12_381 as PairingEngine>::Fr,
  633. <MNT4_298 as PairingEngine>::Fr
  634. );
  635. nonnative_test!(
  636. BLS12,
  637. <Bls12_381 as PairingEngine>::Fq,
  638. <Bls12_381 as PairingEngine>::Fr
  639. );
  640. #[cfg(not(ci))]
  641. nonnative_test!(
  642. MNT6BigMNT4Small,
  643. <MNT6_753 as PairingEngine>::Fr,
  644. <MNT4_298 as PairingEngine>::Fr
  645. );
  646. nonnative_test!(
  647. PallasFrMNT6Fr,
  648. ark_pallas::Fr,
  649. <MNT6_753 as PairingEngine>::Fr
  650. );
  651. nonnative_test!(
  652. MNT6FrPallasFr,
  653. <MNT6_753 as PairingEngine>::Fr,
  654. ark_pallas::Fr
  655. );
  656. nonnative_test!(PallasFqFr, ark_pallas::Fq, ark_pallas::Fr);
  657. nonnative_test!(PallasFrFq, ark_pallas::Fr, ark_pallas::Fq);