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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
module Fp = Plonkers.Fields.Fp
module Fp12 = Plonkers.Fields.Fp12
let fp12 = Testable.make Fp12.to_string Fp12.equal
let f c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 =
Fp12.of_coeffs
Fp.
( of_string c0,
of_string c1,
of_string c2,
of_string c3,
of_string c4,
of_string c5,
of_string c6,
of_string c7,
of_string c8,
of_string c9,
of_string c10,
of_string c11 )
let test_strconv () =
let a =
f
"4043700123595047491019396268386735516906248466322395048554330205778635891095"
"17221541359217652326358277858052631750810340224824921020179729243890155450597"
"2105430645710237792513582393166705872936983935586482637993019277236322297450"
"2750996376970369945896925750392113510825235148588986538251053617614577105984"
"19171164063617800757530920435617715964562251753299218441532022528480014971616"
"1869375785868235117470731287362599916254253000340764413892607328405734271000"
"18046224689788806059892088736232887972325780082048441908207440036617200097851"
"4394211309271417113975629390800575238025478427766436761683137388029266830025"
"18976283199790418408537367722034555229341657915689268301157926107621754668892"
"11126421063345725721927802506124285540060967019186245779441292497972981623917"
"3667157790183584710110277841377835880117476685194559992478342202253216897519"
"927625112157687680628039629075950684431926799823332260093299130490211782953"
in
Alcotest.(check string)
"equals"
"(4043700123595047491019396268386735516906248466322395048554330205778635891095, \
17221541359217652326358277858052631750810340224824921020179729243890155450597, \
2105430645710237792513582393166705872936983935586482637993019277236322297450, \
2750996376970369945896925750392113510825235148588986538251053617614577105984, \
19171164063617800757530920435617715964562251753299218441532022528480014971616, \
1869375785868235117470731287362599916254253000340764413892607328405734271000, \
18046224689788806059892088736232887972325780082048441908207440036617200097851, \
4394211309271417113975629390800575238025478427766436761683137388029266830025, \
18976283199790418408537367722034555229341657915689268301157926107621754668892, \
11126421063345725721927802506124285540060967019186245779441292497972981623917, \
3667157790183584710110277841377835880117476685194559992478342202253216897519, \
927625112157687680628039629075950684431926799823332260093299130490211782953)"
(Fp12.to_string a);
Alcotest.(check fp12)
"equals" a
(Fp12.of_string
"(4043700123595047491019396268386735516906248466322395048554330205778635891095, \
17221541359217652326358277858052631750810340224824921020179729243890155450597, \
2105430645710237792513582393166705872936983935586482637993019277236322297450, \
2750996376970369945896925750392113510825235148588986538251053617614577105984, \
19171164063617800757530920435617715964562251753299218441532022528480014971616, \
1869375785868235117470731287362599916254253000340764413892607328405734271000, \
18046224689788806059892088736232887972325780082048441908207440036617200097851, \
4394211309271417113975629390800575238025478427766436761683137388029266830025, \
18976283199790418408537367722034555229341657915689268301157926107621754668892, \
11126421063345725721927802506124285540060967019186245779441292497972981623917, \
3667157790183584710110277841377835880117476685194559992478342202253216897519, \
927625112157687680628039629075950684431926799823332260093299130490211782953)")
let test_add () =
Alcotest.(check fp12)
"equals"
(f
"679260298844574254658098201490432118201156332014499464072357045783567899838"
"20475919004872449640122744615447506207327525242658307088113520342244945960358"
"13871507983041033919567680142670451553603213953814376172488380435196942700234"
"12850228783435933341205418383649786138378876239236074742023644779482238243459"
"19010719217928472625414626459816630843435532005804375842636239357951625824869"
"353361581120153434542711822928079088462937368808804124349150015227948541179"
"2029344792912984928013093110746176734910474788192840468383948530606464616319"
"224761504179229810724248011021312391012380553234009782153212961210341755046"
"451562162093432102273792043296344588613930115373088228912224071742712972688"
"5192895932298088819213348659049985277006861383184245302543708664337039108570"
"10158021158623517100717170235733910390453779591048565291341062723228765172235"
"6131225099025722618175290550608959453389007048060581783437013508345590116498")
(Fp12.add
(f
"14931999610250342822030012252237969020436152669397159687161020814914197553139"
"12068226242492634649534499085073865283608802649550864019460178310983959118324"
"15769101094691500511973604469451833156840504999292195446944541933407840361132"
"20661609727890788633981333469033291135323566204416455059932944861978471695116"
"2057793890244571119199475975000207559112876700179056915158665930334537872900"
"11480126761539027368178757662940649318911799819183985288507182880644544939911"
"15222168687843425176374981940657799055412877920628856347415463739277380226421"
"2974457513962516407820830877389422281088143975054414666387703223401043716592"
"2348424488598693892192985411549003709285821026463716905647047910644187358017"
"1405728804825785845835731479206008540235534323879806803684210051642564930503"
"101209029551192918234450299377855172547700667160377054726060383975488192056"
"3837972317546152247347794409250781678377461931560089048310163797757975030964")
(f
"7635503560433506654874491694509738186461314819915163439600374125514596555282"
"8407692762379814990588245530373640923718722593107443068653342031260986842034"
"19990649760188808629840481418475893485459020111820004388232876396434328547685"
"14076861927384419929470490659873770091751621192117443344779737812148992756926"
"16952925327683901506215150484816423284322655305625318927477573427617087951969"
"10761477691420401288610359905244704858247448706922642498531005029228629809851"
"8695418976908834973884516915345652768193908024861807783657522685974310598481"
"19138546862055988625149822878889165198620547735477418778454547632454524247037"
"19991380545334013432327212377004615968024420246207194985954214055743751823254"
"3787167127472302973377617179843976736771327059304438498859498612694474178067"
"10056812129072324182482719936356055217906078923888188236615002339253276980179"
"2293252781479570370827496141358177775011545116500492735126849710587615085534"))
let test_sub () =
Alcotest.(check fp12)
"equals"
(f
"15908474088103139349886914563506292774722223644332289754060839597966653834354"
"19468903649148034186312004419961428100646897361413592524656745617046188826035"
"20540424982179362114876198805467627146603412559474874139719472903688974870756"
"3836429692597588529548840838826971241597957436931516374758207719178743608230"
"21830559190270609452459668428089768514857874053026274870545746135494880807637"
"5094374349680316463579780211124660738607018927208960054407665339551047398929"
"7728234632902120206027219485831149847929538205910753111981192796954456596100"
"2797876891638629746607000964279680713235660341952882093805056848165107637974"
"20166472943390066070248168796595470736094244718893955128106082062464538994586"
"8546845534299398595494998189880141057663506092846353038384036300074765595661"
"7640210579555013309302740819505903099659293665740634778638035680546457444740"
"3192553841734433576752699604744306986632824540885364664410616569041893968411")
(Fp12.sub
(f
"5805569491354595219543071656122507705698138220857222292204195295279450601031"
"17420719132934791902466958306912320433737206386115661558254952724857268395785"
"21564681492345603655791194192870315392117291559066745915830361772947234817173"
"7363339439810905491416846001351733412151827187008974189515031471804719866657"
"5964238426350559010840925430005390298918195823963418235621473678586444898238"
"873115171021014455523200811995796381744624930869754151259564914798828757746"
"8607593416247573654022275265889687194660698389188174609607223866074250581700"
"2291604495963149906293106357908558324864001579812690483933454399450635462628"
"2165237414593688322174293381001286773184870016162493277320233445405434254297"
"4415812194973427285927546678028778558625701011516473497601642289339094142740"
"19571255403751560226173444762325349082722761181407645654936453607532580779671"
"21613798221463787690278203646027059887353673424639892424379955754772967467245")
(f
"11785338275090731091902562837873490019672225733822756200832393591958022975260"
"19840058355626032938401359632208167421786620181999892696287245002456305778333"
"1024256510166241540914995387402688245513878999591871776110888869258259946417"
"3526909747213316961868005162524762170553869750077457814756823752625976258427"
"6021922107919224780627662747172896872756632928234967027764765437736790299184"
"17666983693179973214189826346128410731833917160958617759540937469893007567400"
"879358783345453447995055780058537346731160183277421497626031069119793985600"
"21381970476163795381932511138886152700324652395157632052817435445930754033237"
"3887007343042897474172530329663091125786936454566361811903189277586121468294"
"17757209532513303912678954233405912589658506075967944121906643883909554755662"
"11931044824196546916870703942819445983063467515667010876298417926986123334931"
"18421244379729354113525504041282752900720848883754527759969339185731073498834"))
let test_mul () =
Alcotest.(check fp12)
"equals"
(f
"8823818978915783805181616565331969040878879797819598481454052588850485460611"
"17342067505254006854696747055377366784894036844497398369789366435506766106061"
"4460181749512451599930853254947317081415316509251200956882755476302030517218"
"2989864541505855655981241407648859030899418844639260896292378000523322285734"
"6131563575961041210659641231208875099164513998741365855416959149114746613493"
"612999273383988699209096180042826466871099791087758060034530146827776903037"
"217824396591541203076315004412144321172659947882959179658988780407547464397"
"1334243229555105018807996840445782461460452800783774966111589924865137740068"
"9401225268817633060698359209750296257708832438926305447978974797074462742256"
"3122452964485047360743410379835632005339027686211128544529227625617933632632"
"14516783584152973770104960644065406423218736942455586740443875151798452381730"
"12862141850291214733449100168455302645220941815281926312862226415725812746384")
(Fp12.mul
(f
"6948967768617865944982899667620023648328221475287539300508042248094743234515"
"7046400706491288955917718293112336819412128352636241964184889420272069832482"
"1176385575279124403880126584953866531215702698901662691243262531090208747274"
"6157271231395572936222356741453701249917009400986329923156898473163776867375"
"12602932002327759785860910268394732588446182568984616056718210781632617905768"
"7847224741347352395417620596844584634592185397547160260075268300188382673626"
"21730909569914770152829996303596551818955608830043144814027154110020524163458"
"1493315682700915812470161997513890424122703532295699240379189380245672216242"
"14446940862282451624845471434002447742900901850076724275325798511063686417572"
"18469655736724097735553911099641627340281327622528778814612181953467122960165"
"15159629442965085480595880613882183287914599282250274300979165401891091065171"
"8682857601265363140507477056634677315927213720928334491216000329988109481408")
(f
"5267072325748027197742556153957640105461859359409691382355149691412842189062"
"13860225074612684828895475883488906402030398480017068545098320878551171693332"
"20528308977578979501461405548916487126143884599548116314684440223357844484106"
"14900301117804943437504093273693765829216713590821036756558659587614078075181"
"10865416682957561387095694744822715017167214136582183104864204620302886498987"
"8614907467168717704558609396284593818308913710372720444790049949006894118578"
"2911296271706596100511566654004168334006140030049210923581225120516133875480"
"11692632339396190822067214084116224973400417552783595347053750081499566156074"
"21198428102722495178821959702584364354987690338890265399399765532216055913782"
"11893302225633376608282656573764224393980787558045497315206166758262569839656"
"1338072636057400393635925588044072398176682615943934513151529301522509187278"
"12959329259704037762362242830752770509395329838916184355704828609736076981548"))
let test_div () =
Alcotest.(check fp12)
"equals"
(f
"1096803581874169670960297098779105899780688007924067918320102919752182708300"
"9995875973811579901417242213630515940173375903459966681878798696090228036787"
"3366236069588813741179351217208783720698794654464062357207288742843117814761"
"2611740726020013650358809493530292337327075703423177538682869561017208504928"
"16978038323586267447042278676006098836832469726377502891390302026928324356346"
"13990225310798549460842507817183211861953629723187315670443012263170556910620"
"15708725132415572278184615188378799388286737910276549406045149828302331760548"
"13922646542487508952487824019581303897151102688875549649032880615524477708715"
"13989849264798557614151062706464075549675061655681620590943048073671802304949"
"2999450488895033272886335121147596204573319911571544116922024695423270495206"
"1707193605930465946700519771750791799447293109947880961206685427498523417284"
"416569712948182390436868324476465553831984173593246113696858459452543126794")
(Fp12.div
(f
"16891629574128548079304072179932861694695268028581829895449988812958151889068"
"5773428070121667584587697155448628787499399401530717395380822743509515712302"
"1510014905380928573966817876817322588036636044829790691311576928625055774713"
"3484897069108570642536176082552988040898002350875200634245641433336320087452"
"19718291166133617007547736703319040673297932826425091870865978392072812281568"
"17859744514917983533340674875779802110474596234481900219886514483092059069870"
"20437324654495856958641082802073814921383894147185666216954188982917904332878"
"2960345167483834491960471912580543338504765185419418826135735944240543975007"
"7431248571303067589896102358092670922459603228321352003423446458656336374356"
"3753895253518515147013086017379029828017667525827529804307831430901850392657"
"2406550068803257825161686151282932146056678185052400200434529815433282715522"
"21527499377571830635005139066287650700499729934985849257468301501456435601873")
(f
"67887943195798695261820949337218985472375672292075296753186878599440520768"
"13221092658007783265664390560083928475990190337014855192393579704007489867413"
"8425295182175543772634645537444676197117770070441758278552491787485944955143"
"5452242309254919322497256021853961886147467857551647992384478388934952465010"
"16002819843715475015659395477967729218897925694288387242539104147750372425731"
"4793967772144214427321198219730753130655544135281827339549013053471477208473"
"16160972968990591254495688451831377777703706141098146685039319374528010898494"
"2937205914155151267440505688406167297438304682690886695251911934863243504008"
"5856027318101378740288921481950609018965696470858373478768113198173003568240"
"21786389593140873764454033633721078549985584303110658965932205813679697655177"
"15295386324750102363077755441279089627233550655637004662790687327895590046305"
"824194856810356908268669154202468264046536936033436850379538516763834225090"));
Alcotest.(check fp12)
"equals" Fp12.zero
(Fp12.div
(f
"10958220273304108960140356770617266772375080927415838618895832830305759889705"
"13465260772194793648511483227951827021566341247163835532611618114997996407962"
"1157075537382478623643205191944067608345124553202251720110826577009049375217"
"7922926335100307301932417560040310453147890695990664992454446037098126700673"
"3854197206315666756465194050813560230806692032959567144432084335025504342749"
"12002208660574246630553852361550751902863562816424890461995942000992537163163"
"10597191987670354308027891589666620382959026949753684566516632297755284416880"
"15420627205969290772283713743732187786100671782123230284737435344240576449936"
"6802543793339110195182347217544705545690730554181808318302725682544596347672"
"5569849441110190591622396996506105482399895437826867255519649816379826212708"
"17852423389543152155949451338445708565476874751681072167786506882830599204858"
"10904113524921192396634981424155901832103292272159174385913687952131455889939")
Fp12.zero)
let test_neg () =
let a =
f
"18605205790937513393061432931422829429842719850592922039475732913063240424554"
"12407214612973176394609465088181275180209573721437502280700981704118114513425"
"2302243975397132977902561193046139882549564197439606156078083357011819270659"
"2738285309128644623205322608750527409463641342449273398277873439071000338246"
"19319592312706960701826229795892663067089215313407329629222255259911759030857"
"15763745279656661838570297050636906941374326329806024351274342505301090350445"
"20130480934439181563277666741994991665705808107265248886754964759388131724731"
"9620877890335010684997930792443932455373413343757491049206285380122715424492"
"14909574107785408299854013106123871467362127317944663380391766106267340888712"
"10461986004179838170014598182006536556751491190190190100041874184540493450411"
"6739235625602005139923788170786820709848060227361018450724656857473350332405"
"19431892743074308896971441056213912607074572676149412002826263167122874131180"
in
Alcotest.(check fp12)
"equals"
(f
"3283037080901761829184972813834445658853591306704901623213304981581985784029"
"9481028258866098827636940657075999908486737435860321381988056190527111695158"
"19585998896442142244343844552211135206146746959858217506610954537633406937924"
"19149957562710630599041083136506747679232669814848550264411164455574225870337"
"2568650559132314520420175949364612021607095843890494033466782634733467177726"
"6124497592182613383676108694620368147321984827491799311414695389344135858138"
"1757761937400093658968739003262283422990503050032574775934073135257094483852"
"12267364981504264537248474952813342633322897813540332613482752514522510784091"
"6978668764053866922392392639133403621334183839353160282297271788377885319871"
"11426256867659437052231807563250738531944819967107633562647163710104732758172"
"15149007246237270082322617574470454378848250929936805211964381037171875876178"
"2456350128764966325274964689043362481621738481148411659862774727522352077403")
(Fp12.neg a);
Alcotest.(check fp12) "equals" Fp12.zero (Fp12.add a (Fp12.neg a))
let test_inv () =
let a =
f
"15197869645782446670819580844615631526100380266853121434256548370382659320138"
"10627543309547787009232419754376077894952590471427078354138646744158189540404"
"1814853692665074057505353520795390518070085772159341335189512049618927636539"
"11949689541137973499672139858049132789842194843731146425512744199284215943929"
"5222524330918035510176216749476274803906609211476272648212097633307220079528"
"1792818538678490572371603393885403657547207673498243448285801833280210496863"
"16829525197006006684314306774471847704562973817716113268985730574839165072949"
"7542402845708551026929617848839344008856126285276324754388571567846639434824"
"21407871464337343446060102809062189530922585055434671430220200406655129284823"
"7295283709695804870206659116059355882732810218144222393403721923307577665189"
"506076349945751079801619684510142633510371851040994638301723710643137761400"
"15937885146743516578215731869138888251078571985851131433165556423836493883525"
in
Alcotest.(check fp12)
"equals"
(f
"436429649161332244395200468656153955501103571619671423360095979722406060064"
"19703427263517091380071693461996431052346066551061427941406447796972979677580"
"15237458399375262953488655963555676274913157914525801452145663231325785397699"
"2568813005168407627948623044089020521091876501727292526455053390191076786825"
"8374585028324530814788669886595948808089637355106119111322101373159005027675"
"16623336649804830435561507464164224551227223481434415016873158702848533912284"
"17257110226070417269020755132573578358005004798648012375153436547242639978919"
"3888702150606092681263295431645552248270206784952216927162406167861231226331"
"20825319057083721423157488310478166863959825321685333239108930700513089934153"
"8539103339131261762185833769478780195064228372509888611941063026151125653390"
"19940593141145190804508553299020265737918480914795758132715084668534344174565"
"11454523167593227976588122484560257616164530826320021248044988267657603586353")
(Fp12.inv a);
Alcotest.(check fp12) "equals" Fp12.one (Fp12.mul a (Fp12.inv a));
Alcotest.(check fp12) "equals" Fp12.zero (Fp12.inv Fp12.zero)
let tests =
Alcotest.
[
test_case "String Conversion" `Quick test_strconv;
test_case "Addition" `Quick test_add;
test_case "Subtraction" `Quick test_sub;
test_case "Multiplication" `Quick test_mul;
test_case "Division" `Quick test_div;
test_case "Additive Inverse" `Quick test_neg;
test_case "Multiplicative Inverse" `Quick test_inv;
]
|