arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_381/src/curves/tests.rs
bls12_381/src/curves/tests.rsRaw
 1use ark_algebra_test_templates::*;
 2use ark_ec::{AffineRepr, CurveGroup};
 3use ark_ff::{fields::Field, One, UniformRand, Zero};
 4use ark_std::{rand::Rng, test_rng};
 5
 6use crate::{Bls12_381, Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
 7
 8test_group!(g1; G1Projective; sw);
 9test_group!(g2; G2Projective; sw);
10test_group!(pairing_output; ark_ec::pairing::PairingOutput<Bls12_381>; msm);
11test_pairing!(pairing; crate::Bls12_381);
12
13#[test]
14fn test_g1_endomorphism_beta() {
15    assert!(crate::g1::BETA.pow(&[3u64]).is_one());
16}
17
18#[test]
19fn test_g1_subgroup_membership_via_endomorphism() {
20    let mut rng = test_rng();
21    let generator = G1Projective::rand(&mut rng).into_affine();
22    assert!(generator.is_in_correct_subgroup_assuming_on_curve());
23}
24
25#[test]
26fn test_g1_subgroup_non_membership_via_endomorphism() {
27    let mut rng = test_rng();
28    loop {
29        let x = Fq::rand(&mut rng);
30        let greatest = rng.gen();
31
32        if let Some(p) = G1Affine::get_point_from_x_unchecked(x, greatest) {
33            if !p.mul_bigint(Fr::characteristic()).is_zero() {
34                assert!(!p.is_in_correct_subgroup_assuming_on_curve());
35                return;
36            }
37        }
38    }
39}
40
41#[test]
42fn test_g2_subgroup_membership_via_endomorphism() {
43    let mut rng = test_rng();
44    let generator = G2Projective::rand(&mut rng).into_affine();
45    assert!(generator.is_in_correct_subgroup_assuming_on_curve());
46}
47
48#[test]
49fn test_g2_subgroup_non_membership_via_endomorphism() {
50    let mut rng = test_rng();
51    loop {
52        let x = Fq2::rand(&mut rng);
53        let greatest = rng.gen();
54
55        if let Some(p) = G2Affine::get_point_from_x_unchecked(x, greatest) {
56            if !p.mul_bigint(Fr::characteristic()).is_zero() {
57                assert!(!p.is_in_correct_subgroup_assuming_on_curve());
58                return;
59            }
60        }
61    }
62}