Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ns/versionize clean #1326

Merged
merged 12 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check_commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Check first line
uses: gsactions/commit-message-checker@16fa2d5de096ae0d35626443bcd24f1e756cafee
with:
pattern: '^((feat|fix|chore|refactor|style|test|docs|doc)(\([\w\-_]+\))?\:) .+$'
pattern: '^((feat|fix|chore|refactor|style|test|docs|doc)(\([\w\-_]+\))?\!?\:) .+$'
nsarlin-zama marked this conversation as resolved.
Show resolved Hide resolved
flags: "gs"
error: 'Your first line has to contain a commit type and scope like "feat(my_feature): msg".'
excludeDescription: "true" # optional: this excludes the description body of a pull request
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ target/
# In case of symlinked keys
/keys

**/*.rmeta
**/Cargo.lock
**/*.bin

Expand Down
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ members = [
"concrete-csprng",
"backends/tfhe-cuda-backend",
"utils/tfhe-versionable",
"utils/tfhe-versionable-derive"
"utils/tfhe-versionable-derive",
]

exclude = [
"tfhe/backward_compatibility_tests"
"tfhe/backward_compatibility_tests",
"utils/cargo-tfhe-lints-inner",
"utils/cargo-tfhe-lints"
]

[profile.bench]
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BENCH_OP_FLAVOR?=DEFAULT
NODE_VERSION=22
FORWARD_COMPAT?=OFF
BACKWARD_COMPAT_DATA_URL=https://github.com/zama-ai/tfhe-backward-compat-data.git
BACKWARD_COMPAT_DATA_BRANCH=v0.1
IceTDrinker marked this conversation as resolved.
Show resolved Hide resolved
BACKWARD_COMPAT_DATA_DIR=tfhe-backward-compat-data
# sed: -n, do not print input stream, -e means a script/expression
# 1,/version/ indicates from the first line, to the line matching version at the start of the line
Expand Down Expand Up @@ -148,6 +149,11 @@ install_tarpaulin: install_rs_build_toolchain
cargo $(CARGO_RS_BUILD_TOOLCHAIN) install cargo-tarpaulin --locked || \
( echo "Unable to install cargo tarpaulin, unknown error." && exit 1 )

.PHONY: install_tfhe_lints # Install custom tfhe-rs lints
install_tfhe_lints:
(cd utils/cargo-tfhe-lints-inner && cargo install --path .) && \
cd utils/cargo-tfhe-lints && cargo install --path .
Comment on lines +152 to +155
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it try to reinstall everytime ? My main question here being that if the tool gets updated does the install step try to update the already installed tool ?

Alternatively is the installation mandatory or could it be run as a standalone executable maybe ?

Separate question: does it require a dedicated toolchain as was shown in the tutorial ?

Copy link
Contributor Author

@nsarlin-zama nsarlin-zama Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is reinstalled every times but if its code did not change it is instant.
For the moment I don't think it can be run as a standalone tool because of the way the command line arguments are parsed: let tool_args = std::env::args().skip(2).collect::<Vec<_>>();.
This assumes that the command is invoked with cargo tfhe-lints [args] and will not work with ./target/carg-tfhe-lints [args].

Yes it needs a specific toolchain which is the one used by rustc-tools. The toolchain is specified in the toolchain.txt. Only the cargo-tfhe-lints-inner tool needs this, I should remove the toolchain.txt in cargo-tfhe-lints.


.PHONY: check_linelint_installed # Check if linelint newline linter is installed
check_linelint_installed:
@printf "\n" | linelint - > /dev/null 2>&1 || \
Expand Down Expand Up @@ -330,6 +336,11 @@ clippy_cuda_backend: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
-p tfhe-cuda-backend -- --no-deps -D warnings

.PHONY: tfhe_lints # Run custom tfhe-rs lints
tfhe_lints: install_tfhe_lints
cd tfhe && RUSTFLAGS="$(RUSTFLAGS)" cargo tfhe-lints \
--features=$(TARGET_ARCH_FEATURE),boolean,shortint,integer -- -D warnings

.PHONY: build_core # Build core_crypto without experimental features
build_core: install_rs_build_toolchain install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --profile $(CARGO_PROFILE) \
Expand Down Expand Up @@ -1037,7 +1048,7 @@ write_params_to_file: install_rs_check_toolchain

.PHONY: clone_backward_compat_data # Clone the data repo needed for backward compatibility tests
clone_backward_compat_data:
./scripts/clone_backward_compat_data.sh $(BACKWARD_COMPAT_DATA_URL) tfhe/$(BACKWARD_COMPAT_DATA_DIR)
./scripts/clone_backward_compat_data.sh $(BACKWARD_COMPAT_DATA_URL) $(BACKWARD_COMPAT_DATA_BRANCH) tfhe/$(BACKWARD_COMPAT_DATA_DIR)

tfhe/$(BACKWARD_COMPAT_DATA_DIR): clone_backward_compat_data

Expand Down Expand Up @@ -1067,7 +1078,7 @@ sha256_bool: install_rs_check_toolchain

.PHONY: pcc # pcc stands for pre commit checks (except GPU)
pcc: no_tfhe_typo no_dbg_log check_fmt lint_doc check_md_docs_are_tested check_intra_md_links \
clippy_all check_compile_tests
clippy_all tfhe_lints check_compile_tests

.PHONY: pcc_gpu # pcc stands for pre commit checks for GPU compilation
pcc_gpu: clippy_gpu clippy_cuda_backend check_compile_tests_benches_gpu
Expand Down
12 changes: 7 additions & 5 deletions scripts/clone_backward_compat_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

set -e

if [ $# -lt 2 ]; then
echo "$0 git_url dest_path"
if [ $# -lt 3 ]; then
echo "invalid arguments, usage:\n"
echo "$0 git_url branch dest_path"
IceTDrinker marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi

Expand All @@ -12,8 +13,9 @@ if ! git lfs env 2>/dev/null >/dev/null; then
exit 1
fi

if [ -d $2 ]; then
cd $2 && git pull
if [ -d $3 ]; then
cd $3 && git fetch --depth 1 && git reset --hard origin/$2 && git clean -dfx

else
git clone $1 $2
git clone $1 -b $2 --depth 1 $3
fi
5 changes: 3 additions & 2 deletions tfhe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude = [
"/js_on_wasm_tests/",
"/web_wasm_parallel_tests/",
]
rust-version = "1.75"
rust-version = "1.76"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down Expand Up @@ -79,7 +79,7 @@ sha3 = { version = "0.10", optional = true }
itertools = "0.11.0"
rand_core = { version = "0.6.4", features = ["std"] }
tfhe-zk-pok = { version = "0.2.0", path = "../tfhe-zk-pok", optional = true }
tfhe-versionable = { version = "0.1.0", path = "../utils/tfhe-versionable" }
tfhe-versionable = { version = "0.2.0", path = "../utils/tfhe-versionable" }

# wasm deps
wasm-bindgen = { version = "0.2.86", features = [
Expand Down Expand Up @@ -329,4 +329,5 @@ crate-type = ["lib", "staticlib", "cdylib"]
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(bench)',
'cfg(tarpaulin)',
'cfg(tfhe_lints)'
] }
2 changes: 1 addition & 1 deletion tfhe/docs/guides/data_versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ You can load serialized data with the `unversionize` function, even in newer ver
[dependencies]
# ...
tfhe = { version = "0.8.0", features = ["integer","x86_64-unix"]}
tfhe-versionable = "0.1.0"
tfhe-versionable = "0.2.0"
bincode = "1.3.3"
```

Expand Down
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/ciphertext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::ciphertext::{Ciphertext, CompressedCiphertext};

#[derive(VersionsDispatch)]
pub enum CiphertextVersions {
V0(Ciphertext),
}

#[derive(VersionsDispatch)]
pub enum CompressedCiphertextVersions {
V0(CompressedCiphertext),
}
8 changes: 8 additions & 0 deletions tfhe/src/boolean/backward_compatibility/client_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::client_key::ClientKey;

#[derive(VersionsDispatch)]
pub enum ClientKeyVersions {
V0(ClientKey),
}
8 changes: 8 additions & 0 deletions tfhe/src/boolean/backward_compatibility/key_switching_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::key_switching_key::KeySwitchingKey;

#[derive(VersionsDispatch)]
pub enum KeySwitchingKeyVersions {
V0(KeySwitchingKey),
}
6 changes: 6 additions & 0 deletions tfhe/src/boolean/backward_compatibility/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod ciphertext;
pub mod client_key;
pub mod key_switching_key;
pub mod parameters;
pub mod public_key;
pub mod server_key;
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/parameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::parameters::{BooleanKeySwitchingParameters, BooleanParameters};

#[derive(VersionsDispatch)]
pub enum BooleanParametersVersions {
V0(BooleanParameters),
}

#[derive(VersionsDispatch)]
pub enum BooleanKeySwitchingParametersVersions {
V0(BooleanKeySwitchingParameters),
}
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/public_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::public_key::{CompressedPublicKey, PublicKey};

#[derive(VersionsDispatch)]
pub enum PublicKeyVersions {
V0(PublicKey),
}

#[derive(VersionsDispatch)]
pub enum CompressedPublicKeyVersions {
V0(CompressedPublicKey),
}
13 changes: 13 additions & 0 deletions tfhe/src/boolean/backward_compatibility/server_key.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use tfhe_versionable::VersionsDispatch;

use crate::boolean::server_key::{CompressedServerKey, ServerKey};

#[derive(VersionsDispatch)]
pub enum ServerKeyVersions {
V0(ServerKey),
}

#[derive(VersionsDispatch)]
pub enum CompressedServerKeyVersions {
V0(CompressedServerKey),
}
9 changes: 7 additions & 2 deletions tfhe/src/boolean/ciphertext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

use crate::core_crypto::entities::*;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

use super::backward_compatibility::ciphertext::{CiphertextVersions, CompressedCiphertextVersions};

/// A structure containing a ciphertext, meant to encrypt a Boolean message.
///
/// It is used to evaluate a Boolean circuits homomorphically.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Versionize)]
#[versionize(CiphertextVersions)]
pub enum Ciphertext {
Encrypted(LweCiphertextOwned<u32>),
Trivial(bool),
Expand All @@ -17,7 +21,8 @@ pub enum Ciphertext {
/// A structure containing a compressed ciphertext, meant to encrypt a Boolean message.
///
/// It has to be decompressed before evaluating a Boolean circuit.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Versionize)]
#[versionize(CompressedCiphertextVersions)]
pub struct CompressedCiphertext {
pub(crate) ciphertext: SeededLweCiphertext<u32>,
}
Expand Down
6 changes: 5 additions & 1 deletion tfhe/src/boolean/client_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use crate::boolean::parameters::{BooleanParameters, DynamicDistribution, Encrypt
use crate::core_crypto::entities::*;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};
use tfhe_versionable::Versionize;

use super::backward_compatibility::client_key::ClientKeyVersions;

/// A structure containing the client key, which must be kept secret.
///
Expand All @@ -18,7 +21,8 @@ use std::fmt::{Debug, Formatter};
/// * `glwe_secret_key` - a GLWE secret key, used to generate the bootstrapping keys and key
/// switching keys.
/// * `parameters` - the cryptographic parameter set.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Versionize)]
#[versionize(ClientKeyVersions)]
pub struct ClientKey {
pub(crate) lwe_secret_key: LweSecretKeyOwned<u32>,
pub(crate) glwe_secret_key: GlweSecretKeyOwned<u32>,
Expand Down
10 changes: 8 additions & 2 deletions tfhe/src/boolean/engine/bootstrapping.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::boolean::backward_compatibility::server_key::{
CompressedServerKeyVersions, ServerKeyVersions,
};
use crate::boolean::ciphertext::Ciphertext;
use crate::boolean::{ClientKey, PLAINTEXT_TRUE};
use crate::core_crypto::algorithms::*;
Expand All @@ -8,6 +11,7 @@ use crate::core_crypto::commons::parameters::{CiphertextModulus, PBSOrder};
use crate::core_crypto::entities::*;
use crate::core_crypto::fft_impl::fft64::math::fft::Fft;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

/// Memory used as buffer for the bootstrap
///
Expand Down Expand Up @@ -89,7 +93,8 @@ impl Memory {
/// In more details, it contains:
/// * `bootstrapping_key` - a public key, used to perform the bootstrapping operation.
/// * `key_switching_key` - a public key, used to perform the key-switching operation.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Versionize)]
#[versionize(ServerKeyVersions)]
pub struct ServerKey {
pub(crate) bootstrapping_key: FourierLweBootstrapKeyOwned,
pub(crate) key_switching_key: LweKeyswitchKeyOwned<u32>,
Expand Down Expand Up @@ -182,7 +187,8 @@ impl ServerKey {
/// In more details, it contains:
/// * `bootstrapping_key` - a public key, used to perform the bootstrapping operation.
/// * `key_switching_key` - a public key, used to perform the key-switching operation.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Versionize)]
#[versionize(CompressedServerKeyVersions)]
pub struct CompressedServerKey {
pub(crate) bootstrapping_key: SeededLweBootstrapKeyOwned<u32>,
pub(crate) key_switching_key: SeededLweKeyswitchKeyOwned<u32>,
Expand Down
7 changes: 6 additions & 1 deletion tfhe/src/boolean/key_switching_key/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use tfhe_versionable::Versionize;

use crate::boolean::engine::{BooleanEngine, WithThreadLocalEngine};
use crate::boolean::parameters::BooleanKeySwitchingParameters;
use crate::boolean::prelude::Ciphertext;
use crate::boolean::ClientKey;
use crate::core_crypto::prelude::{keyswitch_lwe_ciphertext, LweKeyswitchKeyOwned};

use super::backward_compatibility::key_switching_key::KeySwitchingKeyVersions;

#[cfg(test)]
mod test;

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Versionize)]
#[versionize(KeySwitchingKeyVersions)]
pub struct KeySwitchingKey {
pub(crate) key_switching_key: LweKeyswitchKeyOwned<u32>,
}
Expand Down
1 change: 1 addition & 0 deletions tfhe/src/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use crate::boolean::server_key::ServerKey;
#[cfg(test)]
use rand::Rng;

pub mod backward_compatibility;
pub mod ciphertext;
pub mod client_key;
pub mod engine;
Expand Down
11 changes: 9 additions & 2 deletions tfhe/src/boolean/parameters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ pub use crate::core_crypto::commons::parameters::{
};

use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

use super::backward_compatibility::parameters::{
BooleanKeySwitchingParametersVersions, BooleanParametersVersions,
};

/// A set of cryptographic parameters for homomorphic Boolean circuit evaluation.
/// The choice of encryption key for (`boolean ciphertext`)[`super::ciphertext::Ciphertext`].
Expand All @@ -39,7 +44,8 @@ use serde::{Deserialize, Serialize};
/// key`)[`super::public_key::PublicKey`] sizes are much more manageable and should always fit in
/// memory. When refreshing a ciphertext and/or evaluating a table lookup the keyswitch is
/// computed first followed by a PBS.
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Versionize)]
#[versionize(BooleanParametersVersions)]
pub struct BooleanParameters {
pub lwe_dimension: LweDimension,
pub glwe_dimension: GlweDimension,
Expand Down Expand Up @@ -91,7 +97,8 @@ impl BooleanParameters {
}

/// A set of cryptographic parameters for homomorphic Boolean key switching.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Versionize)]
#[versionize(BooleanKeySwitchingParametersVersions)]
pub struct BooleanKeySwitchingParameters {
pub ks_base_log: DecompositionBaseLog,
pub ks_level: DecompositionLevelCount,
Expand Down
5 changes: 4 additions & 1 deletion tfhe/src/boolean/public_key/compressed.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::boolean::backward_compatibility::public_key::CompressedPublicKeyVersions;
use crate::boolean::engine::{BooleanEngine, WithThreadLocalEngine};
use crate::boolean::prelude::{BooleanParameters, Ciphertext, ClientKey};
use crate::core_crypto::prelude::SeededLwePublicKeyOwned;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

/// A structure containing a compressed public key.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Versionize)]
#[versionize(CompressedPublicKeyVersions)]
pub struct CompressedPublicKey {
pub(crate) compressed_lwe_public_key: SeededLwePublicKeyOwned<u32>,
pub parameters: BooleanParameters,
Expand Down
5 changes: 4 additions & 1 deletion tfhe/src/boolean/public_key/standard.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
//! Module with the definition of the encryption PublicKey.

use super::compressed::CompressedPublicKey;
use crate::boolean::backward_compatibility::public_key::PublicKeyVersions;
use crate::boolean::ciphertext::Ciphertext;
use crate::boolean::client_key::ClientKey;
use crate::boolean::engine::{BooleanEngine, WithThreadLocalEngine};
use crate::boolean::parameters::BooleanParameters;
use crate::core_crypto::entities::*;
use serde::{Deserialize, Serialize};
use tfhe_versionable::Versionize;

/// A structure containing a public key.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, Versionize)]
#[versionize(PublicKeyVersions)]
pub struct PublicKey {
pub(crate) lwe_public_key: LwePublicKeyOwned<u32>,
pub(crate) parameters: BooleanParameters,
Expand Down
Loading
Loading