From 805a2454a084ca85a3b9c124e943b2487b7bfdcf Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 10:42:49 +0200
Subject: [PATCH 01/21] reduce the number of loops and the warmup time

---
 benches/commit.rs   | 10 +++++++++-
 benches/linalg.rs   | 10 +++++++++-
 benches/recoding.rs | 10 +++++++++-
 benches/setup.rs    | 10 +++++++++-
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/benches/commit.rs b/benches/commit.rs
index d6a390c7..35218abe 100644
--- a/benches/commit.rs
+++ b/benches/commit.rs
@@ -1,3 +1,5 @@
+use std::time::Duration;
+
 use ark_bls12_381::{Bls12_381, Fr, G1Projective};
 use ark_ec::{pairing::Pairing, CurveGroup};
 use ark_ff::PrimeField;
@@ -74,5 +76,11 @@ fn ark_commit(c: &mut Criterion) {
     }
 }
 
-criterion_group!(benches, commit, ark_commit);
+criterion_group!(
+    name = benches;
+    config = Criterion::default()
+        .warm_up_time(Duration::from_secs_f32(0.5))
+        .sample_size(10);
+    targets = commit, ark_commit
+);
 criterion_main!(benches);
diff --git a/benches/linalg.rs b/benches/linalg.rs
index 408a90b0..dafffa78 100644
--- a/benches/linalg.rs
+++ b/benches/linalg.rs
@@ -1,3 +1,5 @@
+use std::time::Duration;
+
 use ark_bls12_381::Fr;
 use ark_ff::PrimeField;
 
@@ -54,5 +56,11 @@ fn mul(c: &mut Criterion) {
     }
 }
 
-criterion_group!(benches, inverse, transpose, mul);
+criterion_group!(
+    name = benches;
+    config = Criterion::default()
+        .warm_up_time(Duration::from_secs_f32(0.5))
+        .sample_size(10);
+    targets = inverse, transpose, mul
+);
 criterion_main!(benches);
diff --git a/benches/recoding.rs b/benches/recoding.rs
index db5fedfe..d5b986a4 100644
--- a/benches/recoding.rs
+++ b/benches/recoding.rs
@@ -1,3 +1,5 @@
+use std::time::Duration;
+
 use ark_bls12_381::Fr;
 use ark_ff::PrimeField;
 use ark_std::rand::Rng;
@@ -60,5 +62,11 @@ fn criterion_benchmark(c: &mut Criterion) {
     }
 }
 
-criterion_group!(benches, criterion_benchmark);
+criterion_group!(
+    name = benches;
+    config = Criterion::default()
+        .warm_up_time(Duration::from_secs_f32(0.5))
+        .sample_size(10);
+    targets = criterion_benchmark
+);
 criterion_main!(benches);
diff --git a/benches/setup.rs b/benches/setup.rs
index f8c3c771..675b5516 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -1,3 +1,5 @@
+use std::time::Duration;
+
 use ark_bls12_381::{Bls12_381, Fr, G1Projective};
 use ark_ec::{pairing::Pairing, CurveGroup};
 use ark_ff::PrimeField;
@@ -162,5 +164,11 @@ fn ark_setup(c: &mut Criterion) {
     }
 }
 
-criterion_group!(benches, setup, ark_setup);
+criterion_group!(
+    name = benches;
+    config = Criterion::default()
+        .warm_up_time(Duration::from_secs_f32(0.5))
+        .sample_size(10);
+    targets = setup, ark_setup
+);
 criterion_main!(benches);
-- 
GitLab


From f7ce05c39de88f15158c6ecd6848f178a87af924 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 11:26:06 +0200
Subject: [PATCH 02/21] don't serialize for real to save time

---
 examples/bench_setup_size.rs | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/examples/bench_setup_size.rs b/examples/bench_setup_size.rs
index ff1657f4..6873b44c 100644
--- a/examples/bench_setup_size.rs
+++ b/examples/bench_setup_size.rs
@@ -26,11 +26,6 @@ where
         (Compress::No, Validate::Yes),
         (Compress::No, Validate::No),
     ] {
-        let mut serialized = vec![0; setup.serialized_size(compress)];
-        setup
-            .serialize_with_mode(&mut serialized[..], compress)
-            .unwrap();
-
         println!(
             r#"{{"reason": "benchmark-complete", "id": "serialized size with {} and {} {} on {}", "mean": {}}}"#,
             match compress {
@@ -43,7 +38,7 @@ where
             },
             degree,
             std::any::type_name::<F>(),
-            serialized.len(),
+            setup.serialized_size(compress),
         );
     }
 }
-- 
GitLab


From 37a2a7e26321692c1cf12e3d140a2275604324c0 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 11:26:58 +0200
Subject: [PATCH 03/21] don't try to compress with validation

that's useless.

the commit also modifies the plot script accordingly.
---
 benches/plot.py              |  6 ++----
 examples/bench_setup_size.rs | 15 +++------------
 2 files changed, 5 insertions(+), 16 deletions(-)

diff --git a/benches/plot.py b/benches/plot.py
index 3e9dcdce..6272be95 100644
--- a/benches/plot.py
+++ b/benches/plot.py
@@ -142,10 +142,8 @@ def plot_setup(data: Data, save: bool = False):
     axs[2].legend()
     axs[2].grid()
 
-    plot(data, "serialized size with no compression and no validation", "uncompressed unvalidated", "red", False, axs[3])
-    plot(data, "serialized size with compression and no validation", "compressed unvalidated", "orange", False, axs[3])
-    plot(data, "serialized size with no compression and validation", "uncompressed validated", "blue", False, axs[3])
-    plot(data, "serialized size with compression and validation", "compressed validated", "green", False, axs[3])
+    plot(data, "serialized size with no compression", "uncompressed", "orange", False, axs[3])
+    plot(data, "serialized size with compression", "compressed", "blue", False, axs[3])
     axs[3].set_title("size")
     axs[3].set_xlabel("degree")
     axs[3].set_ylabel("size (in kb)")
diff --git a/examples/bench_setup_size.rs b/examples/bench_setup_size.rs
index 6873b44c..cc7781c2 100644
--- a/examples/bench_setup_size.rs
+++ b/examples/bench_setup_size.rs
@@ -2,7 +2,7 @@ use ark_bls12_381::{Fr, G1Projective};
 use ark_ec::CurveGroup;
 use ark_ff::PrimeField;
 use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
-use ark_serialize::{CanonicalSerialize, Compress, Validate};
+use ark_serialize::{CanonicalSerialize, Compress};
 use ark_std::ops::Div;
 
 use komodo::zk;
@@ -20,22 +20,13 @@ where
 
     let setup = zk::setup::<_, F, G>(degree, rng).unwrap();
 
