aboutsummaryrefslogtreecommitdiff
path: root/test/test_pairing.ml
blob: e4d3fb46e6dd0b612a05be2682227c47739790a0 (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
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" Gt.g Pairing.(e G1.g G2.g)

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 (inv 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;
    ]