aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bls12_381.ml123
-rw-r--r--lib/curves.ml146
-rw-r--r--lib/curves.mli13
-rw-r--r--lib/fields.ml32
-rw-r--r--lib/fields.mli10
-rw-r--r--lib/pairing.ml121
-rw-r--r--lib/pairing.mli48
-rw-r--r--lib/plonkers.ml6
-rw-r--r--test/primitives.ml12
-rw-r--r--test/test_curves.ml85
-rw-r--r--test/test_e.ml2
-rw-r--r--test/test_e12.ml455
-rw-r--r--test/test_e2.ml2
-rw-r--r--test/test_fp.ml2
-rw-r--r--test/test_fp12.ml4
-rw-r--r--test/test_fp2.ml4
-rw-r--r--test/test_pairing.ml41
-rw-r--r--test/test_plonkers.ml2
18 files changed, 237 insertions, 871 deletions
diff --git a/lib/bls12_381.ml b/lib/bls12_381.ml
new file mode 100644
index 0000000..d9399f2
--- /dev/null
+++ b/lib/bls12_381.ml
@@ -0,0 +1,123 @@
+module Fields = struct
+ module Fp = Field.Make (struct
+ let p =
+ Z.of_string
+ "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787"
+ end)
+
+ module Fp2 = Field.MakeExtension (struct
+ module F = Fp
+
+ let q = Fp.[| one; zero |]
+ end)
+
+ module Fp12 = Field.MakeExtension (struct
+ module F = Fp
+
+ let q =
+ Fp.
+ [|
+ of_string "2";
+ zero;
+ zero;
+ zero;
+ zero;
+ zero;
+ of_string "-2";
+ zero;
+ zero;
+ zero;
+ zero;
+ zero;
+ |]
+ end)
+end
+
+module Curves = struct
+ open Fields
+
+ let n =
+ Z.of_string
+ "52435875175126190479447740508185965837690552500527637822603658699938581184513"
+
+ module E = Curve.Make (struct
+ module F = Fp
+
+ let b = Fp.of_string "4"
+
+ let g =
+ Fp.
+ ( of_string
+ "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507",
+ of_string
+ "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"
+ )
+
+ let n = n
+ end)
+
+ module E2 = Curve.Make (struct
+ module F = Fp2
+
+ let of_string_coeffs s = Fp2.of_coeffs @@ Array.map Fp.of_string s
+ let b = of_string_coeffs [| "4"; "4" |]
+
+ let g =
+ ( of_string_coeffs
+ [|
+ "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160";
+ "3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758";
+ |],
+ of_string_coeffs
+ [|
+ "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905";
+ "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582";
+ |] )
+
+ let n = n
+ end)
+end
+
+module Pairing = Pairing.Make (struct
+ open Fields
+ open Curves
+ module G1 = E
+ module G2 = E2
+ module F = Fp12
+
+ let x = Z.of_string "-0xd201000000010000"
+
+ let g1_extend p =
+ E.to_coords p |> Option.map (fun (x, y) -> (Fp12.of_f x, Fp12.of_f y))
+
+ let g2_twist =
+ let o, z = Fp.(one, zero) in
+ let ws =
+ lazy
+ (let w = Fp12.of_coeffs [| z; o; z; z; z; z; z; z; z; z; z; z |] in
+ let w2 = Fp12.(w * w) in
+ let w3 = Fp12.(w2 * w) in
+ let w2inv = Fp12.inv w2 in
+ let w3inv = Fp12.inv w3 in
+ (w2inv, w3inv))
+ in
+ let iso a =
+ let c = Fp2.to_coeffs a in
+ let r0 = Fp.(c.(0) - c.(1)) in
+ let r6 = c.(1) in
+ Fp12.of_coeffs [| r0; z; z; z; z; z; r6; z; z; z; z; z |]
+ in
+ fun p ->
+ match E2.to_coords p with
+ | None -> None
+ | Some (x, y) ->
+ let nx, ny = (iso x, iso y) in
+ let w2inv, w3inv = Lazy.force ws in
+ Some Fp12.(nx * w2inv, ny * w3inv)
+end)
+
+module G1 = Curves.E
+module G2 = Curves.E2
+module Gt = Pairing.Gt
+
+let pairing = Pairing.check
diff --git a/lib/curves.ml b/lib/curves.ml
deleted file mode 100644
index 1182352..0000000
--- a/lib/curves.ml
+++ /dev/null
@@ -1,146 +0,0 @@
-module E = Curve.Make (struct
- module F = Fields.Fp
-
- let b = F.of_string "4"
-
- let g =
- F.
- ( of_string
- "3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507",
- of_string
- "1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"
- )
-
- let n =
- Z.of_string
- "52435875175126190479447740508185965837690552500527637822603658699938581184513"
-end)
-
-module E2 = Curve.Make (struct
- module F = Fields.Fp2
-
- let b = F.of_string "(4,4)"
-
- let g =
- F.
- ( of_coeffs
- Fields.Fp.
- [|
- of_string
- "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160";
- of_string
- "3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758";
- |],
- of_coeffs
- Fields.Fp.
- [|
- of_string
- "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905";
- of_string
- "927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582";
- |] )
-
- let n = E.n
-end)
-
-module E12 = Curve.Make (struct
- module F = Fields.Fp12
-
- let b = F.of_f @@ Fields.Fp.of_string "4"
-
- let g =
- F.
- ( of_coeffs
- Fields.Fp.
- [|
- zero;
- zero;
- zero;
- zero;
- of_string
- "352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160";
- zero;
- zero;
- zero;
- zero;
- zero;
- of_string
- "1353221637328373545892060349371360746048220186341936159219732281025920769516621702780080981380240920942561918531299";
- zero;
- |],
- of_coeffs
- Fields.Fp.
- [|
- zero;
- zero;
- zero;
- of_string
- "1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905";
- zero;
- zero;
- zero;
- zero;
- zero;
- of_string
- "1472406309213353956798468635167385199506877017588472562248853724925831900559844855499883907296819622485916638215732";
- zero;
- zero;
- |] )
-
- let n = E.n
-end)
-
-let twist =
- let ws =
- lazy
- (let w =
- Fields.Fp12.of_coeffs
- Fields.Fp.
- [|
- zero;
- one;
- zero;
- zero;
- zero;
- zero;
- zero;
- zero;
- zero;
- zero;
- zero;
- zero;
- |]
- in
- let w2 = Fields.Fp12.(w * w) in
- let w3 = Fields.Fp12.(w2 * w) in
- let w2inv = Fields.Fp12.inv w2 in
- let w3inv = Fields.Fp12.inv w3 in
- (w2inv, w3inv))
- in
- let iso a =
- let c = Fields.Fp2.to_coeffs a in
- Fields.Fp12.of_coeffs
- Fields.Fp.
- [|
- Fields.Fp.(c.(0) - c.(1));
- zero;
- zero;
- zero;
- zero;
- zero;
- c.(1);
- zero;
- zero;
- zero;
- zero;
- zero;
- |]
- in
- fun p ->
- match E2.to_coords p with
- | None -> E12.inf
- | Some (x, y) ->
- let nx, ny = (iso x, iso y) in
- let w2inv, w3inv = Lazy.force ws in
- let c = Fields.Fp12.(nx * w2inv, ny * w3inv) in
- E12.Unsafe.of_coords_unchecked c
diff --git a/lib/curves.mli b/lib/curves.mli
deleted file mode 100644
index 35f2bd4..0000000
--- a/lib/curves.mli
+++ /dev/null
@@ -1,13 +0,0 @@
-(** BLS12-381 curves used for pairings *)
-
-module E : Curve.S with type f = Fields.Fp.t
-(** The BLS12-381 curve over [Fields.Fp]. *)
-
-module E2 : Curve.S with type f = Fields.Fp2.t
-(** The BLS12-381 curve over [Fields.Fp2]. *)
-
-module E12 : Curve.S with type f = Fields.Fp12.t
-(** The BLS12-381 curve over [Fields.Fp12]. *)
-
-val twist : E2.t -> E12.t
-(** [twist a] is the twisted point of [E2] in [E12] *)
diff --git a/lib/fields.ml b/lib/fields.ml
deleted file mode 100644
index 8bb4c5e..0000000
--- a/lib/fields.ml
+++ /dev/null
@@ -1,32 +0,0 @@
-module Fp = Field.Make (struct
- let p =
- Z.of_string
- "4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787"
-end)
-
-module Fp2 = Field.MakeExtension (struct
- module F = Fp
-
- let q = Fp.[| one; zero |]
-end)
-
-module Fp12 = Field.MakeExtension (struct
- module F = Fp
-
- let q =
- Fp.
- [|
- of_string "2";
- zero;
- zero;
- zero;
- zero;
- zero;
- of_string "-2";
- zero;
- zero;
- zero;
- zero;
- zero;
- |]
-end)
diff --git a/lib/fields.mli b/lib/fields.mli
deleted file mode 100644
index a3d9adc..0000000
--- a/lib/fields.mli
+++ /dev/null
@@ -1,10 +0,0 @@
-(** Finite fields used by the BLS12-381 curve and pairings *)
-
-module Fp : Field.S
-(** The prime field over which the BLS12-381 curve is defined. *)
-
-module Fp2 : Field.SX with type f = Fp.t
-(** The polynomial field extension of degree 2 for BLS12-381 pairings. *)
-
-module Fp12 : Field.SX with type f = Fp.t
-(** The polynomial field extension of degree 12 for BLS12-381 pairings. *)
diff --git a/lib/pairing.ml b/lib/pairing.ml
index ef67901..33c09c6 100644
--- a/lib/pairing.ml
+++ b/lib/pairing.ml
@@ -1,23 +1,86 @@
+(** Boneh-Lynn-Shacham (BLS) pairing curves implementation. *)
+
+(** Module signature BLS pairing curves. *)
+module type S = sig
+ type g1
+ (** The elliptic curve element of the first pairing group. *)
+
+ type g2
+ (** The elliptic curve element of the second pairing group. *)
+
+ (** The target group of the pairing, usually denoted as [GT]. *)
+ module Gt : sig
+ type t
+ (** An element in the pairing target group. *)
+
+ type f
+ (** The underlying field type of the pairing target group. *)
+
+ val id : t
+ (** The group's identity element. *)
+
+ val dot : t -> t -> t
+ (** [dot a b] is the group operation applied to [a] and [b]. *)
+
+ val inv : t -> t
+ (** [inv a] is the inverse of [a]. Note that the invariant
+ [equal id (dot a (inv a))] always holds. *)
+
+ val equal : t -> t -> bool
+ (** [equal a b] is true if [a] has the same value as [b] *)
+
+ val to_f : t -> f
+ (** [to_fp12 a] is the underlying field value of the group element [a]. *)
+
+ val to_string : t -> string
+ (** [to_string a] is the string representation of [a]. *)
+
+ (** Unsafe pairing group construction functions. *)
+ module Unsafe : sig
+ val of_f_unchecked : f -> t
+ (** [of_fp12_unchecked a] is a pairing element of value [a]. This function
+ does not check whether the value actually belongs to the pairing group
+ [Gt]. *)
+
+ val of_string_unchecked : string -> t
+ (** [of_string_unchecked s] returns the pairing element represented by
+ [s]. This function does not check whether the value belongs to the
+ group [Gt]. *)
+ end
+ end
+
+ val e : g1 -> g2 -> Gt.t
+ (** [e p q] is the elliptic curve pairing of [p] and [q]. *)
+
+ val check : (g1 * g2) list -> bool
+ (** [check pairs] checks whether the product of the pairings is equal to
+ [Gt.id]. *)
+end
+
+(** BLS pairing curves construction. *)
module Make (BLS : sig
module G1 : Curve.S
module G2 : Curve.S
module F : Field.SX
val x : Z.t
- val g : F.t
- val g1_to_coords : G1.t -> (F.t * F.t) option
- val g2_to_coords : G2.t -> (F.t * F.t) option
-end) =
+ val g1_extend : G1.t -> (F.t * F.t) option
+ val g2_twist : G2.t -> (F.t * F.t) option
+end) :
+ S with type g1 = BLS.G1.t and type g2 = BLS.G2.t and type Gt.f = BLS.F.t =
struct
module G1 = BLS.G1
module G2 = BLS.G2
module F = BLS.F
+ type g1 = G1.t
+ type g2 = G2.t
+
module Gt = struct
type t = F.t
+ type f = F.t
let id = F.one
- let g = BLS.g
let dot = F.mul
let inv = F.inv
let to_f a = a
@@ -47,17 +110,17 @@ struct
| Some x -> x
| None -> invalid_arg "line with point at infinity"
in
- let g1_to_coords p = BLS.g1_to_coords p |> unwrap in
- let g2_to_coords p = BLS.g2_to_coords p |> unwrap in
+ let g1_extend p = BLS.g1_extend p |> unwrap in
+ let g2_twist p = BLS.g2_twist p |> unwrap in
fun p q r ->
- let xp, yp = g2_to_coords p in
- let xr, yr = g1_to_coords r in
+ let xp, yp = g2_twist p in
+ let xr, yr = g1_extend r in
if G2.equal p q then
let m = F.(three * xp * xp / (two * yp)) in
F.((m * (xr - xp)) - (yr - yp))
else if G2.(equal p (neg q)) then F.(xr - xp)
else
- let xq, yq = g2_to_coords q in
+ let xq, yq = g2_twist q in
let m = F.((yq - yp) / (xq - xp)) in
F.((m * (xr - xp)) - (yr - yp))
@@ -88,41 +151,3 @@ struct
let e p q = pairing [ (p, q) ]
let check pairs = pairing pairs |> Gt.(equal id)
end
-
-module P = Make (struct
- module G1 = Curves.E
- module G2 = Curves.E2
- module F = Fields.Fp12
-
- let x = Z.of_string "-0xd201000000010000"
-
- let g =
- F.of_coeffs
- @@ Array.map Fields.Fp.of_string
- [|
- "3408834164464458755751340723502736743445402614640994055433339214424916442641449510670327077303074893591740399366532";
- "1017299873256115394687936133146817339783508925356207904663165117501336940438300180831508525168135575931758510829235";
- "1919447955347661378578718469488414822573562393353397544098339472673901193098010131520945815709482515519580400649694";
- "233557331756520805040932826416017142246700002714928636467514104620558679338483625829873520553081791155104026612174";
- "2882199334237819327910933128503231887000342950792587449681715803095618652567681747054312179958427092970985872417068";
- "579878855790610229145575079003483905368886712027403088810647643659132674704592975818766405092658613973478871626949";
- "3268798540077874559188095304926415053902298079662269128631117894259354335713488241073281881110999874366368799440511";
- "2688711983546324406847903726099677850388169649284572370749691792743294691894680263880362424577638309433508620982332";
- "3520140447471844017044610248175793726488927385800919015247604269617056365166670232096113218155158979455637700602719";
- "1555267885602801620621747613743921378408444002839854792606782732724136830563310004098024452104661167182680744848589";
- "2626389147790168154036854297373352480470342009417426750876875476996308393122833154115295241935326582225976246741447";
- "873321072950766150592434764742436722571574260472569072177205897167854308426485977134306337249021436737462538398830";
- |]
-
- let g1_to_coords p =
- G1.to_coords p |> Option.map (fun (x, y) -> (F.of_f x, F.of_f y))
-
- let g2_to_coords p = Curves.E12.to_coords @@ Curves.twist p
-end)
-
-module G1 = P.G1
-module G2 = P.G2
-module Gt = P.Gt
-
-let e = P.e
-let check = P.check
diff --git a/lib/pairing.mli b/lib/pairing.mli
deleted file mode 100644
index 3d63df6..0000000
--- a/lib/pairing.mli
+++ /dev/null
@@ -1,48 +0,0 @@
-module G1 : Curve.S with type t = Curves.E.t and type f = Fields.Fp.t
-module G2 : Curve.S with type t = Curves.E2.t and type f = Fields.Fp2.t
-
-module Gt : sig
- type t
-
- val id : t
- (** The group's identity element. *)
-
- val g : t
- (** The group's generator. *)
-
- val dot : t -> t -> t
- (** [dot a b] is the group operation applied to [a] and [b]. *)
-
- val inv : t -> t
- (** [inv a] is the inverse of [a]. Note that the invariant
- [equal id (dot a (inv a))] always holds. *)
-
- val equal : t -> t -> bool
- (** [equal a b] is true if [a] has the same value as [b] *)
-
- val to_f : t -> Fields.Fp12.t
- (** [to_fp12 a] is the underlying field value of the group element [a]. *)
-
- val to_string : t -> string
- (** [to_string a] is the string representation of [a]. *)
-
- (** Unsafe pairing group construction functions. *)
- module Unsafe : sig
- val of_f_unchecked : Fields.Fp12.t -> t
- (** [of_fp12_unchecked a] is a pairing element of value [a]. This function
- does not check whether the value actually belongs to the pairing group
- [Gt]. *)
-
- val of_string_unchecked : string -> t
- (** [of_string_unchecked s] returns the pairing element represented by [s].
- This function does not check whether the value belongs to the group
- [Gt]. *)
- end
-end
-
-val e : G1.t -> G2.t -> Gt.t
-(** [e p q] is the elliptic curve pairing of [p] and [q]. *)
-
-val check : (G1.t * G2.t) list -> bool
-(** [check pairs] checks whether the product of the pairings is equal to
- [Gt.id]. *)
diff --git a/lib/plonkers.ml b/lib/plonkers.ml
index aa14f53..572a3cb 100644
--- a/lib/plonkers.ml
+++ b/lib/plonkers.ml
@@ -1,5 +1 @@
-module Field = Field
-module Fields = Fields
-module Curve = Curve
-module Curves = Curves
-module Pairing = Pairing
+module Bls12_381 = Bls12_381
diff --git a/test/primitives.ml b/test/primitives.ml
index 66d25b9..f2cd043 100644
--- a/test/primitives.ml
+++ b/test/primitives.ml
@@ -1,6 +1,6 @@
-open Plonkers.Curves
-open Plonkers.Fields
-open Plonkers.Pairing
+open Plonkers.Bls12_381.Fields
+open Plonkers.Bls12_381.Curves
+open Plonkers.Bls12_381.Pairing
module Literals = struct
let fp = Fp.of_string
@@ -8,9 +8,6 @@ module Literals = struct
let fp12 c = Fp12.of_coeffs @@ Array.map fp c
let e (x, y) = E.Unsafe.of_coords_unchecked (fp x, fp y)
let e2 (x, y) = E2.Unsafe.of_coords_unchecked (fp2 x, fp2 y)
- let e12 (x, y) = E12.Unsafe.of_coords_unchecked (fp12 x, fp12 y)
- let g1 = e
- let g2 = e2
let gt c = Gt.Unsafe.of_f_unchecked @@ fp12 c
end
@@ -20,8 +17,5 @@ module Testables = struct
let fp12 = Testable.make Fp12.to_string Fp12.equal
let e = Testable.make E.to_string E.equal
let e2 = Testable.make E2.to_string E2.equal
- let e12 = Testable.make E12.to_string E12.equal
- let g1 = e
- let g2 = e2
let gt = Testable.make Gt.to_string Gt.equal
end
diff --git a/test/test_curves.ml b/test/test_curves.ml
deleted file mode 100644
index 143211c..0000000
--- a/test/test_curves.ml
+++ /dev/null
@@ -1,85 +0,0 @@
-module E2 = Plonkers.Curves.E2
-module E12 = Plonkers.Curves.E12
-
-let twist = Plonkers.Curves.twist
-let f2 = Primitives.Literals.e2
-let e12 = Primitives.Testables.e12
-let f12 = Primitives.Literals.e12
-
-let test_twist () =
- Alcotest.(check e12)
- "equals"
- (f2
- ( [|
- "1540172915528940641891926116690100808044692623394504676677921357014659026860895709663805875815315907372328317299798";
- "3225331128895415615728432739064042093474368865193551026434624504244808875880021719074327461050513525930991560321555";
- |],
- [|
- "3821166946900648900183417606277705329456497739035474648486543021526386081458734393093714179436014613784026951537426";
- "3271903498375440374313099549367347360713300158269487781915162011178571021409894476750657145495514462848190134148570";
- |] )
- |> twist)
- (f12
- ( [|
- "0";
- "0";
- "0";
- "0";
- "1540172915528940641891926116690100808044692623394504676677921357014659026860895709663805875815315907372328317299798";
- "0";
- "0";
- "0";
- "0";
- "0";
- "2843783884294071183627148224054922720993279530869027117544380641677090749754981936926604607182106641298278757790772";
- "0";
- |],
- [|
- "0";
- "0";
- "0";
- "3821166946900648900183417606277705329456497739035474648486543021526386081458734393093714179436014613784026951537426";
- "0";
- "0";
- "0";
- "0";
- "0";
- "3727777830959063130482630797280725172185284029556014452046367630950124120466417906271159112158765588569975863865359";
- "0";
- "0";
- |] ))
-
-let test_isomorphism () =
- let a =
- f2
- ( [|
- "2109508776193857273074766488410969484271072993610345872414603016106553977333420070441822701292764210251579683428522";
- "3122689516821528327894678317146234429793657826538065999063801814299529533586972120357919860380161818422867843226102";
- |],
- [|
- "1096288604042692121608580288022426533189175239933724612935896261545208643656951679037482053510338623653634164811915";
- "1170946969994232162449075722035284212661104220582295241050315080132560517926924365377907307339371864116051233088516";
- |] )
- in
- let b =
- f2
- ( [|
- "1249927438163201574866859585937475005480631005557973853506467103895431793859087897855543227858106779532090068273481";
- "3316136808132952082246855662072348414235919944257935059559541300069920601748305368149334910959656758372765105616868";
- |],
- [|
- "81743811270164858346488114131996653093309264515814483449447422378937968491505855199671526555077281996286356618484";
- "1084133614285958528564866737145829519643307320120470464135106404047274008544004224502685177052190672561703116812406";
- |] )
- in
- Alcotest.(check e12)
- "equals"
- (E2.add a b |> twist)
- (E12.add (twist a) (twist b))
-
-let tests =
- Alcotest.
- [
- test_case "Twist" `Quick test_twist;
- test_case "Isomorphism" `Quick test_isomorphism;
- ]
diff --git a/test/test_e.ml b/test/test_e.ml
index e2b5fc8..d71763c 100644
--- a/test/test_e.ml
+++ b/test/test_e.ml
@@ -1,4 +1,4 @@
-module E = Plonkers.Curves.E
+module E = Plonkers.Bls12_381.Curves.E
let e = Primitives.Testables.e
let f = Primitives.Literals.e
diff --git a/test/test_e12.ml b/test/test_e12.ml
deleted file mode 100644
index 6be08a8..0000000
--- a/test/test_e12.ml
+++ /dev/null
@@ -1,455 +0,0 @@
-module E12 = Plonkers.Curves.E12
-
-let e12 = Primitives.Testables.e12
-let f = Primitives.Literals.e12
-
-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
- | Invalid_argument _ -> 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
- | Invalid_argument _ -> 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;
- ]
diff --git a/test/test_e2.ml b/test/test_e2.ml
index d4f951b..fe67d15 100644
--- a/test/test_e2.ml
+++ b/test/test_e2.ml
@@ -1,4 +1,4 @@
-module E2 = Plonkers.Curves.E2
+module E2 = Plonkers.Bls12_381.Curves.E2
let e2 = Primitives.Testables.e2
let f = Primitives.Literals.e2
diff --git a/test/test_fp.ml b/test/test_fp.ml
index f3d24e6..2398e81 100644
--- a/test/test_fp.ml
+++ b/test/test_fp.ml
@@ -1,4 +1,4 @@
-module Fp = Plonkers.Fields.Fp
+module Fp = Plonkers.Bls12_381.Fields.Fp
let fp = Primitives.Testables.fp
let f = Primitives.Literals.fp
diff --git a/test/test_fp12.ml b/test/test_fp12.ml
index 040bea8..8f02f96 100644
--- a/test/test_fp12.ml
+++ b/test/test_fp12.ml
@@ -1,5 +1,5 @@
-module Fp = Plonkers.Fields.Fp
-module Fp12 = Plonkers.Fields.Fp12
+module Fp = Plonkers.Bls12_381.Fields.Fp
+module Fp12 = Plonkers.Bls12_381.Fields.Fp12
let fp12 = Primitives.Testables.fp12
let f = Primitives.Literals.fp12
diff --git a/test/test_fp2.ml b/test/test_fp2.ml
index 5059d97..6c603f7 100644
--- a/test/test_fp2.ml
+++ b/test/test_fp2.ml
@@ -1,5 +1,5 @@
-module Fp = Plonkers.Fields.Fp
-module Fp2 = Plonkers.Fields.Fp2
+module Fp = Plonkers.Bls12_381.Fields.Fp
+module Fp2 = Plonkers.Bls12_381.Fields.Fp2
let fp2 = Primitives.Testables.fp2
let f = Primitives.Literals.fp2
diff --git a/test/test_pairing.ml b/test/test_pairing.ml
index 82e4ab3..d3cdb35 100644
--- a/test/test_pairing.ml
+++ b/test/test_pairing.ml
@@ -1,13 +1,32 @@
-module Pairing = Plonkers.Pairing
-module G1 = Plonkers.Pairing.G1
-module G2 = Plonkers.Pairing.G2
-module Gt = Plonkers.Pairing.Gt
+module Pairing = Plonkers.Bls12_381.Pairing
+module E = Plonkers.Bls12_381.Curves.E
+module E2 = Plonkers.Bls12_381.Curves.E2
+module Gt = Plonkers.Bls12_381.Pairing.Gt
let gt = Primitives.Testables.gt
-let f1 = Primitives.Literals.g1
-let f2 = Primitives.Literals.g2
+let f1 = Primitives.Literals.e
+let f2 = Primitives.Literals.e2
let ft = Primitives.Literals.gt
-let test_generator () = Alcotest.(check gt) "equals" Gt.g Pairing.(e G1.g G2.g)
+
+let test_generator () =
+ Alcotest.(check gt)
+ "equals"
+ (ft
+ [|
+ "3408834164464458755751340723502736743445402614640994055433339214424916442641449510670327077303074893591740399366532";
+ "1017299873256115394687936133146817339783508925356207904663165117501336940438300180831508525168135575931758510829235";
+ "1919447955347661378578718469488414822573562393353397544098339472673901193098010131520945815709482515519580400649694";
+ "233557331756520805040932826416017142246700002714928636467514104620558679338483625829873520553081791155104026612174";
+ "2882199334237819327910933128503231887000342950792587449681715803095618652567681747054312179958427092970985872417068";
+ "579878855790610229145575079003483905368886712027403088810647643659132674704592975818766405092658613973478871626949";
+ "3268798540077874559188095304926415053902298079662269128631117894259354335713488241073281881110999874366368799440511";
+ "2688711983546324406847903726099677850388169649284572370749691792743294691894680263880362424577638309433508620982332";
+ "3520140447471844017044610248175793726488927385800919015247604269617056365166670232096113218155158979455637700602719";
+ "1555267885602801620621747613743921378408444002839854792606782732724136830563310004098024452104661167182680744848589";
+ "2626389147790168154036854297373352480470342009417426750876875476996308393122833154115295241935326582225976246741447";
+ "873321072950766150592434764742436722571574260472569072177205897167854308426485977134306337249021436737462538398830";
+ |])
+ Pairing.(e E.g E2.g)
let test_pairing () =
Alcotest.(check gt)
@@ -55,8 +74,8 @@ let test_bilinearity () =
"equals" true
(Pairing.check
[
- (G1.(scalar_mul a g), G2.(scalar_mul b g));
- (G1.(neg @@ scalar_mul b g), G2.(scalar_mul a g));
+ (E.(scalar_mul a g), E2.(scalar_mul b g));
+ (E.(neg @@ scalar_mul b g), E2.(scalar_mul a g));
])
let test_inverse () =
@@ -66,8 +85,8 @@ let test_inverse () =
"2771533846423619448760061452592233431921571821664938471039058787579168163258312047422278741446979265860731259685588"
)
in
- let t = Pairing.e a G2.g in
- let tinv = Pairing.e G1.(neg a) G2.g in
+ let t = Pairing.e a E2.g in
+ let tinv = Pairing.e E.(neg a) E2.g in
Alcotest.(check gt) "equals" (Gt.inv t) tinv;
Alcotest.(check gt) "equals" Gt.id (Gt.dot t tinv)
diff --git a/test/test_plonkers.ml b/test/test_plonkers.ml
index 4e20fba..044e937 100644
--- a/test/test_plonkers.ml
+++ b/test/test_plonkers.ml
@@ -6,7 +6,5 @@ let () =
("Fp12", Test_fp12.tests);
("E", Test_e.tests);
("E2", Test_e2.tests);
- ("E12", Test_e12.tests);
- ("Curves", Test_curves.tests);
("Pairing", Test_pairing.tests);
]