mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-08 22:28:01 -05:00
chore(zk): add benches for zk v2 bounds ghl and cs
This commit is contained in:
committed by
Nicolas Sarlin
parent
9d5edfa8a1
commit
95772b58e4
@@ -1,5 +1,5 @@
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use tfhe_zk_pok::proofs::pke_v2::{prove, verify};
|
||||
use tfhe_zk_pok::proofs::pke_v2::{prove, verify, Bound};
|
||||
use tfhe_zk_pok::proofs::ComputeLoad;
|
||||
use utils::{init_params_v2, write_to_json, PKEV1_TEST_PARAMS, PKEV2_TEST_PARAMS};
|
||||
|
||||
@@ -16,35 +16,33 @@ fn bench_pke_v2_prove(c: &mut Criterion) {
|
||||
|
||||
let rng = &mut rand::thread_rng();
|
||||
|
||||
for (params, param_name) in [
|
||||
(PKEV1_TEST_PARAMS, "PKEV1_TEST_PARAMS"),
|
||||
(PKEV2_TEST_PARAMS, "PKEV2_TEST_PARAMS"),
|
||||
] {
|
||||
let (public_param, public_commit, private_commit, metadata) = init_params_v2(params);
|
||||
for ((params, param_name), load, bound) in itertools::iproduct!(
|
||||
[
|
||||
(PKEV1_TEST_PARAMS, "PKEV1_TEST_PARAMS"),
|
||||
(PKEV2_TEST_PARAMS, "PKEV2_TEST_PARAMS"),
|
||||
],
|
||||
[ComputeLoad::Proof, ComputeLoad::Verify],
|
||||
[Bound::CS, Bound::GHL]
|
||||
) {
|
||||
let (public_param, public_commit, private_commit, metadata) = init_params_v2(params, bound);
|
||||
let effective_t = params.t >> 1;
|
||||
let bits = (params.k as u32) * effective_t.ilog2();
|
||||
|
||||
for load in [ComputeLoad::Proof, ComputeLoad::Verify] {
|
||||
let zk_load = match load {
|
||||
ComputeLoad::Proof => "compute_load_proof",
|
||||
ComputeLoad::Verify => "compute_load_verify",
|
||||
};
|
||||
let bench_id = format!("{bench_name}::{param_name}_{bits}_bits_packed_{zk_load}");
|
||||
let bench_id = format!("{bench_name}::{param_name}_{bits}_bits_packed_{load}_{bound:?}");
|
||||
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
b.iter(|| {
|
||||
prove(
|
||||
(&public_param, &public_commit),
|
||||
&private_commit,
|
||||
&metadata,
|
||||
load,
|
||||
rng,
|
||||
)
|
||||
})
|
||||
});
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
b.iter(|| {
|
||||
prove(
|
||||
(&public_param, &public_commit),
|
||||
&private_commit,
|
||||
&metadata,
|
||||
load,
|
||||
rng,
|
||||
)
|
||||
})
|
||||
});
|
||||
|
||||
write_to_json(&bench_id, params, param_name, bench_shortname);
|
||||
}
|
||||
write_to_json(&bench_id, params, param_name, bench_shortname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,33 +56,35 @@ fn bench_pke_v2_verify(c: &mut Criterion) {
|
||||
|
||||
let rng = &mut rand::thread_rng();
|
||||
|
||||
for (params, param_name) in [
|
||||
(PKEV1_TEST_PARAMS, "PKEV1_TEST_PARAMS"),
|
||||
(PKEV2_TEST_PARAMS, "PKEV2_TEST_PARAMS"),
|
||||
] {
|
||||
let (public_param, public_commit, private_commit, metadata) = init_params_v2(params);
|
||||
for ((params, param_name), load, bound) in itertools::iproduct!(
|
||||
[
|
||||
(PKEV1_TEST_PARAMS, "PKEV1_TEST_PARAMS"),
|
||||
(PKEV2_TEST_PARAMS, "PKEV2_TEST_PARAMS"),
|
||||
],
|
||||
[ComputeLoad::Proof, ComputeLoad::Verify],
|
||||
[Bound::CS, Bound::GHL]
|
||||
) {
|
||||
let (public_param, public_commit, private_commit, metadata) = init_params_v2(params, bound);
|
||||
let effective_t = params.t >> 1;
|
||||
let bits = (params.k as u32) * effective_t.ilog2();
|
||||
|
||||
for load in [ComputeLoad::Proof, ComputeLoad::Verify] {
|
||||
let bench_id = format!("{bench_name}::{param_name}_{bits}_bits_packed_{load}");
|
||||
let bench_id = format!("{bench_name}::{param_name}_{bits}_bits_packed_{load}_{bound:?}");
|
||||
|
||||
let proof = prove(
|
||||
(&public_param, &public_commit),
|
||||
&private_commit,
|
||||
&metadata,
|
||||
load,
|
||||
rng,
|
||||
);
|
||||
let proof = prove(
|
||||
(&public_param, &public_commit),
|
||||
&private_commit,
|
||||
&metadata,
|
||||
load,
|
||||
rng,
|
||||
);
|
||||
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
b.iter(|| {
|
||||
verify(&proof, (&public_param, &public_commit), &metadata).unwrap();
|
||||
})
|
||||
});
|
||||
bench_group.bench_function(&bench_id, |b| {
|
||||
b.iter(|| {
|
||||
verify(&proof, (&public_param, &public_commit), &metadata).unwrap();
|
||||
})
|
||||
});
|
||||
|
||||
write_to_json(&bench_id, params, param_name, bench_shortname);
|
||||
}
|
||||
write_to_json(&bench_id, params, param_name, bench_shortname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@ use serde::Serialize;
|
||||
use tfhe_zk_pok::proofs::pke::{commit, crs_gen, PrivateCommit, PublicCommit, PublicParams};
|
||||
|
||||
use tfhe_zk_pok::proofs::pke_v2::{
|
||||
commit as commitv2, crs_gen as crs_genv2, PrivateCommit as PrivateCommitv2,
|
||||
PublicCommit as PublicCommitv2, PublicParams as PublicParamsv2,
|
||||
commit as commitv2, crs_gen_cs as crs_genv2_cs, crs_gen_ghl as crs_genv2_ghl, Bound,
|
||||
PrivateCommit as PrivateCommitv2, PublicCommit as PublicCommitv2,
|
||||
PublicParams as PublicParamsv2,
|
||||
};
|
||||
|
||||
// One of our usecases uses 320 bits of additional metadata
|
||||
@@ -414,6 +415,7 @@ pub fn init_params_v1(
|
||||
#[allow(unused)]
|
||||
pub fn init_params_v2(
|
||||
test_params: PkeTestParameters,
|
||||
bound: Bound,
|
||||
) -> (
|
||||
PublicParamsv2<Curve>,
|
||||
PublicCommitv2<Curve>,
|
||||
@@ -435,7 +437,10 @@ pub fn init_params_v2(
|
||||
|
||||
let ct = testcase.encrypt(test_params);
|
||||
|
||||
let public_param = crs_genv2::<Curve>(d, k, B, q, t, msbs_zero_padding_bit_count, rng);
|
||||
let public_param = match bound {
|
||||
Bound::GHL => crs_genv2_ghl::<Curve>(d, k, B, q, t, msbs_zero_padding_bit_count, rng),
|
||||
Bound::CS => crs_genv2_cs::<Curve>(d, k, B, q, t, msbs_zero_padding_bit_count, rng),
|
||||
};
|
||||
|
||||
let (public_commit, private_commit) = commitv2(
|
||||
testcase.a.clone(),
|
||||
|
||||
@@ -525,7 +525,7 @@ Please select a smaller B, d and/or k"
|
||||
// safely used for this
|
||||
assert!(
|
||||
m_bound <= 64,
|
||||
"Invalid paramters for zk_pok, w e only support 64 bits integer. \
|
||||
"Invalid parameters for zk_pok, w e only support 64 bits integer. \
|
||||
The computed m parameter is {m_bound} > 64. Please select a smaller B, d and/or k"
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user