From 739df8656a3533f399a30a33fbbb5fc3b8e4be7c Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Wed, 4 Sep 2024 10:30:48 +0200 Subject: [PATCH] chore(data)!: breaking data changes for future compatibility - invert the LweKeyswitchKey level order and propagate change - remove dependency on unsupported wopbs keys for the HL keys --- Makefile | 2 +- .../cuda/src/crypto/keyswitch.cuh | 6 +- tfhe/Cargo.toml | 2 +- tfhe/docs/guides/data_versioning.md | 65 ----- .../core_crypto/algorithms/lwe_keyswitch.rs | 13 +- .../lwe_keyswitch_key_generation.rs | 3 - .../algorithms/lwe_packing_keyswitch.rs | 2 +- .../lwe_packing_keyswitch_key_generation.rs | 2 - .../entities/lwe_keyswitch_key.rs | 52 +++- .../entities/lwe_packing_keyswitch_key.rs | 55 +++- .../entities/seeded_lwe_keyswitch_key.rs | 22 +- .../seeded_lwe_packing_keyswitch_key.rs | 22 +- .../traits/contiguous_entity_container.rs | 11 + .../algorithms/lwe_shrinking_keyswitch.rs | 3 +- .../backward_compatibility/booleans.rs | 100 +------ .../backward_compatibility/integers.rs | 258 +----------------- .../backward_compatibility/keys.rs | 120 ++++---- .../key_switching_key.rs | 38 ++- .../list_compression.rs | 20 +- .../src/integer/backward_compatibility/mod.rs | 1 - .../backward_compatibility/server_key/mod.rs | 20 +- .../backward_compatibility/wopbs/mod.rs | 8 - tfhe/src/integer/mod.rs | 2 - tfhe/src/integer/wopbs/mod.rs | 6 +- .../key_switching_key.rs | 38 ++- .../list_compression.rs | 20 +- .../shortint/backward_compatibility/mod.rs | 1 - .../backward_compatibility/server_key/mod.rs | 20 +- .../backward_compatibility/wopbs/mod.rs | 8 - tfhe/src/shortint/wopbs/mod.rs | 6 +- .../backward_compatibility/high_level_api.rs | 140 +--------- 31 files changed, 371 insertions(+), 695 deletions(-) delete mode 100644 tfhe/src/integer/backward_compatibility/wopbs/mod.rs delete mode 100644 tfhe/src/shortint/backward_compatibility/wopbs/mod.rs diff --git a/Makefile b/Makefile index 11661bc3d3..0853c0f61b 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ BENCH_OP_FLAVOR?=DEFAULT NODE_VERSION=22.6 FORWARD_COMPAT?=OFF BACKWARD_COMPAT_DATA_URL=https://github.com/zama-ai/tfhe-backward-compat-data.git -BACKWARD_COMPAT_DATA_BRANCH?=v0.2 +BACKWARD_COMPAT_DATA_BRANCH?=v0.3 BACKWARD_COMPAT_DATA_PROJECT=tfhe-backward-compat-data BACKWARD_COMPAT_DATA_DIR=$(BACKWARD_COMPAT_DATA_PROJECT) TFHE_SPEC:=tfhe diff --git a/backends/tfhe-cuda-backend/cuda/src/crypto/keyswitch.cuh b/backends/tfhe-cuda-backend/cuda/src/crypto/keyswitch.cuh index abf3e71804..8f2f4d413e 100644 --- a/backends/tfhe-cuda-backend/cuda/src/crypto/keyswitch.cuh +++ b/backends/tfhe-cuda-backend/cuda/src/crypto/keyswitch.cuh @@ -75,7 +75,8 @@ keyswitch(Torus *lwe_array_out, const Torus *__restrict__ lwe_output_indexes, level_count); Torus state = a_i >> (sizeof(Torus) * 8 - base_log * level_count); - for (int j = 0; j < level_count; j++) { + for (int j = level_count - 1; j >= 0; j--) { + // Levels are stored in reverse order auto ksk_block = get_ith_block(ksk, i, j, lwe_dimension_out, level_count); Torus decomposed = decompose_one(state, mask_mod_b, base_log); @@ -207,7 +208,8 @@ __device__ void packing_keyswitch_lwe_ciphertext_into_glwe_ciphertext( // block of key for current lwe coefficient (cur_input_lwe[i]) auto ksk_block = &fp_ksk[i * ksk_block_size]; - for (int j = 0; j < level_count; j++) { + for (int j = level_count - 1; j >= 0; j--) { + // Levels are stored in reverse order auto ksk_glwe = &ksk_block[j * glwe_size * polynomial_size]; // Iterate through each level and multiply by the ksk piece auto ksk_glwe_chunk = &ksk_glwe[poly_id * coef_per_block]; diff --git a/tfhe/Cargo.toml b/tfhe/Cargo.toml index 8e554b5f6a..bc81211df1 100644 --- a/tfhe/Cargo.toml +++ b/tfhe/Cargo.toml @@ -46,7 +46,7 @@ hex = "0.4.3" # End regex-engine deps # Used for backward compatibility test metadata ron = "0.8" -tfhe-backward-compat-data = { git = "https://github.com/zama-ai/tfhe-backward-compat-data.git", branch = "v0.2", default-features = false, features = [ +tfhe-backward-compat-data = { git = "https://github.com/zama-ai/tfhe-backward-compat-data.git", branch = "v0.3", default-features = false, features = [ "load", ] } diff --git a/tfhe/docs/guides/data_versioning.md b/tfhe/docs/guides/data_versioning.md index feac3178b8..6e367faa8b 100644 --- a/tfhe/docs/guides/data_versioning.md +++ b/tfhe/docs/guides/data_versioning.md @@ -82,68 +82,3 @@ The `Type::unversionize()` function takes a versioned value, upgrades it to the When possible, data will be upgraded automatically without any kind of interraction. However, some changes might need information that are only known by the user of the library. These are called data breaking changes. In these occasions, **TFHE-rs** provides a way to upgrade these types manually. You will find below a list of breaking changes and how to upgrade them. - -# 0.6 -> 0.7 -- `tfhe::integer::ciphertext::CompactCiphertextList`: - in 0.6, these lists of ciphertext were statically typed and homogenous. Since 0.7, they are heterogeneous. The new version stores for each element an information about its type (Signed, Unsigned or Boolean). Since this information were not stored before, the list is set to be made of `Unsigned` integers by default. If that is not the case, you can set its type using the following snippet: - -```rust -use std::io::Cursor; -use tfhe::integer::ciphertext::{ - CompactCiphertextList, DataKind, IntegerCompactCiphertextListExpansionMode, - SignedRadixCiphertext, -}; -use tfhe::integer::{ClientKey, CompactPublicKey}; -use tfhe::shortint::parameters::classic::compact_pk::PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS; -use tfhe_versionable::{Unversionize, Versionize}; - -pub fn main() { - let fhe_params = PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_KS_PBS; - let num_blocks = 4usize; - - let serialized_data = { - let client_key = ClientKey::new(fhe_params); - let pk = CompactPublicKey::new(&client_key); - - // Encrypt a negative value - let compact_ct = CompactCiphertextList::builder(&pk).push(u8::MAX).build(); - - // Versionize the data and store it - let mut serialized_data = Vec::new(); - let versioned_client_key = client_key.versionize(); - let versioned_ct = compact_ct.versionize(); - bincode::serialize_into(&mut serialized_data, &versioned_client_key).unwrap(); - bincode::serialize_into(&mut serialized_data, &versioned_ct).unwrap(); - serialized_data - }; - - // Now load the data, after potential breaking changes in the data format - let mut serialized_data = Cursor::new(serialized_data); - let versioned_client_key = bincode::deserialize_from(&mut serialized_data).unwrap(); - let versioned_ct = bincode::deserialize_from(&mut serialized_data).unwrap(); - let client_key = ClientKey::unversionize(versioned_client_key).unwrap(); - let mut compact_ct = CompactCiphertextList::unversionize(versioned_ct).unwrap(); - - // Reinterpret the data as needed after the load, here we simulate the need to load Unsigned - // data - compact_ct - .reinterpret_data(&[DataKind::Signed(num_blocks)]) - .unwrap(); - let expander = compact_ct - .expand(IntegerCompactCiphertextListExpansionMode::NoCastingAndNoUnpacking) - .unwrap(); - let expanded = expander.get::(0).unwrap().unwrap(); - let decrypted: i8 = client_key.decrypt_signed_radix(&expanded); - // -1i8 == u8::MAX - assert_eq!(-1i8, decrypted); -} -``` - -- `tfhe::{CompactFheInt, CompactFheUint, CompactFheIntList, CompactFheUintList}`: - The types have been deprecated, they are only kept in **TFHE-rs** for backward compatibility. They can now be accessed using the `tfhe::high_level_api::backward_compatibility::integers` module. The only functionality that is still supported is to unversionize them and expand them into regular `FheInt`, `FheUint`, `Vec` and `Vec`: - -```Rust - let loaded_ct = CompactFheUint8::unversionize(versioned_ct).unwrap(); - let ct = loaded_ct.expand(); -``` - Starting with v0.7, this compact list functionality is provided by the `tfhe::CompactCiphertextList` type. diff --git a/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs b/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs index e16c29ebb7..2ebd836094 100644 --- a/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs +++ b/tfhe/src/core_crypto/algorithms/lwe_keyswitch.rs @@ -216,7 +216,8 @@ pub fn keyswitch_lwe_ciphertext_native_mod_compatible +where + C::Element: UnsignedInteger, +{ + data: C, + decomp_base_log: DecompositionBaseLog, + decomp_level_count: DecompositionLevelCount, + output_lwe_size: LweSize, + ciphertext_modulus: CiphertextModulus, +} + +impl> Upgrade> + for LweKeyswitchKeyV0 +{ + type Error = std::convert::Infallible; + + fn upgrade(self) -> Result, Self::Error> { + let Self { + data, + decomp_base_log, + decomp_level_count, + output_lwe_size, + ciphertext_modulus, + } = self; + let mut new_ksk = LweKeyswitchKey::from_container( + data, + decomp_base_log, + decomp_level_count, + output_lwe_size, + ciphertext_modulus, + ); + + // Invert levels + for mut ksk_block in new_ksk.iter_mut() { + ksk_block.reverse(); + } + + Ok(new_ksk) + } +} #[derive(VersionsDispatch)] pub enum LweKeyswitchKeyVersions where C::Element: UnsignedInteger, { - V0(LweKeyswitchKey), + V0(LweKeyswitchKeyV0), + V1(LweKeyswitchKey), } diff --git a/tfhe/src/core_crypto/backward_compatibility/entities/lwe_packing_keyswitch_key.rs b/tfhe/src/core_crypto/backward_compatibility/entities/lwe_packing_keyswitch_key.rs index 814a11fd7a..1c5ad9958a 100644 --- a/tfhe/src/core_crypto/backward_compatibility/entities/lwe_packing_keyswitch_key.rs +++ b/tfhe/src/core_crypto/backward_compatibility/entities/lwe_packing_keyswitch_key.rs @@ -1,11 +1,60 @@ -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; -use crate::core_crypto::prelude::{Container, LwePackingKeyswitchKey, UnsignedInteger}; +use crate::core_crypto::prelude::{ + CiphertextModulus, Container, ContainerMut, ContiguousEntityContainerMut, DecompositionBaseLog, + DecompositionLevelCount, GlweSize, LwePackingKeyswitchKey, PolynomialSize, UnsignedInteger, +}; + +#[derive(Version)] +pub struct LwePackingKeyswitchKeyV0 +where + C::Element: UnsignedInteger, +{ + data: C, + decomp_base_log: DecompositionBaseLog, + decomp_level_count: DecompositionLevelCount, + output_glwe_size: GlweSize, + output_polynomial_size: PolynomialSize, + ciphertext_modulus: CiphertextModulus, +} + +impl> Upgrade> + for LwePackingKeyswitchKeyV0 +{ + type Error = std::convert::Infallible; + + fn upgrade(self) -> Result, Self::Error> { + let Self { + data, + decomp_base_log, + decomp_level_count, + output_glwe_size, + output_polynomial_size, + ciphertext_modulus, + } = self; + let mut new_pksk = LwePackingKeyswitchKey::from_container( + data, + decomp_base_log, + decomp_level_count, + output_glwe_size, + output_polynomial_size, + ciphertext_modulus, + ); + + // Invert levels + for mut pksk_block in new_pksk.iter_mut() { + pksk_block.reverse(); + } + + Ok(new_pksk) + } +} #[derive(VersionsDispatch)] pub enum LwePackingKeyswitchKeyVersions where C::Element: UnsignedInteger, { - V0(LwePackingKeyswitchKey), + V0(LwePackingKeyswitchKeyV0), + V1(LwePackingKeyswitchKey), } diff --git a/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_keyswitch_key.rs b/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_keyswitch_key.rs index 822431c51f..bb9651d180 100644 --- a/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_keyswitch_key.rs +++ b/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_keyswitch_key.rs @@ -1,11 +1,29 @@ -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; use crate::core_crypto::prelude::{Container, SeededLweKeyswitchKey, UnsignedInteger}; +#[derive(Version)] +pub struct UnsupportedSeededLweKeyswitchKeyV0; + +impl> Upgrade> + for UnsupportedSeededLweKeyswitchKeyV0 +{ + type Error = crate::Error; + + fn upgrade(self) -> Result, Self::Error> { + Err(crate::Error::new( + "Unable to load SeededLweKeyswitchKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum SeededLweKeyswitchKeyVersions where C::Element: UnsignedInteger, { - V0(SeededLweKeyswitchKey), + V0(UnsupportedSeededLweKeyswitchKeyV0), + V1(SeededLweKeyswitchKey), } diff --git a/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_packing_keyswitch_key.rs b/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_packing_keyswitch_key.rs index cade040ee0..c74c492a9c 100644 --- a/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_packing_keyswitch_key.rs +++ b/tfhe/src/core_crypto/backward_compatibility/entities/seeded_lwe_packing_keyswitch_key.rs @@ -1,11 +1,29 @@ -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; use crate::core_crypto::prelude::{Container, SeededLwePackingKeyswitchKey, UnsignedInteger}; +#[derive(Version)] +pub struct UnsupportedSeededLwePackingKeyswitchKeyV0; + +impl> + Upgrade> for UnsupportedSeededLwePackingKeyswitchKeyV0 +{ + type Error = crate::Error; + + fn upgrade(self) -> Result, Self::Error> { + Err(crate::Error::new( + "Unable to load SeededLwePackingKeyswitchKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum SeededLwePackingKeyswitchKeyVersions where C::Element: UnsignedInteger, { - V0(SeededLwePackingKeyswitchKey), + V0(UnsupportedSeededLwePackingKeyswitchKeyV0), + V1(SeededLwePackingKeyswitchKey), } diff --git a/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs b/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs index 93b5697a7a..7f34cfe47e 100644 --- a/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs +++ b/tfhe/src/core_crypto/commons/traits/contiguous_entity_container.rs @@ -433,6 +433,17 @@ pub trait ContiguousEntityContainerMut: ContiguousEntityContainer + AsMut<[Self: .map(|(elt, meta)| Self::SelfMutView::<'_>::create_from(elt, meta)) } + fn reverse(&mut self) { + let entity_view_pod_size = self.get_entity_view_pod_size(); + let container = self.as_mut(); + + container.reverse(); + + for entity_slot in self.as_mut().chunks_exact_mut(entity_view_pod_size) { + entity_slot.reverse(); + } + } + fn par_iter_mut<'this>( &'this mut self, ) -> ParallelChunksExactWrappingLendingIteratorMut< diff --git a/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs b/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs index a91657f3de..04cc741054 100644 --- a/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs +++ b/tfhe/src/core_crypto/experimental/algorithms/lwe_shrinking_keyswitch.rs @@ -174,7 +174,8 @@ pub fn shrinking_keyswitch_lwe_ciphertext Result { - // This compact list might have been loaded from an homogenous compact list without type - // info - self.list - .info - .iter_mut() - .for_each(|info| *info = DataKind::Boolean); - - let hl_list = HlCompactCiphertextList { - inner: self.list, - tag: Tag::default(), - }; - let list = hl_list.expand()?; - - let block = list - .inner - .get::(0) - .map(|b| b.ok_or_else(|| Error::new("Failed to expand compact list".to_string())))??; - - let mut ciphertext = FheBool::new(block, Tag::default()); - ciphertext.ciphertext.move_to_device_of_server_key_if_set(); - Ok(ciphertext) - } -} - -#[derive(Versionize)] -#[versionize(CompactFheBoolListVersions)] -#[deprecated(since = "0.7.0", note = "Use CompactCiphertextList instead")] -pub struct CompactFheBoolList { - list: CompactCiphertextList, -} - -impl CompactFheBoolList { - /// Expand to a Vec<[FheBool]> - pub fn expand(mut self) -> Result, Error> { - // This compact list might have been loaded from an homogenous compact list without type - // info - self.list - .info - .iter_mut() - .for_each(|info| *info = DataKind::Boolean); - - let hl_list = HlCompactCiphertextList { - inner: self.list, - tag: Tag::default(), - }; - let list = hl_list.expand()?; - let len = list.len(); - - (0..len) - .map(|idx| { - let block = list - .inner - .get::(idx) - .map(|list| { - list.ok_or_else(|| Error::new("Failed to expand compact list".to_string())) - })??; - - let mut ciphertext = FheBool::new(block, Tag::default()); - ciphertext.ciphertext.move_to_device_of_server_key_if_set(); - Ok(ciphertext) - }) - .collect::, _>>() - } -} diff --git a/tfhe/src/high_level_api/backward_compatibility/integers.rs b/tfhe/src/high_level_api/backward_compatibility/integers.rs index fca57b4ab4..33302968a5 100644 --- a/tfhe/src/high_level_api/backward_compatibility/integers.rs +++ b/tfhe/src/high_level_api/backward_compatibility/integers.rs @@ -1,9 +1,7 @@ -#![allow(deprecated)] - use std::convert::Infallible; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; -use tfhe_versionable::{Upgrade, Version, Versionize, VersionsDispatch}; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; use crate::high_level_api::global_state::with_cpu_internal_keys; use crate::high_level_api::integers::*; @@ -12,14 +10,13 @@ use crate::integer::backward_compatibility::ciphertext::{ CompressedModulusSwitchedSignedRadixCiphertextTFHE06, }; use crate::integer::ciphertext::{ - BaseRadixCiphertext, BaseSignedRadixCiphertext, CompactCiphertextList, + BaseRadixCiphertext, BaseSignedRadixCiphertext, CompressedRadixCiphertext as IntegerCompressedRadixCiphertext, - CompressedSignedRadixCiphertext as IntegerCompressedSignedRadixCiphertext, DataKind, + CompressedSignedRadixCiphertext as IntegerCompressedSignedRadixCiphertext, }; -use crate::prelude::CiphertextList; use crate::shortint::ciphertext::CompressedModulusSwitchedCiphertext; use crate::shortint::{Ciphertext, ServerKey}; -use crate::{CompactCiphertextList as HlCompactCiphertextList, Error, Tag}; +use crate::Tag; use serde::{Deserialize, Serialize}; use self::signed::RadixCiphertext as SignedRadixCiphertext; @@ -152,11 +149,6 @@ pub enum FheIntVersions { V1(FheInt), } -#[derive(VersionsDispatch)] -pub enum CompactFheIntVersions { - V0(CompactFheInt), -} - #[derive(Version)] pub struct CompressedFheIntV0 where @@ -184,11 +176,6 @@ pub enum CompressedFheIntVersions { V1(CompressedFheInt), } -#[derive(VersionsDispatch)] -pub enum CompactFheIntListVersions { - V0(CompactFheIntList), -} - #[derive(Version)] pub struct FheUintV0 { pub(in crate::high_level_api) ciphertext: UnsignedRadixCiphertext, @@ -213,11 +200,6 @@ pub enum FheUintVersions { V1(FheUint), } -#[derive(VersionsDispatch)] -pub enum CompactFheUintVersions { - V0(CompactFheUint), -} - #[derive(Version)] pub struct CompressedFheUintV0 where @@ -240,235 +222,3 @@ pub enum CompressedFheUintVersions { V0(CompressedFheUintV0), V1(CompressedFheUint), } - -#[derive(VersionsDispatch)] -pub enum CompactFheUintListVersions { - V0(CompactFheUintList), -} - -// Basic support for deprecated compact list, to be able to load them and convert them to something -// else - -#[derive(Clone, Versionize)] -#[versionize(CompactFheIntVersions)] -#[deprecated(since = "0.7.0", note = "Use CompactCiphertextList instead")] -pub struct CompactFheInt { - list: CompactCiphertextList, - id: Id, -} - -impl CompactFheInt -where - Id: FheIntId, -{ - /// Expand to a [FheInt] - pub fn expand(mut self) -> Result, Error> { - // This compact list might have been loaded from an homogenous compact list without type - // info - self.list - .info - .iter_mut() - .for_each(|info| *info = DataKind::Signed(info.num_blocks())); - let hl_list = HlCompactCiphertextList { - inner: self.list, - tag: Tag::default(), - }; - let list = hl_list.expand()?; - - let ct = list - .inner - .get::(0) - .map(|list| { - list.ok_or_else(|| Error::new("Failed to expand compact list".to_string())) - })??; - Ok(FheInt::new(ct, Tag::default())) - } -} - -#[derive(Clone, Versionize)] -#[versionize(CompactFheIntListVersions)] -#[deprecated(since = "0.7.0", note = "Use CompactCiphertextList instead")] -pub struct CompactFheIntList { - list: CompactCiphertextList, - id: Id, -} - -impl CompactFheIntList -where - Id: FheIntId, -{ - /// Expand to a Vec<[FheInt]> - pub fn expand(mut self) -> Result>, Error> { - // This compact list might have been loaded from an homogenous compact list without type - // info - self.list - .info - .iter_mut() - .for_each(|info| *info = DataKind::Signed(info.num_blocks())); - - let hl_list = HlCompactCiphertextList { - inner: self.list, - tag: Tag::default(), - }; - let list = hl_list.expand()?; - - let len = list.len(); - - (0..len) - .map(|idx| { - let ct = list - .inner - .get::(idx) - .map(|list| { - list.ok_or_else(|| Error::new("Failed to expand compact list".to_string())) - })??; - Ok(FheInt::new(ct, Tag::default())) - }) - .collect::, _>>() - } -} - -#[derive(Clone, Versionize)] -#[versionize(CompactFheUintVersions)] -#[deprecated(since = "0.7.0", note = "Use CompactCiphertextList instead")] -pub struct CompactFheUint { - list: CompactCiphertextList, - id: Id, -} - -impl CompactFheUint -where - Id: FheUintId, -{ - /// Expand to a [FheUint] - pub fn expand(mut self) -> Result, Error> { - // This compact list might have been loaded from an homogenous compact list without type - // info - self.list - .info - .iter_mut() - .for_each(|info| *info = DataKind::Unsigned(info.num_blocks())); - - let hl_list = HlCompactCiphertextList { - inner: self.list, - tag: Tag::default(), - }; - let list = hl_list.expand()?; - - let ct = list - .inner - .get::(0) - .map(|ct| { - ct.ok_or_else(|| Error::new("Failed to expand compact list".to_string())) - })??; - Ok(FheUint::new(ct, Tag::default())) - } -} -#[derive(Clone, Versionize)] -#[versionize(CompactFheUintListVersions)] -#[deprecated(since = "0.7.0", note = "Use CompactCiphertextList instead")] -pub struct CompactFheUintList { - list: CompactCiphertextList, - id: Id, -} - -impl CompactFheUintList -where - Id: FheUintId, -{ - /// Expand to a Vec<[FheUint]> - pub fn expand(mut self) -> Result>, Error> { - // This compact list might have been loaded from an homogenous compact list without type - // info - self.list - .info - .iter_mut() - .for_each(|info| *info = DataKind::Unsigned(info.num_blocks())); - - let hl_list = HlCompactCiphertextList { - inner: self.list, - tag: Tag::default(), - }; - let list = hl_list.expand()?; - - let len = list.len(); - - (0..len) - .map(|idx| { - let ct = list - .inner - .get::(idx) - .map(|ct| { - ct.ok_or_else(|| Error::new("Failed to expand compact list".to_string())) - })??; - Ok(FheUint::new(ct, Tag::default())) - }) - .collect::, _>>() - } -} - -macro_rules! static_int_type { - (num_bits: $num_bits:literal,) => { - ::paste::paste! { - pub type [] = CompactFheInt<[]>; - - pub type [] = CompactFheIntList<[]>; - - pub type [] = CompactFheUint<[]>; - - pub type [] = CompactFheUintList<[]>; - } - }; -} - -static_int_type! { - num_bits: 2, -} - -static_int_type! { - num_bits: 4, -} - -static_int_type! { - num_bits: 6, -} - -static_int_type! { - num_bits: 8, -} - -static_int_type! { - num_bits: 10, -} - -static_int_type! { - num_bits: 12, -} - -static_int_type! { - num_bits: 14, -} - -static_int_type! { - num_bits: 16, -} - -static_int_type! { - num_bits: 32, -} - -static_int_type! { - num_bits: 64, -} - -static_int_type! { - num_bits: 128, -} - -static_int_type! { - num_bits: 160, -} - -static_int_type! { - num_bits: 256, -} diff --git a/tfhe/src/high_level_api/backward_compatibility/keys.rs b/tfhe/src/high_level_api/backward_compatibility/keys.rs index ae9b2e9dee..0f7d3fa50c 100644 --- a/tfhe/src/high_level_api/backward_compatibility/keys.rs +++ b/tfhe/src/high_level_api/backward_compatibility/keys.rs @@ -1,5 +1,4 @@ use crate::high_level_api::keys::*; -use crate::shortint::list_compression::{CompressionKey, CompressionPrivateKeys, DecompressionKey}; use crate::Tag; use std::convert::Infallible; use std::sync::Arc; @@ -185,41 +184,32 @@ pub(crate) enum IntegerConfigVersions { } #[derive(Version)] -pub(crate) struct IntegerClientKeyV0 { - pub(crate) key: crate::integer::ClientKey, - pub(crate) wopbs_block_parameters: Option, -} +pub struct UnsupportedIntegerClientKeyV0; #[derive(Version)] -pub(crate) struct IntegerClientKeyV1 { - pub(crate) key: crate::integer::ClientKey, - pub(crate) wopbs_block_parameters: Option, - pub(crate) dedicated_compact_private_key: Option, - pub(crate) compression_key: Option, -} +pub struct UnsupportedIntegerClientKeyV1; -impl Upgrade for IntegerClientKeyV0 { - type Error = Infallible; +impl Upgrade for UnsupportedIntegerClientKeyV0 { + type Error = crate::Error; - fn upgrade(self) -> Result { - Ok(IntegerClientKeyV1 { - key: self.key, - wopbs_block_parameters: self.wopbs_block_parameters, - dedicated_compact_private_key: None, - compression_key: None, - }) + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load IntegerClientKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) } } -impl Upgrade for IntegerClientKeyV1 { - type Error = Infallible; +impl Upgrade for UnsupportedIntegerClientKeyV1 { + type Error = crate::Error; fn upgrade(self) -> Result { - Ok(IntegerClientKeyV2 { - key: self.key, - dedicated_compact_private_key: self.dedicated_compact_private_key, - compression_key: self.compression_key, - }) + Err(crate::Error::new( + "Unable to load IntegerClientKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) } } @@ -247,52 +237,39 @@ impl Upgrade for IntegerClientKeyV2 { #[derive(VersionsDispatch)] #[allow(unused)] pub(crate) enum IntegerClientKeyVersions { - V0(IntegerClientKeyV0), - V1(IntegerClientKeyV1), + V0(UnsupportedIntegerClientKeyV0), + V1(UnsupportedIntegerClientKeyV1), V2(IntegerClientKeyV2), V3(IntegerClientKey), } #[derive(Version)] -pub struct IntegerServerKeyV0 { - pub(crate) key: crate::integer::ServerKey, - pub(crate) wopbs_key: Option, -} +pub struct UnsupportedIntegerServerKeyV0; #[derive(Version)] -pub struct IntegerServerKeyV1 { - pub(crate) key: crate::integer::ServerKey, - pub(crate) wopbs_key: Option, - pub(crate) cpk_key_switching_key_material: - Option, - pub(crate) compression_key: Option, - pub(crate) decompression_key: Option, -} +pub struct UnsupportedIntegerServerKeyV1; -impl Upgrade for IntegerServerKeyV0 { - type Error = Infallible; +impl Upgrade for UnsupportedIntegerServerKeyV0 { + type Error = crate::Error; - fn upgrade(self) -> Result { - Ok(IntegerServerKeyV1 { - key: self.key, - wopbs_key: self.wopbs_key, - cpk_key_switching_key_material: None, - compression_key: None, - decompression_key: None, - }) + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load IntegerServerKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) } } -impl Upgrade for IntegerServerKeyV1 { - type Error = Infallible; +impl Upgrade for UnsupportedIntegerServerKeyV1 { + type Error = crate::Error; fn upgrade(self) -> Result { - Ok(IntegerServerKeyV2 { - key: self.key, - cpk_key_switching_key_material: self.cpk_key_switching_key_material, - compression_key: self.compression_key, - decompression_key: self.decompression_key, - }) + Err(crate::Error::new( + "Unable to load IntegerServerKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) } } @@ -324,33 +301,30 @@ impl Upgrade for IntegerServerKeyV2 { #[derive(VersionsDispatch)] pub enum IntegerServerKeyVersions { - V0(IntegerServerKeyV0), - V1(IntegerServerKeyV1), + V0(UnsupportedIntegerServerKeyV0), + V1(UnsupportedIntegerServerKeyV1), V2(IntegerServerKeyV2), V3(IntegerServerKey), } #[derive(Version)] -pub struct IntegerCompressedServerKeyV0 { - pub(crate) key: crate::integer::CompressedServerKey, -} +pub struct UnsupportedIntegerCompressedServerKeyV0; -impl Upgrade for IntegerCompressedServerKeyV0 { - type Error = Infallible; +impl Upgrade for UnsupportedIntegerCompressedServerKeyV0 { + type Error = crate::Error; fn upgrade(self) -> Result { - Ok(IntegerCompressedServerKey { - key: self.key, - cpk_key_switching_key_material: None, - compression_key: None, - decompression_key: None, - }) + Err(crate::Error::new( + "Unable to load IntegerCompressedServerKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) } } #[derive(VersionsDispatch)] pub enum IntegerCompressedServerKeyVersions { - V0(IntegerCompressedServerKeyV0), + V0(UnsupportedIntegerCompressedServerKeyV0), V1(IntegerCompressedServerKey), } diff --git a/tfhe/src/integer/backward_compatibility/key_switching_key.rs b/tfhe/src/integer/backward_compatibility/key_switching_key.rs index 646d298228..dfed143fe9 100644 --- a/tfhe/src/integer/backward_compatibility/key_switching_key.rs +++ b/tfhe/src/integer/backward_compatibility/key_switching_key.rs @@ -1,4 +1,4 @@ -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; use crate::integer::key_switching_key::{ CompressedKeySwitchingKey, CompressedKeySwitchingKeyMaterial, KeySwitchingKey, @@ -15,12 +15,44 @@ pub enum KeySwitchingKeyVersions { V0(KeySwitchingKey), } +#[derive(Version)] +pub struct UnsupportedCompressedKeySwitchingKeyMaterialV0; + +impl Upgrade for UnsupportedCompressedKeySwitchingKeyMaterialV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedKeySwitchingKeyMaterial, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum CompressedKeySwitchingKeyMaterialVersions { - V0(CompressedKeySwitchingKeyMaterial), + V0(UnsupportedCompressedKeySwitchingKeyMaterialV0), + V1(CompressedKeySwitchingKeyMaterial), +} + +#[derive(Version)] +pub struct UnsupportedCompressedKeySwitchingKeyV0; + +impl Upgrade for UnsupportedCompressedKeySwitchingKeyV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedKeySwitchingKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } } #[derive(VersionsDispatch)] pub enum CompressedKeySwitchingKeyVersions { - V0(CompressedKeySwitchingKey), + V0(UnsupportedCompressedKeySwitchingKeyV0), + V1(CompressedKeySwitchingKey), } diff --git a/tfhe/src/integer/backward_compatibility/list_compression.rs b/tfhe/src/integer/backward_compatibility/list_compression.rs index 8ddc63a5d1..b73e8bcfa4 100644 --- a/tfhe/src/integer/backward_compatibility/list_compression.rs +++ b/tfhe/src/integer/backward_compatibility/list_compression.rs @@ -2,7 +2,7 @@ use crate::integer::compression_keys::{ CompressedCompressionKey, CompressedDecompressionKey, CompressionKey, CompressionPrivateKeys, DecompressionKey, }; -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; #[derive(VersionsDispatch)] pub enum CompressionKeyVersions { @@ -14,9 +14,25 @@ pub enum DecompressionKeyVersions { V0(DecompressionKey), } +#[derive(Version)] +pub struct UnsupportedCompressedCompressionKeyV0; + +impl Upgrade for UnsupportedCompressedCompressionKeyV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedCompressionKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum CompressedCompressionKeyVersions { - V0(CompressedCompressionKey), + V0(UnsupportedCompressedCompressionKeyV0), + V1(CompressedCompressionKey), } #[derive(VersionsDispatch)] diff --git a/tfhe/src/integer/backward_compatibility/mod.rs b/tfhe/src/integer/backward_compatibility/mod.rs index fba2e6ebee..293c904141 100644 --- a/tfhe/src/integer/backward_compatibility/mod.rs +++ b/tfhe/src/integer/backward_compatibility/mod.rs @@ -6,4 +6,3 @@ pub mod key_switching_key; pub mod list_compression; pub mod public_key; pub mod server_key; -pub mod wopbs; diff --git a/tfhe/src/integer/backward_compatibility/server_key/mod.rs b/tfhe/src/integer/backward_compatibility/server_key/mod.rs index 00e31961ea..219d5ad253 100644 --- a/tfhe/src/integer/backward_compatibility/server_key/mod.rs +++ b/tfhe/src/integer/backward_compatibility/server_key/mod.rs @@ -1,4 +1,4 @@ -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; use crate::integer::{CompressedServerKey, ServerKey}; @@ -7,7 +7,23 @@ pub enum ServerKeyVersions { V0(ServerKey), } +#[derive(Version)] +pub struct UnsupportedCompressedServerKeyV0; + +impl Upgrade for UnsupportedCompressedServerKeyV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedServerKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum CompressedServerKeyVersions { - V0(CompressedServerKey), + V0(UnsupportedCompressedServerKeyV0), + V1(CompressedServerKey), } diff --git a/tfhe/src/integer/backward_compatibility/wopbs/mod.rs b/tfhe/src/integer/backward_compatibility/wopbs/mod.rs deleted file mode 100644 index ddc0f350c7..0000000000 --- a/tfhe/src/integer/backward_compatibility/wopbs/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -use tfhe_versionable::VersionsDispatch; - -use crate::integer::wopbs::WopbsKey; - -#[derive(VersionsDispatch)] -pub enum WopbsKeyVersions { - V0(WopbsKey), -} diff --git a/tfhe/src/integer/mod.rs b/tfhe/src/integer/mod.rs index 03ae281b20..b83ed0d417 100755 --- a/tfhe/src/integer/mod.rs +++ b/tfhe/src/integer/mod.rs @@ -65,8 +65,6 @@ pub mod public_key; pub mod server_key; #[cfg(feature = "experimental")] pub mod wopbs; -#[cfg(not(feature = "experimental"))] -pub(crate) mod wopbs; #[cfg(feature = "gpu")] pub mod gpu; diff --git a/tfhe/src/integer/wopbs/mod.rs b/tfhe/src/integer/wopbs/mod.rs index a9f468fd7d..a3fee243c8 100644 --- a/tfhe/src/integer/wopbs/mod.rs +++ b/tfhe/src/integer/wopbs/mod.rs @@ -6,13 +6,9 @@ #[cfg(all(test, feature = "experimental"))] mod test; -use super::backward_compatibility::wopbs::WopbsKeyVersions; - use serde::{Deserialize, Serialize}; -use tfhe_versionable::Versionize; -#[derive(Clone, Serialize, Deserialize, Versionize)] -#[versionize(WopbsKeyVersions)] +#[derive(Clone, Serialize, Deserialize)] pub struct WopbsKey { wopbs_key: crate::shortint::wopbs::WopbsKey, } diff --git a/tfhe/src/shortint/backward_compatibility/key_switching_key.rs b/tfhe/src/shortint/backward_compatibility/key_switching_key.rs index 7686a21153..9a8d933fab 100644 --- a/tfhe/src/shortint/backward_compatibility/key_switching_key.rs +++ b/tfhe/src/shortint/backward_compatibility/key_switching_key.rs @@ -1,4 +1,4 @@ -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; use crate::shortint::key_switching_key::{ CompressedKeySwitchingKeyMaterial, KeySwitchingKeyMaterial, @@ -15,12 +15,44 @@ pub enum KeySwitchingKeyVersions { V0(KeySwitchingKey), } +#[derive(Version)] +pub struct UnsupportedCompressedKeySwitchingKeyMaterialV0; + +impl Upgrade for UnsupportedCompressedKeySwitchingKeyMaterialV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedKeySwitchingKeyMaterial, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum CompressedKeySwitchingKeyMaterialVersions { - V0(CompressedKeySwitchingKeyMaterial), + V0(UnsupportedCompressedKeySwitchingKeyMaterialV0), + V1(CompressedKeySwitchingKeyMaterial), +} + +#[derive(Version)] +pub struct UnsupportedCompressedKeySwitchingKeyV0; + +impl Upgrade for UnsupportedCompressedKeySwitchingKeyV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedKeySwitchingKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } } #[derive(VersionsDispatch)] pub enum CompressedKeySwitchingKeyVersions { - V0(CompressedKeySwitchingKey), + V0(UnsupportedCompressedKeySwitchingKeyV0), + V1(CompressedKeySwitchingKey), } diff --git a/tfhe/src/shortint/backward_compatibility/list_compression.rs b/tfhe/src/shortint/backward_compatibility/list_compression.rs index 5f2a129d57..a5959a16c3 100644 --- a/tfhe/src/shortint/backward_compatibility/list_compression.rs +++ b/tfhe/src/shortint/backward_compatibility/list_compression.rs @@ -1,4 +1,4 @@ -use tfhe_versionable::VersionsDispatch; +use tfhe_versionable::{Upgrade, Version, VersionsDispatch}; use crate::shortint::list_compression::{ CompressedCompressionKey, CompressedDecompressionKey, CompressionKey, CompressionPrivateKeys, @@ -15,9 +15,25 @@ pub enum DecompressionKeyVersions { V0(DecompressionKey), } +#[derive(Version)] +pub struct UnsupportedCompressedCompressionKeyV0; + +impl Upgrade for UnsupportedCompressedCompressionKeyV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedCompressionKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum CompressedCompressionKeyVersions { - V0(CompressedCompressionKey), + V0(UnsupportedCompressedCompressionKeyV0), + V1(CompressedCompressionKey), } #[derive(VersionsDispatch)] diff --git a/tfhe/src/shortint/backward_compatibility/mod.rs b/tfhe/src/shortint/backward_compatibility/mod.rs index 15e371dbbf..7fd49a6fe6 100644 --- a/tfhe/src/shortint/backward_compatibility/mod.rs +++ b/tfhe/src/shortint/backward_compatibility/mod.rs @@ -7,4 +7,3 @@ pub mod list_compression; pub mod parameters; pub mod public_key; pub mod server_key; -pub mod wopbs; diff --git a/tfhe/src/shortint/backward_compatibility/server_key/mod.rs b/tfhe/src/shortint/backward_compatibility/server_key/mod.rs index fa89f6f2eb..03ae0cfc05 100644 --- a/tfhe/src/shortint/backward_compatibility/server_key/mod.rs +++ b/tfhe/src/shortint/backward_compatibility/server_key/mod.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use tfhe_versionable::{UnversionizeError, VersionsDispatch}; +use tfhe_versionable::{UnversionizeError, Upgrade, Version, VersionsDispatch}; use crate::core_crypto::prelude::{Container, IntoContainerOwned}; use crate::shortint::server_key::*; @@ -58,7 +58,23 @@ pub enum ShortintCompressedBootstrappingKeyVersions { V0(ShortintCompressedBootstrappingKey), } +#[derive(Version)] +pub struct UnsupportedCompressedServerKeyV0; + +impl Upgrade for UnsupportedCompressedServerKeyV0 { + type Error = crate::Error; + + fn upgrade(self) -> Result { + Err(crate::Error::new( + "Unable to load CompressedServerKey, \ + this format is unsupported by this TFHE-rs version." + .to_string(), + )) + } +} + #[derive(VersionsDispatch)] pub enum CompressedServerKeyVersions { - V0(CompressedServerKey), + V0(UnsupportedCompressedServerKeyV0), + V1(CompressedServerKey), } diff --git a/tfhe/src/shortint/backward_compatibility/wopbs/mod.rs b/tfhe/src/shortint/backward_compatibility/wopbs/mod.rs deleted file mode 100644 index 8426b1da1b..0000000000 --- a/tfhe/src/shortint/backward_compatibility/wopbs/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -use tfhe_versionable::VersionsDispatch; - -use crate::shortint::wopbs::WopbsKey; - -#[derive(VersionsDispatch)] -pub enum WopbsKeyVersions { - V0(WopbsKey), -} diff --git a/tfhe/src/shortint/wopbs/mod.rs b/tfhe/src/shortint/wopbs/mod.rs index dbcfea1e45..8ba6fcceba 100644 --- a/tfhe/src/shortint/wopbs/mod.rs +++ b/tfhe/src/shortint/wopbs/mod.rs @@ -11,16 +11,12 @@ use crate::core_crypto::entities::*; use crate::shortint::{ServerKey, WopbsParameters}; use serde::{Deserialize, Serialize}; -use tfhe_versionable::Versionize; - -use super::backward_compatibility::wopbs::WopbsKeyVersions; #[cfg(all(test, feature = "experimental"))] mod test; // Struct for WoPBS based on the private functional packing keyswitch. -#[derive(Clone, Debug, Serialize, Deserialize, Versionize)] -#[versionize(WopbsKeyVersions)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct WopbsKey { //Key for the private functional keyswitch pub wopbs_server_key: ServerKey, diff --git a/tfhe/tests/backward_compatibility/high_level_api.rs b/tfhe/tests/backward_compatibility/high_level_api.rs index bf274b04e8..9a74682d97 100644 --- a/tfhe/tests/backward_compatibility/high_level_api.rs +++ b/tfhe/tests/backward_compatibility/high_level_api.rs @@ -1,11 +1,6 @@ -#![allow(deprecated)] +use super::shortint::load_params; +use crate::{load_and_unversionize, TestedModule}; use std::path::Path; - -use tfhe::backward_compatibility::booleans::{CompactFheBool, CompactFheBoolList}; -use tfhe::backward_compatibility::integers::{ - CompactFheInt8, CompactFheInt8List, CompactFheUint8, CompactFheUint8List, -}; - use tfhe::prelude::{CiphertextList, FheDecrypt, FheEncrypt}; use tfhe::shortint::PBSParameters; #[cfg(feature = "zk-pok")] @@ -21,17 +16,12 @@ use tfhe_backward_compat_data::load::{ load_versioned_auxiliary, DataFormat, TestFailure, TestResult, TestSuccess, }; use tfhe_backward_compat_data::{ - DataKind, HlBoolCiphertextListTest, HlBoolCiphertextTest, HlCiphertextListTest, - HlCiphertextTest, HlClientKeyTest, HlHeterogeneousCiphertextListTest, HlPublicKeyTest, - HlServerKeyTest, HlSignedCiphertextListTest, HlSignedCiphertextTest, TestMetadata, - TestParameterSet, TestType, Testcase, ZkPkePublicParamsTest, + DataKind, HlBoolCiphertextTest, HlCiphertextTest, HlClientKeyTest, + HlHeterogeneousCiphertextListTest, HlPublicKeyTest, HlServerKeyTest, HlSignedCiphertextTest, + TestMetadata, TestParameterSet, TestType, Testcase, ZkPkePublicParamsTest, }; use tfhe_versionable::Unversionize; -use crate::{load_and_unversionize, TestedModule}; - -use super::shortint::load_params; - fn load_hl_params(test_params: &TestParameterSet) -> PBSParameters { let pbs_params = load_params(test_params); @@ -57,9 +47,6 @@ pub fn test_hl_ciphertext( let ct = if test.compressed { let compressed: CompressedFheUint8 = load_and_unversionize(dir, test, format)?; compressed.decompress() - } else if test.compact { - let compact: CompactFheUint8 = load_and_unversionize(dir, test, format)?; - compact.expand().unwrap() } else { load_and_unversionize(dir, test, format)? }; @@ -98,9 +85,6 @@ pub fn test_hl_signed_ciphertext( let ct = if test.compressed { let compressed: CompressedFheInt8 = load_and_unversionize(dir, test, format)?; compressed.decompress() - } else if test.compact { - let compact: CompactFheInt8 = load_and_unversionize(dir, test, format)?; - compact.expand().unwrap() } else { load_and_unversionize(dir, test, format)? }; @@ -139,9 +123,6 @@ pub fn test_hl_bool_ciphertext( let ct = if test.compressed { let compressed: CompressedFheBool = load_and_unversionize(dir, test, format)?; compressed.decompress() - } else if test.compact { - let compact: CompactFheBool = load_and_unversionize(dir, test, format)?; - compact.expand().unwrap() } else { load_and_unversionize(dir, test, format)? }; @@ -161,108 +142,6 @@ pub fn test_hl_bool_ciphertext( } } -/// Test HL ciphertext list: loads the ciphertext list and compare the decrypted values to the ones -/// in the metadata. -pub fn test_hl_ciphertext_list( - dir: &Path, - test: &HlCiphertextListTest, - format: DataFormat, -) -> Result { - let key_file = dir.join(&*test.key_filename); - let key = ClientKey::unversionize( - load_versioned_auxiliary(key_file).map_err(|e| test.failure(e, format))?, - ) - .map_err(|e| test.failure(e, format))?; - - let server_key = key.generate_server_key(); - set_server_key(server_key); - - let compact: CompactFheUint8List = load_and_unversionize(dir, test, format)?; - let ct_list = compact.expand().unwrap(); - - let clear_list: Vec = ct_list.into_iter().map(|ct| ct.decrypt(&key)).collect(); - let ref_values: Vec = test.clear_values.iter().map(|v| *v as u8).collect(); - if clear_list != ref_values { - Err(test.failure( - format!( - "Invalid {} decrypted cleartext:\n Expected :\n{:?}\nGot:\n{:?}", - format, clear_list, ref_values - ), - format, - )) - } else { - Ok(test.success(format)) - } -} - -/// Test HL signed ciphertext list: loads the ciphertext list and compare the decrypted values to -/// the ones in the metadata. -pub fn test_hl_signed_ciphertext_list( - dir: &Path, - test: &HlSignedCiphertextListTest, - format: DataFormat, -) -> Result { - let key_file = dir.join(&*test.key_filename); - let key = ClientKey::unversionize( - load_versioned_auxiliary(key_file).map_err(|e| test.failure(e, format))?, - ) - .map_err(|e| test.failure(e, format))?; - - let server_key = key.generate_server_key(); - set_server_key(server_key); - - let compact: CompactFheInt8List = load_and_unversionize(dir, test, format)?; - let ct_list = compact.expand().unwrap(); - - let clear_list: Vec = ct_list.into_iter().map(|ct| ct.decrypt(&key)).collect(); - let ref_values: Vec = test.clear_values.iter().map(|v| *v as i8).collect(); - if clear_list != ref_values { - Err(test.failure( - format!( - "Invalid {} decrypted cleartext:\n Expected :\n{:?}\nGot:\n{:?}", - format, clear_list, ref_values - ), - format, - )) - } else { - Ok(test.success(format)) - } -} - -/// Test HL bool ciphertext list: loads the ciphertext list and compare the decrypted values to the -/// ones in the metadata. -pub fn test_hl_bool_ciphertext_list( - dir: &Path, - test: &HlBoolCiphertextListTest, - format: DataFormat, -) -> Result { - let key_file = dir.join(&*test.key_filename); - let key = ClientKey::unversionize( - load_versioned_auxiliary(key_file).map_err(|e| test.failure(e, format))?, - ) - .map_err(|e| test.failure(e, format))?; - - let server_key = key.generate_server_key(); - set_server_key(server_key); - - let compact: CompactFheBoolList = load_and_unversionize(dir, test, format)?; - let ct_list = compact.expand().unwrap(); - - let clear_list: Vec = ct_list.into_iter().map(|ct| ct.decrypt(&key)).collect(); - let ref_values: Vec = test.clear_values.iter().copied().collect(); - if clear_list != ref_values { - Err(test.failure( - format!( - "Invalid {} decrypted cleartext:\n Expected :\n{:?}\nGot:\n{:?}", - format, clear_list, ref_values - ), - format, - )) - } else { - Ok(test.success(format)) - } -} - /// Test Zk Public params pub fn test_zk_params( dir: &Path, @@ -520,15 +399,6 @@ impl TestedModule for Hl { TestMetadata::HlBoolCiphertext(test) => { test_hl_bool_ciphertext(test_dir.as_ref(), test, format).into() } - TestMetadata::HlBoolCiphertextList(test) => { - test_hl_bool_ciphertext_list(test_dir.as_ref(), test, format).into() - } - TestMetadata::HlCiphertextList(test) => { - test_hl_ciphertext_list(test_dir.as_ref(), test, format).into() - } - TestMetadata::HlSignedCiphertextList(test) => { - test_hl_signed_ciphertext_list(test_dir.as_ref(), test, format).into() - } TestMetadata::HlHeterogeneousCiphertextList(test) => { test_hl_heterogeneous_ciphertext_list(test_dir.as_ref(), test, format).into() }