Skip to content

Commit

Permalink
chore(core): use real modulus in test
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Feb 13, 2025
1 parent 37934e4 commit 9e4b585
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::core_crypto::commons::traits::{Container, ContainerMut, UnsignedInteg
use crate::core_crypto::entities::{LweCiphertext, LweCiphertextList};
use crate::core_crypto::fft_impl::common::modulus_switch;
use crate::core_crypto::prelude::{
CiphertextModulusLog, ContiguousEntityContainer, DispersionParameter,
CiphertextModulus, CiphertextModulusLog, ContiguousEntityContainer, DispersionParameter,
};
use itertools::Itertools;

Expand Down Expand Up @@ -128,6 +128,12 @@ where
0,
"Expected at least one encryption of zero"
);
assert_eq!(
lwe.ciphertext_modulus(),
CiphertextModulus::new_native(),
"Non native modulus are not supported, got {}",
lwe.ciphertext_modulus(),
);

let modulus = lwe.ciphertext_modulus().raw_modulus_float();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,14 @@ fn check_noise_improve_modulus_switch_noise(
variance_improved / base_variance,
);

let modulus = ciphertext_modulus.raw_modulus_float();

let expected_base_variance = {
let lwe_dim = lwe_dimension.0 as f64;

let poly_size = 2_f64.powi((log_modulus.0 - 1) as i32);

(lwe_dim + 2.) * 2_f64.powi(128) / (96. * poly_size * poly_size) + (lwe_dim - 4.) / 48.
(lwe_dim + 2.) * modulus * modulus / (96. * poly_size * poly_size) + (lwe_dim - 4.) / 48.
};

assert!(
Expand All @@ -480,7 +482,7 @@ fn check_noise_improve_modulus_switch_noise(
);

let expected_variance_improved = Variance(expected_variance_improved.0 - input_variance.0)
.get_modular_variance(2_f64.powi(64))
.get_modular_variance(modulus)
.value;

assert!(
Expand Down

0 comments on commit 9e4b585

Please sign in to comment.