aboutsummaryrefslogtreecommitdiff
path: root/test/test_fp2.ml
blob: c108cfcb6f22fb1983452a1a57131a09d69a3b7d (plain)
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
module Fp = Plonkers.Fields.Fp
module Fp2 = Plonkers.Fields.Fp2

let fp2 = Testable.make Fp2.to_string Fp2.equal
let f c0 c1 = Fp2.of_coeffs Fp.(of_string c0, of_string c1)

let test_strconv () =
  let a =
    f
      "3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707"
      "3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044"
  in
  Alcotest.(check string)
    "equals"
    "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707,3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)"
    (Fp2.to_string a);
  Alcotest.(check fp2)
    "equals" a
    (Fp2.of_string
       "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707,3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)")

let test_add () =
  Alcotest.(check fp2)
    "equals"
    (f
       "1510922689064524402660706287794383764925405808912063605538062764260624404168626064439638568280286334446426980599265"
       "1496432034719009204104939852773510654757730640471573422565456754717202107187391202678306935556569591898047519241723")
    (Fp2.add
       (f
          "2704945784483088396721340837125430974578228372397373052449492346866782679603876968318204562585444722881993787072969"
          "3352713865626504319356760967861765786693715633606160360950371888464145243153004345983441305675063325004158251106532")
       (f
          "2808386459803103399357155276404856946904060256453698438420628553517873375055586960564121634823857275602327466086083"
          "2146127724314172278165968710647649024620897826804420946947143002377088514525224721137553259010521930931783540694978"))

let test_sub () =
  Alcotest.(check fp2)
    "equals"
    (f
       "2746233490314206119922872871732785027444344635498924519980558228449368171837071387946659139045523440232024909392314"
       "2448129066313268798189916410701811180368378842353203391514920640569880371240863965817664159595772806445686456192024")
    (Fp2.sub
       (f
          "3718052663769508561298229087440516584831920387492170643569413395812990566524218001757670372308077205706322080181599"
          "2341793402065270422967665886452846002018783895673345084011697286747619532326972232127106898002302648025798998240672")
       (f
          "971819173455302441375356215707731557387575751993246123588855167363622394687146613811011233262553765474297170789285"
          "3896073890973669018195539301486938978207287873259149577828834782301770811576946130752130367535545505618006814608435"))

let test_mul () =
  Alcotest.(check fp2)
    "equals"
    (f
       "1885423083277797471109639559263547433578030928072896554966830817836333890642646249004478238507722056220637045498600"
       "3207243584937107335460533661085834171833693638143693295511055862451917226660443578426964769719700546772951496395996")
    (Fp2.mul
       (f
          "803369954224906884563405258732068127499444124373729560274472206073891173218445424518997451866034346092384213329883"
          "503859036923320084991265627572913800252671955497792544998415381318131015579573065357816625000610831510288652298964")
       (f
          "1859749334750628929451690227707687335137511133983531364679291438693098079713802711484547274759649760701831974491385"
          "319479918179863684323943763511758417353324391274148720422945903908894556320269100349817409794148843141967413849647"))

let test_div () =
  Alcotest.(check fp2)
    "equals"
    (f
       "2325686290754200682121145718202670986494244660819308027034132423071687323315606671884154529323382987150473976768330"
       "3239216598855324114836362759253541458361602150483475976924117760584009168234436493512552837300363568825071136536608")
    (Fp2.div
       (f
          "2688262090907385109797388649018262997913625856978785865546511105491589076903808300443238242582958974774562346365422"
          "620412794822327085382870755739471012462590600882879640428242176258125002321042095639472359615918267969245549940520")
       (f
          "117974554526362724345489824744262248121856237810884003402927315860807227932189517320482013911923392063068425858030"
          "2142419467175775193318602789320722018616077971991495171114531437934768498979157636382154413194108550314043215582110"));
  Alcotest.(check fp2)
    "equals" Fp2.zero
    (Fp2.div
       (f
          "2856688501118144969553652456291973087251256250655576140296976320844142067655542164500037157598802323742365765731618"
          "91558039329695554504260627328728230183446829018778898668517468830173959679663774362827298058047294625048351979470")
       Fp2.zero)

let test_neg () =
  Alcotest.(check fp2)
    "equals"
    (f
       "1652265803669885112428961827998763844356192502384525464729566587325430585803412442963299000002746518202319166455569"
       "3148086661203569599939489297515929514901363299142047909817073525316870145634606314218990062256965667072857382426277")
    (Fp2.neg
       (f
          "2350143751551782280988827997737140312200690317554482420602491548798601064687425421479388629126269145835575106104218"
          "854322894018097793478300528219974641655519520796959975514984610807161504856231550223697566872049996965036890133510"));
  let a =
    f
      "3755242969290908447416997081739091519087375707422634859355840356380094840094873991320874195734523076514815397321243"
      "1849949402789644720627099830974848465908019020270918322229375845176468537369459245375868854333718071380139986243176"
  in
  Alcotest.(check fp2) "equals" Fp2.zero (Fp2.add a (Fp2.neg a))

let test_inv () =
  Alcotest.(check fp2)
    "equals"
    (f
       "3171328058141487552606964490094256865782521411579367440944677919764391101552560722992448953525776730005333301011061"
       "117788241764364141558165207260211125711335775044260038750142676288749728539425977597521263176199168588971967704898")
    (Fp2.inv
       (f
          "3132683201126346359997649079543944507328912651674927308673497534307262164772016129965211842871422381557518724206099"
          "135021294749983899985272892787067246478709822352712818248214312648840971448796031511036377049998504006594698872092"));
  let a =
    f
      "1091358140339556525084474003788455245476134161423421088817134261365285167798938852556734938868755532003979871690585"
      "3020178740353647556832143367266239362247768279656392658297101610073850568065890310189767257933036353291058805033028"
  in
  Alcotest.(check fp2) "equals" Fp2.one (Fp2.mul a (Fp2.inv a));
  Alcotest.(check fp2) "equals" Fp2.zero (Fp2.inv Fp2.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;
    ]