-    for (compress, validate) in [
-        (Compress::Yes, Validate::Yes),
-        (Compress::Yes, Validate::No),
-        (Compress::No, Validate::Yes),
-        (Compress::No, Validate::No),
-    ] {
+    for compress in [Compress::Yes, Compress::No] {
         println!(
-            r#"{{"reason": "benchmark-complete", "id": "serialized size with {} and {} {} on {}", "mean": {}}}"#,
+            r#"{{"reason": "benchmark-complete", "id": "serialized size with {} {} on {}", "mean": {}}}"#,
             match compress {
                 Compress::Yes => "compression",
                 Compress::No => "no compression",
             },
-            match validate {
-                Validate::Yes => "validation",
-                Validate::No => "no validation",
-            },
             degree,
             std::any::type_name::<F>(),
             setup.serialized_size(compress),
-- 
GitLab


From 409f3e3c7c7fa8e3e1acc3aecd3520d2b5eabcca Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 13:01:38 +0200
Subject: [PATCH 04/21] don't multiply degree by 1_024

---
 benches/commit.rs            | 4 ++--
 benches/setup.rs             | 4 ++--
 examples/bench_setup_size.rs | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/benches/commit.rs b/benches/commit.rs
index 35218abe..de0c6e1d 100644
--- a/benches/commit.rs
+++ b/benches/commit.rs
@@ -63,7 +63,7 @@ where
 
 fn commit(c: &mut Criterion) {
     for n in [1, 2, 4, 8, 16] {
-        commit_template::<Fr, G1Projective, DensePolynomial<Fr>>(c, black_box(n * 1024));
+        commit_template::<Fr, G1Projective, DensePolynomial<Fr>>(c, black_box(n));
     }
 }
 
@@ -71,7 +71,7 @@ fn ark_commit(c: &mut Criterion) {
     for n in [1, 2, 4, 8, 16] {
         ark_commit_template::<Bls12_381, DensePolynomial<<Bls12_381 as Pairing>::ScalarField>>(
             c,
-            black_box(n * 1024),
+            black_box(n),
         );
     }
 }
diff --git a/benches/setup.rs b/benches/setup.rs
index 675b5516..935c05c8 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -151,7 +151,7 @@ where
 
 fn setup(c: &mut Criterion) {
     for n in [1, 2, 4, 8, 16] {
-        setup_template::<Fr, G1Projective, DensePolynomial<Fr>>(c, black_box(n * 1024));
+        setup_template::<Fr, G1Projective, DensePolynomial<Fr>>(c, black_box(n));
     }
 }
 
@@ -159,7 +159,7 @@ fn ark_setup(c: &mut Criterion) {
     for n in [1, 2, 4, 8, 16] {
         ark_setup_template::<Bls12_381, DensePolynomial<<Bls12_381 as Pairing>::ScalarField>>(
             c,
-            black_box(n * 1024),
+            black_box(n),
         );
     }
 }
diff --git a/examples/bench_setup_size.rs b/examples/bench_setup_size.rs
index cc7781c2..804181c8 100644
--- a/examples/bench_setup_size.rs
+++ b/examples/bench_setup_size.rs
@@ -36,6 +36,6 @@ where
 
 fn main() {
     for n in [1, 2, 4, 8, 16] {
-        setup_template::<Fr, G1Projective, DensePolynomial<Fr>>(n * 1024);
+        setup_template::<Fr, G1Projective, DensePolynomial<Fr>>(n);
     }
 }
-- 
GitLab


From 610024a9260c1d7b44a2c5bc4981152bc18ae5b6 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 13:11:24 +0200
Subject: [PATCH 05/21] fix setup

---
 benches/setup.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/benches/setup.rs b/benches/setup.rs
index 935c05c8..c266458c 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -32,7 +32,7 @@ where
         |b| b.iter(|| zk::setup::<_, F, G>(degree, rng).unwrap()),
     );
 
-    let setup = zk::setup::<_, F, G>(zk::nb_elements_in_setup::<F>(degree), rng).unwrap();
+    let setup = zk::setup::<_, F, G>(degree, rng).unwrap();
 
     group.bench_function(
         &format!(
-- 
GitLab


From 3d5e7c584cb20a48a9bea25af09e513f8a6b729b Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 13:36:22 +0200
Subject: [PATCH 06/21] fix setup

---
 benches/setup.rs | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/benches/setup.rs b/benches/setup.rs
index c266458c..42f3e166 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -1,6 +1,6 @@
 use std::time::Duration;
 
-use ark_bls12_381::{Bls12_381, Fr, G1Projective};
+use ark_bls12_381::Bls12_381;
 use ark_ec::{pairing::Pairing, CurveGroup};
 use ark_ff::PrimeField;
 use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
@@ -108,11 +108,7 @@ where
             ),
             |b| {
                 b.iter(|| {
-                    Powers::<Fr, G1Projective>::deserialize_with_mode(
-                        &serialized[..],
-                        compress,
-                        validate,
-                    )
+                    Powers::<F, G>::deserialize_with_mode(&serialized[..], compress, validate)
                 })
             },
         );
-- 
GitLab


From 3d3167fb6beabbf458c7ba8bb3dc08ae4156b475 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 13:53:37 +0200
Subject: [PATCH 07/21] run benchmarks on BLS12-381, BN-254 and PALLAS

---
 benches/commit.rs            | 22 ++++++++++++++--------
 benches/linalg.rs            | 15 ++++++++++-----
 benches/recoding.rs          |  5 +++--
 benches/setup.rs             | 19 +++++++++++++------
 examples/bench_setup_size.rs |  9 +++++++--
 5 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/benches/commit.rs b/benches/commit.rs
index de0c6e1d..c2d50a3e 100644
--- a/benches/commit.rs
+++ b/benches/commit.rs
@@ -1,12 +1,10 @@
 use std::time::Duration;
 
-use ark_bls12_381::{Bls12_381, Fr, G1Projective};
 use ark_ec::{pairing::Pairing, CurveGroup};
 use ark_ff::PrimeField;
 use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
-use ark_std::ops::Div;
-
 use ark_poly_commit::kzg10::{Powers, KZG10};
+use ark_std::ops::Div;
 
 use criterion::{black_box, criterion_group, criterion_main, Criterion};
 
@@ -62,17 +60,25 @@ where
 }
 
 fn commit(c: &mut Criterion) {
+    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(c: &mut Criterion, degree: usize) {
+        commit_template::<F, G, DensePolynomial<F>>(c, black_box(degree));
+    }
+
     for n in [1, 2, 4, 8, 16] {
-        commit_template::<Fr, G1Projective, DensePolynomial<Fr>>(c, black_box(n));
+        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n);
+        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n);
+        aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n);
     }
 }
 
 fn ark_commit(c: &mut Criterion) {
+    fn aux<E: Pairing>(c: &mut Criterion, degree: usize) {
+        ark_commit_template::<E, DensePolynomial<E::ScalarField>>(c, black_box(degree));
+    }
+
     for n in [1, 2, 4, 8, 16] {
-        ark_commit_template::<Bls12_381, DensePolynomial<<Bls12_381 as Pairing>::ScalarField>>(
-            c,
-            black_box(n),
-        );
+        aux::<ark_bls12_381::Bls12_381>(c, n);
+        aux::<ark_bn254::Bn254>(c, n);
     }
 }
 
diff --git a/benches/linalg.rs b/benches/linalg.rs
index dafffa78..632484e4 100644
--- a/benches/linalg.rs
+++ b/benches/linalg.rs
@@ -1,6 +1,5 @@
 use std::time::Duration;
 
-use ark_bls12_381::Fr;
 use ark_ff::PrimeField;
 
 use criterion::{black_box, criterion_group, criterion_main, Criterion};
@@ -19,7 +18,9 @@ fn inverse_template<F: PrimeField>(c: &mut Criterion, n: usize) {
 
 fn inverse(c: &mut Criterion) {
     for n in [10, 15, 20, 30, 40, 60, 80, 120, 160, 240, 320] {
-        inverse_template::<Fr>(c, black_box(n));
+        inverse_template::<ark_bls12_381::Fr>(c, black_box(n));
+        inverse_template::<ark_bn254::Fr>(c, black_box(n));
+        inverse_template::<ark_pallas::Fr>(c, black_box(n));
     }
 }
 
@@ -35,7 +36,9 @@ fn transpose_template<F: PrimeField>(c: &mut Criterion, n: usize) {
 
 fn transpose(c: &mut Criterion) {
     for n in [10, 15, 20, 30, 40, 60, 80, 120, 160, 240, 320] {
-        transpose_template::<Fr>(c, black_box(n));
+        transpose_template::<ark_bls12_381::Fr>(c, black_box(n));
+        transpose_template::<ark_bn254::Fr>(c, black_box(n));
+        transpose_template::<ark_pallas::Fr>(c, black_box(n));
     }
 }
 
@@ -51,8 +54,10 @@ fn mul_template<F: PrimeField>(c: &mut Criterion, n: usize) {
 }
 
 fn mul(c: &mut Criterion) {
-    for n in [10, 15, 20, 30, 40, 60, 80, 120, 160, 240, 320] {
-        mul_template::<Fr>(c, black_box(n));
+    for n in [10, 15, 20, 30, 40, 60, 80, 120] {
+        mul_template::<ark_bls12_381::Fr>(c, black_box(n));
+        mul_template::<ark_bn254::Fr>(c, black_box(n));
+        mul_template::<ark_pallas::Fr>(c, black_box(n));
     }
 }
 
diff --git a/benches/recoding.rs b/benches/recoding.rs
index d5b986a4..e9a19e93 100644
--- a/benches/recoding.rs
+++ b/benches/recoding.rs
@@ -1,6 +1,5 @@
 use std::time::Duration;
 
-use ark_bls12_381::Fr;
 use ark_ff::PrimeField;
 use ark_std::rand::Rng;
 
@@ -56,7 +55,9 @@ fn criterion_benchmark(c: &mut Criterion) {
     for nb_bytes in [1, 1_024, 1_024 * 1_024] {
         for nb_shards in [2, 4, 8, 16] {
             for k in [2, 4, 8, 16] {
-                bench_template::<Fr>(c, nb_bytes, k, nb_shards);
+                bench_template::<ark_bls12_381::Fr>(c, nb_bytes, k, nb_shards);
+                bench_template::<ark_bn254::Fr>(c, nb_bytes, k, nb_shards);
+                bench_template::<ark_pallas::Fr>(c, nb_bytes, k, nb_shards);
             }
         }
     }
diff --git a/benches/setup.rs b/benches/setup.rs
index 42f3e166..a4405d14 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -1,6 +1,5 @@
 use std::time::Duration;
 
-use ark_bls12_381::Bls12_381;
 use ark_ec::{pairing::Pairing, CurveGroup};
 use ark_ff::PrimeField;
 use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
@@ -146,17 +145,25 @@ where
 }
 
 fn setup(c: &mut Criterion) {
+    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(c: &mut Criterion, degree: usize) {
+        setup_template::<F, G, DensePolynomial<F>>(c, black_box(degree));
+    }
+
     for n in [1, 2, 4, 8, 16] {
-        setup_template::<Fr, G1Projective, DensePolynomial<Fr>>(c, black_box(n));
+        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n);
+        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n);
+        aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n);
     }
 }
 
 fn ark_setup(c: &mut Criterion) {
+    fn aux<E: Pairing>(c: &mut Criterion, degree: usize) {
+        ark_setup_template::<E, DensePolynomial<E::ScalarField>>(c, black_box(degree));
+    }
+
     for n in [1, 2, 4, 8, 16] {
-        ark_setup_template::<Bls12_381, DensePolynomial<<Bls12_381 as Pairing>::ScalarField>>(
-            c,
-            black_box(n),
-        );
+        aux::<ark_bls12_381::Bls12_381>(c, n);
+        aux::<ark_bn254::Bn254>(c, n);
     }
 }
 
