ark-curves-cherry-picked/bn254/src/fields/fr.rs
bn254/src/fields/fr.rsRaw
1use ark_ff::{
2 biginteger::{BigInt, BigInteger256 as BigInteger},
3 fields::*,
4};
5
6pub type Fr = Fp256<FrParameters>;
7
8pub struct FrParameters;
9
10impl Fp256Parameters for FrParameters {}
11impl FftParameters for FrParameters {
12 type BigInt = BigInteger;
13
14 const TWO_ADICITY: u32 = 28;
15
16 #[rustfmt::skip]
17 const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
18 7164790868263648668u64,
19 11685701338293206998u64,
20 6216421865291908056u64,
21 1756667274303109607u64,
22 ]);
23}
24impl FpParameters for FrParameters {
25 /// MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617
26 #[rustfmt::skip]
27 const MODULUS: BigInteger = BigInt::new([
28 4891460686036598785u64,
29 2896914383306846353u64,
30 13281191951274694749u64,
31 3486998266802970665u64,
32 ]);
33
34 const MODULUS_BITS: u32 = 254;
35
36 const CAPACITY: u32 = Self::MODULUS_BITS - 1;
37
38 const REPR_SHAVE_BITS: u32 = 2;
39
40 /// R = pow(2, 256) % MODULUS
41 /// = 6350874878119819312338956282401532410528162663560392320966563075034087161851
42 #[rustfmt::skip]
43 const R: BigInteger = BigInt::new([
44 12436184717236109307u64,
45 3962172157175319849u64,
46 7381016538464732718u64,
47 1011752739694698287u64,
48 ]);
49
50 /// R2 = R * R % MODULUS
51 /// = 944936681149208446651664254269745548490766851729442924617792859073125903783
52 #[rustfmt::skip]
53 const R2: BigInteger = BigInt::new([
54 1997599621687373223u64,
55 6052339484930628067u64,
56 10108755138030829701u64,
57 150537098327114917u64,
58 ]);
59
60 /// INV = (-MODULUS) ^ {-1} % pow(2, 64) = 14042775128853446655
61 const INV: u64 = 14042775128853446655u64;
62
63 /// GENERATOR = 5
64 #[rustfmt::skip]
65 const GENERATOR: BigInteger = BigInt::new([
66 1949230679015292902u64,
67 16913946402569752895u64,
68 5177146667339417225u64,
69 1571765431670520771u64,
70 ]);
71
72 /// (MODULUS - 1)/2 =
73 /// 10944121435919637611123202872628637544274182200208017171849102093287904247808
74 #[rustfmt::skip]
75 const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
76 0xa1f0fac9f8000000,
77 0x9419f4243cdcb848,
78 0xdc2822db40c0ac2e,
79 0x183227397098d014,
80 ]);
81
82 // T and T_MINUS_ONE_DIV_TWO, where r - 1 = 2^s * t
83
84 /// T = (MODULUS - 1) / 2^s =
85 /// 81540058820840996586704275553141814055101440848469862132140264610111
86 #[rustfmt::skip]
87 const T: BigInteger = BigInt::new([
88 0x9b9709143e1f593f,
89 0x181585d2833e8487,
90 0x131a029b85045b68,
91 0x30644e72e,
92 ]);
93
94 /// (T - 1) / 2 =
95 /// 40770029410420498293352137776570907027550720424234931066070132305055
96 #[rustfmt::skip]
97 const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
98 0xcdcb848a1f0fac9f,
99 0x0c0ac2e9419f4243,
100 0x098d014dc2822db4,
101 0x183227397,
102 ]);
103}