diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2024-09-14 18:23:28 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2024-09-29 09:39:02 +0200 |
| commit | 2efcbfd67799537be7ebdb2d18495076b9ddcacc (patch) | |
| tree | 5c85f668ed08b9dac9d8c7c2eff4af6ea8e8d1c7 /test | |
| parent | 97a35bd8aefecc502de05a7d040b8d7bbda15216 (diff) | |
Implemented Elliptic Curve Operations
This includes operations for all 3 curves relevant to PLONK.
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_e.ml | 53 | ||||
| -rw-r--r-- | test/test_fp12.ml | 26 | ||||
| -rw-r--r-- | test/test_fp2.ml | 6 | ||||
| -rw-r--r-- | test/test_plonkers.ml | 5 |
4 files changed, 61 insertions, 29 deletions
diff --git a/test/test_e.ml b/test/test_e.ml new file mode 100644 index 0000000..4ed48f3 --- /dev/null +++ b/test/test_e.ml @@ -0,0 +1,53 @@ +module E = Plonkers.Curves.E + +let e = Testable.make E.to_string E.equal +let f x y = E.of_coords E.F.(of_string x, of_string y) + +let test_strconv () = + let a = + f + "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507" + "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569" + in + Alcotest.(check string) + "equals" + "{3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507;1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569}" + (E.to_string a); + Alcotest.(check e) + "equals" a + (E.of_string + "{3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507;1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569}") + +let test_curve () = + Alcotest.(check bool) + "fails" true + (try + E.of_string "{0;0}" |> ignore; + false + with + | Plonkers.Curves.Not_on_curve -> true + | _ -> 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) + in + fails + "{980669326159545649263804252026951545804569479867856393900195820932308021605342594512359315664807832835593476691977;2495572288805567003614829204459695097025160810248948605097890007546743160366866086918562910297675348438728151671429}"; + fails + "{1069666319329652829987469716448407827813054733044804636498977267777209654377372971020541102311296686223746457925861;2002055975540879804411492431965632823513627576867073743429207373519001811700965967624073843443645677059600261577048}" + +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_fp12.ml b/test/test_fp12.ml index 2918018..e88b96b 100644 --- a/test/test_fp12.ml +++ b/test/test_fp12.ml @@ -37,34 +37,12 @@ let test_strconv () = in Alcotest.(check string) "equals" - "(2916030131112425910736728833294966280877348127497066861802260324152389116184665963977658957216391196180579077474202, \ - 1519862437235303187188961557435602349317662069421862747209181232217613587604953767705018210876984976062405524645622, \ - 296645580800680675009621881920997395213790816778008448436221746142308017377314413585580661715141084537701545554168, \ - 1981557211956889095227901276564616817712990386953892187870249475222326830471202728108345999615285753394142232132312, \ - 833361220704354884434302513333442088322974161003072803264824357410372777926316698647896734024111451895881451892941, \ - 2711755601893075919832148493574676626069798533950866837790424822014009949251210477322950287178868808802513013310092, \ - 371213053563436252645940045458060653872935108881239949520789125958735351804960527435344045802826289621926519389359, \ - 504151947300534428538773393472324784669777301827817398729819216017440270289061739490404467920801765270857364809526, \ - 3563993255617322600585910657699631528415397776575273554957383151855598758349437838089591153976674032653746780002367, \ - 1396274584009387615887886835913193518070291009462177144922465656390031512961216497255957290669783178741610222179461, \ - 1791645971276582626341761994075837917473870474245353102664092427839586202945803660199735855654457386807016012521755, \ - 171029163675750402723404477137748189341455451129895111449568566066650114642345344282976819697533131681587059212847)" + "(2916030131112425910736728833294966280877348127497066861802260324152389116184665963977658957216391196180579077474202,1519862437235303187188961557435602349317662069421862747209181232217613587604953767705018210876984976062405524645622,296645580800680675009621881920997395213790816778008448436221746142308017377314413585580661715141084537701545554168,1981557211956889095227901276564616817712990386953892187870249475222326830471202728108345999615285753394142232132312,833361220704354884434302513333442088322974161003072803264824357410372777926316698647896734024111451895881451892941,2711755601893075919832148493574676626069798533950866837790424822014009949251210477322950287178868808802513013310092,371213053563436252645940045458060653872935108881239949520789125958735351804960527435344045802826289621926519389359,504151947300534428538773393472324784669777301827817398729819216017440270289061739490404467920801765270857364809526,3563993255617322600585910657699631528415397776575273554957383151855598758349437838089591153976674032653746780002367,1396274584009387615887886835913193518070291009462177144922465656390031512961216497255957290669783178741610222179461,1791645971276582626341761994075837917473870474245353102664092427839586202945803660199735855654457386807016012521755,171029163675750402723404477137748189341455451129895111449568566066650114642345344282976819697533131681587059212847)" (Fp12.to_string a); Alcotest.(check fp12) "equals" a (Fp12.of_string - "(2916030131112425910736728833294966280877348127497066861802260324152389116184665963977658957216391196180579077474202, \ - 1519862437235303187188961557435602349317662069421862747209181232217613587604953767705018210876984976062405524645622, \ - 296645580800680675009621881920997395213790816778008448436221746142308017377314413585580661715141084537701545554168, \ - 1981557211956889095227901276564616817712990386953892187870249475222326830471202728108345999615285753394142232132312, \ - 833361220704354884434302513333442088322974161003072803264824357410372777926316698647896734024111451895881451892941, \ - 2711755601893075919832148493574676626069798533950866837790424822014009949251210477322950287178868808802513013310092, \ - 371213053563436252645940045458060653872935108881239949520789125958735351804960527435344045802826289621926519389359, \ - 504151947300534428538773393472324784669777301827817398729819216017440270289061739490404467920801765270857364809526, \ - 3563993255617322600585910657699631528415397776575273554957383151855598758349437838089591153976674032653746780002367, \ - 1396274584009387615887886835913193518070291009462177144922465656390031512961216497255957290669783178741610222179461, \ - 1791645971276582626341761994075837917473870474245353102664092427839586202945803660199735855654457386807016012521755, \ - 171029163675750402723404477137748189341455451129895111449568566066650114642345344282976819697533131681587059212847)") + "(2916030131112425910736728833294966280877348127497066861802260324152389116184665963977658957216391196180579077474202,1519862437235303187188961557435602349317662069421862747209181232217613587604953767705018210876984976062405524645622,296645580800680675009621881920997395213790816778008448436221746142308017377314413585580661715141084537701545554168,1981557211956889095227901276564616817712990386953892187870249475222326830471202728108345999615285753394142232132312,833361220704354884434302513333442088322974161003072803264824357410372777926316698647896734024111451895881451892941,2711755601893075919832148493574676626069798533950866837790424822014009949251210477322950287178868808802513013310092,371213053563436252645940045458060653872935108881239949520789125958735351804960527435344045802826289621926519389359,504151947300534428538773393472324784669777301827817398729819216017440270289061739490404467920801765270857364809526,3563993255617322600585910657699631528415397776575273554957383151855598758349437838089591153976674032653746780002367,1396274584009387615887886835913193518070291009462177144922465656390031512961216497255957290669783178741610222179461,1791645971276582626341761994075837917473870474245353102664092427839586202945803660199735855654457386807016012521755,171029163675750402723404477137748189341455451129895111449568566066650114642345344282976819697533131681587059212847)") let test_add () = Alcotest.(check fp12) diff --git a/test/test_fp2.ml b/test/test_fp2.ml index e0bb5ba..c108cfc 100644 --- a/test/test_fp2.ml +++ b/test/test_fp2.ml @@ -12,14 +12,12 @@ let test_strconv () = in Alcotest.(check string) "equals" - "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707, \ - 3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)" + "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707,3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)" (Fp2.to_string a); Alcotest.(check fp2) "equals" a (Fp2.of_string - "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707, \ - 3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)") + "(3216159770949743003016282596382810410524821318260601360202344327568616081946682522800622973525694628320886337554707,3042776432360195460319296407183823967792916594876398306463713661277272294244991791711647871371679651495395139475044)") let test_add () = Alcotest.(check fp2) diff --git a/test/test_plonkers.ml b/test/test_plonkers.ml index 31859c4..9dc396a 100644 --- a/test/test_plonkers.ml +++ b/test/test_plonkers.ml @@ -1,5 +1,8 @@ let () = Alcotest.run "Plonkers" [ - ("Fp", Test_fp.tests); ("Fp2", Test_fp2.tests); ("Fp12", Test_fp12.tests); + ("Fp", Test_fp.tests); + ("Fp2", Test_fp2.tests); + ("Fp12", Test_fp12.tests); + ("E", Test_e.tests); ] |