diff --git a/examples/bench_setup_size.rs b/examples/bench_setup_size.rs
index 804181c8..c3673224 100644
--- a/examples/bench_setup_size.rs
+++ b/examples/bench_setup_size.rs
@@ -1,4 +1,3 @@
-use ark_bls12_381::{Fr, G1Projective};
 use ark_ec::CurveGroup;
 use ark_ff::PrimeField;
 use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
@@ -35,7 +34,13 @@ where
 }
 
 fn main() {
+    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(degree: usize) {
+        setup_template::<F, G, DensePolynomial<F>>(degree);
+    }
+
     for n in [1, 2, 4, 8, 16] {
-        setup_template::<Fr, G1Projective, DensePolynomial<Fr>>(n);
+        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(n);
+        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(n);
+        aux::<ark_pallas::Fr, ark_pallas::Projective>(n);
     }
 }
-- 
GitLab


From da2a71a1e96a74a7cc3194afcf8589ea72564e8d Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 14:06:34 +0200
Subject: [PATCH 08/21] pass name of the curve as parameter

---
 benches/commit.rs            | 48 +++++++++++++----------------
 benches/linalg.rs            | 45 +++++++++++++--------------
 benches/recoding.rs          | 19 +++++++-----
 benches/setup.rs             | 59 ++++++++++++++----------------------
 examples/bench_setup_size.rs | 14 ++++-----
 5 files changed, 83 insertions(+), 102 deletions(-)

diff --git a/benches/commit.rs b/benches/commit.rs
index c2d50a3e..178ede8a 100644
--- a/benches/commit.rs
+++ b/benches/commit.rs
@@ -10,7 +10,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
 
 use komodo::zk;
 
-fn commit_template<F, G, P>(c: &mut Criterion, degree: usize)
+fn commit_template<F, G, P>(c: &mut Criterion, degree: usize, curve: &str)
 where
     F: PrimeField,
     G: CurveGroup<ScalarField = F>,
@@ -22,17 +22,12 @@ where
     let setup = zk::setup::<_, F, G>(degree, rng).unwrap();
     let polynomial = P::rand(degree, rng);
 
-    c.bench_function(
-        &format!(
-            "commit (komodo) {} on {}",
-            degree,
-            std::any::type_name::<F>()
-        ),
-        |b| b.iter(|| zk::commit(&setup, &polynomial)),
-    );
+    c.bench_function(&format!("commit (komodo) {} on {}", degree, curve), |b| {
+        b.iter(|| zk::commit(&setup, &polynomial))
+    });
 }
 
-fn ark_commit_template<E, P>(c: &mut Criterion, degree: usize)
+fn ark_commit_template<E, P>(c: &mut Criterion, degree: usize, curve: &str)
 where
     E: Pairing,
     P: DenseUVPolynomial<E::ScalarField>,
@@ -49,36 +44,35 @@ where
     };
     let polynomial = P::rand(degree, rng);
 
