aboutsummaryrefslogtreecommitdiff
path: root/test/test_pairing.ml
blob: 8b9f9d6d14a1a7165c9ee38af197788319eb5e4e (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
module Pairing = Plonkers.Pairing
module G1 = Plonkers.Pairing.G1
module G2 = Plonkers.Pairing.G2
module Gt = Plonkers.Pairing.Gt

let gt = Primitives.Testables.gt
let f1 = Primitives.Literals.g1
let f2 = Primitives.Literals.g2
let ft = Primitives.Literals.gt

let test_generator () =
  Alcotest.(check gt)
    "equals"
    Pairing.(e G1.g G2.g)
    (ft
       [|
         "3408834164464458755751340723502736743445402614640994055433339214424916442641449510670327077303074893591740399366532";
         "1017299873256115394687936133146817339783508925356207904663165117501336940438300180831508525168135575931758510829235";
         "1919447955347661378578718469488414822573562393353397544098339472673901193098010131520945815709482515519580400649694";
         "233557331756520805040932826416017142246700002714928636467514104620558679338483625829873520553081791155104026612174";
         "2882199334237819327910933128503231887000342950792587449681715803095618652567681747054312179958427092970985872417068";
         "579878855790610229145575079003483905368886712027403088810647643659132674704592975818766405092658613973478871626949";
         "3268798540077874559188095304926415053902298079662269128631117894259354335713488241073281881110999874366368799440511";
         "2688711983546324406847903726099677850388169649284572370749691792743294691894680263880362424577638309433508620982332";
         "3520140447471844017044610248175793726488927385800919015247604269617056365166670232096113218155158979455637700602719";
         "1555267885602801620621747613743921378408444002839854792606782732724136830563310004098024452104661167182680744848589";
         "2626389147790168154036854297373352480470342009417426750876875476996308393122833154115295241935326582225976246741447";
         "873321072950766150592434764742436722571574260472569072177205897167854308426485977134306337249021436737462538398830";
       |])

let test_pairing () =
  Alcotest.(check gt)
    "equals"
    (ft
       [|
         "448697226789963268348912232951073713452968894642929214443994147359412138639526655164503406978236522025734912852606";
         "151261630108668103390829365027365404889205408289235816621708275624780812413761415129004835746255625267607732639563";
         "2909423043708809630024534763367123821438139353180175913125076930835302419897651130667995073651726848611333745205986";
         "952434542917010958697197601576391780800301526127664682598671275809818228531516224262590129674712650458795890584553";
         "1478486475752483299362722402760792915820803227192648258365429143818886181422874016577411765850893129689832973264031";
         "652834415768413017856200607794773610957395062979681182931987046704660733141291027961343651372030380321651719802520";
         "951656253138365825024367899445523415181713017704780705176410361641958854486267870078190603032432549582347900417624";
         "1991042670420833845569811948628174796662344145916123310837646809687525541032370298949411402142207368319354069329317";
         "2920440541157943770850967007055029075931555684879417457120436377239540586798148490244301682350449674796660182631922";
         "3554199917981379540114579517242213458150684556713432050906212290132174074734340424484104596198947386114933622334567";
         "1091458823916905664137346388296576506864216891159041434853650685402092824487985812791698734521558868411023155785769";
         "43181594668188258041148789943396863898539176535733231639633582884332884962913532441125648697214326572900496337037";
       |])
    (Pairing.e
       (f1
          ( "1759244594739438101652572364306631993712897577542654736932660460743445183171945408603399266474637228371219384150089",
            "2746850152127019659862408918732227356169104535991470589122155020934454571292242598343702169898773975726309716165198"
          ))
       (f2
          ( [|
              "1256740661954421835404627287451128275298916640367011495362432993289541383031490867768256365295187693751267667845404";
              "3717522504942038420636575612519050548073203872805747528897870222147344374794751097864928254417486766328132878640824";
            |],
            [|
              "2512342532199657251630152291613780551312453521116783301133995957210838938697636876773382152437204041044762830468417";
              "77870636695957247485070729371505785036022507830356763789646790529980989972767478012625350608049848760401081873614";
            |] )))

let test_bilinearity () =
  let a =
    f1
      ( "3155009934535908241854382503496913376741892294245863405401597462641760243133882235624423397847127767716934062555793",
        "2234019121465620231805578079882835966262487276444547332538208418002132978001247983358670643174241518454728236294862"
      )
  in
  let b =
    f2
      ( [|
          "2647899611276867777535497861408512411465691530078703925817898320530901433230690986081010166625858940444369794593258";
          "2888256862829316108006975470566918581509317636890719189755447540552883010802407709863131290915043648752253159925232";
        |],
        [|
          "2192519177806038492881176172205451311854538798364777947095907984617867826862323453026127520221274922616271304335259";
          "3004620411053362146054721503134832661166005188461559731409518090929136380431931464671889917597096234887634360879239";
        |] )
  in
  let t = Pairing.e a b in
  let tt = Gt.dot t t in
  Alcotest.(check (pair gt gt))
    "equals" (tt, tt)
    (Pairing.e G1.(add a a) b, Pairing.e a G2.(add b b))

let test_inverse () =
  let a =
    f1
      ( "91452683776864857297317878636149143411849300822645600833640900844653175011086096281183060418629991226462334719230",
        "2771533846423619448760061452592233431921571821664938471039058787579168163258312047422278741446979265860731259685588"
      )
  in
  let b =
    f1
      ( "1370766558783140535152500693223113089394078759152774320389619861811343135317811753270627096528148539713374385472074",
        "1158300532618179468953717893171547786621985273328026665132493211269013369890783422334256435364557531790375173858380"
      )
  in
  let ta = Pairing.e a G2.g in
  let tb = Pairing.e b G2.g in
  Alcotest.(check gt)
    "equals"
    Gt.(dot ta (inverse tb))
    (Pairing.e (G1.sub a b) G2.g)

let tests =
  Alcotest.
    [
      test_case "Generator" `Quick test_generator;
      test_case "Pairing" `Quick test_pairing;
      test_case "Bilinearity" `Quick test_bilinearity;
      test_case "Inverse" `Quick test_inverse;
    ]