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 E = Plonkers.Curves.E
let e = Primitives.Testables.e
let f = Primitives.Literals.e
let test_strconv () =
let a =
f
( "704648225832996754434548433071026029921434261490324062624046528007387592893305783031149959865132570914021074338890",
"2790809590887885290880356803296049708176452905760090772131241016249472860044571856060358509135396867961864286840213"
)
in
let s =
"{704648225832996754434548433071026029921434261490324062624046528007387592893305783031149959865132570914021074338890;2790809590887885290880356803296049708176452905760090772131241016249472860044571856060358509135396867961864286840213}"
in
Alcotest.(check string) "equals" s (E.to_string a);
Alcotest.(check e) "equals" a (E.of_string s)
let test_curve () =
Alcotest.(check bool)
"fails" true
(try
E.of_string "{0;0}" |> ignore;
false
with
| Invalid_argument _ -> true
| _ -> false)
let test_subgroup () =
Alcotest.(check bool)
"fails" true
(try
E.of_string
"{1408129534356243367832052928099913992304651055488638954780633513706178736784848313850316003837543087214824267124696;3572102251607930234099216160523741049730449126093114409014947741659190641290410485354864536261071899055735703220899}"
|> ignore;
false
with
| Invalid_argument _ -> true
| _ -> false)
let test_add () =
Alcotest.(check e)
"equals"
(f
( "2732848421806933458055216662842663503751428072772029771533370760315348414319694592240768520876175341987716520797550",
"2954464846774599053097780011068897191733983980290260437633461565406800411699491071546253465288167362995079357027871"
))
(E.add
(f
( "1840283922001395670795119289697588143466119761033432968923752536154183507956399910760936094073043042902070150237666",
"2435928528633846363548965937010170747763592518731703976253428871194016124789594596420862163693375094956371363693568"
))
(f
( "571033441095339769561050329047836607559757996909911746970000233940080782217640964772866527140482257683410794602275",
"3751513699951780822806204149545068929347461752396128233032372349172282127292099402193824058844455410431018547944025"
)))
let test_double () =
let a =
f
( "1948821978587447897789631658127568747564453341960450352257323012875526005675549792824154216114310204101716468014510",
"3805369745912496441131578309581807518996252052482176821838803458068084239405605134308394924115132794385888965780503"
)
in
Alcotest.(check e) "equals" (E.add a a) (E.double a)
let test_sub () =
Alcotest.(check e)
"equals"
(f
( "1065664903311802711883855953960241132042312919064412218977797750859438116499136425070701529990848206724729373134394",
"3828224933887415137804089846896095902450405724640402095510481781504713634254836891357622934547480985549264035957202"
))
(E.sub
(f
( "569713281464432123940419792794667906886387781217235827058538230598383416735537971774329038789662229041505709016151",
"507866778674612040501945809996411600066982283825728984146845807722822788180266344145139553998843014766672161118189"
))
(f
( "320516338292453551949272557105773528190260160795255351762548348902870907892802238932012154400256119846725752875631",
"332356225023154996422766027677238490574502325265257760464083075027175592739213840800887632705272849868365518606138"
)))
let test_scalar_mul () =
Alcotest.(check e)
"equals"
(f
( "2147268162765015109201667050261280318609818220619179616739419731542037190650706037211530298532745597400678392647871",
"1822569631528531419070603952760167309674278828504570075585130903766336929975557974083136509531508332985028088493375"
))
(E.scalar_mul
(Z.of_string
"34076944663681539617575489333515490120154419691065167429080578803276402241842")
(f
( "3872438102744901432868151057829019352425910481545269510591218290059835422749132295706099147073522490538524825314162",
"244022099586493667172296645843335057731326087432941293350787873695950734077660496958795394807248616844411556537170"
)))
let test_neg () =
Alcotest.(check e)
"equals"
(f
( "2105851117015157825448768787589743408062880571161114852134896430722466721293912161596062995325833210500961066149764",
"1835613369986611690971022618026582756933883838586482973006162582193858829397447622159678449565672339451620438958993"
))
(E.neg
(f
( "2105851117015157825448768787589743408062880571161114852134896430722466721293912161596062995325833210500961066149764",
"2166796185235055702446767207709321399622998981352524912325895553930172821093390242283009179563343324586273833600794"
)));
let a =
f
( "1941684181438987475678618661128509185580141750065988950539114961538558200585083736783163136882151604727855756516325",
"1662255517347795641618887042798002285595962168500080871445759274019356536297975481332071671342481234773972808352293"
)
in
Alcotest.(check e) "equals" E.inf (E.add a (E.neg a))
let tests =
Alcotest.
[
test_case "String Conversion" `Quick test_strconv;
test_case "Is On Curve" `Quick test_curve;
test_case "Is In Canonical Subgroup" `Quick test_subgroup;
test_case "Addition" `Quick test_add;
test_case "Double" `Quick test_double;
test_case "Subtraction" `Quick test_sub;
test_case "Scalar Multiplication" `Quick test_scalar_mul;
test_case "Additive Inverse" `Quick test_neg;
]
|