wip: show instantiated template for 1.5

This commit is contained in:
Nicolas Sarlin
2025-10-15 10:37:26 +02:00
parent 8ad8279a91
commit 9a3c5a531b
5 changed files with 204 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "tfhe"
version = "1.4.0"
version = "1.5.0"
edition = "2021"
readme = "../README.md"
keywords = ["fully", "homomorphic", "encryption", "fhe", "cryptography"]

View File

@@ -0,0 +1,30 @@
[package]
name = "generate_1_5"
edition = "2024"
license.workspace = true
version.workspace = true
[dependencies]
clap.workspace = true
# TFHE-rs
tfhe = { features = [
"boolean",
"integer",
"shortint",
"zk-pok",
"experimental-force_fft_algo_dif4",
], path = "../../../../tfhe" }
tfhe-versionable = { path = "../../../tfhe-versionable" }
# Uncomment this and remove the lines above once the current tfhe-rs version has been released
# tfhe = { git = "https://github.com/zama-ai/tfhe-rs.git", tag = "tfhe-rs-1.5.0", features = [
# "boolean",
# "integer",
# "shortint",
# "zk-pok",
# "experimental-force_fft_algo_dif4",
# ] }
# tfhe-versionable = { git = "https://github.com/zama-ai/tfhe-rs.git", tag = "tfhe-rs-1.5.0" }
tfhe-backward-compat-data = { path = "../.." }

View File

@@ -0,0 +1,102 @@
mod utils;
use utils::*;
use std::fs::create_dir_all;
use std::path::Path;
use tfhe_backward_compat_data::generate::*;
use tfhe_backward_compat_data::*;
// <TODO> To complete this file, you can use examples in the data generation crates for
// <TODO> other versions.
// <TODO> Here you can add constants that defines the metadata for your data tests.
// <TODO> The metadata should use one of the types inside the `TestMetadata` enum in
// <TODO> `tfhe-backward-compat-data/src/lib.rs`.
// <TODO> Feel free to add a new variant if none of the existing one cover your needs.
// <TODO>
// <TODO> Example:
// <TODO> const SHORTINT_CLIENT_KEY_FILENAME: &str = "client_key";
// <TODO>
// <TODO> const SHORTINT_CLIENTKEY_TEST: ShortintClientKeyTest = ShortintClientKeyTest {
// <TODO> test_filename: Cow::Borrowed(SHORTINT_CLIENT_KEY_FILENAME),
// <TODO> parameters: VALID_TEST_PARAMS,
// <TODO> };
// <TODO> const SHORTINT_CT_TEST: ShortintCiphertextTest = ShortintCiphertextTest {
// <TODO> test_filename: Cow::Borrowed("ct"),
// <TODO> key_filename: Cow::Borrowed(SHORTINT_CLIENT_KEY_FILENAME),
// <TODO> clear_value: 0,
// <TODO> };
pub struct V1_5;
impl TfhersVersion for V1_5 {
const VERSION_NUMBER: &'static str = "1.5";
fn seed_prng(seed: u128) {
// <TODO> Include here the code required to seed the prng for this version of TFHE-rs.
// <TODO> This might require: seeding shortint and boolean engines
// <TODO>
// <TODO> Example:
// <TODO> let mut seeder = DeterministicSeeder::<DefaultRandomGenerator>::new(Seed(seed));
// <TODO> let shortint_engine = ShortintEngine::new_from_seeder(&mut seeder);
// <TODO> ShortintEngine::with_thread_local_mut(|local_engine| {
// <TODO> let _ = std::mem::replace(local_engine, shortint_engine);
// <TODO> });
// <TODO>
// <TODO> let boolean_engine = BooleanEngine::new_from_seeder(&mut seeder);
// <TODO> BooleanEngine::replace_thread_local(boolean_engine);
todo!()
}
// <TODO> You now need to generate the data for the shortint and hl layer. This means:
// <TODO> - Create the TFHE-rs objects you want to test from the metadata defined above
// <TODO> - Store them using `store_versioned_test`
// <TODO> - If the test needs some auxiliary data (such as a client key), store it with
// <TODO> `store_versioned_auxiliary`
// <TODO> - Returns all the metadata in a Vec
// <TODO>
// <TODO> Example:
// <TODO> fn gen_shortint_data<P: AsRef<Path>>(base_data_dir: P) -> Vec<TestMetadata> {
// <TODO> let dir = Self::data_dir(base_data_dir).join(SHORTINT_MODULE_NAME);
// <TODO> create_dir_all(&dir).unwrap();
// <TODO>
// <TODO> // generate a client key
// <TODO> let shortint_client_key =
// <TODO> shortint::ClientKey::new(SHORTINT_CLIENTKEY_TEST.parameters.convert());
// <TODO>
// <TODO> store_versioned_test(
// <TODO> &shortint_client_key,
// <TODO> &dir,
// <TODO> &SHORTINT_CLIENTKEY_TEST.test_filename,
// <TODO> );
// <TODO>
// <TODO> // generate a ciphertext
// <TODO> let ct = shortint_client_key.encrypt(SHORTINT_CT_TEST.clear_value);
// <TODO>
// <TODO> // Serialize it
// <TODO> store_versioned_test(&ct, &dir, &SHORTINT_CT_TEST.test_filename);
// <TODO>
// <TODO> vec![
// <TODO> TestMetadata::ShortintClientKey(SHORTINT_CLIENTKEY_TEST),
// <TODO> TestMetadata::ShortintCiphertext(SHORTINT_CT_TEST),
// <TODO> ]
// <TODO> }
fn gen_shortint_data<P: AsRef<Path>>(base_data_dir: P) -> Vec<TestMetadata> {
// <TODO> Remove this if you do not generate shortint data for this version
let dir = Self::data_dir(base_data_dir).join(SHORTINT_MODULE_NAME);
create_dir_all(&dir).unwrap();
// <TODO> Add shortint data here
Vec::new()
}
fn gen_hl_data<P: AsRef<Path>>(base_data_dir: P) -> Vec<TestMetadata> {
// <TODO> Remove this if you do not generate hl data for this version
let dir = Self::data_dir(base_data_dir).join(HL_MODULE_NAME);
create_dir_all(&dir).unwrap();
// <TODO> Add hl data here
Vec::new()
}
}

