Skip to content

Commit

Permalink
chore(zk): check that k <= d for zk crs
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarlin-zama committed Dec 16, 2024
1 parent ef68464 commit 03956a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions tfhe-zk-pok/src/proofs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ fn assert_pke_proof_preconditions(
big_d: usize,
big_d_max: usize,
) {
assert!(k_max <= d);
assert_eq!(c1.len(), d);
assert_eq!(e1.len(), d);

Expand Down
8 changes: 7 additions & 1 deletion tfhe-zk-pok/src/proofs/pke_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ pub fn compute_crs_params(
msbs_zero_padding_bit_count: u64,
bound_type: Bound,
) -> (usize, usize, u128, usize) {
assert!(
k <= d,
"Invalid parameters for zk_pok, the maximum number of messages k should be smaller \
than the lwe dimension d. Please pick a smaller k: k = {k}, d = {d}"
);

let mut B_bound_squared = {
(match bound_type {
// GHL factor is 9.75, 9.75**2 = 95.0625
Expand Down Expand Up @@ -526,7 +532,7 @@ Please select a smaller B, d and/or k"
// safely used for this
assert!(
m_bound <= 64,
"Invalid parameters for zk_pok, w e only support 64 bits integer. \
"Invalid parameters for zk_pok, we only support 64 bits integer. \
The computed m parameter is {m_bound} > 64. Please select a smaller B, d and/or k"
);

Expand Down
4 changes: 4 additions & 0 deletions tfhe/src/zk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ impl CompactPkeCrs {
Scalar: UnsignedInteger + CastInto<u64> + Debug,
NoiseDistribution: BoundedDistribution<Scalar::Signed>,
{
if max_num_cleartext.0 > lwe_dim.0 {
return Err("Maximum number of cleartexts is greater than the lwe dimension".into());
}

let noise_bound = match zk_scheme {
CompactPkeZkScheme::V1 => Self::compute_bound_v1(noise_distribution)?,
CompactPkeZkScheme::V2 => Self::compute_bound_v2(noise_distribution)?,
Expand Down

0 comments on commit 03956a9

Please sign in to comment.