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