Skip to content

Commit

Permalink
chore(zk): add a test for compute_crs_params
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarlin-zama committed Nov 22, 2024
1 parent 51e8f72 commit 60bd8ad
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tfhe-zk-pok/src/proofs/pke_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ pub fn compute_crs_params(
let effective_t_for_decomposition = t >> msbs_zero_padding_bit_count;

// formula in Prove_pp: 2.
let D = d + k * effective_t_for_decomposition.ilog2() as usize;
let D = d + k * (effective_t_for_decomposition.ilog2() as usize);
let n = D + 128 * m_bound;

(n, D, B_bound_squared, m_bound)
Expand Down Expand Up @@ -2861,6 +2861,36 @@ mod tests {
}
}

/// Compare the computed params with manually calculated ones to check the formula
#[test]
fn test_compute_crs_params() {
let PkeTestParameters {
d,
k,
B,
q: _,
t,
msbs_zero_padding_bit_count,
} = PKEV2_TEST_PARAMS;

let B_squared = inf_norm_bound_to_euclidean_squared(B, d + k);
assert_eq!(B_squared, 40681930227712);

let (n, D, B_bound_squared, m_bound) =
compute_crs_params(d, k, B_squared, t, msbs_zero_padding_bit_count, Bound::GHL);
assert_eq!(n, 6784);
assert_eq!(D, 3328);
assert_eq!(B_bound_squared, 3867562496364372);
assert_eq!(m_bound, 27);

let (n, D, B_bound_squared, m_bound) =
compute_crs_params(d, k, B_squared, t, msbs_zero_padding_bit_count, Bound::CS);
assert_eq!(n, 7168);
assert_eq!(D, 3328);
assert_eq!(B_bound_squared, 192844141830554880);
assert_eq!(m_bound, 30);
}

/// Test that the proof is rejected if we don't have the padding bit set to 0
#[test]
fn test_pke_w_padding_fail_verify() {
Expand Down

0 comments on commit 60bd8ad

Please sign in to comment.