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.

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