aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/test_e.ml92
-rw-r--r--test/test_e2.ml71
-rw-r--r--test/test_plonkers.ml1
3 files changed, 147 insertions, 17 deletions
diff --git a/test/test_e.ml b/test/test_e.ml
index 4ed48f3..0238544 100644
--- a/test/test_e.ml
+++ b/test/test_e.ml
@@ -6,17 +6,17 @@ let f x y = E.of_coords E.F.(of_string x, of_string y)
let test_strconv () =
let a =
f
- "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507"
- "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"
+ "2376759339040134764212872788353941124992112438470797710505260327947509392797392045352255582857163267674668587297510"
+ "2680611318541745317201589928800822277854035293387537860457713871028948345023926973028031532994931068370323829388300"
in
Alcotest.(check string)
"equals"
- "{3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507;1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569}"
+ "{2376759339040134764212872788353941124992112438470797710505260327947509392797392045352255582857163267674668587297510;2680611318541745317201589928800822277854035293387537860457713871028948345023926973028031532994931068370323829388300}"
(E.to_string a);
Alcotest.(check e)
"equals" a
(E.of_string
- "{3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507;1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569}")
+ "{2376759339040134764212872788353941124992112438470797710505260327947509392797392045352255582857163267674668587297510;2680611318541745317201589928800822277854035293387537860457713871028948345023926973028031532994931068370323829388300}")
let test_curve () =
Alcotest.(check bool)
@@ -29,20 +29,74 @@ let test_curve () =
| _ -> false)
let test_subgroup () =
- let fails s =
- Alcotest.(check bool)
- "fails" true
- (try
- E.of_string s |> ignore;
- false
- with
- | Plonkers.Curves.Not_in_canonical_subgroup -> true
- | _ -> false)
+ Alcotest.(check bool)
+ "fails" true
+ (try
+ E.of_string
+ "{1408129534356243367832052928099913992304651055488638954780633513706178736784848313850316003837543087214824267124696;3572102251607930234099216160523741049730449126093114409014947741659190641290410485354864536261071899055735703220899}"
+ |> ignore;
+ false
+ with
+ | Plonkers.Curves.Not_in_canonical_subgroup -> true
+ | _ -> false)
+
+let test_add () =
+ Alcotest.(check e)
+ "equals"
+ (f
+ "2732848421806933458055216662842663503751428072772029771533370760315348414319694592240768520876175341987716520797550"
+ "2954464846774599053097780011068897191733983980290260437633461565406800411699491071546253465288167362995079357027871")
+ (E.add
+ (f
+ "1840283922001395670795119289697588143466119761033432968923752536154183507956399910760936094073043042902070150237666"
+ "2435928528633846363548965937010170747763592518731703976253428871194016124789594596420862163693375094956371363693568")
+ (f
+ "571033441095339769561050329047836607559757996909911746970000233940080782217640964772866527140482257683410794602275"
+ "3751513699951780822806204149545068929347461752396128233032372349172282127292099402193824058844455410431018547944025"))
+
+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
- fails
- "{980669326159545649263804252026951545804569479867856393900195820932308021605342594512359315664807832835593476691977;2495572288805567003614829204459695097025160810248948605097890007546743160366866086918562910297675348438728151671429}";
- fails
- "{1069666319329652829987469716448407827813054733044804636498977267777209654377372971020541102311296686223746457925861;2002055975540879804411492431965632823513627576867073743429207373519001811700965967624073843443645677059600261577048}"
+ Alcotest.(check e) "equals" E.inf (E.add a (E.neg a))
let tests =
Alcotest.
@@ -50,4 +104,8 @@ let tests =
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;
]
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;
+ ]
diff --git a/test/test_plonkers.ml b/test/test_plonkers.ml
index 9dc396a..17aaf19 100644
--- a/test/test_plonkers.ml
+++ b/test/test_plonkers.ml
@@ -5,4 +5,5 @@ let () =
("Fp2", Test_fp2.tests);
("Fp12", Test_fp12.tests);
("E", Test_e.tests);
+ ("E2", Test_e2.tests);
]