From 1ca2f988038e3d05ce667fd3af5abb417b2c37b3 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Tue, 9 Apr 2024 10:03:19 +0200 Subject: [PATCH 1/5] add all the Arkworks curves as dependencies compute the list of all the curve crates from `arkwork-rs/algebra` ```nushell const ARK_REMOTE = "https://raw.githubusercontent.com/arkworks-rs/algebra/master/curves" let pkgs = http get ([$ARK_REMOTE, "Cargo.toml"] | str join '/') | get workspace.members | where $it != "curve-constraint-tests" | sort | wrap path | insert name {|it| print $it.path http get ([$ARK_REMOTE, $it.path, "Cargo.toml"] | str join '/') | get package.name } ``` add all the curves as dev dependencies ```nushell $pkgs | each { cargo add $in.name --dev } ``` --- Cargo.toml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index bf76cdf2..ec49a3c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,32 @@ tracing = "0.1.40" tracing-subscriber = "0.3.17" [dev-dependencies] +ark-bls12-377 = "0.4.0" +ark-bls12-381 = "0.4.0" +ark-bn254 = "0.4.0" +ark-bw6-761 = "0.4.0" +ark-cp6-782 = "0.4.0" +ark-curve25519 = "0.4.0" +ark-ed-on-bls12-377 = "0.4.0" +ark-ed-on-bls12-381 = "0.4.0" +ark-ed-on-bls12-381-bandersnatch = "0.4.0" +ark-ed-on-bn254 = "0.4.0" +ark-ed-on-bw6-761 = "0.4.0" +ark-ed-on-cp6-782 = "0.4.0" +ark-ed-on-mnt4-298 = "0.4.0" +ark-ed-on-mnt4-753 = "0.4.0" +ark-ed25519 = "0.4.0" +ark-mnt4-298 = "0.4.0" +ark-mnt4-753 = "0.4.0" +ark-mnt6-298 = "0.4.0" +ark-mnt6-753 = "0.4.0" +ark-pallas = "0.4.0" ark-poly-commit = "0.4.0" +ark-secp256k1 = "0.4.0" +ark-secp256r1 = "0.4.0" +ark-secp384r1 = "0.4.0" +ark-secq256k1 = "0.4.0" +ark-vesta = "0.4.0" criterion = "0.3" [[bench]] -- GitLab From e6d90f66177764eb285a2c4c3ad288725ab54630 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Tue, 9 Apr 2024 10:20:57 +0200 Subject: [PATCH 2/5] add an example to show all the curves to generate the list of all curves to put in the macro ```nushell open Cargo.toml | get dev-dependencies | transpose k v | where k =~ "ark-" and k !~ "ark-poly" | get k | str replace --all '-' '_' | str join ",\n" ``` --- examples/curves.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 examples/curves.rs diff --git a/examples/curves.rs b/examples/curves.rs new file mode 100644 index 00000000..2e13df10 --- /dev/null +++ b/examples/curves.rs @@ -0,0 +1,46 @@ +use ark_ff::PrimeField; + +fn show_curve<Fr: PrimeField, Fq: PrimeField>(name: &str) { + println!( + "{}: {} -> {}", + name, + Fq::MODULUS_BIT_SIZE, + Fr::MODULUS_BIT_SIZE + ); +} + +macro_rules! show_curve { + ($($c:ident),+ $(,)?) => { + $(show_curve::<$c::Fr, $c::Fq>(stringify!($c));)* + } +} + +fn main() { + show_curve!( + ark_bls12_377, + ark_bls12_381, + ark_bn254, + ark_bw6_761, + ark_cp6_782, + ark_curve25519, + ark_ed_on_bls12_377, + ark_ed_on_bls12_381, + ark_ed_on_bls12_381_bandersnatch, + ark_ed_on_bn254, + ark_ed_on_bw6_761, + ark_ed_on_cp6_782, + ark_ed_on_mnt4_298, + ark_ed_on_mnt4_753, + ark_ed25519, + ark_mnt4_298, + ark_mnt4_753, + ark_mnt6_298, + ark_mnt6_753, + ark_pallas, + ark_secp256k1, + ark_secp256r1, + ark_secp384r1, + ark_secq256k1, + ark_vesta, + ); +} -- GitLab From 6d69baaa7f2e3eb3b04fb9ca70132cb768d79ab3 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Tue, 9 Apr 2024 10:25:11 +0200 Subject: [PATCH 3/5] add documentation on the macro --- examples/curves.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/examples/curves.rs b/examples/curves.rs index 2e13df10..037976ed 100644 --- a/examples/curves.rs +++ b/examples/curves.rs @@ -9,6 +9,34 @@ fn show_curve<Fr: PrimeField, Fq: PrimeField>(name: &str) { ); } +/// takes a sequence of curve crate names and calls the [`show_curve`] function +/// for you +/// +/// this macro accepts a trailling comma in case you have a big list that spans +/// over multiple lines, e.g. +/// +/// ## examples +/// ```rust +/// show_curve(ark_bls12_381) +/// ``` +/// or +/// ```rust +/// show_curve( +/// ark_bls12_381, +/// ark_bn254, +/// ark_pallas, +/// ark_vesta +/// ) +/// ``` +/// or +/// ```rust +/// show_curve( +/// ark_bls12_381, +/// ark_bn254, +/// ark_pallas, +/// ark_vesta, +/// ) +/// ``` macro_rules! show_curve { ($($c:ident),+ $(,)?) => { $(show_curve::<$c::Fr, $c::Fq>(stringify!($c));)* -- GitLab From 93abca47c0a11fe49aa33bae273b6106e1d90378 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Tue, 9 Apr 2024 10:35:53 +0200 Subject: [PATCH 4/5] add documentation to the whole example --- examples/curves.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/examples/curves.rs b/examples/curves.rs index 037976ed..d972fa48 100644 --- a/examples/curves.rs +++ b/examples/curves.rs @@ -1,3 +1,41 @@ +//! example usage of this example code +//! ```shell +//! cargo run --example curves +//! | lines +//! | parse "{curve}: {fq} -> {fr}" +//! | into int fq fr +//! | insert x { (1 - $in.fr / $in.fq) * 100 | math round --precision 1 } +//! ``` +//! +//! which gives the followin table +//! +//! | curve | fq | fr | x | +//! | -------------------------------- | --- | --- | ---- | +//! | ark_bls12_377 | 377 | 253 | 32.9 | +//! | ark_bls12_381 | 381 | 255 | 33.1 | +//! | ark_bn254 | 254 | 254 | 0 | +//! | ark_bw6_761 | 761 | 377 | 50.5 | +//! | ark_cp6_782 | 782 | 377 | 51.8 | +//! | ark_curve25519 | 255 | 253 | 0.8 | +//! | ark_ed_on_bls12_377 | 253 | 251 | 0.8 | +//! | ark_ed_on_bls12_381 | 255 | 252 | 1.2 | +//! | ark_ed_on_bls12_381_bandersnatch | 255 | 253 | 0.8 | +//! | ark_ed_on_bn254 | 254 | 251 | 1.2 | +//! | ark_ed_on_bw6_761 | 377 | 374 | 0.8 | +//! | ark_ed_on_cp6_782 | 377 | 374 | 0.8 | +//! | ark_ed_on_mnt4_298 | 298 | 296 | 0.7 | +//! | ark_ed_on_mnt4_753 | 753 | 750 | 0.4 | +//! | ark_ed25519 | 255 | 253 | 0.8 | +//! | ark_mnt4_298 | 298 | 298 | 0 | +//! | ark_mnt4_753 | 753 | 753 | 0 | +//! | ark_mnt6_298 | 298 | 298 | 0 | +//! | ark_mnt6_753 | 753 | 753 | 0 | +//! | ark_pallas | 255 | 255 | 0 | +//! | ark_secp256k1 | 256 | 256 | 0 | +//! | ark_secp256r1 | 256 | 256 | 0 | +//! | ark_secp384r1 | 384 | 384 | 0 | +//! | ark_secq256k1 | 256 | 256 | 0 | +//! | ark_vesta | 255 | 255 | 0 | use ark_ff::PrimeField; fn show_curve<Fr: PrimeField, Fq: PrimeField>(name: &str) { -- GitLab From 446df57d1e36449c02558dfedd7f73e85b99fd75 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Tue, 9 Apr 2024 11:13:20 +0200 Subject: [PATCH 5/5] add a comment next to the deps --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index ec49a3c7..b79c5b88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ tracing = "0.1.40" tracing-subscriber = "0.3.17" [dev-dependencies] +# all the curve dependencies below are used by the `curves` example ark-bls12-377 = "0.4.0" ark-bls12-381 = "0.4.0" ark-bn254 = "0.4.0" -- GitLab