aboutsummaryrefslogtreecommitdiff
path: root/test/test_pairing.ml
blob: 82e4ab38a0da535dbe2c9f019eebcea4bda0e983 (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
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 =
    Z.of_string
      "49635613352584733781027070618160862805950329685486063826980172894235303933946"
  in
  let b =
    Z.of_string
      "4249060523776624689160540763312478010481990280247166863389957742757316747171"
  in
  Alcotest.(check bool)
    "equals" true
    (Pairing.check
       [
         (G1.(scalar_mul a g), G2.(scalar_mul b g));
         (G1.(neg @@ scalar_mul b g), G2.(scalar_mul a g));
       ])

let test_inverse () =
  let a =
    f1
      ( "91452683776864857297317878636149143411849300822645600833640900844653175011086096281183060418629991226462334719230",
        "2771533846423619448760061452592233431921571821664938471039058787579168163258312047422278741446979265860731259685588"
      )
  in
  let t = Pairing.e a G2.g in
  let tinv = Pairing.e G1.(neg a) G2.g in
  Alcotest.(check gt) "equals" (Gt.inv t) tinv;
  Alcotest.(check gt) "equals" Gt.id (Gt.dot t tinv)

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