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 #[rustfmt::skip]
38 const R: BigInteger = BigInteger([
39 12436184717236109307u64,
40 3962172157175319849u64,
41 7381016538464732718u64,
42 1011752739694698287u64,
43 ]);
44
45 #[rustfmt::skip]
46 const R2: BigInteger = BigInteger([
47 1997599621687373223u64,
48 6052339484930628067u64,
49 10108755138030829701u64,
50 150537098327114917u64,
51 ]);
52
53 const INV: u64 = 14042775128853446655u64;
54
55 // GENERATOR = 5
56 #[rustfmt::skip]
57 const GENERATOR: BigInteger = BigInteger([
58 1949230679015292902u64,
59 16913946402569752895u64,
60 5177146667339417225u64,
61 1571765431670520771u64,
62 ]);
63
64 /// (r - 1)/2 =
65 /// 10944121435919637611123202872628637544274182200208017171849102093287904247808
66 #[rustfmt::skip]
67 const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
68 0xa1f0fac9f8000000,
69 0x9419f4243cdcb848,
70 0xdc2822db40c0ac2e,
71 0x183227397098d014,
72 ]);
73
74 // T and T_MINUS_ONE_DIV_TWO, where r - 1 = 2^s * t
75
76 /// t = (r - 1) / 2^s =
77 /// 81540058820840996586704275553141814055101440848469862132140264610111
78 #[rustfmt::skip]
79 const T: BigInteger = BigInteger([
80 0x9b9709143e1f593f,
81 0x181585d2833e8487,
82 0x131a029b85045b68,
83 0x30644e72e,
84 ]);
85
86 /// (t - 1) / 2 =
87 /// 40770029410420498293352137776570907027550720424234931066070132305055
88 #[rustfmt::skip]
89 const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
90 0xcdcb848a1f0fac9f,
91 0x0c0ac2e9419f4243,
92 0x098d014dc2822db4,
93 0x183227397,
94 ]);
95}