From 2c4ad32cd2a71bf09bbf4820aa50611e711b5461 Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Wed, 15 Jan 2025 16:30:51 +0100 Subject: [PATCH] test(core): use 5 bits parameters tweaked to 4 bits to avoid high pfail --- .../algorithms/test/lwe_fast_keyswitch.rs | 31 ++++++++++--------- .../algorithms/test/lwe_stair_keyswitch.rs | 28 +++++++++-------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/tfhe/src/core_crypto/experimental/algorithms/test/lwe_fast_keyswitch.rs b/tfhe/src/core_crypto/experimental/algorithms/test/lwe_fast_keyswitch.rs index bcd6b34a8e..917c9ca97a 100644 --- a/tfhe/src/core_crypto/experimental/algorithms/test/lwe_fast_keyswitch.rs +++ b/tfhe/src/core_crypto/experimental/algorithms/test/lwe_fast_keyswitch.rs @@ -13,7 +13,7 @@ pub struct FastKSParam { pub bsk_partial_glwe_secret_key_fill: PartialGlweSecretKeyRandomCoefCount, pub bsk_glwe_noise_distribution: DynamicDistribution, pub lwe_dimension: LweDimension, - pub ks1_lwe_modular_std_dev: DynamicDistribution, + pub ks1_lwe_modular_noise_distribution: DynamicDistribution, pub pbs_level: DecompositionLevelCount, pub pbs_base_log: DecompositionBaseLog, pub ks1_level: DecompositionLevelCount, @@ -25,27 +25,28 @@ pub struct FastKSParam { pub ciphertext_modulus: CiphertextModulus, } +/// This is the original precision 5 parameters tweaked to use for 4 bits, such that the pfail is +/// much lower than 2^-14, it should be approximately ~2^-49 pub const PRECISION_4_FAST_KS: FastKSParam = FastKSParam { - log_precision: MessageModulusLog(4), - _log_mu: 4, - glwe_dimension: GlweDimension(2), - polynomial_size: PolynomialSize(1024), + log_precision: MessageModulusLog(4), // original: log_precision: 5, + _log_mu: 5, + glwe_dimension: GlweDimension(1), + polynomial_size: PolynomialSize(2048), bsk_partial_glwe_secret_key_fill: PartialGlweSecretKeyRandomCoefCount(2048), bsk_glwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev( 3.162026630747649e-16, )), - lwe_dimension: LweDimension(682), - ks1_lwe_modular_std_dev: DynamicDistribution::new_gaussian_from_std_dev(StandardDev( - 2.7313997525878062e-5, - )), + lwe_dimension: LweDimension(766), + ks1_lwe_modular_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev( + StandardDev(5.822_216_831_056_818e-6), + ), pbs_level: DecompositionLevelCount(1), pbs_base_log: DecompositionBaseLog(23), - ks1_level: DecompositionLevelCount(14), + ks1_level: DecompositionLevelCount(15), ks1_base_log: DecompositionBaseLog(1), ks1_polynomial_size: PolynomialSize(512), - ks_in_glwe_dimension: GlweDimension(3), // Original value - // ks_in_glwe_dimension: GlweDimension(4), // Test non square pseudo GGSWs - phi_in: 1366, + ks_in_glwe_dimension: GlweDimension(3), + phi_in: 1282, ks_out_glwe_dimension: GlweDimension(3), ciphertext_modulus: CiphertextModulus::new_native(), }; @@ -71,7 +72,7 @@ fn lwe_encrypt_fast_ks_decrypt_custom_mod< bsk_partial_glwe_secret_key_fill, bsk_glwe_noise_distribution, lwe_dimension, - ks1_lwe_modular_std_dev, + ks1_lwe_modular_noise_distribution, pbs_level, pbs_base_log, ks1_level, @@ -222,7 +223,7 @@ fn lwe_encrypt_fast_ks_decrypt_custom_mod< &small_glwe_secret_key, &large_glwe_secret_key_unshared, &mut ggsw, - ks1_lwe_modular_std_dev, + ks1_lwe_modular_noise_distribution, &mut rsc.encryption_random_generator, ); diff --git a/tfhe/src/core_crypto/experimental/algorithms/test/lwe_stair_keyswitch.rs b/tfhe/src/core_crypto/experimental/algorithms/test/lwe_stair_keyswitch.rs index 4216f1a9e0..ae404c2c7f 100644 --- a/tfhe/src/core_crypto/experimental/algorithms/test/lwe_stair_keyswitch.rs +++ b/tfhe/src/core_crypto/experimental/algorithms/test/lwe_stair_keyswitch.rs @@ -29,30 +29,32 @@ pub struct StairKSParam { pub ciphertext_modulus: CiphertextModulus, } +/// This is the original precision 5 parameters tweaked to use for 4 bits, such that the pfail is +/// much lower than 2^-14, it should be approximately ~2^-49 pub const PRECISION_4_STAIR: StairKSParam = StairKSParam { - log_precision: MessageModulusLog(4), - _log_mu: 4, - glwe_dimension: GlweDimension(2), - polynomial_size: PolynomialSize(1024), + log_precision: MessageModulusLog(4), //original: log_precision: 5, + _log_mu: 5, + glwe_dimension: GlweDimension(1), + polynomial_size: PolynomialSize(2048), partial_glwe_secret_key_fill: PartialGlweSecretKeyRandomCoefCount(2048), bsk_glwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev( 3.16202663074765e-16, )), - lwe_dimension: LweDimension(664), + lwe_dimension: LweDimension(732), ks1_lwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev( - 7.60713313301797e-9, + 3.31119701700870e-9, )), ks2_lwe_noise_distribution: DynamicDistribution::new_gaussian_from_std_dev(StandardDev( - 0.0000380960250519291, + 0.0000108646407745138, )), pbs_level: DecompositionLevelCount(1), - pbs_base_log: DecompositionBaseLog(22), - ks1_level: DecompositionLevelCount(1), - ks1_base_log: DecompositionBaseLog(13), - ks2_level: DecompositionLevelCount(6), + pbs_base_log: DecompositionBaseLog(23), + ks1_level: DecompositionLevelCount(2), + ks1_base_log: DecompositionBaseLog(9), + ks2_level: DecompositionLevelCount(7), ks2_base_log: DecompositionBaseLog(2), - ks1_unshared_coeff_count: LweSecretKeyUnsharedCoefCount(922), - ks2_unshared_coeff_count: LweSecretKeyUnsharedCoefCount(462), + ks1_unshared_coeff_count: LweSecretKeyUnsharedCoefCount(877), + ks2_unshared_coeff_count: LweSecretKeyUnsharedCoefCount(439), ciphertext_modulus: CiphertextModulus::new_native(), };