View File

@@ -0,0 +1,36 @@
use std::fs::remove_dir_all;
use std::path::PathBuf;
use clap::Parser;
use generate_1_5::V1_5;
use tfhe_backward_compat_data::dir_for_version;
use tfhe_backward_compat_data::generate::{
display_metadata, gen_all_data, update_metadata_for_version,
};
#[derive(Parser, Debug)]
struct Args {
/// The path where the backward data should be stored
#[arg(long)]
data_path: PathBuf,
/// Output metadata to stdout instead of writing them to the ron file
#[arg(long, action)]
stdout: bool,
}
fn main() {
let args = Args::parse();
let version_dir = dir_for_version(&args.data_path, "1.5");
// Ignore if directory does not exist
let _ = remove_dir_all(&version_dir);
let data = gen_all_data::<V1_5>(&args.data_path);
if args.stdout {
display_metadata(&data);
} else {
update_metadata_for_version(data, args.data_path);
}
}

View File

@@ -0,0 +1,35 @@
use std::path::Path;
use tfhe_versionable::Versionize;
use tfhe_backward_compat_data::generate::*;
use tfhe_backward_compat_data::*;
pub(crate) fn store_versioned_test<Data: Versionize + 'static, P: AsRef<Path>>(
msg: &Data,
dir: P,
test_filename: &str,
) {
generic_store_versioned_test(Versionize::versionize, msg, dir, test_filename)
}
#[allow(dead_code)]
pub(crate) fn store_versioned_auxiliary<Data: Versionize + 'static, P: AsRef<Path>>(
msg: &Data,
dir: P,
test_filename: &str,
) {
generic_store_versioned_auxiliary(Versionize::versionize, msg, dir, test_filename)
}
/// This trait allows to convert version independent parameters types defined in
/// `tfhe-backward-compat-data` to the equivalent TFHE-rs parameters for this version.
///
/// This is similar to `Into` but allows to circumvent the orphan rule.
pub(crate) trait ConvertParams<TfheRsParams> {
fn convert(self) -> TfheRsParams;
}
// <TODO> Add here the impl of ConvertParams for the TestXXXParameterSet that you need.
// <TODO> You can start by simply copying the implementations of this trait from the crate for
// <TODO> the previous version, and then eventually fix parameter types that have been updated.