-    c.bench_function(
-        &format!(
-            "commit (arkworks) {} on {}",
-            degree,
-            std::any::type_name::<E>()
-        ),
-        |b| b.iter(|| KZG10::commit(&powers, &polynomial, None, None)),
-    );
+    c.bench_function(&format!("commit (arkworks) {} on {}", degree, curve), |b| {
+        b.iter(|| KZG10::commit(&powers, &polynomial, None, None))
+    });
 }
 
 fn commit(c: &mut Criterion) {
-    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(c: &mut Criterion, degree: usize) {
-        commit_template::<F, G, DensePolynomial<F>>(c, black_box(degree));
+    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(
+        c: &mut Criterion,
+        degree: usize,
+        curve: &str,
+    ) {
+        commit_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve);
     }
 
     for n in [1, 2, 4, 8, 16] {
-        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n);
-        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n);
-        aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n);
+        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n, "BLS12-381");
+        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n, "BN-254");
+        aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n, "PALLAS");
     }
 }
 
 fn ark_commit(c: &mut Criterion) {
-    fn aux<E: Pairing>(c: &mut Criterion, degree: usize) {
-        ark_commit_template::<E, DensePolynomial<E::ScalarField>>(c, black_box(degree));
+    fn aux<E: Pairing>(c: &mut Criterion, degree: usize, curve: &str) {
+        ark_commit_template::<E, DensePolynomial<E::ScalarField>>(c, black_box(degree), curve);
     }
 
     for n in [1, 2, 4, 8, 16] {
-        aux::<ark_bls12_381::Bls12_381>(c, n);
-        aux::<ark_bn254::Bn254>(c, n);
+        aux::<ark_bls12_381::Bls12_381>(c, n, "BLS12-381");
+        aux::<ark_bn254::Bn254>(c, n, "BN-254");
     }
 }
 
diff --git a/benches/linalg.rs b/benches/linalg.rs
index 632484e4..be77730b 100644
--- a/benches/linalg.rs
+++ b/benches/linalg.rs
@@ -6,58 +6,55 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
 
 use komodo::linalg::Matrix;
 
-fn inverse_template<F: PrimeField>(c: &mut Criterion, n: usize) {
+fn inverse_template<F: PrimeField>(c: &mut Criterion, n: usize, curve: &str) {
     let mut rng = rand::thread_rng();
     let matrix = Matrix::<F>::random(n, n, &mut rng);
 
-    c.bench_function(
-        &format!("inverse {}x{} on {}", n, n, std::any::type_name::<F>()),
-        |b| b.iter(|| matrix.invert().unwrap()),
-    );
+    c.bench_function(&format!("inverse {}x{} on {}", n, n, curve), |b| {
+        b.iter(|| matrix.invert().unwrap())
+    });
 }
 
 fn inverse(c: &mut Criterion) {
     for n in [10, 15, 20, 30, 40, 60, 80, 120, 160, 240, 320] {
-        inverse_template::<ark_bls12_381::Fr>(c, black_box(n));
-        inverse_template::<ark_bn254::Fr>(c, black_box(n));
-        inverse_template::<ark_pallas::Fr>(c, black_box(n));
+        inverse_template::<ark_bls12_381::Fr>(c, black_box(n), "BLS12-381");
+        inverse_template::<ark_bn254::Fr>(c, black_box(n), "BN-254");
+        inverse_template::<ark_pallas::Fr>(c, black_box(n), "PALLAS");
     }
 }
 
-fn transpose_template<F: PrimeField>(c: &mut Criterion, n: usize) {
+fn transpose_template<F: PrimeField>(c: &mut Criterion, n: usize, curve: &str) {
     let mut rng = rand::thread_rng();
     let matrix = Matrix::<F>::random(n, n, &mut rng);
 
-    c.bench_function(
-        &format!("transpose {}x{} on {}", n, n, std::any::type_name::<F>()),
-        |b| b.iter(|| matrix.transpose()),
-    );
+    c.bench_function(&format!("transpose {}x{} on {}", n, n, curve), |b| {
+        b.iter(|| matrix.transpose())
+    });
 }
 
 fn transpose(c: &mut Criterion) {
     for n in [10, 15, 20, 30, 40, 60, 80, 120, 160, 240, 320] {
-        transpose_template::<ark_bls12_381::Fr>(c, black_box(n));
-        transpose_template::<ark_bn254::Fr>(c, black_box(n));
-        transpose_template::<ark_pallas::Fr>(c, black_box(n));
+        transpose_template::<ark_bls12_381::Fr>(c, black_box(n), "BLS-12-381");
+        transpose_template::<ark_bn254::Fr>(c, black_box(n), "BN-254");
+        transpose_template::<ark_pallas::Fr>(c, black_box(n), "PALLAS");
     }
 }
 
-fn mul_template<F: PrimeField>(c: &mut Criterion, n: usize) {
+fn mul_template<F: PrimeField>(c: &mut Criterion, n: usize, curve: &str) {
     let mut rng = rand::thread_rng();
     let mat_a = Matrix::<F>::random(n, n, &mut rng);
     let mat_b = Matrix::<F>::random(n, n, &mut rng);
 
-    c.bench_function(
-        &format!("mul {}x{} on {}", n, n, std::any::type_name::<F>()),
-        |b| b.iter(|| mat_a.mul(&mat_b)),
-    );
+    c.bench_function(&format!("mul {}x{} on {}", n, n, curve), |b| {
+        b.iter(|| mat_a.mul(&mat_b))
+    });
 }
 
 fn mul(c: &mut Criterion) {
     for n in [10, 15, 20, 30, 40, 60, 80, 120] {
-        mul_template::<ark_bls12_381::Fr>(c, black_box(n));
-        mul_template::<ark_bn254::Fr>(c, black_box(n));
-        mul_template::<ark_pallas::Fr>(c, black_box(n));
+        mul_template::<ark_bls12_381::Fr>(c, black_box(n), "BLS-12-381");
+        mul_template::<ark_bn254::Fr>(c, black_box(n), "BN-254");
+        mul_template::<ark_pallas::Fr>(c, black_box(n), "PALLAS");
     }
 }
 
diff --git a/benches/recoding.rs b/benches/recoding.rs
index e9a19e93..7eb3f569 100644
--- a/benches/recoding.rs
+++ b/benches/recoding.rs
@@ -29,7 +29,13 @@ fn create_fake_shard<F: PrimeField>(nb_bytes: usize, k: usize) -> Shard<F> {
     }
 }
 
-fn bench_template<F: PrimeField>(c: &mut Criterion, nb_bytes: usize, k: usize, nb_shards: usize) {
+fn bench_template<F: PrimeField>(
+    c: &mut Criterion,
+    nb_bytes: usize,
+    k: usize,
+    nb_shards: usize,
+    curve: &str,
+) {
     let shards: Vec<Shard<F>> = (0..nb_shards)
         .map(|_| create_fake_shard(nb_bytes, k))
         .collect();
@@ -42,10 +48,7 @@ fn bench_template<F: PrimeField>(c: &mut Criterion, nb_bytes: usize, k: usize, n
     c.bench_function(
         &format!(
             "recoding {} bytes and {} shards with k = {} on {}",
-            nb_bytes,
-            nb_shards,
-            k,
-            std::any::type_name::<F>()
+            nb_bytes, nb_shards, k, curve
         ),
         |b| b.iter(|| combine(&shards, &coeffs)),
     );
@@ -55,9 +58,9 @@ fn criterion_benchmark(c: &mut Criterion) {
     for nb_bytes in [1, 1_024, 1_024 * 1_024] {
         for nb_shards in [2, 4, 8, 16] {
             for k in [2, 4, 8, 16] {
-                bench_template::<ark_bls12_381::Fr>(c, nb_bytes, k, nb_shards);
-                bench_template::<ark_bn254::Fr>(c, nb_bytes, k, nb_shards);
-                bench_template::<ark_pallas::Fr>(c, nb_bytes, k, nb_shards);
+                bench_template::<ark_bls12_381::Fr>(c, nb_bytes, k, nb_shards, "BLS-12-381");
+                bench_template::<ark_bn254::Fr>(c, nb_bytes, k, nb_shards, "BN-254");
+                bench_template::<ark_pallas::Fr>(c, nb_bytes, k, nb_shards, "PALLAS");
             }
         }
     }
diff --git a/benches/setup.rs b/benches/setup.rs
index a4405d14..226d52de 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -11,7 +11,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
 
 use komodo::zk::{self, Powers};
 
-fn setup_template<F, G, P>(c: &mut Criterion, degree: usize)
+fn setup_template<F, G, P>(c: &mut Criterion, degree: usize, curve: &str)
 where
     F: PrimeField,
     G: CurveGroup<ScalarField = F>,
@@ -22,23 +22,14 @@ where
 
     let rng = &mut rand::thread_rng();
 
-    group.bench_function(
-        &format!(
-            "setup (komodo) {} on {}",
-            degree,
-            std::any::type_name::<F>()
-        ),
-        |b| b.iter(|| zk::setup::<_, F, G>(degree, rng).unwrap()),
-    );
+    group.bench_function(&format!("setup (komodo) {} on {}", degree, curve), |b| {
+        b.iter(|| zk::setup::<_, F, G>(degree, rng).unwrap())
+    });
 
     let setup = zk::setup::<_, F, G>(degree, rng).unwrap();
 
     group.bench_function(
-        &format!(
-            "serializing with compression {} on {}",
-            degree,
-            std::any::type_name::<F>()
-        ),
+        &format!("serializing with compression {} on {}", degree, curve),
         |b| {
             b.iter(|| {
                 let mut serialized = vec![0; setup.serialized_size(Compress::Yes)];
@@ -50,11 +41,7 @@ where
     );
 
     group.bench_function(
-        &format!(
-            "serializing with no compression {} on {}",
-            degree,
-            std::any::type_name::<F>()
-        ),
+        &format!("serializing with no compression {} on {}", degree, curve),
         |b| {
             b.iter(|| {
                 let mut serialized = vec![0; setup.serialized_size(Compress::No)];
@@ -87,7 +74,7 @@ where
                 Validate::Yes => "validation",
                 Validate::No => "no validation",
             },
-            std::any::type_name::<F>(),
+            curve,
             serialized.len(),
         );
 
@@ -103,7 +90,7 @@ where
                     Validate::No => "no validation",
                 },
                 degree,
-                std::any::type_name::<F>()
+                curve
             ),
             |b| {
                 b.iter(|| {
@@ -116,7 +103,7 @@ where
     group.finish();
 }
 
-fn ark_setup_template<E, P>(c: &mut Criterion, degree: usize)
+fn ark_setup_template<E, P>(c: &mut Criterion, degree: usize, curve: &str)
 where
     E: Pairing,
     P: DenseUVPolynomial<E::ScalarField>,
@@ -125,11 +112,7 @@ where
     let rng = &mut rand::thread_rng();
 
     c.bench_function(
-        &format!(
-            "setup (arkworks) {} bytes on {}",
-            degree,
-            std::any::type_name::<E>()
-        ),
+        &format!("setup (arkworks) {} bytes on {}", degree, curve),
         |b| {
             b.iter(|| {
                 let setup = KZG10::<E, P>::setup(degree, false, rng).unwrap();
@@ -145,25 +128,29 @@ where
 }
 
 fn setup(c: &mut Criterion) {
-    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(c: &mut Criterion, degree: usize) {
-        setup_template::<F, G, DensePolynomial<F>>(c, black_box(degree));
+    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(
+        c: &mut Criterion,
+        degree: usize,
+        curve: &str,
+    ) {
+        setup_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve);
     }
 
     for n in [1, 2, 4, 8, 16] {
-        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n);
-        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n);
-        aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n);
+        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n, "BLS-12-381");
+        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n, "BN-254");
+        aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n, "PALLAS");
     }
 }
 
 fn ark_setup(c: &mut Criterion) {
-    fn aux<E: Pairing>(c: &mut Criterion, degree: usize) {
-        ark_setup_template::<E, DensePolynomial<E::ScalarField>>(c, black_box(degree));
+    fn aux<E: Pairing>(c: &mut Criterion, degree: usize, curve: &str) {
+        ark_setup_template::<E, DensePolynomial<E::ScalarField>>(c, black_box(degree), curve);
     }
 
     for n in [1, 2, 4, 8, 16] {
-        aux::<ark_bls12_381::Bls12_381>(c, n);
-        aux::<ark_bn254::Bn254>(c, n);
+        aux::<ark_bls12_381::Bls12_381>(c, n, "BLS-12-381");
+        aux::<ark_bn254::Bn254>(c, n, "BN-254");
     }
 }
 
diff --git a/examples/bench_setup_size.rs b/examples/bench_setup_size.rs
index c3673224..34304c8e 100644
--- a/examples/bench_setup_size.rs
+++ b/examples/bench_setup_size.rs
@@ -6,7 +6,7 @@ use ark_std::ops::Div;
 
 use komodo::zk;
 
-fn setup_template<F, G, P>(degree: usize)
+fn setup_template<F, G, P>(degree: usize, curve: &str)
 where
     F: PrimeField,
     G: CurveGroup<ScalarField = F>,
@@ -27,20 +27,20 @@ where
                 Compress::No => "no compression",
             },
             degree,
-            std::any::type_name::<F>(),
+            curve,
             setup.serialized_size(compress),
         );
     }
 }
 
 fn main() {
-    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(degree: usize) {
-        setup_template::<F, G, DensePolynomial<F>>(degree);
+    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(degree: usize, curve: &str) {
+        setup_template::<F, G, DensePolynomial<F>>(degree, curve);
     }
 
     for n in [1, 2, 4, 8, 16] {
-        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(n);
-        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(n);
-        aux::<ark_pallas::Fr, ark_pallas::Projective>(n);
+        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(n, "BLS12-381");
+        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(n, "BN-254");
+        aux::<ark_pallas::Fr, ark_pallas::Projective>(n, "PALLAS");
     }
 }
-- 
GitLab


From 954fd6d30b756502c2ddbdd15d2857bd785fb31e Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 15:40:27 +0200
Subject: [PATCH 09/21] plot commit for all curves

---
 benches/plot.py | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/benches/plot.py b/benches/plot.py
index 6272be95..58acd8c8 100644
--- a/benches/plot.py
+++ b/benches/plot.py
@@ -162,8 +162,13 @@ def plot_commit(data: Data, save: bool = False):
     fig, ax = plt.subplots(1, 1, figsize=(16, 9))
 
     # key: the start of the `$.id` field
-    def plot(data: Data, key: str, color: str, ax):
-        filtered_data = list(filter(lambda line: line["id"].startswith(key), data))
+    def plot(data: Data, key: str, curve: str, style: str, color: str, ax):
+        filtered_data = list(filter(
+            lambda line: line["id"].startswith(key) and line["id"].endswith(f" on {curve}"),
+            data
+        ))
+        if len(filtered_data) == 0:
+            return
 
         sizes = [
             int(line["id"].lstrip(key).split(' ')[0]) for line in filtered_data
@@ -173,14 +178,12 @@ def plot_commit(data: Data, save: bool = False):
         up = ns_to_ms(extract(filtered_data, "mean", "upper_bound"))
         down = ns_to_ms(extract(filtered_data, "mean", "lower_bound"))
 
-        ax.plot(sizes, means, label=key, color=color)
-        ax.fill_between(sizes, down, up, color=color, alpha=0.3)
-
-    keys = ["commit (komodo)", "commit (arkworks)"]
-    colors = ["blue", "orange"]
+        ax.plot(sizes, means, label=f"{key} on {curve}", color=color, linestyle=style)
+        ax.fill_between(sizes, down, up, color=color, linestyle=style, alpha=0.3)
 
-    for (k, c) in zip(keys, colors):
-        plot(data, key=k, color=c, ax=ax)
+    for (curve, color) in [("BLS12-381", "blue"), ("BN-254", "orange"), ("PALLAS", "green")]:
+        plot(data, key="commit (komodo)", curve=curve, style="solid", color=color, ax=ax)
+        plot(data, key="commit (arkworks)", curve=curve, style="dashed", color=color, ax=ax)
 
     ax.set_title("commit times")
     ax.set_ylabel("time (in ms)")
-- 
GitLab


From f980b30fce9cf1b564a9d2b0a752f80b6bc32add Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 15:59:00 +0200
Subject: [PATCH 10/21] plot all curves in linalg

---
 benches/plot.py | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/benches/plot.py b/benches/plot.py
index 58acd8c8..348d9f00 100644
--- a/benches/plot.py
+++ b/benches/plot.py
@@ -55,8 +55,13 @@ def read_data(data_file: str) -> Data:
 
 def plot_linalg(data: Data, save: bool = False):
     # key: the start of the `$.id` field
-    def plot(data: Data, key: str, ax):
-        filtered_data = list(filter(lambda line: line["id"].startswith(key), data))
+    def plot(data: Data, key: str, curve: str, color: str, ax):
+        filtered_data = list(filter(
+            lambda line: line["id"].startswith(key) and line["id"].endswith(f" on {curve}"),
+            data
+        ))
+        if len(filtered_data) == 0:
+            return
 
         sizes = [
             int(line["id"].split(' ')[1].split('x')[0]) for line in filtered_data
@@ -66,22 +71,16 @@ def plot_linalg(data: Data, save: bool = False):
         up = ns_to_ms(extract(filtered_data, "mean", "upper_bound"))
         down = ns_to_ms(extract(filtered_data, "mean", "lower_bound"))
 
-        ax.plot(sizes, means, label="mean", color="blue")
-        ax.fill_between(sizes, down, up, color="blue", alpha=0.3)
-
-        medians = ns_to_ms(extract(filtered_data, "median", "estimate"))
-        up = ns_to_ms(extract(filtered_data, "median", "upper_bound"))
-        down = ns_to_ms(extract(filtered_data, "median", "lower_bound"))
-
-        ax.plot(sizes, medians, label="median", color="orange")
-        ax.fill_between(sizes, down, up, color="orange", alpha=0.3)
+        ax.plot(sizes, means, label=curve, color=color)
+        ax.fill_between(sizes, down, up, color=color, alpha=0.3)
 
     labels = ["transpose", "mul", "inverse"]
 
     fig, axs = plt.subplots(len(labels), 1, figsize=(16, 9))
 
     for label, ax in zip(labels, axs):
-        plot(data, key=label, ax=ax)
+        for (curve, color) in [("BLS12-381", "blue"), ("BN-254", "orange"), ("PALLAS", "green")]:
+            plot(data, key=label, curve=curve, color=color, ax=ax)
         ax.set_title(label)
         ax.set_yscale("log")
         ax.set_ylabel("time in ms")
-- 
GitLab


From 5e41df1dd1c3f89171ee3818a0476bd9781ce3e0 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 16:04:46 +0200
Subject: [PATCH 11/21] rename `labels` to `keys` in commit

---
 benches/plot.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/benches/plot.py b/benches/plot.py
index 348d9f00..6c160b8a 100644
--- a/benches/plot.py
+++ b/benches/plot.py
@@ -74,14 +74,14 @@ def plot_linalg(data: Data, save: bool = False):
         ax.plot(sizes, means, label=curve, color=color)
         ax.fill_between(sizes, down, up, color=color, alpha=0.3)
 
-    labels = ["transpose", "mul", "inverse"]
+    keys = ["transpose", "mul", "inverse"]
 
-    fig, axs = plt.subplots(len(labels), 1, figsize=(16, 9))
+    fig, axs = plt.subplots(len(keys), 1, figsize=(16, 9))
 
-    for label, ax in zip(labels, axs):
+    for key, ax in zip(keys, axs):
         for (curve, color) in [("BLS12-381", "blue"), ("BN-254", "orange"), ("PALLAS", "green")]:
-            plot(data, key=label, curve=curve, color=color, ax=ax)
-        ax.set_title(label)
+            plot(data, key=key, curve=curve, color=color, ax=ax)
+        ax.set_title(key)
         ax.set_yscale("log")
         ax.set_ylabel("time in ms")
         ax.legend()
-- 
GitLab


From 8bb64f99920b7b4d4e72bfcc2e5de54292480a97 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 16:06:16 +0200
Subject: [PATCH 12/21] filter setup by curves

---
 benches/plot.py | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/benches/plot.py b/benches/plot.py
index 6c160b8a..02d98ae5 100644
--- a/benches/plot.py
+++ b/benches/plot.py
@@ -99,8 +99,14 @@ def plot_setup(data: Data, save: bool = False):
     fig, axs = plt.subplots(4, 1, sharex=True, figsize=(16, 9))
 
     # key: the start of the `$.id` field
-    def plot(data: Data, key: str, label: str, color: str, error_bar: bool, ax):
-        filtered_data = list(filter(lambda line: line["id"].startswith(key), data))
+    def plot(data: Data, key: str, curve: str, label: str, color: str, error_bar: bool, ax):
+        filtered_data = list(filter(
+            lambda line: line["id"].startswith(key) and line["id"].endswith(f" on {curve}"),
+            data
+        ))
+        if len(filtered_data) == 0:
+            return
+
         sizes = [int(line["id"].lstrip(key).split(' ')[0]) for line in filtered_data]
 
         if error_bar:
@@ -115,34 +121,36 @@ def plot_setup(data: Data, save: bool = False):
         if error_bar:
             ax.fill_between(sizes, down, up, color=color, alpha=0.3)
 
+    curve = "BLS12-381"
+
     # setup
-    plot(data, "setup/setup (komodo)", "komodo", "orange", True, axs[0])
-    plot(data, "setup (arkworks)", "arkworks", "blue", True, axs[0])
+    plot(data, "setup/setup (komodo)", curve, "komodo", "orange", True, axs[0])
+    plot(data, "setup (arkworks)", curve, "arkworks", "blue", True, axs[0])
     axs[0].set_title("time to generate a random trusted setup")
     axs[0].set_ylabel("time (in ms)")
     axs[0].legend()
     axs[0].grid()
 
     # serialization
-    plot(data, "setup/serializing with compression", "compressed", "orange", True, axs[1])
-    plot(data, "setup/serializing with no compression", "uncompressed", "blue", True, axs[1])
+    plot(data, "setup/serializing with compression", curve, "compressed", "orange", True, axs[1])
+    plot(data, "setup/serializing with no compression", curve, "uncompressed", "blue", True, axs[1])
     axs[1].set_title("serialization")
     axs[1].set_ylabel("time (in ms)")
     axs[1].legend()
     axs[1].grid()
 
     # deserialization
-    plot(data, "setup/deserializing with no compression and no validation", "uncompressed unvalidated", "red", True, axs[2])
-    plot(data, "setup/deserializing with compression and no validation", "compressed unvalidated", "orange", True, axs[2])
-    plot(data, "setup/deserializing with no compression and validation", "uncompressed validated", "blue", True, axs[2])
-    plot(data, "setup/deserializing with compression and validation", "compressed validated", "green", True, axs[2])
+    plot(data, "setup/deserializing with no compression and no validation", curve, "uncompressed unvalidated", "red", True, axs[2])
+    plot(data, "setup/deserializing with compression and no validation", curve, "compressed unvalidated", "orange", True, axs[2])
+    plot(data, "setup/deserializing with no compression and validation", curve, "uncompressed validated", "blue", True, axs[2])
+    plot(data, "setup/deserializing with compression and validation", curve, "compressed validated", "green", True, axs[2])
     axs[2].set_title("deserialization")
     axs[2].set_ylabel("time (in ms)")
     axs[2].legend()
     axs[2].grid()
 
-    plot(data, "serialized size with no compression", "uncompressed", "orange", False, axs[3])
-    plot(data, "serialized size with compression", "compressed", "blue", False, axs[3])
+    plot(data, "serialized size with no compression", curve, "uncompressed", "orange", False, axs[3])
+    plot(data, "serialized size with compression", curve, "compressed", "blue", False, axs[3])
     axs[3].set_title("size")
     axs[3].set_xlabel("degree")
     axs[3].set_ylabel("size (in kb)")
-- 
GitLab


From 0163c8f929968fb50e218f205bae67b1a8fb24e8 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Tue, 9 Apr 2024 17:00:30 +0200
Subject: [PATCH 13/21] plot all curves in setup

---
 benches/plot.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/benches/plot.py b/benches/plot.py
index 02d98ae5..7433ddf4 100644
--- a/benches/plot.py
+++ b/benches/plot.py
@@ -99,7 +99,7 @@ def plot_setup(data: Data, save: bool = False):
     fig, axs = plt.subplots(4, 1, sharex=True, figsize=(16, 9))
 
     # key: the start of the `$.id` field
-    def plot(data: Data, key: str, curve: str, label: str, color: str, error_bar: bool, ax):
+    def plot(data: Data, key: str, curve: str, label: str, color: str, style: str, error_bar: bool, ax):
         filtered_data = list(filter(
             lambda line: line["id"].startswith(key) and line["id"].endswith(f" on {curve}"),
             data
@@ -116,41 +116,43 @@ def plot_setup(data: Data, save: bool = False):
         else:
             means = b_to_kb(extract(filtered_data, "mean", None))
 
-        ax.plot(sizes, means, label=label, color=color)
+        ax.plot(sizes, means, label=f"{label} on {curve}", color=color, linestyle=style)
 
         if error_bar:
             ax.fill_between(sizes, down, up, color=color, alpha=0.3)
 
-    curve = "BLS12-381"
-
     # setup
-    plot(data, "setup/setup (komodo)", curve, "komodo", "orange", True, axs[0])
-    plot(data, "setup (arkworks)", curve, "arkworks", "blue", True, axs[0])
+    for (curve, color) in [("BLS12-381", "blue"), ("BN-254", "orange"), ("PALLAS", "green")]:
+        plot(data, "setup/setup (komodo)", curve, "komodo", color, "solid", True, axs[0])
+        plot(data, "setup (arkworks)", curve, "arkworks", color, "dashed", True, axs[0])
     axs[0].set_title("time to generate a random trusted setup")
     axs[0].set_ylabel("time (in ms)")
     axs[0].legend()
     axs[0].grid()
 
     # serialization
-    plot(data, "setup/serializing with compression", curve, "compressed", "orange", True, axs[1])
-    plot(data, "setup/serializing with no compression", curve, "uncompressed", "blue", True, axs[1])
+    for (curve, color) in [("BLS12-381", "blue"), ("BN-254", "orange"), ("PALLAS", "green")]:
+        plot(data, "setup/serializing with compression", curve, "compressed", color, "solid", True, axs[1])
+        plot(data, "setup/serializing with no compression", curve, "uncompressed", color, "dashed", True, axs[1])
     axs[1].set_title("serialization")
     axs[1].set_ylabel("time (in ms)")
     axs[1].legend()
     axs[1].grid()
 
     # deserialization
-    plot(data, "setup/deserializing with no compression and no validation", curve, "uncompressed unvalidated", "red", True, axs[2])
-    plot(data, "setup/deserializing with compression and no validation", curve, "compressed unvalidated", "orange", True, axs[2])
-    plot(data, "setup/deserializing with no compression and validation", curve, "uncompressed validated", "blue", True, axs[2])
-    plot(data, "setup/deserializing with compression and validation", curve, "compressed validated", "green", True, axs[2])
+    for (curve, color) in [("BLS12-381", "blue"), ("BN-254", "orange"), ("PALLAS", "green")]:
+        plot(data, "setup/deserializing with no compression and no validation", curve, "uncompressed unvalidated", color, "dotted", True, axs[2])
+        plot(data, "setup/deserializing with compression and no validation", curve, "compressed unvalidated", color, "dashed", True, axs[2])
+        plot(data, "setup/deserializing with no compression and validation", curve, "uncompressed validated", color, "dashdot", True, axs[2])
+        plot(data, "setup/deserializing with compression and validation", curve, "compressed validated", color, "solid", True, axs[2])
     axs[2].set_title("deserialization")
     axs[2].set_ylabel("time (in ms)")
     axs[2].legend()
     axs[2].grid()
 
-    plot(data, "serialized size with no compression", curve, "uncompressed", "orange", False, axs[3])
-    plot(data, "serialized size with compression", curve, "compressed", "blue", False, axs[3])
+    for (curve, color) in [("BLS12-381", "blue"), ("BN-254", "orange"), ("PALLAS", "green")]:
+        plot(data, "serialized size with no compression", curve, "uncompressed", color, "dashed", False, axs[3])
+        plot(data, "serialized size with compression", curve, "compressed", color, "solid", False, axs[3])
     axs[3].set_title("size")
     axs[3].set_xlabel("degree")
     axs[3].set_ylabel("size (in kb)")
-- 
GitLab


From 8c91c6d864b99fee4704aa1a4706f2621eab3c92 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 10:18:28 +0200
Subject: [PATCH 14/21] split the setup of Komodo and the serde benchmarks

---
 benches/setup.rs | 81 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 54 insertions(+), 27 deletions(-)

diff --git a/benches/setup.rs b/benches/setup.rs
index 226d52de..82fd8e12 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -18,13 +18,47 @@ where
     P: DenseUVPolynomial<F>,
     for<'a, 'b> &'a P: Div<&'b P, Output = P>,
 {
-    let mut group = c.benchmark_group("setup");
-
     let rng = &mut rand::thread_rng();
 
-    group.bench_function(&format!("setup (komodo) {} on {}", degree, curve), |b| {
+    c.bench_function(&format!("setup (komodo) {} on {}", degree, curve), |b| {
         b.iter(|| zk::setup::<_, F, G>(degree, rng).unwrap())
     });
+}
+
+fn ark_setup_template<E, P>(c: &mut Criterion, degree: usize, curve: &str)
+where
+    E: Pairing,
+    P: DenseUVPolynomial<E::ScalarField>,
+    for<'a, 'b> &'a P: Div<&'b P, Output = P>,
+{
+    let rng = &mut rand::thread_rng();
+
+    c.bench_function(
+        &format!("setup (arkworks) {} bytes on {}", degree, curve),
+        |b| {
+            b.iter(|| {
+                let setup = KZG10::<E, P>::setup(degree, false, rng).unwrap();
+                let powers_of_g = setup.powers_of_g[..=degree].to_vec();
+                let powers_of_gamma_g = (0..=degree).map(|i| setup.powers_of_gamma_g[&i]).collect();
+                kzg10::Powers::<E> {
+                    powers_of_g: ark_std::borrow::Cow::Owned(powers_of_g),
+                    powers_of_gamma_g: ark_std::borrow::Cow::Owned(powers_of_gamma_g),
+                }
+            })
+        },
+    );
+}
+
+fn serde_template<F, G, P>(c: &mut Criterion, degree: usize, curve: &str)
+where
+    F: PrimeField,
+    G: CurveGroup<ScalarField = F>,
+    P: DenseUVPolynomial<F>,
+    for<'a, 'b> &'a P: Div<&'b P, Output = P>,
+{
+    let mut group = c.benchmark_group("setup");
+
+    let rng = &mut rand::thread_rng();
 
     let setup = zk::setup::<_, F, G>(degree, rng).unwrap();
 
@@ -103,37 +137,30 @@ where
     group.finish();
 }
 
-fn ark_setup_template<E, P>(c: &mut Criterion, degree: usize, curve: &str)
-where
-    E: Pairing,
-    P: DenseUVPolynomial<E::ScalarField>,
-    for<'a, 'b> &'a P: Div<&'b P, Output = P>,
-{
-    let rng = &mut rand::thread_rng();
+fn setup(c: &mut Criterion) {
+    fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(
+        c: &mut Criterion,
+        degree: usize,
+        curve: &str,
+    ) {
+        setup_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve);
+    }
 
-    c.bench_function(
-        &format!("setup (arkworks) {} bytes on {}", degree, curve),
-        |b| {
-            b.iter(|| {
-                let setup = KZG10::<E, P>::setup(degree, false, rng).unwrap();
-                let powers_of_g = setup.powers_of_g[..=degree].to_vec();
-                let powers_of_gamma_g = (0..=degree).map(|i| setup.powers_of_gamma_g[&i]).collect();
-                kzg10::Powers::<E> {
-                    powers_of_g: ark_std::borrow::Cow::Owned(powers_of_g),
-                    powers_of_gamma_g: ark_std::borrow::Cow::Owned(powers_of_gamma_g),
-                }
-            })
-        },
-    );
+    for n in [1, 2, 4, 8, 16] {
+        aux::<ark_bls12_381::Fr, ark_bls12_381::G1Projective>(c, n, "BLS-12-381");
+        aux::<ark_bn254::Fr, ark_bn254::G1Projective>(c, n, "BN-254");
+        aux::<ark_pallas::Fr, ark_pallas::Projective>(c, n, "PALLAS");
+    }
 }
 
-fn setup(c: &mut Criterion) {
+
+fn serde(c: &mut Criterion) {
     fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(
         c: &mut Criterion,
         degree: usize,
         curve: &str,
     ) {
-        setup_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve);
+        serde_template::<F, G, DensePolynomial<F>>(c, black_box(degree), curve);
     }
 
     for n in [1, 2, 4, 8, 16] {
@@ -159,6 +186,6 @@ criterion_group!(
     config = Criterion::default()
         .warm_up_time(Duration::from_secs_f32(0.5))
         .sample_size(10);
-    targets = setup, ark_setup
+    targets = setup, ark_setup, serde
 );
 criterion_main!(benches);
-- 
GitLab


From 0784f2947a91dce1caabec7019f8786d1ff2c125 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 10:57:56 +0200
Subject: [PATCH 15/21] add a manual benchmark to measure the commit

---
 examples/bench_commit.rs | 80 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 examples/bench_commit.rs

diff --git a/examples/bench_commit.rs b/examples/bench_commit.rs
new file mode 100644
index 00000000..641ca4fd
--- /dev/null
+++ b/examples/bench_commit.rs
@@ -0,0 +1,80 @@
+use std::time::Instant;
+
+use ark_ec::CurveGroup;
+use ark_ff::PrimeField;
+use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
+use ark_std::{ops::Div, rand::RngCore};
+
+use komodo::zk;
+use rand::rngs::ThreadRng;
+
+fn run<F, G, P, R>(degrees: &Vec<usize>, curve: &str)
+where
+    F: PrimeField,
+    G: CurveGroup<ScalarField = F>,
+    P: DenseUVPolynomial<F>,
+    R: RngCore,
+    for<'a, 'b> &'a P: Div<&'b P, Output = P>,
+{
+    eprintln!("curve: {}", curve);
+    let rng = &mut rand::thread_rng();
+
+    let max_degree = *degrees.iter().max().unwrap_or(&0);
+
+    eprint!("building trusted setup for degree {}... ", max_degree);
+    let setup = zk::setup::<_, F, G>(max_degree, rng).unwrap();
+    eprintln!("done");
+
+    for (i, degree) in degrees.iter().enumerate() {
+        eprint!("     d: {} [{}/{}]\r", degree, i + 1, degrees.len());
+        let polynomial = P::rand(*degree, rng);
+
+        let start_time = Instant::now();
+        let _ = zk::commit(&setup, &polynomial);
+        let end_time = Instant::now();
+
+        println!(
+            "{}: {} -> {}",
+            curve,
+            degree,
+            end_time.duration_since(start_time).as_nanos()
+        );
+    }
+    eprintln!("");
+}
+
+/// ## example
+/// ```rust
+/// measure!(ark_pallas, degrees, G1=Projective, name="PALLAS");
+/// ```
+/// will produce
+/// ```rust
+/// run::<ark_pallas::Fr, ark_pallas::Projective, DensePolynomial<ark_pallas::Fr>, ThreadRng>(&degrees, "PALLAS");
+/// ```
+macro_rules! measure {
+    ($c:ident, $d:ident, G1=$g:ident, name=$n:expr) => {
+        run::<$c::Fr, $c::$g, DensePolynomial<$c::Fr>, ThreadRng>(&$d, $n);
+    };
+}
+
+fn main() {
+    let n = 20;
+
+    let mut degrees = Vec::with_capacity(n);
+    let mut cur = 1;
+    for _ in 1..n {
+        degrees.push(cur);
+        cur *= 2;
+    }
+
+    measure!(ark_pallas, degrees, G1 = Projective, name = "PALLAS");
+    measure!(
+        ark_bls12_381,
+        degrees,
+        G1 = G1Projective,
+        name = "BLS12-381"
+    );
+    measure!(ark_bn254, degrees, G1 = G1Projective, name = "BN-254");
+    measure!(ark_secp256k1, degrees, G1 = Projective, name = "SECP256-K1");
+    measure!(ark_secp256r1, degrees, G1 = Projective, name = "SECP256-R1");
+}
-- 
GitLab


From 608a3fd18632c655574c11216cfb2be643fe5a58 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 11:04:17 +0200
Subject: [PATCH 16/21] move the "example benches" to `examples/benches/`

---
 Cargo.toml                                              | 8 ++++++++
 examples/{bench_commit.rs => benches/commit.rs}         | 0
 examples/{bench_setup_size.rs => benches/setup_size.rs} | 0
 3 files changed, 8 insertions(+)
 rename examples/{bench_commit.rs => benches/commit.rs} (100%)
 rename examples/{bench_setup_size.rs => benches/setup_size.rs} (100%)

diff --git a/Cargo.toml b/Cargo.toml
index b79c5b88..8fda2ddd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -64,3 +64,11 @@ harness = false
 [[bench]]
 name = "commit"
 harness = false
+
+[[example]]
+name = "bench_commit"
+path = "examples/benches/commit.rs"
+
+[[example]]
+name = "bench_setup_size"
+path = "examples/benches/setup_size.rs"
diff --git a/examples/bench_commit.rs b/examples/benches/commit.rs
similarity index 100%
rename from examples/bench_commit.rs
rename to examples/benches/commit.rs
diff --git a/examples/bench_setup_size.rs b/examples/benches/setup_size.rs
similarity index 100%
rename from examples/bench_setup_size.rs
rename to examples/benches/setup_size.rs
-- 
GitLab


From 10f9a37c8446532decdcaa0e7f99d9d57942821a Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 11:33:32 +0200
Subject: [PATCH 17/21] add a script to plot results from `bench_commit`

---
 scripts/plot/bench_commit.py | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 scripts/plot/bench_commit.py

diff --git a/scripts/plot/bench_commit.py b/scripts/plot/bench_commit.py
new file mode 100644
index 00000000..6b189eb7
--- /dev/null
+++ b/scripts/plot/bench_commit.py
@@ -0,0 +1,36 @@
+# ## usage
+# ```nushell
+# let res = cargo run --example bench_commit
+#     | lines
+#     | parse "{curve}: {degree} -> {t}"
+#     | into int degree
+#     | update t { into int | into duration }
+#
+# python scripts/plot/bench_commit.py (
+#     $res | group-by curve --to-table | update items { reject curve } | to json
+# )
+# ```
+import json
+import sys
+import matplotlib.pyplot as plt
+
+NB_NS_IN_MS = 1e6
+
+
+if __name__ == "__main__":
+    data = json.loads(sys.argv[1])
+
+    for group in data:
+        xs = [x["degree"] for x in group["items"]]
+        ys = [x["t"] / NB_NS_IN_MS for x in group["items"]]
+
+        plt.plot(xs, ys, label=group["group"], marker='o')
+
+    plt.xlabel("degree")
+    plt.ylabel("time (in ns)")
+
+    plt.title("time to commit polynomials for certain curves")
+
+    plt.legend()
+    plt.grid(True)
+    plt.show()
-- 
GitLab


From 6d512fa6e415c23f327cadd524cbae30ef3b2eb7 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 11:35:24 +0200
Subject: [PATCH 18/21] move plot script from `benches/` to `scripts/plot/`

---
 benches/README.md                          | 4 ++--
 benches/plot.py => scripts/plot/benches.py | 0
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename benches/plot.py => scripts/plot/benches.py (100%)

diff --git a/benches/README.md b/benches/README.md
index d085dee9..2bfa060f 100644
--- a/benches/README.md
+++ b/benches/README.md
@@ -10,6 +10,6 @@ nushell> cargo run --example bench_setup_size out>> results.ndjson
 
 ## plot the results
 ```shell
-python benches/plot.py results.ndjson --bench linalg
-python benches/plot.py results.ndjson --bench setup
+python scripts/plot/benches.py results.ndjson --bench linalg
+python scripts/plot/benches.py results.ndjson --bench setup
 ```
diff --git a/benches/plot.py b/scripts/plot/benches.py
similarity index 100%
rename from benches/plot.py
rename to scripts/plot/benches.py
-- 
GitLab


From a4e6ffbcf339e8bc0c0e1215ade8ebed34351481 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 11:41:12 +0200
Subject: [PATCH 19/21] measure VESTA

---
 examples/benches/commit.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/examples/benches/commit.rs b/examples/benches/commit.rs
index 641ca4fd..7860612d 100644
--- a/examples/benches/commit.rs
+++ b/examples/benches/commit.rs
@@ -77,4 +77,5 @@ fn main() {
     measure!(ark_bn254, degrees, G1 = G1Projective, name = "BN-254");
     measure!(ark_secp256k1, degrees, G1 = Projective, name = "SECP256-K1");
     measure!(ark_secp256r1, degrees, G1 = Projective, name = "SECP256-R1");
+    measure!(ark_vesta, degrees, G1 = Projective, name = "VESTA");
 }
-- 
GitLab


From dfa6d52820160216ec710585865c2c3ce5b014a4 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 12:23:56 +0200
Subject: [PATCH 20/21] format

---
 benches/setup.rs | 1 -
 1 file changed, 1 deletion(-)

diff --git a/benches/setup.rs b/benches/setup.rs
index 82fd8e12..1a4dcffe 100644
--- a/benches/setup.rs
+++ b/benches/setup.rs
@@ -153,7 +153,6 @@ fn setup(c: &mut Criterion) {
     }
 }
 
-
 fn serde(c: &mut Criterion) {
     fn aux<F: PrimeField, G: CurveGroup<ScalarField = F>>(
         c: &mut Criterion,
-- 
GitLab


From 2a496910cbea5155eeebc07375b43af6eacaf064 Mon Sep 17 00:00:00 2001
From: "a.stevan" <antoine.stevan@isae-supaero.fr>
Date: Wed, 10 Apr 2024 12:24:49 +0200
Subject: [PATCH 21/21] make clippy happy

---
 examples/benches/commit.rs | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/examples/benches/commit.rs b/examples/benches/commit.rs
index 7860612d..733b3622 100644
--- a/examples/benches/commit.rs
+++ b/examples/benches/commit.rs
@@ -3,17 +3,15 @@ use std::time::Instant;
 use ark_ec::CurveGroup;
 use ark_ff::PrimeField;
 use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial};
-use ark_std::{ops::Div, rand::RngCore};
+use ark_std::ops::Div;
 
 use komodo::zk;
-use rand::rngs::ThreadRng;
 
-fn run<F, G, P, R>(degrees: &Vec<usize>, curve: &str)
+fn run<F, G, P>(degrees: &Vec<usize>, curve: &str)
 where
     F: PrimeField,
     G: CurveGroup<ScalarField = F>,
     P: DenseUVPolynomial<F>,
-    R: RngCore,
     for<'a, 'b> &'a P: Div<&'b P, Output = P>,
 {
     eprintln!("curve: {}", curve);
@@ -40,7 +38,7 @@ where
             end_time.duration_since(start_time).as_nanos()
         );
     }
-    eprintln!("");
+    eprintln!();
 }
 
 /// ## example
@@ -53,7 +51,7 @@ where
 /// ```
 macro_rules! measure {
     ($c:ident, $d:ident, G1=$g:ident, name=$n:expr) => {
-        run::<$c::Fr, $c::$g, DensePolynomial<$c::Fr>, ThreadRng>(&$d, $n);
+        run::<$c::Fr, $c::$g, DensePolynomial<$c::Fr>>(&$d, $n);
     };
 }
 
-- 
GitLab