From caf5b420b86ab923f4da9a8ff83206613a9e57c2 Mon Sep 17 00:00:00 2001 From: "Mayeul@Zama" <69792125+mayeul-zama@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:16:31 +0200 Subject: [PATCH] refactor(hlapi): remove wopbs_block_parameters from IntegerConfig --- tfhe/benches/high_level_api/bench.rs | 3 +-- tfhe/examples/dist_tuniform.rs | 2 +- tfhe/examples/sha256.rs | 14 ++++++-------- .../utilities/hlapi_compact_pk_ct_sizes.rs | 8 ++++---- tfhe/src/c_api/high_level_api/config.rs | 4 +--- tfhe/src/high_level_api/booleans/tests.rs | 4 ++-- tfhe/src/high_level_api/compact_list.rs | 2 -- .../compressed_ciphertext_list.rs | 1 - tfhe/src/high_level_api/config.rs | 16 ++++------------ .../high_level_api/integers/signed/tests.rs | 8 ++------ .../integers/unsigned/tests/cpu.rs | 18 +++++++++--------- tfhe/src/high_level_api/keys/inner.rs | 15 ++------------- .../js_on_wasm_api/js_high_level_api/config.rs | 2 +- 13 files changed, 33 insertions(+), 64 deletions(-) diff --git a/tfhe/benches/high_level_api/bench.rs b/tfhe/benches/high_level_api/bench.rs index c21c8e4105..8361b0587f 100644 --- a/tfhe/benches/high_level_api/bench.rs +++ b/tfhe/benches/high_level_api/bench.rs @@ -108,8 +108,7 @@ bench_type!(FheUint64); bench_type!(FheUint128); fn main() { - let config = - ConfigBuilder::with_custom_parameters(PARAM_MESSAGE_2_CARRY_2_KS_PBS, None).build(); + let config = ConfigBuilder::with_custom_parameters(PARAM_MESSAGE_2_CARRY_2_KS_PBS).build(); let cks = ClientKey::generate(config); let compressed_sks = CompressedServerKey::new(&cks); diff --git a/tfhe/examples/dist_tuniform.rs b/tfhe/examples/dist_tuniform.rs index 1681ca2014..019ac07225 100644 --- a/tfhe/examples/dist_tuniform.rs +++ b/tfhe/examples/dist_tuniform.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), Box> { my_params.glwe_noise_distribution = DynamicDistribution::new_t_uniform(10); let config = ConfigBuilder::default() - .use_custom_parameters(my_params, None) + .use_custom_parameters(my_params) .build(); let (keys, server_keys) = generate_keys(config); diff --git a/tfhe/examples/sha256.rs b/tfhe/examples/sha256.rs index 371c538e8a..a38bb2d035 100644 --- a/tfhe/examples/sha256.rs +++ b/tfhe/examples/sha256.rs @@ -186,14 +186,12 @@ fn main() -> Result<(), std::io::Error> { println!("key gen start"); let config = match args.multibit { None => ConfigBuilder::default(), - Some(2) => ConfigBuilder::with_custom_parameters( - PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS, - None, - ), - Some(3) => ConfigBuilder::with_custom_parameters( - PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, - None, - ), + Some(2) => { + ConfigBuilder::with_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_2_KS_PBS) + } + Some(3) => { + ConfigBuilder::with_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS) + } Some(v) => { panic!("Invalid multibit setting {v}"); } diff --git a/tfhe/examples/utilities/hlapi_compact_pk_ct_sizes.rs b/tfhe/examples/utilities/hlapi_compact_pk_ct_sizes.rs index e047903713..ae51340a9c 100644 --- a/tfhe/examples/utilities/hlapi_compact_pk_ct_sizes.rs +++ b/tfhe/examples/utilities/hlapi_compact_pk_ct_sizes.rs @@ -41,7 +41,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) { { let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS; let config = ConfigBuilder::default() - .use_custom_parameters(params, None) + .use_custom_parameters(params) .build(); let (client_key, _) = generate_keys(config); let test_name = format!("hlapi_sizes_{}_cpk", params.name()); @@ -99,7 +99,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) { { let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS; let config = ConfigBuilder::default() - .use_custom_parameters(params, None) + .use_custom_parameters(params) .build(); let (client_key, _) = generate_keys(config); let test_name = format!("hlapi_sizes_{}_cpk", params.name()); @@ -158,7 +158,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) { { let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS; let config = ConfigBuilder::default() - .use_custom_parameters(params, None) + .use_custom_parameters(params) .build(); let (client_key, _) = generate_keys(config); @@ -206,7 +206,7 @@ pub fn cpk_and_cctl_sizes(results_file: &Path) { { let params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS; let config = ConfigBuilder::default() - .use_custom_parameters(params, None) + .use_custom_parameters(params) .build(); let (client_key, _) = generate_keys(config); diff --git a/tfhe/src/c_api/high_level_api/config.rs b/tfhe/src/c_api/high_level_api/config.rs index 478a37d5ec..fbe9190a2f 100644 --- a/tfhe/src/c_api/high_level_api/config.rs +++ b/tfhe/src/c_api/high_level_api/config.rs @@ -69,9 +69,7 @@ pub unsafe extern "C" fn config_builder_use_custom_parameters( let params: crate::shortint::ClassicPBSParameters = shortint_block_parameters.try_into().unwrap(); - let inner = Box::from_raw(*builder) - .0 - .use_custom_parameters(params, None); + let inner = Box::from_raw(*builder).0.use_custom_parameters(params); *builder = Box::into_raw(Box::new(ConfigBuilder(inner))); }) } diff --git a/tfhe/src/high_level_api/booleans/tests.rs b/tfhe/src/high_level_api/booleans/tests.rs index e680a33902..af0a76e2f6 100644 --- a/tfhe/src/high_level_api/booleans/tests.rs +++ b/tfhe/src/high_level_api/booleans/tests.rs @@ -676,7 +676,7 @@ mod cpu { fn test_safe_deserialize_conformant_fhe_bool() { let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let (client_key, server_key) = - generate_keys(ConfigBuilder::with_custom_parameters(block_params, None)); + generate_keys(ConfigBuilder::with_custom_parameters(block_params)); set_server_key(server_key.clone()); let clear_a = random::(); @@ -698,7 +698,7 @@ mod cpu { fn test_safe_deserialize_conformant_compressed_fhe_bool() { let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let (client_key, server_key) = - generate_keys(ConfigBuilder::with_custom_parameters(block_params, None)); + generate_keys(ConfigBuilder::with_custom_parameters(block_params)); set_server_key(server_key.clone()); let clear_a = random::(); let a = CompressedFheBool::encrypt(clear_a, &client_key); diff --git a/tfhe/src/high_level_api/compact_list.rs b/tfhe/src/high_level_api/compact_list.rs index 9d86d6c596..d774243ce0 100644 --- a/tfhe/src/high_level_api/compact_list.rs +++ b/tfhe/src/high_level_api/compact_list.rs @@ -382,7 +382,6 @@ mod tests { let config = crate::ConfigBuilder::with_custom_parameters( PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, - None, ) .build(); @@ -446,7 +445,6 @@ mod tests { let config = crate::ConfigBuilder::with_custom_parameters( PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, - None, ) .use_dedicated_compact_public_key_parameters(( PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, diff --git a/tfhe/src/high_level_api/compressed_ciphertext_list.rs b/tfhe/src/high_level_api/compressed_ciphertext_list.rs index 2a95958630..cf8f8626f3 100644 --- a/tfhe/src/high_level_api/compressed_ciphertext_list.rs +++ b/tfhe/src/high_level_api/compressed_ciphertext_list.rs @@ -163,7 +163,6 @@ mod tests { fn test_compressed_ct_list() { let config = crate::ConfigBuilder::with_custom_parameters( PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, - None, ) .enable_compression(COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64) .build(); diff --git a/tfhe/src/high_level_api/config.rs b/tfhe/src/high_level_api/config.rs index b4891fcd71..255a26db46 100644 --- a/tfhe/src/high_level_api/config.rs +++ b/tfhe/src/high_level_api/config.rs @@ -70,16 +70,13 @@ impl ConfigBuilder { } } - pub fn with_custom_parameters

( - block_parameters: P, - wopbs_block_parameters: Option, - ) -> Self + pub fn with_custom_parameters

(block_parameters: P) -> Self where P: Into, { Self { config: Config { - inner: IntegerConfig::new(block_parameters.into(), wopbs_block_parameters, None), + inner: IntegerConfig::new(block_parameters.into()), }, } } @@ -96,16 +93,11 @@ impl ConfigBuilder { self } - pub fn use_custom_parameters

( - mut self, - block_parameters: P, - wopbs_block_parameters: Option, - ) -> Self + pub fn use_custom_parameters

(mut self, block_parameters: P) -> Self where P: Into, { - self.config.inner = - IntegerConfig::new(block_parameters.into(), wopbs_block_parameters, None); + self.config.inner = IntegerConfig::new(block_parameters.into()); self } diff --git a/tfhe/src/high_level_api/integers/signed/tests.rs b/tfhe/src/high_level_api/integers/signed/tests.rs index 90bcb38211..3cc0d539ea 100644 --- a/tfhe/src/high_level_api/integers/signed/tests.rs +++ b/tfhe/src/high_level_api/integers/signed/tests.rs @@ -279,7 +279,6 @@ fn test_multi_bit_rotate() { let config = ConfigBuilder::default() .use_custom_parameters( crate::shortint::parameters::PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, - None, ) .build(); fhe_int64_rotate(config); @@ -368,7 +367,6 @@ fn test_multi_div_rem() { let config = ConfigBuilder::default() .use_custom_parameters( crate::shortint::parameters::PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, - None, ) .build(); fhe_int32_div_rem(config); @@ -546,7 +544,6 @@ fn test_compact_public_key_big() { let config = ConfigBuilder::default() .use_custom_parameters( crate::shortint::parameters::classic::compact_pk::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS, - None, ) .build(); let (client_key, _) = generate_keys(config); @@ -567,7 +564,6 @@ fn test_compact_public_key_small() { let config = ConfigBuilder::default() .use_custom_parameters( crate::shortint::parameters::classic::compact_pk::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS, - None, ) .build(); let (client_key, _) = generate_keys(config); @@ -646,7 +642,7 @@ fn test_leading_trailing_zeros_ones() { fn test_safe_deserialize_conformant_fhe_int32() { let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let (client_key, server_key) = - generate_keys(ConfigBuilder::with_custom_parameters(block_params, None)); + generate_keys(ConfigBuilder::with_custom_parameters(block_params)); set_server_key(server_key.clone()); let clear_a = random::(); @@ -668,7 +664,7 @@ fn test_safe_deserialize_conformant_fhe_int32() { fn test_safe_deserialize_conformant_compressed_fhe_int32() { let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let (client_key, server_key) = - generate_keys(ConfigBuilder::with_custom_parameters(block_params, None)); + generate_keys(ConfigBuilder::with_custom_parameters(block_params)); set_server_key(server_key.clone()); let clear_a = random::(); diff --git a/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs b/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs index e5a03fd56c..4f9e21bf7f 100644 --- a/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs +++ b/tfhe/src/high_level_api/integers/unsigned/tests/cpu.rs @@ -18,7 +18,7 @@ use rand::prelude::*; fn setup_cpu(params: Option>) -> ClientKey { let config = params .map_or_else(ConfigBuilder::default, |p| { - ConfigBuilder::with_custom_parameters(p.into(), None) + ConfigBuilder::with_custom_parameters(p.into()) }) .build(); @@ -108,7 +108,7 @@ fn test_uint32_shift() { #[test] fn test_uint32_shift_multibit() { let config = ConfigBuilder::default() - .use_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, None) + .use_custom_parameters(PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS) .build(); let (client_key, server_key) = generate_keys(config); @@ -196,7 +196,7 @@ fn test_decompressed_public_key_encrypt() { #[test] fn test_compact_public_key_big() { let config = ConfigBuilder::default() - .use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS, None) + .use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS) .build(); let (client_key, _) = generate_keys(config); @@ -214,7 +214,7 @@ fn test_compact_public_key_big() { #[test] fn test_compact_public_key_small() { let config = ConfigBuilder::default() - .use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS, None) + .use_custom_parameters(PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS) .build(); let (client_key, _) = generate_keys(config); @@ -401,7 +401,7 @@ fn test_sum() { fn test_safe_deserialize_conformant_fhe_uint32() { let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let (client_key, server_key) = - generate_keys(ConfigBuilder::with_custom_parameters(block_params, None)); + generate_keys(ConfigBuilder::with_custom_parameters(block_params)); set_server_key(server_key.clone()); let clear_a = random::(); @@ -422,7 +422,7 @@ fn test_safe_deserialize_conformant_fhe_uint32() { fn test_safe_deserialize_conformant_compressed_fhe_uint32() { let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let (client_key, server_key) = - generate_keys(ConfigBuilder::with_custom_parameters(block_params, None)); + generate_keys(ConfigBuilder::with_custom_parameters(block_params)); set_server_key(server_key.clone()); let clear_a = random::(); @@ -445,7 +445,7 @@ fn test_safe_deserialize_conformant_compressed_fhe_uint32() { fn test_safe_deserialize_conformant_compact_fhe_uint32() { let block_params = PARAM_MESSAGE_2_CARRY_2_KS_PBS; let (client_key, server_key) = - generate_keys(ConfigBuilder::with_custom_parameters(block_params, None)); + generate_keys(ConfigBuilder::with_custom_parameters(block_params)); set_server_key(server_key); let pk = CompactPublicKey::new(&client_key); @@ -491,7 +491,7 @@ fn test_cpk_encrypt_cast_compute_hl() { let modulus = param_fhe.message_modulus.0.pow(num_block as u32) as u64; let (client_key, server_key) = generate_keys( - ConfigBuilder::with_custom_parameters(param_fhe, None) + ConfigBuilder::with_custom_parameters(param_fhe) .use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk)), ); set_server_key(server_key); @@ -539,7 +539,7 @@ fn test_compressed_cpk_encrypt_cast_compute_hl() { let modulus = param_fhe.message_modulus.0.pow(num_block as u32) as u64; - let config = ConfigBuilder::with_custom_parameters(param_fhe, None) + let config = ConfigBuilder::with_custom_parameters(param_fhe) .use_dedicated_compact_public_key_parameters((param_pke_only, param_ksk)) .build(); let client_key = ClientKey::generate(config); diff --git a/tfhe/src/high_level_api/keys/inner.rs b/tfhe/src/high_level_api/keys/inner.rs index 72cf101db0..a270acb188 100644 --- a/tfhe/src/high_level_api/keys/inner.rs +++ b/tfhe/src/high_level_api/keys/inner.rs @@ -20,7 +20,6 @@ use tfhe_versionable::Versionize; #[allow(clippy::struct_field_names)] pub(crate) struct IntegerConfig { pub(crate) block_parameters: crate::shortint::PBSParameters, - pub(crate) wopbs_block_parameters: Option, pub(crate) dedicated_compact_public_key_parameters: Option<( crate::shortint::parameters::CompactPublicKeyEncryptionParameters, crate::shortint::parameters::ShortintKeySwitchingParameters, @@ -29,18 +28,10 @@ pub(crate) struct IntegerConfig { } impl IntegerConfig { - pub(crate) fn new( - block_parameters: crate::shortint::PBSParameters, - wopbs_block_parameters: Option, - dedicated_compact_public_key_parameters: Option<( - crate::shortint::parameters::CompactPublicKeyEncryptionParameters, - crate::shortint::parameters::ShortintKeySwitchingParameters, - )>, - ) -> Self { + pub(crate) fn new(block_parameters: crate::shortint::PBSParameters) -> Self { Self { block_parameters, - wopbs_block_parameters, - dedicated_compact_public_key_parameters, + dedicated_compact_public_key_parameters: None, compression_parameters: None, } } @@ -48,7 +39,6 @@ impl IntegerConfig { pub(in crate::high_level_api) fn default_big() -> Self { Self { block_parameters: crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS.into(), - wopbs_block_parameters: None, dedicated_compact_public_key_parameters: None, compression_parameters: None, } @@ -57,7 +47,6 @@ impl IntegerConfig { pub(in crate::high_level_api) fn default_small() -> Self { Self { block_parameters: crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_PBS_KS.into(), - wopbs_block_parameters: None, dedicated_compact_public_key_parameters: None, compression_parameters: None, } diff --git a/tfhe/src/js_on_wasm_api/js_high_level_api/config.rs b/tfhe/src/js_on_wasm_api/js_high_level_api/config.rs index 91526fa937..b6b9e5aa00 100644 --- a/tfhe/src/js_on_wasm_api/js_high_level_api/config.rs +++ b/tfhe/src/js_on_wasm_api/js_high_level_api/config.rs @@ -29,7 +29,7 @@ impl TfheConfigBuilder { self, block_parameters: &crate::js_on_wasm_api::shortint::ShortintParameters, ) -> Self { - Self(self.0.use_custom_parameters(block_parameters.0, None)) + Self(self.0.use_custom_parameters(block_parameters.0)) } #[wasm_bindgen]