1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
use ark_ff::{
    biginteger::BigInteger768 as BigInteger,
    fields::{FftParameters, Fp768, Fp768Parameters, FpParameters},
};

pub type Fr = Fp768<FrParameters>;

pub struct FrParameters;

impl Fp768Parameters for FrParameters {}
impl FftParameters for FrParameters {
    type BigInt = BigInteger;

    const TWO_ADICITY: u32 = 7u32;

    // ROOT_OF_UNITY = GENERATOR ^ t =
    // 5051348772165646558710889803432238607797392809516000790038615454406641638798360636639094562941749878118669420392611632754442159525900729019616828636182878045303562497793780656635901271279409699078868658041674335385318499053954
    // t is defined below
    // This number needs to be in the Montgomery residue form.
    // I.e., write
    // 5051348772165646558710889803432238607797392809516000790038615454406641638798360636639094562941749878118669420392611632754442159525900729019616828636182878045303562497793780656635901271279409699078868658041674335385318499053954
    // * R
    // = 3163945077843586747114473523156080008349200300253316071422414259389979351386670787753361998953450578171951209600907861296956453653582402723399808696724060539858637307706671971132333536614595846054039300191656599533885935499352
    #[rustfmt::skip]
    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
        17630237153019476056u64,
        13843632041501582123u64,
        8277579215948731020u64,
        16543319700733887487u64,
        17904443422768964556u64,
        4398189354108552378u64,
        15178824470536352826u64,
        5393472405610595666u64,
        9815530206026813666u64,
        9111703519527971535u64,
        9880873531994141485u64,
        37593433148184u64,
    ]);
}
impl FpParameters for FrParameters {
    // MODULUS = 5237311370989869175293026848905079641021338739994243633972937865128169101571388346632361720473792365177258871486054600656048925740061347509722287043067341250552640264308621296888446513816907173362124418513727200975392177480577
    // Factors of MODULUS - 1:
    //      2^7
    //      3
    //      67
    //      193189
    //      5324381
    //      20502324317011
    //      12991385268608969143
    //      743005941432538001939136029613828619428586060274612824031793373798492678674419102414979927623550862639644071557313558044209469997283394306590808303316688123808776073253386140931
    #[rustfmt::skip]
    const MODULUS: BigInteger = BigInteger([
        1918157353135465345u64,
        963476667289301255u64,
        6719983938249379016u64,
        3655897403342429413u64,
        14998997414201165002u64,
        13135040821375901270u64,
        12914675130452106995u64,
        6989506515121216945u64,
        12382362535852178190u64,
        13186314214759855613u64,
        2451174275904461237u64,
        62228802984066u64,
    ]);

    const MODULUS_BITS: u32 = 750;

    const CAPACITY: u32 = Self::MODULUS_BITS - 1;

    const REPR_SHAVE_BITS: u32 = 18;

    // see ark_ff/src/fields/mod.rs for more information
    // R = pow(2,768) % MODULUS
    // R = 933352698056040166367534174176950366489065242993745918174914647273231163953185260894581718311971532174387033963715296372791285468903747270837716556902938133611910788060028435531754797383796835009316018259656953442114538695438
    #[rustfmt::skip]
    const R: BigInteger = BigInteger([
        13829252738394483470u64,
        3696102008259415033u64,
        13727024804350215797u64,
        13923468026436718769u64,
        5924604905079742862u64,
        10708002647109138222u64,
        14670460945619011269u64,
        10920055614013427454u64,
        16773322069409968132u64,
        11648025004657998992u64,
        5853759956175613481u64,
        11089930891582u64,
    ]);

    // R2 = R * R % MODULUS
    // R2 = 2468731867191023344597744941938926307216338526282824416880609839804154918771848044056240157551420210981962520047623686977567450338290776997282473798413876535168711321018336215486289519735826959884564283681071791441993286279295
    #[rustfmt::skip]
    const R2: BigInteger = BigInteger([
        10440129917231554687u64,
        8797934528693354276u64,
        14378434434829994158u64,
        7755707164286885667u64,
        16206546501540671680u64,
        8674228973811871262u64,
        12794601382709871071u64,
        17194287857269754157u64,
        2120600029739364160u64,
        15454005187782655500u64,
        18107041519543174727u64,
        29333033326005u64,
    ]);

    // INV = -(MODULUS)^(-1) % 2^64
    const INV: u64 = 3079018560679650175u64;

    // GENERATOR = 5
    // This number needs to be in the Montgomery residue form.
    // I.e., write 5 * R =
    // 4666763490280200831837670870884751832445326214968729590874573236366155819765926304472908591559857660871935169818576481863956427344518736354188582784514690668059553940300142177658773986918984175046580091298284767210572693477190
    #[rustfmt::skip]
    const GENERATOR: BigInteger = BigInteger([
        13806031470843762502u64,
        33765967587523552u64,
        13294891800622424138u64,
        14277107911054939000u64,
        11176280451689162697u64,
        16646525088126587879u64,
        18012072506966401499u64,
        17706789922648034041u64,
        10079634052211634198u64,
        2899892802161340116u64,
        10822055707168515792u64,
        55449654457911u64,
    ]);

    // (n-1)/2 = 2618655685494934587646513424452539820510669369997121816986468932564084550785694173316180860236896182588629435743027300328024462870030673754861143521533670625276320132154310648444223256908453586681062209256863600487696088740288
    #[rustfmt::skip]
    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
        10182450713422508480u64,
        481738333644650627u64,
        12583364005979465316u64,
        1827948701671214706u64,
        7499498707100582501u64,
        15790892447542726443u64,
        15680709602080829305u64,
        3494753257560608472u64,
        15414553304780864903u64,
        15816529144234703614u64,
        1225587137952230618u64,
        31114401492033u64,
    ]);

    // t = (n - 1) / 2^{TWO_ADICITY} =
    // 40916495085858352931976772257070934695479208906205028390413577071313821106026471458065325941201502852947334933484801567625382232344229277419705367523963603519942502064911103881940988389194587291891597019638493757620251386567
    const T: BigInteger = BigInteger([
        1023791920852361927u64,
        10383820702924820450u64,
        14608133870179016345u64,
        10693085616076947257u64,
        12511085841822051593u64,
        16675864135140424508u64,
        7162540115173594813u64,
        2072218152711366715u64,
        18111135716793329142u64,
        7741123047823172587u64,
        307380175182215347u64,
        486162523313u64,
    ]);

    // (t-1)/2 = 20458247542929176465988386128535467347739604453102514195206788535656910553013235729032662970600751426473667466742400783812691116172114638709852683761981801759971251032455551940970494194597293645945798509819246878810125693283
    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
        511895960426180963u64,
        14415282388317186033u64,
        16527438971944283980u64,
        14569914844893249436u64,
        6255542920911025796u64,
        17561304104424988062u64,
        12804642094441573214u64,
        1036109076355683357u64,
        18278939895251440379u64,
        13093933560766362101u64,
        9377062124445883481u64,
        243081261656u64,
    ]);
}