Skip to content

Commit

Permalink
feat(zk): recompute big d in zk v1 to be more efficient when k < k_max
Browse files Browse the repository at this point in the history
  • Loading branch information
IceTDrinker committed Sep 13, 2024
1 parent 95ab73c commit f9026f1
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions tfhe-zk-pok/src/proofs/pke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ pub fn compute_crs_params(
) -> (usize, usize, u64) {
let b_r = d as u64 / 2 + 1;

// This formulation is equivalent to the formula of the paper as 1 + b_r.ilog2() == d.ilog2()
// for any d power of 2 > 2
let big_d =
d + k * t.ilog2() as usize + (d + k) * (2 + b.ilog2() as usize + b_r.ilog2() as usize);
let n = big_d + 1;
Expand Down Expand Up @@ -200,14 +202,14 @@ pub fn prove<G: Curve>(
) -> Proof<G> {
let &PublicParams {
ref g_lists,
big_d,
big_d: big_d_max,
n,
d,
b,
b_r,
q,
t,
k,
k: k_max,
ref hash,
ref hash_t,
ref hash_agg,
Expand All @@ -223,8 +225,12 @@ pub fn prove<G: Curve>(
let PublicCommit { a, b, c1, c2, .. } = public.1;
let PrivateCommit { r, e1, m, e2, .. } = private_commit;

assert!(c2.len() <= k);
let k = k.min(c2.len());
let k = c2.len();
assert!(k <= k_max);

let big_d =
d + k * t.ilog2() as usize + (d + k) * (2 + b_i.ilog2() as usize + b_r.ilog2() as usize);
assert!(big_d <= big_d_max);

// FIXME: div_round
let delta = {
Expand Down Expand Up @@ -721,14 +727,14 @@ pub fn verify<G: Curve>(

let &PublicParams {
ref g_lists,
big_d,
big_d: big_d_max,
n,
d,
b,
b_r,
q,
t,
k,
k: k_max,
ref hash,
ref hash_t,
ref hash_agg,
Expand All @@ -748,10 +754,16 @@ pub fn verify<G: Curve>(
};

let PublicCommit { a, b, c1, c2, .. } = public.1;
if c2.len() > k {
let k = c2.len();
if k > k_max {
return Err(());
}

let big_d =
d + k * t.ilog2() as usize + (d + k) * (2 + b_i.ilog2() as usize + b_r.ilog2() as usize);
if big_d > big_d_max {
return Err(());
}
let k = k.min(c2.len());

let x_bytes = &*[
q.to_le_bytes().as_slice(),
Expand Down Expand Up @@ -1114,7 +1126,10 @@ mod tests {
PublicParams::deserialize_with_mode(data.as_slice(), compress, Validate::No)
};

let original_public_param = crs_gen::<Curve>(d, k, b_i, q, t, rng);
// To check management of bigger k_max from CRS during test
let crs_k = k + 1 + (rng.gen::<usize>() % (d - k));

let original_public_param = crs_gen::<Curve>(d, crs_k, b_i, q, t, rng);
let public_param_that_was_compressed =
serialize_then_deserialize(&original_public_param, Compress::No).unwrap();
let public_param_that_was_not_compressed =
Expand Down

0 comments on commit f9026f1

Please sign in to comment.