diff --git a/Cargo.lock b/Cargo.lock index e125a2d..c88ce21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -214,6 +214,16 @@ dependencies = [ "rayon", ] +[[package]] +name = "concrete-csprng" +version = "0.4.1" +source = "git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs#62ec37221312b6a20ee80b28051224be5aec16a1" +dependencies = [ + "aes", + "libc", + "rayon", +] + [[package]] name = "concrete-fft" version = "0.5.1" @@ -689,7 +699,7 @@ dependencies = [ "aligned-vec", "bincode", "bytemuck", - "concrete-csprng", + "concrete-csprng 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "concrete-fft", "concrete-ntt", "dyn-stack", @@ -700,8 +710,8 @@ dependencies = [ "rayon", "serde", "sha3", - "tfhe-versionable", - "tfhe-zk-pok", + "tfhe-versionable 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tfhe-zk-pok 0.3.2", ] [[package]] @@ -713,7 +723,7 @@ dependencies = [ "aligned-vec", "bincode", "bytemuck", - "concrete-csprng", + "concrete-csprng 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "concrete-fft", "concrete-ntt", "dyn-stack", @@ -724,8 +734,31 @@ dependencies = [ "rayon", "serde", "sha3", - "tfhe-versionable", - "tfhe-zk-pok", + "tfhe-versionable 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tfhe-zk-pok 0.3.2", +] + +[[package]] +name = "tfhe" +version = "0.11.0" +source = "git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs#62ec37221312b6a20ee80b28051224be5aec16a1" +dependencies = [ + "aligned-vec", + "bincode", + "bytemuck", + "concrete-csprng 0.4.1 (git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs)", + "concrete-fft", + "concrete-ntt", + "dyn-stack", + "itertools 0.11.0", + "paste", + "pulp", + "rand_core", + "rayon", + "serde", + "sha3", + "tfhe-versionable 0.3.2 (git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs)", + "tfhe-zk-pok 0.3.1", ] [[package]] @@ -806,8 +839,10 @@ dependencies = [ "serde", "strum", "tfhe 0.10.0", + "tfhe 0.11.0", "tfhe 0.8.7", - "tfhe-versionable", + "tfhe-versionable 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tfhe-versionable 0.3.2 (git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs)", ] [[package]] @@ -819,7 +854,18 @@ dependencies = [ "aligned-vec", "num-complex", "serde", - "tfhe-versionable-derive", + "tfhe-versionable-derive 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tfhe-versionable" +version = "0.3.2" +source = "git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs#62ec37221312b6a20ee80b28051224be5aec16a1" +dependencies = [ + "aligned-vec", + "num-complex", + "serde", + "tfhe-versionable-derive 0.3.2 (git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs)", ] [[package]] @@ -833,6 +879,34 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "tfhe-versionable-derive" +version = "0.3.2" +source = "git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs#62ec37221312b6a20ee80b28051224be5aec16a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "tfhe-zk-pok" +version = "0.3.1" +source = "git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs#62ec37221312b6a20ee80b28051224be5aec16a1" +dependencies = [ + "num-bigint", + "rand", + "rayon", + "serde", + "sha3", + "tfhe-ark-bls12-381", + "tfhe-ark-ec", + "tfhe-ark-ff", + "tfhe-ark-poly", + "tfhe-versionable 0.3.2 (git+https://github.com/zama-ai/tfhe-rs/?branch=ns/rename_pp_crs)", + "zeroize", +] + [[package]] name = "tfhe-zk-pok" version = "0.3.2" @@ -848,7 +922,7 @@ dependencies = [ "tfhe-ark-ec", "tfhe-ark-ff", "tfhe-ark-poly", - "tfhe-versionable", + "tfhe-versionable 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index 98af2b8..a1a2678 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,9 +25,18 @@ tfhe_0_10 = { version = "0.10", features = [ "zk-pok", "experimental-force_fft_algo_dif4", ], package = "tfhe", optional = true } +tfhe_0_11 = { version = "0.11", features = [ + "boolean", + "integer", + "shortint", + "x86_64-unix", + "zk-pok", + "experimental-force_fft_algo_dif4", +], package = "tfhe", optional = true, git = "https://github.com/zama-ai/tfhe-rs/", branch = "ns/rename_pp_crs" } # TFHE-rs 0.8 and 0.10 use the same version of versionable tfhe-versionable = { version = "0.3.2", optional = true } +tfhe_0_11-versionable = { version = "0.3.2", optional = true, package = "tfhe-versionable", git = "https://github.com/zama-ai/tfhe-rs/", branch = "ns/rename_pp_crs" } # other deps serde = { version = "1.0", features = ["derive"] } @@ -47,6 +56,8 @@ default = ["generate"] generate = [ "dep:tfhe_0_8", "dep:tfhe_0_10", + "dep:tfhe_0_11", "dep:tfhe-versionable", + "dep:tfhe_0_11-versionable", ] load = ["dep:semver"] diff --git a/data/0_11/high_level_api/zk_pke_crs.bcode b/data/0_11/high_level_api/zk_pke_crs.bcode new file mode 100644 index 0000000..58cac0e --- /dev/null +++ b/data/0_11/high_level_api/zk_pke_crs.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8266d6a67a066d8fc4293fd585ca47a2d37aaf1f92f2529188f56a5c41cee650 +size 71361608 diff --git a/data/0_11/high_level_api/zk_pke_crs.cbor b/data/0_11/high_level_api/zk_pke_crs.cbor new file mode 100644 index 0000000..bd00e9b --- /dev/null +++ b/data/0_11/high_level_api/zk_pke_crs.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e97570c813f155afd26e67fd1ddd6da9c36ba27927f6e2afb1c98c39de051cfb +size 83628033 diff --git a/data/high_level_api.ron b/data/high_level_api.ron index cb13d4f..f0b4142 100644 --- a/data/high_level_api.ron +++ b/data/high_level_api.ron @@ -366,4 +366,17 @@ compressed: false, )), ), + ( + tfhe_version_min: "0.11", + tfhe_module: "high_level_api", + metadata: ZkPkePublicParams(( + test_filename: "zk_pke_crs", + lwe_dimension: 2048, + max_num_cleartext: 16, + noise_bound: 46, + ciphertext_modulus: 18446744073709551616, + plaintext_modulus: 32, + padding_bit_count: 1, + )), + ), ] \ No newline at end of file diff --git a/src/data_0_11.rs b/src/data_0_11.rs new file mode 100644 index 0000000..f90c860 --- /dev/null +++ b/src/data_0_11.rs @@ -0,0 +1,137 @@ +use crate::generate::{ + store_versioned_test_tfhe_011, TfhersVersion, PRNG_SEED, VALID_TEST_PARAMS_TUNIFORM, +}; +use crate::{ + TestDistribution, TestMetadata, TestParameterSet, ZkPkePublicParamsTest, HL_MODULE_NAME, +}; +use std::{borrow::Cow, fs::create_dir_all}; +use tfhe_0_11::core_crypto::commons::math::random::RandomGenerator; +use tfhe_0_11::core_crypto::prelude::TUniform; +use tfhe_0_11::zk::{CompactPkeCrs, ZkMSBZeroPaddingBitCount}; +use tfhe_0_11::{ + boolean::engine::BooleanEngine, + core_crypto::commons::generators::DeterministicSeeder, + core_crypto::commons::math::random::ActivatedRandomGenerator, + shortint::engine::ShortintEngine, + shortint::parameters::{ + CarryModulus, CiphertextModulus, ClassicPBSParameters, DecompositionBaseLog, + DecompositionLevelCount, DynamicDistribution, EncryptionKeyChoice, GlweDimension, + LweDimension, MaxNoiseLevel, MessageModulus, PBSParameters, PolynomialSize, StandardDev, + }, + Seed, +}; + +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_tfhe_011($msg, $dir, $test_filename) + }; +} + +impl From for DynamicDistribution { + fn from(value: TestDistribution) -> Self { + match value { + TestDistribution::Gaussian { stddev } => { + DynamicDistribution::new_gaussian_from_std_dev(StandardDev(stddev)) + } + TestDistribution::TUniform { bound_log2 } => { + DynamicDistribution::new_t_uniform(bound_log2) + } + } + } +} + +impl From for ClassicPBSParameters { + fn from(value: TestParameterSet) -> Self { + ClassicPBSParameters { + lwe_dimension: LweDimension(value.lwe_dimension), + glwe_dimension: GlweDimension(value.glwe_dimension), + polynomial_size: PolynomialSize(value.polynomial_size), + lwe_noise_distribution: value.lwe_noise_distribution.into(), + glwe_noise_distribution: value.glwe_noise_distribution.into(), + pbs_base_log: DecompositionBaseLog(value.pbs_base_log), + pbs_level: DecompositionLevelCount(value.pbs_level), + ks_base_log: DecompositionBaseLog(value.ks_base_log), + ks_level: DecompositionLevelCount(value.ks_level), + message_modulus: MessageModulus(value.message_modulus), + carry_modulus: CarryModulus(value.carry_modulus), + max_noise_level: MaxNoiseLevel::new(value.max_noise_level), + log2_p_fail: value.log2_p_fail, + ciphertext_modulus: CiphertextModulus::try_new(value.ciphertext_modulus).unwrap(), + encryption_key_choice: { + match &*value.encryption_key_choice { + "big" => EncryptionKeyChoice::Big, + "small" => EncryptionKeyChoice::Small, + _ => panic!("Invalid encryption key choice"), + } + }, + } + } +} + +impl From for PBSParameters { + fn from(value: TestParameterSet) -> Self { + let tmp: ClassicPBSParameters = value.into(); + tmp.into() + } +} + +// The CRS is structurally equivalent to the public params type so we reuse the test +const ZK_PKE_CRS_TEST: ZkPkePublicParamsTest = ZkPkePublicParamsTest { + test_filename: Cow::Borrowed("zk_pke_crs"), + lwe_dimension: VALID_TEST_PARAMS_TUNIFORM.polynomial_size + * VALID_TEST_PARAMS_TUNIFORM.glwe_dimension, // Lwe dimension of the "big" key is glwe dimension * polynomial size + max_num_cleartext: 16, + noise_bound: match VALID_TEST_PARAMS_TUNIFORM.lwe_noise_distribution { + TestDistribution::Gaussian { .. } => unreachable!(), + TestDistribution::TUniform { bound_log2 } => bound_log2 as usize, + }, + ciphertext_modulus: VALID_TEST_PARAMS_TUNIFORM.ciphertext_modulus, + plaintext_modulus: VALID_TEST_PARAMS_TUNIFORM.message_modulus + * VALID_TEST_PARAMS_TUNIFORM.carry_modulus + * 2, // *2 for padding bit + padding_bit_count: 1, +}; + +pub struct V0_11; + +impl TfhersVersion for V0_11 { + const VERSION_NUMBER: &'static str = "0.11"; + + fn seed_prng(seed: u128) { + let mut seeder = DeterministicSeeder::::new(Seed(seed)); + let shortint_engine = ShortintEngine::new_from_seeder(&mut seeder); + ShortintEngine::with_thread_local_mut(|local_engine| { + let _ = std::mem::replace(local_engine, shortint_engine); + }); + + let boolean_engine = BooleanEngine::new_from_seeder(&mut seeder); + BooleanEngine::replace_thread_local(boolean_engine); + } + + fn gen_shortint_data() -> Vec { + Vec::new() + } + + fn gen_hl_data() -> Vec { + let dir = Self::data_dir().join(HL_MODULE_NAME); + create_dir_all(&dir).unwrap(); + + let mut zk_rng: RandomGenerator = + RandomGenerator::new(Seed(PRNG_SEED)); + + let crs = CompactPkeCrs::new( + LweDimension(ZK_PKE_CRS_TEST.lwe_dimension), + ZK_PKE_CRS_TEST.max_num_cleartext, + TUniform::::new(ZK_PKE_CRS_TEST.noise_bound as u32), + CiphertextModulus::new(ZK_PKE_CRS_TEST.ciphertext_modulus), + ZK_PKE_CRS_TEST.plaintext_modulus as u64, + ZkMSBZeroPaddingBitCount(ZK_PKE_CRS_TEST.padding_bit_count as u64), + &mut zk_rng, + ) + .unwrap(); + + store_versioned_test!(&crs, &dir, &ZK_PKE_CRS_TEST.test_filename,); + + vec![TestMetadata::ZkPkePublicParams(ZK_PKE_CRS_TEST)] + } +} diff --git a/src/generate.rs b/src/generate.rs index e305a45..9eb4bf8 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -6,6 +6,7 @@ use std::{ use bincode::Options; use serde::Serialize; +use tfhe_0_11_versionable::Versionize as VersionizeTfhe011; use tfhe_versionable::Versionize as VersionizeTfhe010; use tfhe_versionable::Versionize as VersionizeTfhe08; @@ -163,6 +164,7 @@ macro_rules! define_store_versioned_test_fn { } define_store_versioned_test_fn!(store_versioned_test_tfhe_08, VersionizeTfhe08); define_store_versioned_test_fn!(store_versioned_test_tfhe_010, VersionizeTfhe010); +define_store_versioned_test_fn!(store_versioned_test_tfhe_011, VersionizeTfhe011); /// Stores the auxiliary data in `dir`, encoded in cbor, using the right tfhe-versionable version macro_rules! define_store_versioned_auxiliary_fn { diff --git a/src/lib.rs b/src/lib.rs index d9ec1d4..81006d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "generate")] pub mod data_0_10; #[cfg(feature = "generate")] +pub mod data_0_11; +#[cfg(feature = "generate")] pub mod data_0_8; #[cfg(feature = "generate")] pub mod generate; diff --git a/src/main.rs b/src/main.rs index 6ab78aa..e5c93fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use std::fs::remove_dir_all; use tfhe_backward_compat_data::{ data_0_10::V0_10, + data_0_11::V0_11, data_0_8::V0_8, data_dir, generate::{store_metadata, TfhersVersion, PRNG_SEED}, @@ -39,6 +40,7 @@ fn main() { let mut testcases = gen_all_data::(); testcases.extend(gen_all_data::()); + testcases.extend(gen_all_data::()); let shortint_testcases: Vec = testcases .iter()