aboutsummaryrefslogtreecommitdiff
path: root/test/test_e2.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_e2.ml')
-rw-r--r--test/test_e2.ml71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/test_e2.ml b/test/test_e2.ml
new file mode 100644
index 0000000..3d32e2e
--- /dev/null
+++ b/test/test_e2.ml
@@ -0,0 +1,71 @@
+module E2 = Plonkers.Curves.E2
+
+let e = Testable.make E2.to_string E2.equal
+let f x y = E2.of_coords E2.F.(of_string x, of_string y)
+
+let test_strconv () =
+ let a = f "(3923956693534187645032295788275476556797005515401770698112017479322355330641673615130042139434743269864444600110358,3756061633580935129993713607807160763781916371393378245686685529371403362444782981986040174265375059065676026913571)" "(218832824795677895374510600285671262542496010031251688921012107594797186788029893705858653131702371905931715865189,3031692580053002544887243919412706690059252512665311278727474095626933035689247794033137231742422077733611734919005)" in
+ Alcotest.(check string)
+ "equals"
+ "{(3923956693534187645032295788275476556797005515401770698112017479322355330641673615130042139434743269864444600110358,3756061633580935129993713607807160763781916371393378245686685529371403362444782981986040174265375059065676026913571);(218832824795677895374510600285671262542496010031251688921012107594797186788029893705858653131702371905931715865189,3031692580053002544887243919412706690059252512665311278727474095626933035689247794033137231742422077733611734919005)}"
+ (E2.to_string a);
+ Alcotest.(check e)
+ "equals" a
+ (E2.of_string "{(3923956693534187645032295788275476556797005515401770698112017479322355330641673615130042139434743269864444600110358,3756061633580935129993713607807160763781916371393378245686685529371403362444782981986040174265375059065676026913571);(218832824795677895374510600285671262542496010031251688921012107594797186788029893705858653131702371905931715865189,3031692580053002544887243919412706690059252512665311278727474095626933035689247794033137231742422077733611734919005)}")
+let test_curve () =
+ Alcotest.(check bool)
+ "fails" true
+ (try
+ E2.of_string "{(0,0);(0,0)}" |> ignore;
+ false
+ with
+ | Plonkers.Curves.Not_on_curve -> true
+ | _ -> false)
+let test_subgroup () =
+ Alcotest.(check bool)
+ "fails" true
+ (try
+ E2.of_string "{(1892439472479153589801064982851113576513855369383752766070453260535595479925033899105674578530308757833348467758334,1754566506869274301718190827735363782447329239031987366461838092103444111363078178418905338941768026382060426750966);(794551614141569136399571058573462200719130525886688829309738555530265772199592670562441013794848828639618754399483,3178059973541833847838400063594433908549328373729351972490312027443775384638577658076883634527704803989808995997410)}" |> ignore;
+ false
+ with
+ | Plonkers.Curves.Not_in_canonical_subgroup -> true
+ | _ -> false)
+let test_add () =
+ Alcotest.(check e2)
+ "equals"
+ (f "(2781343196420519423632422433587022540727162848306722364576877777060569884337547027596131977437417838859630676701276,1562467798215687776242522022358259549420197197101293070974570291387202520220768782383682920655951887531502364910943)" "(3457841611713041343433378215845200350595339514173366640511044400430736079303588026590492575458181436146388806048227,7228685485454948383961090818997050729503296774515502493264656775599897514746848883912818267380288160758952637281)")
+ (E2.add
+ (f "(599086761411406415954402349202245343302961031710865047455679311068681525149248601596200133628584188948522354931706,3511452255954981131282546809158670518933017501665934770275055677464908859882909088952822745951471523295910594620902)" "(1858532949424024310983629891100206243481849330010648636074347012778532917202183541352107441782262852186868167906111,725462570126405273129434809948141447008736630543695800107361780351341875465831434362474077467747725130225103267715)")
+ (f "(986494921070683276373543285472007888620184198150171094905637237552953519277411505118726407466333007412685045565931,2016401256337455957339336505249631820209884653501871827809766163209347917563971639588398616420005472314360364831469)" "(3297017169562975982847858172017863660737484791751375684556582394877628290551172601568539124399307623499009873598715,3431600145727956472898569788713031962824194739791483457998849536322695338531728554192550359623310559846707423449600)"))
+let test_sub () =
+ Alcotest.(check e2)
+ "equals"
+ (f "(1107616141833631890648220034802985012266585522465503062630624461469787068817507662710486135292720797212734918198603,2475301156396341518860712215478236964158637090539965287548370374197365724799357580121235669362940434636566182494987)" "(870790757455156722761569961180122448867292520888798362106398811030352353495900008983755243236944998134351895598415,3397233965917193203508893996752163354491083837521365739261804011181926354684486210978984258146460301225646145999715)")
+ (E2.sub
+ (f "(3270310664207088013254320850731367986355912543633525689785953976375884082419887229176064436799656868307602730661122,2635383553308960798103821213099798739134889006717670307440032270217455570436208767533188105071643978079872249820753)" "(2500912375665846368322740960797430066858985989087673976899719672987173330102143464287179769799965720377994734709570,2144057285800108792412733050101667056571828997793081230558422324103798194453682994763365415691475509985762303855717)")
+ (f "(1002981184304042612904273749964727487113808230133976959870733118775016088585411325500383128284551807500598508585644,598424802931660017567261609928489437916087628133865008176623363617479728506523154891647018514707820974678495782908)" "(2779356086241559529056963756527484755728688125754147609395562536891566602273974746860594639939216922892175330447034,3034817612905701460940481106756293661790214078415811023668574321046776481025701166890033025634359455996376523478767)"))
+let test_scalar_mul () =
+ Alcotest.(check e2)
+ "equals"
+ (f "(3810130678824403915647893326329407688276314060503782614041947303461689009432356906821404199448178849347940313756085,2220495839665515827548078136227893391699436344542032984335607669783765851101052216092924101081718980461722245873556)" "(1324329677491030278489696226427690673221937855962470233412076025336658621394897786383060111592866096007331531129621,3512664666449059568403903861280589932910233223607036913190860947335458748854213831919418684756565331416555243042063)")
+ (E2.scalar_mul
+ (f "(3523957907858391262907088016377865078521764246069022944438198465831924410822656113341965583598931999664598946541493,748349505869728007229892226148681803063559050483969510584997534258252794397186898676963942671456991144909405512254)" "(61385783622782903467689592421665098262656188504623244266983011351886936254296884079210942788445047788491270481484,3463618385364777232681821644033997541936274771912546823871472375117920764428834810172532177083933038531369619276039)")
+ (Z.of_string "3815964398135289600381093205750983240026391694776236280842690252393462186522"))
+let test_neg () =
+ Alcotest.(check e2)
+ "equals"
+ (f "(2832125252114490079090653551459419524550307378594993307426217469035124656817814921206351452333476502825851582942923,2774490150344266921534652087680983095842469113614636003252657826642251958285432375564301828410555769234605178724106)" "(3907853156448358489448342566233259975620515054034191917571458781588245723702401939835730459276085380301654647561464,621222305739086507417127305122520269663755897943923075633864566129632606833658144665628603712138110532834908367647)")
+ (E2.neg (f "(2832125252114490079090653551459419524550307378594993307426217469035124656817814921206351452333476502825851582942923,2774490150344266921534652087680983095842469113614636003252657826642251958285432375564301828410555769234605178724106)" "(94556398773308903969447259502644180936367765904815967760599354535785926788435924606957169852930283736239624998323,3381187249482580886000662520613383886893126921995084809698193569994399043657179719777059025416877553505059364192140)"));
+ let a = f "(3830461410083936889354928320639781774706170548021823825963924131487021843625227208879673806496421446697530627344289,797122006267364646383517126124142012780153690255487734905658092239678791458112328220739855822765190574893521825364)" "(3662537629577369606153265166748780089980738909813423444965726649520816736216443130712496521548460748658055145504590,2709007645146089274914263692534911298242702699525491524191698098321889897252066448584301600091985544894580898484468)" in
+ Alcotest.(check e2)
+ "equals"
+ E2.inf
+ (E2.add a (E2.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;
+ ]