Skip to content

Commit f411ca9

Browse files
committed
Fix and surpress deepfold warnings, better benchmark names
1 parent 0be0653 commit f411ca9

7 files changed

Lines changed: 83 additions & 63 deletions

File tree

benches/my_benchmark.rs

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use ark_ff::Field;
12
use ark_std::rand::{rngs::StdRng, SeedableRng};
23
use criterion::{black_box, criterion_group, criterion_main, Criterion};
34
use polynomial_proving::{
@@ -10,6 +11,47 @@ use util::{
1011
CODE_RATE,
1112
};
1213

14+
#[cfg(feature = "rayon")]
15+
const PARALLEL: &str = "(parallel)";
16+
#[cfg(not(feature = "rayon"))]
17+
const PARALLEL: &str = "(single thread)";
18+
19+
trait FieldName {
20+
const FIELD_NAME: &str;
21+
}
22+
23+
impl FieldName for sqisign::level_i::Fp2251 {
24+
const FIELD_NAME: &str = "5·2²⁴⁸-1 (SQIsign I)";
25+
}
26+
impl FieldName for sqisign::level_iii::Fp2383 {
27+
const FIELD_NAME: &str = "65·2³⁷⁶-1 (SQIsign III)";
28+
}
29+
impl FieldName for sqisign::level_v::Fp2505 {
30+
const FIELD_NAME: &str = "27·2⁵⁰⁰-1 (SQIsign V)";
31+
}
32+
impl FieldName for p434::Fp2434 {
33+
const FIELD_NAME: &str = "2²¹⁶·3¹³⁷-1 (p434)";
34+
}
35+
impl FieldName for p503::Fp2503 {
36+
const FIELD_NAME: &str = "2²⁵⁰·3¹⁵⁹-1 (p503)";
37+
}
38+
impl FieldName for p610::Fp2610 {
39+
const FIELD_NAME: &str = "2³⁰⁵·3¹⁹²-1 (p610)";
40+
}
41+
impl FieldName for p751::Fp2751 {
42+
const FIELD_NAME: &str = "2³⁷²·3²³⁹-1 (p751)";
43+
}
44+
45+
trait PublicKeyName {
46+
const NAME: &str;
47+
}
48+
impl<F: Field> PublicKeyName for RadicalPublicKey<F> {
49+
const NAME: &str = "pk=(A, C)";
50+
}
51+
impl<F: Field> PublicKeyName for JInvariantPublicKey<F> {
52+
const NAME: &str = "pk=j";
53+
}
54+
1355
fn test_prove_verify<
1456
const VARIABLE_COUNT: usize,
1557
const PATH_LENGTH: usize,
@@ -22,19 +64,27 @@ fn test_prove_verify<
2264
const COMMITMENT_SIZE: usize,
2365
const Q_VARIABLE_COUNT: usize,
2466
const FINAL_ROUND_EVALUATIONS: usize,
25-
F: FftField,
26-
PK: PublicKey<F>,
67+
F: FftField + FieldName,
68+
PK: PublicKey<F> + PublicKeyName,
2769
>(
2870
c: &mut Criterion,
29-
name: &str,
3071
) {
3172
// Generate the public and private key
3273
let compressed_private_key =
3374
CompressedPrivateKey::<PATH_LENGTH_DIV_64>::rand(StdRng::from_entropy());
3475
let (public_key, private_key) = expand_keys(&compressed_private_key);
3576
assert!(private_key.check(&public_key));
3677

37-
let keygen_id = format!("{name}: keygen ({} bits security)", SECURITY_BITS);
78+
let id_for_function = |func| format!(
79+
"{}, e={}, λ={}, {}, {}: {func}",
80+
F::FIELD_NAME,
81+
PATH_LENGTH,
82+
SECURITY_BITS,
83+
PK::NAME,
84+
PARALLEL
85+
);
86+
87+
let keygen_id = id_for_function("keygen");
3888
c.bench_function(&keygen_id, |b| {
3989
b.iter(|| {
4090
let compressed_private_key =
@@ -49,10 +99,10 @@ fn test_prove_verify<
4999
SECURITY_BITS / CODE_RATE,
50100
);
51101

52-
let proof_id = format!("{name}: prove ({} bits security)", SECURITY_BITS);
53-
let verify_id = format!("{name}: verify ({} bits security)", SECURITY_BITS);
102+
let prove_id = id_for_function("prove");
103+
let verify_id = id_for_function("verify");
54104

55-
c.bench_function(&proof_id, |b| {
105+
c.bench_function(&prove_id, |b| {
56106
b.iter(|| {
57107
prove::<
58108
VARIABLE_COUNT,
@@ -140,7 +190,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
140190
{ CFG_SQISIGN_I.final_round_evaluations() },
141191
sqisign::level_i::Fp2251,
142192
RadicalPublicKey<_>,
143-
>(c, "Fp2251 (SQISign I) (Radical Public Key)");
193+
>(c);
144194
test_prove_verify::<
145195
{ CFG_SQISIGN_I.variable_count() },
146196
{ CFG_SQISIGN_I.path_length() },
@@ -155,7 +205,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
155205
{ CFG_SQISIGN_I.final_round_evaluations() },
156206
sqisign::level_i::Fp2251,
157207
JInvariantPublicKey<_>,
158-
>(c, "Fp2251 (SQISign I) (J-invariant Public Key)");
208+
>(c);
159209
}
160210
{
161211
const CFG_SQISIGN_III: RunForParamsConfig = RunForParamsConfig {
@@ -177,7 +227,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
177227
{ CFG_SQISIGN_III.final_round_evaluations() },
178228
sqisign::level_iii::Fp2383,
179229
RadicalPublicKey<_>,
180-
>(c, "Fp2383 (SQISign III) (Radical Public Key)");
230+
>(c);
181231
test_prove_verify::<
182232
{ CFG_SQISIGN_III.variable_count() },
183233
{ CFG_SQISIGN_III.path_length() },
@@ -192,7 +242,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
192242
{ CFG_SQISIGN_III.final_round_evaluations() },
193243
sqisign::level_iii::Fp2383,
194244
JInvariantPublicKey<_>,
195-
>(c, "Fp2383 (SQISign III) (J-invariant Public Key)");
245+
>(c);
196246
}
197247
{
198248
const CFG_SQISIGN_V: RunForParamsConfig = RunForParamsConfig {
@@ -214,7 +264,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
214264
{ CFG_SQISIGN_V.final_round_evaluations() },
215265
sqisign::level_v::Fp2505,
216266
RadicalPublicKey<_>,
217-
>(c, "Fp2505 (SQISign V) (Radical Public Key)");
267+
>(c);
218268
test_prove_verify::<
219269
{ CFG_SQISIGN_V.variable_count() },
220270
{ CFG_SQISIGN_V.path_length() },
@@ -229,7 +279,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
229279
{ CFG_SQISIGN_V.final_round_evaluations() },
230280
sqisign::level_v::Fp2505,
231281
JInvariantPublicKey<_>,
232-
>(c, "Fp2505 (SQISign V) (J-invariant Public Key)");
282+
>(c);
233283
}
234284
{
235285
const CFG_P434: RunForParamsConfig = RunForParamsConfig {
@@ -251,7 +301,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
251301
{ CFG_P434.final_round_evaluations() },
252302
p434::Fp2434,
253303
RadicalPublicKey<_>,
254-
>(c, "Fp2434 (path length 1024, λ=128) (Radical Public Key)");
304+
>(c);
255305
test_prove_verify::<
256306
{ CFG_P434.variable_count() },
257307
{ CFG_P434.path_length() },
@@ -266,10 +316,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
266316
{ CFG_P434.final_round_evaluations() },
267317
p434::Fp2434,
268318
JInvariantPublicKey<_>,
269-
>(
270-
c,
271-
"Fp2434 (path length 1024, λ=128) (J-Invariant Public Key)",
272-
);
319+
>(c);
273320
}
274321
{
275322
const CFG_P503: RunForParamsConfig = RunForParamsConfig {
@@ -291,7 +338,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
291338
{ CFG_P503.final_round_evaluations() },
292339
p503::Fp2503,
293340
RadicalPublicKey<_>,
294-
>(c, "Fp2503 (path length 1024, λ=128) (Radical Public Key)");
341+
>(c);
295342
test_prove_verify::<
296343
{ CFG_P503.variable_count() },
297344
{ CFG_P503.path_length() },
@@ -306,10 +353,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
306353
{ CFG_P503.final_round_evaluations() },
307354
p503::Fp2503,
308355
JInvariantPublicKey<_>,
309-
>(
310-
c,
311-
"Fp2503 (path length 1024, λ=128) (J-Invariant Public Key)",
312-
);
356+
>(c);
313357
}
314358
{
315359
const CFG_P610: RunForParamsConfig = RunForParamsConfig {
@@ -331,7 +375,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
331375
{ CFG_P610.final_round_evaluations() },
332376
p610::Fp2610,
333377
RadicalPublicKey<_>,
334-
>(c, "Fp2610 (path length 1024, λ=192) (Radical Public Key)");
378+
>(c);
335379
test_prove_verify::<
336380
{ CFG_P610.variable_count() },
337381
{ CFG_P610.path_length() },
@@ -346,10 +390,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
346390
{ CFG_P610.final_round_evaluations() },
347391
p610::Fp2610,
348392
JInvariantPublicKey<_>,
349-
>(
350-
c,
351-
"Fp2610 (path length 1024, λ=192) (J-Invariant Public Key)",
352-
);
393+
>(c);
353394
}
354395
{
355396
const CFG_P751: RunForParamsConfig = RunForParamsConfig {
@@ -371,7 +412,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
371412
{ CFG_P751.final_round_evaluations() },
372413
p751::Fp2751,
373414
RadicalPublicKey<_>,
374-
>(c, "Fp2751 (path length 2048, λ=256) (Radical Public Key)");
415+
>(c);
375416
test_prove_verify::<
376417
{ CFG_P751.variable_count() },
377418
{ CFG_P751.path_length() },
@@ -386,10 +427,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
386427
{ CFG_P751.final_round_evaluations() },
387428
p751::Fp2751,
388429
JInvariantPublicKey<_>,
389-
>(
390-
c,
391-
"Fp2751 (path length 2048, λ=256) (J-Invariant Public Key)",
392-
);
430+
>(c);
393431
}
394432
}
395433

deepfold/util/src/algebra/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::merkle_tree::MERKLE_ROOT_SIZE;
2-
use ark_ff::{Field, Fp2, PrimeField, Fp2Config, Fp2ConfigWrapper, QuadExtConfig, QuadExtField};
2+
use ark_ff::Field;
33
use ark_serialize::CanonicalSerialize;
44
use rand::RngCore;
55
use std::{

deepfold/util/src/algebra/field/arkfield.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
use std::hash::Hash;
2-
use std::iter::{Product, Sum};
3-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
1+
use std::iter::Sum;
42

53
use crate::algebra::field::FftField;
64

7-
use super::MyField;
8-
use ark_ff::{Fp2ConfigWrapper};
95
use ark_ff::{
10-
fp2, AdditiveGroup, Field, Fp256, Fp2Config, MontBackend, MontConfig, MontFp, UniformRand,
6+
fp2, AdditiveGroup, Field, Fp256, Fp2Config, MontBackend, MontConfig, MontFp,
117
};
12-
use ark_serialize::{CanonicalDeserialize, CanonicalDeserializeWithFlags, CanonicalSerialize, CanonicalSerializeWithFlags, Valid};
138
use num_traits::Zero;
14-
use num_traits::One;
159

1610
#[derive(MontConfig)]
1711
#[modulus = "2261564242916331941866620800950935700259179388000792266395655937654553313279"]

deepfold/util/src/algebra/field/arkfield_192.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
use std::cmp;
2-
use std::hash::Hash;
3-
use std::iter::{Product, Sum};
4-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
1+
use std::iter::Sum;
52

63
use crate::algebra::field::FftField;
74

8-
use super::MyField;
9-
use ark_ff::{Fp2ConfigWrapper, Fp384};
5+
use ark_ff::Fp384;
106
use ark_ff::{
11-
fp2, AdditiveGroup, Field, Fp2Config, MontBackend, MontConfig, MontFp, UniformRand,
7+
fp2, AdditiveGroup, Fp2Config, MontBackend, MontConfig, MontFp,
128
};
13-
use ark_serialize::{CanonicalDeserialize, CanonicalDeserializeWithFlags, CanonicalSerialize, CanonicalSerializeWithFlags, Valid};
14-
use num_traits::Zero;
15-
use num_traits::One;
169

1710
#[derive(MontConfig)]
1811
#[modulus = "21240143965243898950369170053983666816800796950485279844440876913226209392447715095215502903023899837622322901024767"]

deepfold/util/src/algebra/field/arkfield_256.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
use std::hash::Hash;
2-
use std::iter::{Product, Sum};
3-
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
1+
use std::iter::Sum;
42

53
use crate::algebra::field::FftField;
64

7-
use super::MyField;
8-
use ark_ff::{Fp2ConfigWrapper, Fp512};
5+
use ark_ff::Fp512;
96
use ark_ff::{
10-
fp2, AdditiveGroup, Field, Fp256, Fp2Config, MontBackend, MontConfig, MontFp, UniformRand,
7+
fp2, AdditiveGroup, Field, Fp2Config, MontBackend, MontConfig, MontFp,
118
};
12-
use ark_serialize::{CanonicalDeserialize, CanonicalDeserializeWithFlags, CanonicalSerialize, CanonicalSerializeWithFlags, Valid};
13-
use halo2curves::ff_ext::inverse;
14-
use num_traits::ops::mul_add;
159
use num_traits::Zero;
16-
use num_traits::One;
1710

1811
#[derive(MontConfig)]
1912
#[modulus = "864175120484581453683482079962486176185193500155369104423588921177379322250834082489183304374038697487834084609675858746433355728113743766078731283595263"]

deepfold/util/src/algebra/field/m31_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl MyField for M31ext {
8787
}
8888

8989
#[inline]
90-
fn from_hash(hash: [u8; crate::merkle_tree::MERKLE_ROOT_SIZE]) -> Self {
90+
fn from_hash(_hash: [u8; crate::merkle_tree::MERKLE_ROOT_SIZE]) -> Self {
9191
todo!()
9292
// Self(F::deserialize(&hash.into()))
9393
}

deepfold/util/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(warnings)]
2+
13
pub mod algebra {
24
pub mod coset;
35
pub mod field;

0 commit comments

Comments
 (0)