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
|
module E12 = Plonkers.Curves.E12
let e12 = Testable.make E12.to_string E12.equal
let f x y = E12.Unsafe.of_coords_unchecked E12.F.(of_string x, of_string y)
let test_strconv () =
let a =
f
"(0,0,0,0,3091671843177195696877148918276666486988770529143376300427304497723309492066409434415541799043648972299038428357487,0,0,0,0,0,3815085543371984344309954270809206701981910198711326563248651510366005113177104447633168433375165299595858892446448,0)"
"(0,0,0,3216482895116454205593926684868111924113047860439420435341632962637183676219338960167585843036993749097939480933003,0,0,0,0,0,2109732944141953385179814554641632616877235126971969222393178311770562775710586207386814389023669882647548613327750,0,0)"
in
let s =
"{(0,0,0,0,3091671843177195696877148918276666486988770529143376300427304497723309492066409434415541799043648972299038428357487,0,0,0,0,0,3815085543371984344309954270809206701981910198711326563248651510366005113177104447633168433375165299595858892446448,0);(0,0,0,3216482895116454205593926684868111924113047860439420435341632962637183676219338960167585843036993749097939480933003,0,0,0,0,0,2109732944141953385179814554641632616877235126971969222393178311770562775710586207386814389023669882647548613327750,0,0)}"
in
Alcotest.(check string) "equals" s (E12.to_string a);
Alcotest.(check e12) "equals" a (E12.of_string s)
let test_curve () =
Alcotest.(check bool)
"fails" true
(try
E12.of_string "{(0,0,0,0,0,0,0,0,0,0,0,0);(0,0,0,0,0,0,0,0,0,0,0,0)}"
|> ignore;
false
with
| Plonkers.Curve.Not_on_curve -> true
| _ -> false)
let test_subgroup () =
Alcotest.(check bool)
"fails" true
(try
E12.of_string
"{(0,0,0,0,1892439472479153589801064982851113576513855369383752766070453260535595479925033899105674578530308757833348467758334,0,0,0,0,0,3933473072416727749376352748178029259523619754763125185527750551907955966209860004099303009334745298312250252056103,0);(0,0,0,794551614141569136399571058573462200719130525886688829309738555530265772199592670562441013794848828639618754399483,0,0,0,0,0,3192958957310966052428309415378437932193540333890835514256315804018770631464911425978565124930935819694042257078857,0,0)}"
|> ignore;
false
with
| Plonkers.Curve.Not_in_canonical_subgroup -> true
| _ -> false)
let test_add () =
Alcotest.(check e12)
"equals"
(f
"(0,0,0,0,2929451176954387799194033409256344834898378201802754981173591542622666580295883587745860521250662884121876062549983,0,0,0,0,0,3461759878132083262758004943698898296800121697473199295622886337999821087592477923031706633208800009194815413801518,0)"
"(0,0,0,942624260271445495579165381526574569202111666876112362964832930049127003568811892520272165788145686052177002469346,0,0,0,0,0,3359602987414003489897229475537961953001886362351876752895373868269680338526524405951089727852832481417055207619739,0,0)")
(E12.add
(f
"(0,0,0,0,3577779649806248054643775548832767759316348940252471854726074628830920332172047644506373975311425491914524969724781,0,0,0,0,0,2399602958687966675444499051795357243399654745487511551062570132634625817263531954834246389717858349513538423979839,0)"
"(0,0,0,3469592015573153874932067971174117536042353913949658146829883594661681707207832993352017346593533677053567177917365,0,0,0,0,0,1151400766283648126691959067795471138907053142308666569304665656476264270870733893928854872692788980876149632731266,0,0)")
(f
"(0,0,0,0,3359139998119707196528515154517032529878638458125880871059769187012893082790375046547813363647182669061408112484760,0,0,0,0,0,62497013792237496829604596520223735291518619338562343287921465074342037807885618452846713288828357151810745569900,0)"
"(0,0,0,2160638480464909694045638391084460619982867776766949998529832158649043460368937062272954230999807453239744952753962,0,0,0,0,0,1126329043102416166228707569418335696072154646728752961333880357646274870334482490410779225488804211857673854639763,0,0)"))
let test_sub () =
Alcotest.(check e12)
"equals"
(f
"(0,0,0,0,260820864302800499055951456737734696520749024683574951158372641177953505726197462888820002139337144943486830755127,0,0,0,0,0,2309504807264682131023954645694244888958846929437569256970234438110912672798339047228059898746397460880680243113234,0)"
"(0,0,0,1884262644549124297286999423197037917702698957768720465436456735668246940838254360191765967749870609253415859480075,0,0,0,0,0,1458765347227296194079361565401588615835349340270921870155075823051943355511654368453233851359781030485555331973821,0,0)")
(E12.sub
(f
"(0,0,0,0,2548602455258519267027441838112041855729507725494336811234353266047952196432771974216852033238608280273800578504341,0,0,0,0,0,2506983850042387088709693983583400906243074258926729247169056174398175244377107659017228070877516224003507328999567,0)"
"(0,0,0,1697001650665816015571508376404481973733665579127989008532059292342460117240801454003662803080007480979986625768578,0,0,0,0,0,786940995340872797209857163071225469740844223100851966708730789135747927137475425247846950807186157855050793117595,0,0)")
(f
"(0,0,0,0,335585570380237738269479499019064005630181432684740610104387294850079646947794944339384592807744830934034358319148,0,0,0,0,0,3928039984576404929321729629401457719785598103596404127762810286191874666699102144281999415955166246019051362402625,0)"
"(0,0,0,2738843309836194684111788072521876850689450836525674623422145438705528038163470601918566915043088888961341964517564,0,0,0,0,0,1712943099674700879795417735364378450430564895281158485064468710245655725591367633459097560637616611829823884827868,0,0)"))
let test_scalar_mul () =
Alcotest.(check e12)
"equals"
(f
"(0,0,0,0,3357855297579876784089148534308911222130978631684443825955438012453799536767627749242490964002530400421373781469533,0,0,0,0,0,2677804744293618541446194559207414126615217723294705750716365310934351437624898175352847955786724875817376614717219,0)"
"(0,0,0,1915502024687773287090662296267210584286994097198288317665526658659200922203992392110288118787661761019927810880977,0,0,0,0,0,1760921192099020069214533105397817595823932059994647772858020372402134581938309465971031516925918886223193490944630,0,0)")
(E12.scalar_mul
(Z.of_string
"703594376515145504600149806566586228383250905518012106197988171833561726440")
(f
"(0,0,0,0,1749021454757251805466302363090849032461428103311018075473114210413137797790930850580625254459899665288368449856937,0,0,0,0,0,2186129250262469085814801856197751909890991632841241156466941822089525090504923468858070412713902752872342023901749,0)"
"(0,0,0,886919149452047606753370501423204305132698474831088324208349828000112295671876445794020761886983391377923459546785,0,0,0,0,0,2884680018184262851673782573133878840881948626212500716086567795728465064168792509223042657485292396482495135092395,0,0)"))
let test_neg () =
Alcotest.(check e12)
"equals"
(f
"(0,0,0,0,2510731992258037488917923072779386912130593748560772070925187720759618936807988199231840501866378139127146033382420,0,0,0,0,0,139994380365044868720503499540211498999674505225457299682186297734122616101065195677155394940127752473050846199674,0)"
"(0,0,0,2953323231939446131835641091801583289848813559944641025189986405134032624530476053107287527843032990989824459319311,0,0,0,0,0,3006319017089597825899390606645412383505581997773614203793702942169217973661078287028360663533881006950619741641054,0,0)")
(E12.neg
(f
"(0,0,0,0,2510731992258037488917923072779386912130593748560772070925187720759618936807988199231840501866378139127146033382420,0,0,0,0,0,139994380365044868720503499540211498999674505225457299682186297734122616101065195677155394940127752473050846199674,0)"
"(0,0,0,1049086323282221261582148733934320866708069259994366860142071730989999025960361811335400101285982673048069813240476,0,0,0,0,0,996090538132069567518399219090491773051300822165393681538355193954813676829759577414326965595134657087274530918733,0,0)"));
let a =
f
"(0,0,0,0,174596558160867992931929381678564420867047966812951865620128480620036445313093830658810814465792025017812429878751,0,0,0,0,0,3492629321158940080093431519188658666684469676506878174071465032762267492492939017933177917408814913264887997167785,0)"
"(0,0,0,2480687101688729026958456527114342859137384944778496301906088322119864429059527285116213514015556557832700420458645,0,0,0,0,0,1764449632710224012943205738233577179745318497967961642347638292997400684086372242247269616317573230446730496336696,0,0)"
in
Alcotest.(check e12) "equals" E12.inf (E12.add a (E12.neg a))
let test_g () =
Alcotest.(check e12)
"equals" E12.g
(f
"(0,0,0,0,352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160,0,0,0,0,0,1353221637328373545892060349371360746048220186341936159219732281025920769516621702780080981380240920942561918531299,0)"
"(0,0,0,1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905,0,0,0,0,0,1472406309213353956798468635167385199506877017588472562248853724925831900559844855499883907296819622485916638215732,0,0)")
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 "Subtraction" `Quick test_sub;
test_case "Scalar Multiplication" `Quick test_scalar_mul;
test_case "Additive Inverse" `Quick test_neg;
test_case "Generator" `Quick test_g;
]
|