From d667fb53c2a891bf4bee959c65c209a51965cee1 Mon Sep 17 00:00:00 2001 From: "Mayeul@Zama" <69792125+mayeul-zama@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:07:48 +0200 Subject: [PATCH] chore(hlapi): remove Wop --- tfhe/benches/high_level_api/bench.rs | 3 +- tfhe/docs/fundamentals/compress.md | 3 +- tfhe/docs/fundamentals/serialization.md | 2 +- tfhe/docs/guides/parallelized_pbs.md | 2 - tfhe/docs/guides/public_key.md | 1 - tfhe/docs/guides/run_on_gpu.md | 4 +- tfhe/docs/guides/zk-pok.md | 4 +- 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 +- .../backward_compatibility/keys.rs | 2 - 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 | 22 +--- .../high_level_api/integers/signed/tests.rs | 8 +- .../high_level_api/integers/unsigned/mod.rs | 1 - .../high_level_api/integers/unsigned/ops.rs | 66 +---------- .../integers/unsigned/tests/cpu.rs | 18 +-- .../integers/unsigned/tests/gpu.rs | 2 +- .../high_level_api/integers/unsigned/wopbs.rs | 104 ------------------ tfhe/src/high_level_api/keys/client.rs | 3 - tfhe/src/high_level_api/keys/inner.rs | 58 +--------- tfhe/src/high_level_api/keys/server.rs | 5 - tfhe/src/high_level_api/tests/mod.rs | 17 --- .../js_high_level_api/config.rs | 2 +- .../backward_compatibility/high_level_api.rs | 2 +- 28 files changed, 42 insertions(+), 322 deletions(-) delete mode 100644 tfhe/src/high_level_api/integers/unsigned/wopbs.rs 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/docs/fundamentals/compress.md b/tfhe/docs/fundamentals/compress.md index 7595be0b42..9769beb72b 100644 --- a/tfhe/docs/fundamentals/compress.md +++ b/tfhe/docs/fundamentals/compress.md @@ -66,7 +66,7 @@ use tfhe::{ }; fn main() { - let config = tfhe::ConfigBuilder::with_custom_parameters(PARAM_MESSAGE_2_CARRY_2, None) + let config = tfhe::ConfigBuilder::with_custom_parameters(PARAM_MESSAGE_2_CARRY_2) .enable_compression(COMP_PARAM_MESSAGE_2_CARRY_2) .build(); @@ -212,7 +212,6 @@ fn main() { let config = ConfigBuilder::default() .use_custom_parameters( tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS, - None, ) .build(); let (client_key, _) = generate_keys(config); diff --git a/tfhe/docs/fundamentals/serialization.md b/tfhe/docs/fundamentals/serialization.md index 1e10bc90dd..52ee964133 100644 --- a/tfhe/docs/fundamentals/serialization.md +++ b/tfhe/docs/fundamentals/serialization.md @@ -113,7 +113,7 @@ fn main() { let params_2 = PARAM_MESSAGE_2_CARRY_2_PBS_KS; let (client_key, server_key) = generate_keys( - ConfigBuilder::with_custom_parameters(params_1, None).build() + ConfigBuilder::with_custom_parameters(params_1).build() ); let conformance_params_1 = FheUint8ConformanceParams::from(params_1); diff --git a/tfhe/docs/guides/parallelized_pbs.md b/tfhe/docs/guides/parallelized_pbs.md index d4fcf2aba0..081c875839 100644 --- a/tfhe/docs/guides/parallelized_pbs.md +++ b/tfhe/docs/guides/parallelized_pbs.md @@ -18,7 +18,6 @@ fn main() -> Result<(), Box> { let config = ConfigBuilder::default() .use_custom_parameters( tfhe::shortint::parameters::PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, - None, ) .build(); @@ -52,7 +51,6 @@ fn main() -> Result<(), Box> { let config = ConfigBuilder::default() .use_custom_parameters( tfhe::shortint::parameters::PARAM_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS.with_deterministic_execution(), - None, ) .build(); diff --git a/tfhe/docs/guides/public_key.md b/tfhe/docs/guides/public_key.md index 83cda88527..798d36bf7b 100644 --- a/tfhe/docs/guides/public_key.md +++ b/tfhe/docs/guides/public_key.md @@ -46,7 +46,6 @@ fn main() { let config = ConfigBuilder::default() .use_custom_parameters( tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS, - None, ) .build(); let (client_key, _) = generate_keys(config); diff --git a/tfhe/docs/guides/run_on_gpu.md b/tfhe/docs/guides/run_on_gpu.md index 6c31dd3afd..3b8d12effd 100644 --- a/tfhe/docs/guides/run_on_gpu.md +++ b/tfhe/docs/guides/run_on_gpu.md @@ -133,7 +133,7 @@ Finally, the client decrypts the results using: **TFHE-rs** allows to leverage the high number of threads given by a GPU. To maximize the number of GPU threads, update your configuration accordingly: ```Rust -let config = ConfigBuilder::with_custom_parameters(PARAM_GPU_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, None).build(); +let config = ConfigBuilder::with_custom_parameters(PARAM_GPU_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS).build(); ``` Here's the complete example: @@ -145,7 +145,7 @@ use tfhe::shortint::parameters::PARAM_GPU_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS fn main() { - let config = ConfigBuilder::with_custom_parameters(PARAM_GPU_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS, None).build(); + let config = ConfigBuilder::with_custom_parameters(PARAM_GPU_MULTI_BIT_MESSAGE_2_CARRY_2_GROUP_3_KS_PBS).build(); let client_key= ClientKey::generate(config); let compressed_server_key = CompressedServerKey::new(&client_key); diff --git a/tfhe/docs/guides/zk-pok.md b/tfhe/docs/guides/zk-pok.md index ab46fb4d61..f4b49f14c4 100644 --- a/tfhe/docs/guides/zk-pok.md +++ b/tfhe/docs/guides/zk-pok.md @@ -21,7 +21,7 @@ pub fn main() -> Result<(), Box> { let params = tfhe::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; - let config = tfhe::ConfigBuilder::with_custom_parameters(params, None); + let config = tfhe::ConfigBuilder::with_custom_parameters(params); let client_key = tfhe::ClientKey::generate(config.clone()); // This is done in an offline phase and the CRS is shared to all clients and the server @@ -91,7 +91,7 @@ pub fn main() -> Result<(), Box> { // And parameters allowing to keyswitch/cast to the computation parameters. let casting_params = tfhe::shortint::parameters::key_switching::PARAM_KEYSWITCH_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64; // Enable the dedicated parameters on the config - let config = tfhe::ConfigBuilder::with_custom_parameters(params, None) + let config = tfhe::ConfigBuilder::with_custom_parameters(params) .use_dedicated_compact_public_key_parameters((cpk_params, casting_params)); // Then use TFHE-rs as usual 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/backward_compatibility/keys.rs b/tfhe/src/high_level_api/backward_compatibility/keys.rs index 05d2e7e8d6..77ea3501af 100644 --- a/tfhe/src/high_level_api/backward_compatibility/keys.rs +++ b/tfhe/src/high_level_api/backward_compatibility/keys.rs @@ -76,7 +76,6 @@ impl Upgrade for IntegerClientKeyV0 { fn upgrade(self) -> Result { Ok(IntegerClientKey { key: self.key, - wopbs_block_parameters: self.wopbs_block_parameters, dedicated_compact_private_key: None, compression_key: None, }) @@ -102,7 +101,6 @@ impl Upgrade for IntegerServerKeyV0 { fn upgrade(self) -> Result { Ok(IntegerServerKey { key: self.key, - wopbs_key: self.wopbs_key, cpk_key_switching_key_material: None, compression_key: None, decompression_key: None, diff --git a/tfhe/src/high_level_api/booleans/tests.rs b/tfhe/src/high_level_api/booleans/tests.rs index 485926a5e8..ddb05ddb3c 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 b6bf99ec49..56a43381b1 100644 --- a/tfhe/src/high_level_api/compressed_ciphertext_list.rs +++ b/tfhe/src/high_level_api/compressed_ciphertext_list.rs @@ -167,7 +167,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..a96e2a7946 100644 --- a/tfhe/src/high_level_api/config.rs +++ b/tfhe/src/high_level_api/config.rs @@ -36,12 +36,6 @@ impl Default for ConfigBuilder { } impl ConfigBuilder { - #[doc(hidden)] - pub fn enable_function_evaluation(mut self) -> Self { - self.config.inner.enable_wopbs(); - self - } - pub fn enable_compression(mut self, compression_parameters: CompressionParameters) -> Self { self.config.inner.enable_compression(compression_parameters); @@ -70,16 +64,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(), None), }, } } @@ -96,16 +87,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(), None); 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/mod.rs b/tfhe/src/high_level_api/integers/unsigned/mod.rs index d4d04cf80f..59ec71f492 100644 --- a/tfhe/src/high_level_api/integers/unsigned/mod.rs +++ b/tfhe/src/high_level_api/integers/unsigned/mod.rs @@ -15,7 +15,6 @@ pub(in crate::high_level_api) use inner::RadixCiphertextVersionOwned; mod base; mod compressed; mod static_; -mod wopbs; mod encrypt; mod inner; diff --git a/tfhe/src/high_level_api/integers/unsigned/ops.rs b/tfhe/src/high_level_api/integers/unsigned/ops.rs index bb3c90b223..6fd26b4308 100644 --- a/tfhe/src/high_level_api/integers/unsigned/ops.rs +++ b/tfhe/src/high_level_api/integers/unsigned/ops.rs @@ -10,7 +10,7 @@ use crate::high_level_api::global_state::with_thread_local_cuda_streams; use crate::high_level_api::integers::FheUintId; use crate::high_level_api::keys::InternalServerKey; use crate::high_level_api::traits::{ - DivRem, FheBootstrap, FheEq, FheMax, FheMin, FheOrd, RotateLeft, RotateLeftAssign, RotateRight, + DivRem, FheEq, FheMax, FheMin, FheOrd, RotateLeft, RotateLeftAssign, RotateRight, RotateRightAssign, }; #[cfg(feature = "gpu")] @@ -550,70 +550,6 @@ where } } -impl FheBootstrap for FheUint -where - Id: FheUintId, - crate::integer::wopbs::WopbsKey: super::wopbs::WopbsEvaluationKey< - crate::integer::ServerKey, - crate::integer::RadixCiphertext, - >, -{ - fn map u64>(&self, func: F) -> Self { - use super::wopbs::WopbsEvaluationKey; - global_state::with_internal_keys(|key| match key { - InternalServerKey::Cpu(cpu_key) => { - let res = cpu_key - .wopbs_key - .as_ref() - .expect("Function evaluation on integers was not enabled in the config") - .apply_wopbs(cpu_key.pbs_key(), &*self.ciphertext.on_cpu(), func); - Self::new(res) - } - #[cfg(feature = "gpu")] - InternalServerKey::Cuda(_) => { - panic!("Cuda devices do not support function evaluation yet"); - } - }) - } - - fn apply u64>(&mut self, func: F) { - let result = self.map(func); - *self = result; - } -} - -impl FheUint -where - Id: FheUintId, - crate::integer::wopbs::WopbsKey: super::wopbs::WopbsEvaluationKey< - crate::integer::ServerKey, - crate::integer::RadixCiphertext, - >, -{ - pub fn bivariate_function(&self, other: &Self, func: F) -> Self - where - F: Fn(u64, u64) -> u64, - { - use super::wopbs::WopbsEvaluationKey; - global_state::with_internal_keys(|key| match key { - InternalServerKey::Cpu(cpu_key) => { - let lhs = self.ciphertext.on_cpu(); - let rhs = other.ciphertext.on_cpu(); - let res = cpu_key - .wopbs_key - .as_ref() - .expect("Function evaluation on integers was not enabled in the config") - .apply_bivariate_wopbs(cpu_key.pbs_key(), &*lhs, &*rhs, func); - Self::new(res) - } - #[cfg(feature = "gpu")] - InternalServerKey::Cuda(_) => { - panic!("Cuda devices do not support bivariate functions yet"); - } - }) - } -} - impl DivRem for FheUint where Id: FheUintId, 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/integers/unsigned/tests/gpu.rs b/tfhe/src/high_level_api/integers/unsigned/tests/gpu.rs index ab81139223..960bed6e20 100644 --- a/tfhe/src/high_level_api/integers/unsigned/tests/gpu.rs +++ b/tfhe/src/high_level_api/integers/unsigned/tests/gpu.rs @@ -9,7 +9,7 @@ use crate::{set_server_key, ClientKey, ConfigBuilder}; fn setup_gpu(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(); diff --git a/tfhe/src/high_level_api/integers/unsigned/wopbs.rs b/tfhe/src/high_level_api/integers/unsigned/wopbs.rs deleted file mode 100644 index e02d16e43d..0000000000 --- a/tfhe/src/high_level_api/integers/unsigned/wopbs.rs +++ /dev/null @@ -1,104 +0,0 @@ -use crate::integer::ciphertext::RadixCiphertext; -use crate::integer::wopbs::WopbsKey; - -pub(in crate::high_level_api) fn wopbs_radix( - wopbs_key: &WopbsKey, - server_key: &crate::integer::ServerKey, - ct_in: &RadixCiphertext, - func: impl Fn(u64) -> u64, -) -> RadixCiphertext -where - RadixCiphertext: crate::integer::IntegerCiphertext, -{ - let switched_ct = wopbs_key.keyswitch_to_wopbs_params(server_key, ct_in); - let luts = wopbs_key.generate_lut_radix(&switched_ct, func); - let res = wopbs_key.wopbs(&switched_ct, &luts); - wopbs_key.keyswitch_to_pbs_params(&res) -} - -pub(in crate::high_level_api) fn bivariate_wopbs_radix( - wopbs_key: &WopbsKey, - server_key: &crate::integer::ServerKey, - lhs: &RadixCiphertext, - rhs: &RadixCiphertext, - func: impl Fn(u64, u64) -> u64, -) -> RadixCiphertext -where - RadixCiphertext: crate::integer::IntegerCiphertext, -{ - let switched_lhs = wopbs_key.keyswitch_to_wopbs_params(server_key, lhs); - let switched_rhs = wopbs_key.keyswitch_to_wopbs_params(server_key, rhs); - let lut = wopbs_key.generate_lut_bivariate_radix(&switched_lhs, &switched_rhs, func); - let res = wopbs_key.bivariate_wopbs_with_degree(&switched_lhs, &switched_rhs, &lut); - wopbs_key.keyswitch_to_pbs_params(&res) -} - -pub trait WopbsEvaluationKey { - fn apply_wopbs(&self, sks: &ServerKey, ct: &Ciphertext, f: impl Fn(u64) -> u64) -> Ciphertext; - - fn apply_bivariate_wopbs( - &self, - sks: &ServerKey, - lhs: &Ciphertext, - rhs: &Ciphertext, - f: impl Fn(u64, u64) -> u64, - ) -> Ciphertext; -} - -impl WopbsEvaluationKey for WopbsKey { - fn apply_wopbs( - &self, - sks: &crate::integer::ServerKey, - ct: &RadixCiphertext, - f: impl Fn(u64) -> u64, - ) -> RadixCiphertext { - let mut tmp_ct: RadixCiphertext; - - let ct = if ct.block_carries_are_empty() { - ct - } else { - tmp_ct = ct.clone(); - sks.full_propagate_parallelized(&mut tmp_ct); - &tmp_ct - }; - - wopbs_radix(self, sks, ct, f) - } - - fn apply_bivariate_wopbs( - &self, - sks: &crate::integer::ServerKey, - lhs: &RadixCiphertext, - rhs: &RadixCiphertext, - f: impl Fn(u64, u64) -> u64, - ) -> RadixCiphertext { - let mut tmp_lhs: RadixCiphertext; - let mut tmp_rhs: RadixCiphertext; - - // Clean carries to have a small wopbs to compute - let (lhs, rhs) = match (lhs.block_carries_are_empty(), rhs.block_carries_are_empty()) { - (true, true) => (lhs, rhs), - (true, false) => { - tmp_rhs = rhs.clone(); - sks.full_propagate_parallelized(&mut tmp_rhs); - (lhs, &tmp_rhs) - } - (false, true) => { - tmp_lhs = lhs.clone(); - sks.full_propagate_parallelized(&mut tmp_lhs); - (&tmp_lhs, rhs) - } - (false, false) => { - tmp_lhs = lhs.clone(); - tmp_rhs = rhs.clone(); - rayon::join( - || sks.full_propagate_parallelized(&mut tmp_lhs), - || sks.full_propagate_parallelized(&mut tmp_rhs), - ); - (&tmp_lhs, &tmp_rhs) - } - }; - - bivariate_wopbs_radix(self, sks, lhs, rhs, f) - } -} diff --git a/tfhe/src/high_level_api/keys/client.rs b/tfhe/src/high_level_api/keys/client.rs index 442adca793..ce139d4320 100644 --- a/tfhe/src/high_level_api/keys/client.rs +++ b/tfhe/src/high_level_api/keys/client.rs @@ -68,7 +68,6 @@ impl ClientKey { self, ) -> ( crate::integer::ClientKey, - Option, Option, Option, ) { @@ -77,7 +76,6 @@ impl ClientKey { pub fn from_raw_parts( key: crate::integer::ClientKey, - wopbs_block_parameters: Option, dedicated_compact_private_key: Option<( crate::integer::CompactPrivateKey>, crate::shortint::parameters::key_switching::ShortintKeySwitchingParameters, @@ -87,7 +85,6 @@ impl ClientKey { Self { key: IntegerClientKey::from_raw_parts( key, - wopbs_block_parameters, dedicated_compact_private_key, compression_key, ), diff --git a/tfhe/src/high_level_api/keys/inner.rs b/tfhe/src/high_level_api/keys/inner.rs index 72cf101db0..0057c5a8b1 100644 --- a/tfhe/src/high_level_api/keys/inner.rs +++ b/tfhe/src/high_level_api/keys/inner.rs @@ -8,7 +8,7 @@ use crate::shortint::list_compression::{ DecompressionKey, }; use crate::shortint::parameters::list_compression::CompressionParameters; -use crate::shortint::{EncryptionKeyChoice, MessageModulus}; +use crate::shortint::MessageModulus; use crate::Error; use concrete_csprng::seeders::Seed; use serde::{Deserialize, Serialize}; @@ -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, @@ -31,7 +30,6 @@ 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, @@ -39,7 +37,6 @@ impl IntegerConfig { ) -> Self { Self { block_parameters, - wopbs_block_parameters, dedicated_compact_public_key_parameters, compression_parameters: None, } @@ -48,7 +45,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,21 +53,11 @@ 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, } } - pub fn enable_wopbs(&mut self) { - let wopbs_block_parameters = match self.block_parameters.encryption_key_choice() { - EncryptionKeyChoice::Big => crate::shortint::parameters::parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_2_CARRY_2_KS_PBS, - EncryptionKeyChoice::Small=> panic!("WOPBS only support KS_PBS parameters") - }; - - self.wopbs_block_parameters = Some(wopbs_block_parameters); - } - pub fn enable_compression(&mut self, compression_parameters: CompressionParameters) { self.compression_parameters = Some(compression_parameters); } @@ -97,7 +83,6 @@ pub type CompactPrivateKey = ( #[versionize(IntegerClientKeyVersions)] pub(crate) struct IntegerClientKey { pub(crate) key: crate::integer::ClientKey, - pub(crate) wopbs_block_parameters: Option, pub(crate) dedicated_compact_private_key: Option, pub(crate) compression_key: Option, } @@ -123,7 +108,6 @@ impl IntegerClientKey { .map(|p| (crate::integer::CompactPrivateKey::new(p.0), p.1)); Self { key, - wopbs_block_parameters: config.wopbs_block_parameters, dedicated_compact_private_key, compression_key, } @@ -134,22 +118,15 @@ impl IntegerClientKey { self, ) -> ( crate::integer::ClientKey, - Option, Option, Option, ) { let Self { key, - wopbs_block_parameters, dedicated_compact_private_key, compression_key, } = self; - ( - key, - wopbs_block_parameters, - dedicated_compact_private_key, - compression_key, - ) + (key, dedicated_compact_private_key, compression_key) } /// Construct a, [`IntegerClientKey`] from its constituents. @@ -159,21 +136,10 @@ impl IntegerClientKey { /// Panics if the provided raw parts are not compatible with the provided parameters. pub fn from_raw_parts( key: crate::integer::ClientKey, - wopbs_block_parameters: Option, dedicated_compact_private_key: Option, compression_key: Option, ) -> Self { let shortint_cks: &crate::shortint::ClientKey = key.as_ref(); - if let Some(wop_params) = wopbs_block_parameters.as_ref() { - assert_eq!( - shortint_cks.parameters.message_modulus(), - wop_params.message_modulus - ); - assert_eq!( - shortint_cks.parameters.carry_modulus(), - wop_params.carry_modulus - ); - } if let Some(dedicated_compact_private_key) = dedicated_compact_private_key.as_ref() { assert_eq!( @@ -196,7 +162,6 @@ impl IntegerClientKey { Self { key, - wopbs_block_parameters, dedicated_compact_private_key, compression_key, } @@ -226,7 +191,6 @@ impl From for IntegerClientKey { Self { key, - wopbs_block_parameters: config.wopbs_block_parameters, dedicated_compact_private_key, compression_key, } @@ -237,7 +201,6 @@ impl From for IntegerClientKey { #[versionize(IntegerServerKeyVersions)] pub struct IntegerServerKey { pub(crate) key: crate::integer::ServerKey, - pub(crate) wopbs_key: Option, // Storing a KeySwitchingKeyView would require a self reference -> nightmare // Storing a KeySwitchingKey would mean cloning the ServerKey and means more memory traffic to // fetch the exact same key, so we store the part of the key that are not ServerKeys and we @@ -262,12 +225,6 @@ impl IntegerServerKey { ); let base_integer_key = crate::integer::ServerKey::new_radix_server_key(cks); - let wopbs_key = client_key - .wopbs_block_parameters - .as_ref() - .map(|wopbs_params| { - crate::integer::wopbs::WopbsKey::new_wopbs_key(cks, &base_integer_key, wopbs_params) - }); let cpk_key_switching_key_material = client_key @@ -285,7 +242,6 @@ impl IntegerServerKey { }); Self { key: base_integer_key, - wopbs_key, cpk_key_switching_key_material, compression_key, decompression_key, @@ -326,15 +282,6 @@ pub struct IntegerCompressedServerKey { impl IntegerCompressedServerKey { pub(in crate::high_level_api) fn new(client_key: &IntegerClientKey) -> Self { let cks = &client_key.key; - assert!( - client_key.wopbs_block_parameters.is_none(), - "The configuration used to create the ClientKey \ - had function evaluation on integers enabled. - This feature requires an additional key that is not - compressible. Thus, It is not possible - to create a CompressedServerKey. - " - ); let key = crate::integer::CompressedServerKey::new_radix_compressed_server_key(cks); @@ -421,7 +368,6 @@ impl IntegerCompressedServerKey { IntegerServerKey { key: self.key.decompress(), - wopbs_key: None, cpk_key_switching_key_material: self.cpk_key_switching_key_material.as_ref().map( crate::integer::key_switching_key::CompressedKeySwitchingKeyMaterial::decompress, ), diff --git a/tfhe/src/high_level_api/keys/server.rs b/tfhe/src/high_level_api/keys/server.rs index a6a16fa1fb..3875791af3 100644 --- a/tfhe/src/high_level_api/keys/server.rs +++ b/tfhe/src/high_level_api/keys/server.rs @@ -38,14 +38,12 @@ impl ServerKey { self, ) -> ( crate::integer::ServerKey, - Option, Option, Option, Option, ) { let IntegerServerKey { key, - wopbs_key, cpk_key_switching_key_material, compression_key, decompression_key, @@ -53,7 +51,6 @@ impl ServerKey { ( key, - wopbs_key, cpk_key_switching_key_material, compression_key, decompression_key, @@ -62,7 +59,6 @@ impl ServerKey { pub fn from_raw_parts( key: crate::integer::ServerKey, - wopbs_key: Option, cpk_key_switching_key_material: Option< crate::integer::key_switching_key::KeySwitchingKeyMaterial, >, @@ -72,7 +68,6 @@ impl ServerKey { Self { key: Arc::new(IntegerServerKey { key, - wopbs_key, cpk_key_switching_key_material, compression_key, decompression_key, diff --git a/tfhe/src/high_level_api/tests/mod.rs b/tfhe/src/high_level_api/tests/mod.rs index a4ea1d7b1e..33d17238d3 100644 --- a/tfhe/src/high_level_api/tests/mod.rs +++ b/tfhe/src/high_level_api/tests/mod.rs @@ -114,23 +114,6 @@ fn test_with_seed() { assert_ne!(&cks1_serialized, &cks4_serialized); } -#[test] -#[should_panic( - expected = "The configuration used to create the ClientKey had function evaluation on integers enabled. - This feature requires an additional key that is not - compressible. Thus, It is not possible - to create a CompressedServerKey. - " -)] -fn test_compressed_server_key_creation_panic_if_function_eval() { - let config = ConfigBuilder::default() - .enable_function_evaluation() - .build(); - - let cks = ClientKey::generate(config); - let _ = CompressedServerKey::new(&cks); -} - #[test] fn test_with_context() { let config = ConfigBuilder::default().build(); 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] diff --git a/tfhe/tests/backward_compatibility/high_level_api.rs b/tfhe/tests/backward_compatibility/high_level_api.rs index 3c42ca9a94..f93b21112d 100644 --- a/tfhe/tests/backward_compatibility/high_level_api.rs +++ b/tfhe/tests/backward_compatibility/high_level_api.rs @@ -267,7 +267,7 @@ pub fn test_hl_clientkey( let test_params = load_hl_params(&test.parameters); let key: ClientKey = load_and_unversionize(dir, test, format)?; - let (integer_key, _, _, _) = key.into_raw_parts(); + let (integer_key, _, _) = key.into_raw_parts(); let key_params = integer_key.parameters(); if test_params != key_params {