diff --git a/.gitattributes b/.gitattributes index ee0af648b4..d48c77249f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ *.hpu filter=lfs diff=lfs merge=lfs -text +*.bcode filter=lfs diff=lfs merge=lfs -text +*.cbor filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/aws_tfhe_backward_compat_tests.yml b/.github/workflows/aws_tfhe_backward_compat_tests.yml index 6509d0f3c7..2dadb7fdd7 100644 --- a/.github/workflows/aws_tfhe_backward_compat_tests.yml +++ b/.github/workflows/aws_tfhe_backward_compat_tests.yml @@ -71,45 +71,26 @@ jobs: with: toolchain: stable - - name: Use specific data branch - if: ${{ contains(github.event.pull_request.labels.*.name, 'data_PR') }} - env: - PR_BRANCH: ${{ github.head_ref || github.ref_name }} - run: | - echo "BACKWARD_COMPAT_DATA_BRANCH=${PR_BRANCH}" >> "${GITHUB_ENV}" - - - name: Get backward compat branch - id: backward_compat_branch + # Cache key is an aggregated hash of lfs files hashes + - name: Get LFS data sha + id: hash-lfs-data run: | - BRANCH="$(make backward_compat_branch)" - echo "branch=${BRANCH}" >> "${GITHUB_OUTPUT}" - - - name: Get backward compat branch head SHA - id: backward_compat_sha - run: | - SHA=$(git ls-remote "${REPO_URL}" refs/heads/"${BACKWARD_COMPAT_BRANCH}" | awk '{print $1}') + SHA=$(git lfs ls-files -l -I utils/tfhe-backward-compat-data | sha256sum | cut -d' ' -f1) echo "sha=${SHA}" >> "${GITHUB_OUTPUT}" - env: - REPO_URL: "https://github.com/zama-ai/tfhe-backward-compat-data" - BACKWARD_COMPAT_BRANCH: ${{ steps.backward_compat_branch.outputs.branch }} - name: Retrieve data from cache id: retrieve-data-cache uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3 with: - path: tests/tfhe-backward-compat-data - key: ${{ steps.backward_compat_branch.outputs.branch }}_${{ steps.backward_compat_sha.outputs.sha }} + path: | + utils/tfhe-backward-compat-data/**/*.cbor + utils/tfhe-backward-compat-data/**/*.bcode + key: ${{ steps.hash-lfs-data.outputs.sha }} - - name: Clone test data + - name: Pull test data if: steps.retrieve-data-cache.outputs.cache-hit != 'true' - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - with: - persist-credentials: 'false' - token: ${{ env.CHECKOUT_TOKEN }} - repository: zama-ai/tfhe-backward-compat-data - path: tests/tfhe-backward-compat-data - lfs: 'true' - ref: ${{ steps.backward_compat_branch.outputs.branch }} + run: | + make pull_backward_compat_data - name: Run backward compatibility tests run: | @@ -120,8 +101,10 @@ jobs: continue-on-error: true uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 #v4.2.3 with: - path: tests/tfhe-backward-compat-data - key: ${{ steps.backward_compat_branch.outputs.branch }}_${{ steps.backward_compat_sha.outputs.sha }} + path: | + utils/tfhe-backward-compat-data/**/*.cbor + utils/tfhe-backward-compat-data/**/*.bcode + key: ${{ steps.hash-lfs-data.outputs.sha }} - name: Set pull-request URL if: ${{ failure() && github.event_name == 'pull_request' }} diff --git a/.github/workflows/benchmark_hpu_integer.yml b/.github/workflows/benchmark_hpu_integer.yml index ceb6fc968f..3e8a2f59c9 100644 --- a/.github/workflows/benchmark_hpu_integer.yml +++ b/.github/workflows/benchmark_hpu_integer.yml @@ -62,7 +62,7 @@ jobs: - name: Run benchmarks run: | - git lfs pull --include="*" --exclude="" + make pull_hpu_files make bench_integer_hpu make bench_hlapi_erc20_hpu diff --git a/.linelint.yml b/.linelint.yml index fbbba0e349..1cc2bdd1e4 100644 --- a/.linelint.yml +++ b/.linelint.yml @@ -10,6 +10,7 @@ ignore: - keys - coverage - utils/tfhe-lints/ui/main.stderr + - utils/tfhe-backward-compat-data/**/*.ron # ron files are autogenerated rules: # checks if file ends in a newline character diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92731e06b1..e8fb08c213 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -170,6 +170,8 @@ On the contrary, these changes are *not* data breaking: * Renaming a type (unless it implements the `Named` trait). * Adding a variant to the end of an enum. +Historical data from previous TFHE-rs versions are stored inside `utils/tfhe-backward-compat-data`. They are used to check on every PR that backward compatibility has been preserved. + ## Example: adding a field Suppose you want to add an i32 field to a type named `MyType`. The original type is defined as: diff --git a/Cargo.toml b/Cargo.toml index dcf978b490..5dc5686fd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ members = [ ] exclude = [ - "tests/backward_compatibility_tests", + "utils/tfhe-backward-compat-data", "utils/tfhe-lints", "apps/trivium", ] diff --git a/Makefile b/Makefile index c42a3eec7d..4106862367 100644 --- a/Makefile +++ b/Makefile @@ -22,21 +22,7 @@ BENCH_TYPE?=latency BENCH_PARAM_TYPE?=classical BENCH_PARAMS_SET?=default NODE_VERSION=22.6 -BACKWARD_COMPAT_DATA_URL=https://github.com/zama-ai/tfhe-backward-compat-data.git -BACKWARD_COMPAT_DATA_DEFAULT_BRANCH:=$(shell ./scripts/backward_compat_data_version.py) -BACKWARD_COMPAT_DATA_BRANCH?=$(BACKWARD_COMPAT_DATA_DEFAULT_BRANCH) -BACKWARD_COMPAT_DATA_PROJECT=tfhe-backward-compat-data -BACKWARD_COMPAT_DATA_DIR=$(BACKWARD_COMPAT_DATA_PROJECT) -ifeq ($(BACKWARD_COMPAT_DATA_DEFAULT_BRANCH), $(BACKWARD_COMPAT_DATA_BRANCH)) - BACKWARD_COMPAT_CLIPPY_PATCH= -else -# We need to override the url for cargo patch accept it, see: https://github.com/rust-lang/cargo/issues/5478 - BACKWARD_COMPAT_PATCHED_URL=https://www.github.com/zama-ai/tfhe-backward-compat-data.git - BACKWARD_COMPAT_CLIPPY_PATCH=\ - --config "patch.'$(BACKWARD_COMPAT_DATA_URL)'.$(BACKWARD_COMPAT_DATA_PROJECT).branch=\"$(BACKWARD_COMPAT_DATA_BRANCH)\"" \ - --config "patch.'$(BACKWARD_COMPAT_DATA_URL)'.$(BACKWARD_COMPAT_DATA_PROJECT).git=\"$(BACKWARD_COMPAT_PATCHED_URL)\"" -endif - +BACKWARD_COMPAT_DATA_DIR=utils/tfhe-backward-compat-data TFHE_SPEC:=tfhe WASM_PACK_VERSION="0.13.1" # We are kind of hacking the cut here, the version cannot contain a quote '"' @@ -170,23 +156,23 @@ install_tarpaulin: install_rs_build_toolchain .PHONY: install_cargo_dylint # Install custom tfhe-rs lints install_cargo_dylint: - cargo install cargo-dylint dylint-link + cargo install --locked cargo-dylint dylint-link .PHONY: install_typos_checker # Install typos checker install_typos_checker: install_rs_build_toolchain @typos --version > /dev/null 2>&1 || \ - cargo $(CARGO_RS_BUILD_TOOLCHAIN) install typos-cli || \ + cargo $(CARGO_RS_BUILD_TOOLCHAIN) install --locked typos-cli || \ ( echo "Unable to install typos-cli, unknown error." && exit 1 ) .PHONY: install_zizmor # Install zizmor workflow security checker install_zizmor: install_rs_build_toolchain @zizmor --version > /dev/null 2>&1 || \ - cargo $(CARGO_RS_BUILD_TOOLCHAIN) install zizmor --version ~1.9 || \ + cargo $(CARGO_RS_BUILD_TOOLCHAIN) install --locked zizmor --version ~1.9 || \ ( echo "Unable to install zizmor, unknown error." && exit 1 ) -.PHONY: install_cargo_cross # Install custom tfhe-rs lints +.PHONY: install_cargo_cross # Install cross for big endian tests install_cargo_cross: install_rs_build_toolchain - cargo $(CARGO_RS_BUILD_TOOLCHAIN) install cross + cargo $(CARGO_RS_BUILD_TOOLCHAIN) install --locked cross .PHONY: setup_venv # Setup Python virtualenv for wasm tests setup_venv: @@ -263,6 +249,9 @@ install_mlc: install_rs_build_toolchain .PHONY: fmt # Format rust code fmt: install_rs_check_toolchain cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" fmt + cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" -Z unstable-options -C $(BACKWARD_COMPAT_DATA_DIR) fmt + cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" -Z unstable-options -C utils/tfhe-lints fmt + cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" -Z unstable-options -C apps/trivium fmt .PHONY: fmt_js # Format javascript code fmt_js: check_nvm_installed @@ -284,6 +273,9 @@ fmt_c_tests: .PHONY: check_fmt # Check rust code format check_fmt: install_rs_check_toolchain cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" fmt --check + cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" -Z unstable-options -C $(BACKWARD_COMPAT_DATA_DIR) fmt --check + cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" -Z unstable-options -C utils/tfhe-lints fmt --check + cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" -Z unstable-options -C apps/trivium fmt --check .PHONY: check_fmt_c_tests # Check C tests format check_fmt_c_tests: @@ -453,7 +445,6 @@ clippy_trivium: install_rs_check_toolchain .PHONY: clippy_ws_tests # Run clippy on the workspace level tests clippy_ws_tests: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --tests \ - $(BACKWARD_COMPAT_CLIPPY_PATCH) \ -p tests --features=shortint,integer,zk-pok -- --no-deps -D warnings .PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.) @@ -495,10 +486,17 @@ clippy_param_dedup: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ -p param_dedup -- --no-deps -D warnings +.PHONY: clippy_backward_compat_data # Run clippy lints on tfhe-backward-compat-data +clippy_backward_compat_data: install_rs_check_toolchain # the toolchain is selected with toolchain.toml + RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" -Z unstable-options \ + -C $(BACKWARD_COMPAT_DATA_DIR) clippy --all-targets \ + -- --no-deps -D warnings + .PHONY: clippy_all # Run all clippy targets clippy_all: clippy_rustdoc clippy clippy_boolean clippy_shortint clippy_integer clippy_all_targets \ clippy_c_api clippy_js_wasm_api clippy_tasks clippy_core clippy_tfhe_csprng clippy_zk_pok clippy_trivium \ -clippy_versionable clippy_tfhe_lints clippy_ws_tests clippy_bench clippy_param_dedup +clippy_versionable clippy_tfhe_lints clippy_ws_tests clippy_bench clippy_param_dedup \ +clippy_backward_compat_data .PHONY: clippy_fast # Run main clippy targets clippy_fast: clippy_rustdoc clippy clippy_all_targets clippy_c_api clippy_js_wasm_api clippy_tasks \ @@ -1054,16 +1052,11 @@ test_tfhe_lints: install_cargo_dylint # Here we use the "patch" functionality of Cargo to make sure the repo used for the data is the same as the one used for the code. .PHONY: test_backward_compatibility_ci test_backward_compatibility_ci: install_rs_build_toolchain - TFHE_BACKWARD_COMPAT_DATA_DIR="$(BACKWARD_COMPAT_DATA_DIR)" RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ - --config "patch.'$(BACKWARD_COMPAT_DATA_URL)'.$(BACKWARD_COMPAT_DATA_PROJECT).path=\"tests/$(BACKWARD_COMPAT_DATA_DIR)\"" \ + TFHE_BACKWARD_COMPAT_DATA_DIR="../$(BACKWARD_COMPAT_DATA_DIR)" RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --profile $(CARGO_PROFILE) \ --features=shortint,integer,zk-pok -p tests test_backward_compatibility -- --nocapture .PHONY: test_backward_compatibility # Same as test_backward_compatibility_ci but tries to clone the data repo first if needed -test_backward_compatibility: tests/$(BACKWARD_COMPAT_DATA_DIR) test_backward_compatibility_ci - -.PHONY: backward_compat_branch # Prints the required backward compatibility branch -backward_compat_branch: - @echo "$(BACKWARD_COMPAT_DATA_BRANCH)" +test_backward_compatibility: pull_backward_compat_data test_backward_compatibility_ci .PHONY: doc # Build rust doc doc: install_rs_check_toolchain @@ -1522,11 +1515,13 @@ write_params_to_file: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) run \ --example write_params_to_file --features=boolean,shortint,hpu,internal-keycache -.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) $(BACKWARD_COMPAT_DATA_BRANCH) tests/$(BACKWARD_COMPAT_DATA_DIR) +.PHONY: pull_backward_compat_data # Pull the data files needed for backward compatibility tests +pull_backward_compat_data: + ./scripts/pull_lfs_data.sh $(BACKWARD_COMPAT_DATA_DIR) -tests/$(BACKWARD_COMPAT_DATA_DIR): clone_backward_compat_data +.PHONY: pull_hpu_files # Pull the hpu files +pull_hpu_files: + ./scripts/pull_lfs_data.sh backends/tfhe-hpu-backend/ # # Real use case examples diff --git a/backends/tfhe-hpu-backend/README.md b/backends/tfhe-hpu-backend/README.md index 260523d39b..a43f8e50e0 100644 --- a/backends/tfhe-hpu-backend/README.md +++ b/backends/tfhe-hpu-backend/README.md @@ -201,9 +201,9 @@ There are some example applications already available in `tfhe/examples/hpu`: In order to run those applications on hardware, user must build from the project root (i.e `tfhe-rs-internal`) with `hpu-v80` features: > NB: Running examples required to have correctly pulled the `.hpu` files. Those files, due to their size, are backed by git-lfs and disabled by default. -> In order to retrieve them, use the following command: +> In order to retrieve them, run the following command from **TFHE-rs** root folder: > ```bash -> git lfs pull --include="*" --exclude="" +> make pull_hpu_files > ``` ``` bash @@ -217,7 +217,7 @@ source setup_hpu.sh --config v80 > NB: Error that occurred when ".hpu" files weren't correctly fetch could be a bit enigmatic: `memory allocation of ... bytes failed` > If you encountered this issue, you should run the following command: > ```bash -> git lfs pull --include="*" --exclude="" +> make pull_hpu_files > ``` diff --git a/scripts/backward_compat_data_version.py b/scripts/backward_compat_data_version.py deleted file mode 100755 index 1a6fa49365..0000000000 --- a/scripts/backward_compat_data_version.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/python3 - -try: - import tomllib # Python v3.11+ -except ModuleNotFoundError: - import pip._vendor.tomli as tomllib # the same tomllib that's now included in Python v3.11+ - - -fname = "tests/Cargo.toml" -with open(fname, "rb") as f: - data = tomllib.load(f) - - dev_dependencies = data["dev-dependencies"] - - branch_name = dev_dependencies["tfhe-backward-compat-data"]["branch"] - - print(branch_name) diff --git a/scripts/clone_backward_compat_data.sh b/scripts/clone_backward_compat_data.sh deleted file mode 100755 index 2917bab92f..0000000000 --- a/scripts/clone_backward_compat_data.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash - -set -e - -if [ $# -lt 3 ]; then - echo "invalid arguments, usage:\n" - echo "$0 git_url branch dest_path" - exit 1 -fi - -if ! git lfs env 2>/dev/null >/dev/null; then - echo "git lfs is not installed, please install it and try again" - exit 1 -fi - -if [ -d $3 ]; then - cd $3 && git remote set-branches origin '*' && git fetch --depth 1 && git reset --hard origin/$2 && git clean -dfx - -else - git clone $1 -b $2 --depth 1 $3 -fi diff --git a/scripts/pull_lfs_data.sh b/scripts/pull_lfs_data.sh new file mode 100755 index 0000000000..3c60c6a59d --- /dev/null +++ b/scripts/pull_lfs_data.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e + +if [ $# -lt 1 ]; then + echo "invalid arguments, usage:\n" + echo "$0 " + exit 1 +fi + +if ! git lfs env 2>/dev/null >/dev/null; then + echo "git lfs is not installed, please install it and try again" + exit 1 +fi + +git lfs pull --include="$1/*" --exclude="" diff --git a/tasks/src/check_tfhe_docs_are_tested.rs b/tasks/src/check_tfhe_docs_are_tested.rs index b2bc9e0273..e8af17215e 100644 --- a/tasks/src/check_tfhe_docs_are_tested.rs +++ b/tasks/src/check_tfhe_docs_are_tested.rs @@ -3,14 +3,9 @@ use std::collections::HashSet; use std::io::{Error, ErrorKind}; // TODO use .gitignore or git to resolve ignored files -const DIR_TO_IGNORE: [&str; 3] = [ - ".git", - "target", - // If the data repo has been cloned, we ignore its README - "tests/tfhe-backward-compat-data", -]; +const DIR_TO_IGNORE: [&str; 2] = [".git", "target"]; -const FILES_TO_IGNORE: [&str; 8] = [ +const FILES_TO_IGNORE: [&str; 9] = [ // This contains fragments of code that are unrelated to TFHE-rs "tfhe/docs/tutorials/sha256_bool.md", // TODO: This contains code that could be executed as a trivium docstring @@ -24,6 +19,7 @@ const FILES_TO_IGNORE: [&str; 8] = [ "utils/tfhe-lints/README.md", "CONTRIBUTING.md", "backends/tfhe-hpu-backend/README.md", + "utils/tfhe-backward-compat-data/README.md", ]; pub fn check_tfhe_docs_are_tested() -> Result<(), Error> { diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 5c526871c3..f557eba0e7 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dev-dependencies] tfhe = { path = "../tfhe" } tfhe-versionable = { path = "../utils/tfhe-versionable" } -tfhe-backward-compat-data = { git = "https://github.com/zama-ai/tfhe-backward-compat-data.git", branch = "v0.8", default-features = false, features = [ +tfhe-backward-compat-data = { path = "../utils/tfhe-backward-compat-data", default-features = false, features = [ "load", ] } cargo_toml = "0.22" diff --git a/tests/backward_compatibility_tests.rs b/tests/backward_compatibility_tests.rs index e5b1e445f0..9a3c3fb3aa 100644 --- a/tests/backward_compatibility_tests.rs +++ b/tests/backward_compatibility_tests.rs @@ -1,5 +1,5 @@ -//! Tests breaking change in serialized data by trying to load historical data stored in https://github.com/zama-ai/tfhe-backward-compat-data. -//! For each tfhe-rs module, there is a folder with some serialized messages and a [ron](https://github.com/ron-rs/ron) +//! Tests breaking change in serialized data by trying to load historical data stored with git LFS +//! inside `utils/tfhe-backward-compat-data`. For each tfhe-rs module, there is a folder with some serialized messages and a [ron](https://github.com/ron-rs/ron) //! file. The ron file stores some metadata that are parsed in this test. These metadata tell us //! what to test for each message. @@ -22,11 +22,13 @@ fn test_data_dir() -> PathBuf { } else { PathBuf::from_str(env!("CARGO_MANIFEST_DIR")) .unwrap() + .join("..") + .join("utils") .join("tfhe-backward-compat-data") }; if !root_dir.exists() { - panic!("Missing backward compatibility test data. Clone them using `make clone_backward_compat_data`") + panic!("Wrong backward compat data folder: {}", root_dir.display()) } data_dir(root_dir) @@ -103,6 +105,13 @@ fn run_all_tests(base_dir: &Path) -> Vec { // If we ran 0 test, it is likely that something wrong happened assert!(!results.is_empty()); + if results.iter().all(|res| res.is_failure()) { + println!( + "\nAll tests failed. Maybe the backward compatibility data files are missing. \ +Pull them using `make pull_backward_compat_data`" + ) + } + results } diff --git a/utils/tfhe-backward-compat-data/Cargo.toml b/utils/tfhe-backward-compat-data/Cargo.toml new file mode 100644 index 0000000000..95f9a7d198 --- /dev/null +++ b/utils/tfhe-backward-compat-data/Cargo.toml @@ -0,0 +1,96 @@ +[package] +name = "tfhe-backward-compat-data" +version = "0.8.0" +license = "BSD-3-Clause-Clear" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# This is a list of tfhe-rs versions we will generate data for. This list will grow over time. +# They are only activated when generating data, with the binary target and the "generate" feature. +tfhe_0_8 = { version = "0.8", features = [ + "boolean", + "integer", + "shortint", + "x86_64-unix", + "zk-pok", + "experimental-force_fft_algo_dif4", +], package = "tfhe", optional = true } +tfhe_0_10 = { version = "0.10", features = [ + "boolean", + "integer", + "shortint", + "x86_64-unix", + "zk-pok", + "experimental-force_fft_algo_dif4", +], package = "tfhe", optional = true } +tfhe_0_11 = { version = "0.11.2", features = [ + "boolean", + "integer", + "shortint", + "zk-pok", + "experimental-force_fft_algo_dif4", +], package = "tfhe", optional = true } +tfhe_1_0 = { version = "=1.0.0", features = [ + "boolean", + "integer", + "shortint", + "zk-pok", + "experimental-force_fft_algo_dif4", +], package = "tfhe", optional = true } + +# From here on we need to use git tag dependencies because versions are semver compatibles +tfhe_1_1 = { git = "https://github.com/zama-ai/tfhe-rs.git", features = [ + "boolean", + "integer", + "shortint", + "zk-pok", + "experimental-force_fft_algo_dif4", +], package = "tfhe", tag = "tfhe-rs-1.1.0", optional = true } +tfhe_1_3 = { git = "https://github.com/zama-ai/tfhe-rs.git", features = [ + "boolean", + "integer", + "shortint", + "zk-pok", + "experimental-force_fft_algo_dif4", +], package = "tfhe", tag = "tfhe-rs-1.3.0", optional = true } + + +# TFHE-rs 0.8 and 0.10 use the same version of versionable +tfhe-versionable = { version = "0.3.2", optional = true, package = "tfhe-versionable" } +tfhe_0_11-versionable = { version = "0.4.0", optional = true, package = "tfhe-versionable" } +tfhe_1_0-versionable = { version = "0.5.0", optional = true, package = "tfhe-versionable" } +tfhe_1_1-versionable = { git = "https://github.com/zama-ai/tfhe-rs.git", tag = "tfhe-rs-1.1.0", optional = true, package = "tfhe-versionable" } +tfhe_1_3-versionable = { git = "https://github.com/zama-ai/tfhe-rs.git", tag = "tfhe-rs-1.3.0", optional = true, package = "tfhe-versionable" } + + +# other deps +serde = { version = "1.0", features = ["derive"] } +strum = { version = "0.26", features = ["derive"] } +semver = { version = "1.0", optional = true } +ron = { version = "0.8", features = ["integer128"] } +ciborium = "0.2" +bincode = "1.3" + +[[bin]] +name = "tfhe-backward-compat-data" +required-features = ["generate"] + +[features] +default = ["generate"] + +generate = [ + "dep:tfhe_0_8", + "dep:tfhe_0_10", + "dep:tfhe_0_11", + "dep:tfhe_1_0", + "dep:tfhe_1_1", + "dep:tfhe_1_3", + "dep:tfhe-versionable", + "dep:tfhe_0_11-versionable", + "dep:tfhe_1_0-versionable", + "dep:tfhe_1_1-versionable", + "dep:tfhe_1_3-versionable", +] +load = ["dep:semver"] diff --git a/utils/tfhe-backward-compat-data/README.md b/utils/tfhe-backward-compat-data/README.md new file mode 100644 index 0000000000..f205a3e7d8 --- /dev/null +++ b/utils/tfhe-backward-compat-data/README.md @@ -0,0 +1,193 @@ +# tfhe-rs backwards compatibility test corpus +This folder contains historical data types from **TFHE-rs** that have been versioned and serialized. +The goal is to detect in TFHE-rs CI when the version of a type should be updated because a breaking change has been added. + +The messages are serialized using cbor and bincode because they both support large arrays and are vulnerable to different sets of breaking changes. Each message is stored with a set of metadata to verify that the values are loaded correctly. + +# Usage +## Backward compatibility test +From TFHE-rs root folder, run the following command +``` +make test_backward_compatibility +``` +This test will load the data stored in this folder, try to convert them to the latest version and check their correctness. + +## Data generation +To re-generate the data, run the binary target for this project: `cargo run --release`. The prng is seeded with a fixed seed, so the data should be identical. + +## Adding a test for an existing type +To add a new test for a type that is already tested, you need to create a const global variable with the metadata for that test. The type of metadata depends on the type being tested (for example, the metadata for a test of the `ClientKey` from the `high_level_api` is `HlClientKey`). Then go to the `data_vvv.rs` file (where "vvv" is the TFHE-rs version of the tested data) and update the `gen_xxx_data` method (where "xxx" is the API layer of your test (hl, shortint, integer,...)). In this method, create the object you want to test and serialize it using the `store_versioned_test` macro. Add the metadata of your test to the vector returned by this method. + +The test will be automatically selected when you run TFHE-rs `make test_backward_compatibility`. + +### Example +```rust +// 1. Define the metadata associated with the test +const HL_CT1_TEST: HlCiphertextTest = HlCiphertextTest { + test_filename: Cow::Borrowed("ct1"), + key_filename: Cow::Borrowed("client_key.cbor"), + compressed: false, + compact: false, + clear_value: 0, +}; + +impl TfhersVersion for V0_6 { + // ... + // Impl of trait + // ... + + fn gen_hl_data() -> Vec { + // ... + // Init code and generation of other tests + // ... + + // 2. Create the type + let ct1 = fheint8::encrypt(HL_CT1_TEST.clear_value, &hl_client_key); + + // 3. Store it + store_versioned_test!(&ct1, &dir, &HL_CT1_TEST.test_filename); + + // 4. Return the metadata + vec![ + TestMetadata::HlCiphertext(HL_CT1_TEST), + // ... + // Metadata for other tests + // ... + ] + + } + +``` + +## Adding tests for a new type + +### In this folder +To add a test for a type that has not yet been tested, you should create a new type that implements the `TestType` trait. The type should also store the metadata needed for the test, and be serializable. By convention, its name should start with the API layer being tested. The metadata can be anything that can be used to check that the correct value is retrieved after deserialization. However, it should not use a TFHE-rs internal type. + +Once the type is created, it should be added to the `TestMetadata` enum. You can then add a new testcase using the procedure in the previous paragraph. + +#### Example +```rust +// We use `Cow` for strings so that we can define them statically in this crate and load them +// dynamically in the test driver. +// Note that this type do not use anything from TFHE-rs +#derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub compressed: bool, + pub compact: bool, + pub clear_value: u64, +} + +impl TestType for HlCiphertextTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "FheUint".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug, Display)] +pub enum TestMetadata { + // Hl + HlCiphertext(HlCiphertextTest), + // ... + // All other supported types + // ... +} +``` + +### In TFHE-rs +In TFHE-rs, you should update the test driver (in `tests/backward_compatibility/`) to handle your new test type. To do this, create a function that loads and unversionizes the message, and then checks its value against the metadata provided: + +#### Example +```rust +/// Test HL ciphertext: loads the ciphertext and compares the decrypted value with the one in the +/// metadata. +pub fn test_hl_ciphertext( + dir: &Path, + test: &HlCiphertextTest, + 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 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)? + }; + + let clear: u8 = ct.decrypt(&key); + + if clear != (test.clear_value as u8) { + Err(test.failure( + format!( + "Invalid {} decrypted cleartext:\n Expected :\n{:?}\nGot:\n{:?}", + format, clear, test.clear_value + ), + format, + )) + } else { + Ok(test.success(format)) + } +} + +// ... +// Other tests +// ... + +impl TestedModule for Hl { + const METADATA_FILE: &'static str = "high_level_api.ron"; + + fn run_test>( + test_dir: P, + testcase: &Testcase, + format: DataFormat, + ) -> TestResult { + #[allow(unreachable_patterns)] + match &testcase.metadata { + TestMetadata::HlCiphertext(test) => { + test_hl_ciphertext(test_dir.as_ref(), test, format).into() + } + // ... + // Match other tests + // ... + _ => { + println!("WARNING: missing test: {:?}", testcase.metadata) + TestResult::Skipped(testcase.skip()) + } + } + } +} +``` + +## Adding a new tfhe-rs release +To add data for a new released version of tfhe-rs, you should first add a dependency to that version in the `Cargo.toml` of this project. This dependency should only be enabled with the `generate` feature to avoid conflicts during testing. + +You should then implement the `TfhersVersion` trait for this version. You can use the code in `data_0_6.rs` as an example. + +## Using the test data +The data is stored using git-lfs, but they are not pulled by default. You need to pull them by running: +``` +make pull_backward_compat_data +``` + +To be able to parse the metadata and check if the loaded data is valid, you should add this crate as a dependency with the `load` feature enabled. diff --git a/utils/tfhe-backward-compat-data/_typos.toml b/utils/tfhe-backward-compat-data/_typos.toml new file mode 100644 index 0000000000..a3c8590b5c --- /dev/null +++ b/utils/tfhe-backward-compat-data/_typos.toml @@ -0,0 +1,2 @@ +[files] +extend-exclude = ["*.cbor"] diff --git a/utils/tfhe-backward-compat-data/data/0_10/high_level_api/client_key.bcode b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/client_key.bcode new file mode 100644 index 0000000000..ad75a29d46 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/client_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e431d4f131647646961ed1ab1cc880fd61f15f83348d2ae1b8f442ee7e75fc1e +size 32106 diff --git a/utils/tfhe-backward-compat-data/data/0_10/high_level_api/client_key.cbor b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/client_key.cbor new file mode 100644 index 0000000000..211502cc78 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/client_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8cb90afb13749e5c9cf5cf2756bfde435bd92f664c5e65ad9cc4bc908eb36ab +size 4950 diff --git a/utils/tfhe-backward-compat-data/data/0_10/high_level_api/compressed_server_key.bcode b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/compressed_server_key.bcode new file mode 100644 index 0000000000..a1badfc19d --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/compressed_server_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca23804965ad52b18c4c55e092c7f8fb9155d7118eff45bb5eaffa769d671a3a +size 79479387 diff --git a/utils/tfhe-backward-compat-data/data/0_10/high_level_api/compressed_server_key.cbor b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/compressed_server_key.cbor new file mode 100644 index 0000000000..bf29bf3642 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/compressed_server_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3fb66b429b3fc8bb722e5161b84aac0e71a528bd457089adafe4e527dc6a53ab +size 89414885 diff --git a/utils/tfhe-backward-compat-data/data/0_10/high_level_api/server_key_with_compression.bcode b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/server_key_with_compression.bcode new file mode 100644 index 0000000000..b11eba16b7 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/server_key_with_compression.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb1e0dd0d081b34f2819d216028777b26a38e161055bfd15d20b3d5e2ad5446e +size 281931995 diff --git a/utils/tfhe-backward-compat-data/data/0_10/high_level_api/server_key_with_compression.cbor b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/server_key_with_compression.cbor new file mode 100644 index 0000000000..ae09d2c560 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_10/high_level_api/server_key_with_compression.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6549ea09324d0d9cccee89b21eb85982fa1bf41cf21873fda78939f06e1613b +size 324955532 diff --git a/utils/tfhe-backward-compat-data/data/0_11/high_level_api/client_key.cbor b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/client_key.cbor new file mode 100644 index 0000000000..3039761a5c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/client_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0665c8fd54940bb07b3b77520666840c8b5c24be1e5a09ba45bdedb1c064dc72 +size 3578 diff --git a/utils/tfhe-backward-compat-data/data/0_11/high_level_api/hl_proven_heterogeneous_list_zkv2.bcode b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/hl_proven_heterogeneous_list_zkv2.bcode new file mode 100644 index 0000000000..ae74836adb --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/hl_proven_heterogeneous_list_zkv2.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15bbcc8caf2de5bfaf8c19f84f380664e92094b49f5f0728d08abb8d781d03c3 +size 19241 diff --git a/utils/tfhe-backward-compat-data/data/0_11/high_level_api/hl_proven_heterogeneous_list_zkv2.cbor b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/hl_proven_heterogeneous_list_zkv2.cbor new file mode 100644 index 0000000000..501a22324c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/hl_proven_heterogeneous_list_zkv2.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d70134cca9b2a0e68cc4b147a0177e6475831dda57e58405323c8a0f58cc5506 +size 21985 diff --git a/utils/tfhe-backward-compat-data/data/0_11/high_level_api/public_key.cbor b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/public_key.cbor new file mode 100644 index 0000000000..25c096796c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/public_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25f01ede3660a9b0720d0f4a80c675d4c2a8ed95574d0d07a7a1f80db254cc73 +size 37310 diff --git a/utils/tfhe-backward-compat-data/data/0_11/high_level_api/zk_pke_crs.bcode b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/zk_pke_crs.bcode new file mode 100644 index 0000000000..5bc3d7ed65 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/zk_pke_crs.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a399e9866ffe9110e6c42914daf246a551c06fa70f64f9b3f9b109a802db2e9d +size 5569088 diff --git a/utils/tfhe-backward-compat-data/data/0_11/high_level_api/zk_pke_crs.cbor b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/zk_pke_crs.cbor new file mode 100644 index 0000000000..12c387ebb9 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_11/high_level_api/zk_pke_crs.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e615cbcbe08eeaf16688f2bd8bad302b7d7f1d6fe6c0b1ca061419c9aed5f06 +size 6528206 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_1_client_key.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_1_client_key.bcode new file mode 100644 index 0000000000..28fc5b8ec5 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_1_client_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:146d966218f0f778b9293839215a232e141ec0199779425660229ab98028b805 +size 23766 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_1_client_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_1_client_key.cbor new file mode 100644 index 0000000000..8eac2cd289 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_1_client_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47a478a96630436611d31d6a79c0bde8749a980d99a079af60b5e4e9c37cdc6d +size 3578 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_2_client_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_2_client_key.cbor new file mode 100644 index 0000000000..20cef2d95d --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/batch_2_client_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71db61e78f0d276e865346970bd8deea122e0f46e195a7ac274bdc3c05d3dd42 +size 4950 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool1.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool1.bcode new file mode 100644 index 0000000000..89a351202e --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool1.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc7a4ab83002e4683189ad424287d76ff56c5ff1d840cd837f8164ab9f51f73f +size 16516 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool1.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool1.cbor new file mode 100644 index 0000000000..843e447cbc --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool1.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea98b569589885bebb74328e59b085d785370b4df15bd0292acf301de90db03c +size 18651 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool2.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool2.bcode new file mode 100644 index 0000000000..4174009dc8 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool2.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd15a41d66f3e31fbe22cae273923faa3490388337262b1e177bfc7d47cade54 +size 16516 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool2.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool2.cbor new file mode 100644 index 0000000000..17ec6481a3 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/bool2.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:368460a46dd08f30a9bf9d86832fe250f419e8dbbe4c77e7581e22c7529836a8 +size 18651 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_for_pubkey.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_for_pubkey.cbor new file mode 100644 index 0000000000..53dc2a6248 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_for_pubkey.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf4b2e7f41739279478ef97b66c3b6ecc31d18579d9124c644893e8551f4ee68 +size 2696 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_with_compression.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_with_compression.bcode new file mode 100644 index 0000000000..6a8312b21c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_with_compression.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a151f56655e58ba7acda326e95eea7a7189f116f59641de6c049b8e3047092a9 +size 32106 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_with_compression.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_with_compression.cbor new file mode 100644 index 0000000000..20cef2d95d --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/client_key_with_compression.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71db61e78f0d276e865346970bd8deea122e0f46e195a7ac274bdc3c05d3dd42 +size 4950 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compact_public_key.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compact_public_key.bcode new file mode 100644 index 0000000000..8a7c25463f --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compact_public_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12021e06a8bfc377d88c32a584008bddff31ad54f17b30452af2203bd53f0f0b +size 32952 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compact_public_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compact_public_key.cbor new file mode 100644 index 0000000000..47ff1ee4c1 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compact_public_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b976505df0bc4b475bb34636f86acc03a3568644cba96ecaaedb149c179093b9 +size 37281 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_compact_public_key.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_compact_public_key.bcode new file mode 100644 index 0000000000..8f3ec0236c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_compact_public_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0d2cc68b39fc2529bb9115eca21dd7f94c87e2f71a7ca0a9a0c3ceddf4a76a31 +size 16588 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_compact_public_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_compact_public_key.cbor new file mode 100644 index 0000000000..e8a7126a5a --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_compact_public_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b17d65d770f29860c37967caf803486b4d06ec56ae047b9477277936bcbdda7 +size 18893 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_legacy_public_key.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_legacy_public_key.bcode new file mode 100644 index 0000000000..828c3ed91d --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_legacy_public_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8aa5e8c7b74078e2a8d86cea8824cfa438974a795da47f5f0d9c4c3c8e865d87 +size 1050440 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_legacy_public_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_legacy_public_key.cbor new file mode 100644 index 0000000000..f23676be3f --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_legacy_public_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50c30df30f274cb44940049b47515a764dcabfc4d3a4e014222262c500aefa67 +size 1182066 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_modswitched_bool.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_modswitched_bool.bcode new file mode 100644 index 0000000000..f9ee4c53dc --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_modswitched_bool.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4c1bc3c59328d829b8b91fda11b10542066d73502df89a35adcad94770a121eb +size 156 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_modswitched_bool.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_modswitched_bool.cbor new file mode 100644 index 0000000000..cdb5f9905d --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_modswitched_bool.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:840a8de5a8453b4155e6717a8e9726ae9ca205c9849ceafb5eb2d8a5a0dc4c01 +size 276 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_seeded_bool.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_seeded_bool.bcode new file mode 100644 index 0000000000..22fec10684 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_seeded_bool.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc5a5a7730bf3c9d88c179b9ac660936da62c36a8f4ec2a4339402ac6f640da2 +size 156 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_seeded_bool.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_seeded_bool.cbor new file mode 100644 index 0000000000..b8f9acb667 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/compressed_seeded_bool.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e6a55d561f1d4e4702944ccfb3f79fd7663fc6ad986b46ee0d508453bcfb9c9 +size 276 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1.bcode new file mode 100644 index 0000000000..6f047885de --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1fd37585babb5df46a7f3fb59ec40a481ee5bd7997ea26cd0551752ea29119a7 +size 66000 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1.cbor new file mode 100644 index 0000000000..2f3f215f44 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51c71499c8318d8206206ff7b4e97750c3e2c22e79792c16c20c72b214f45a0f +size 74497 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1_signed.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1_signed.bcode new file mode 100644 index 0000000000..87567e1e9d --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1_signed.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d1b2cf05880a7aaee6cc5eda9d8e6c4a1a7985dbe3a709beb3d47b5514c833f +size 66000 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1_signed.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1_signed.cbor new file mode 100644 index 0000000000..5aecb48eb0 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct1_signed.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:09f81282b98ac41860ab7629d481e7979a62d834189f7c48c04ebf0d8525e244 +size 74497 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2.bcode new file mode 100644 index 0000000000..c9c49226bb --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbaf57d728f9061ada49adab6b892283ac26d143ddfe40e5bfd0023042336edd +size 66000 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2.cbor new file mode 100644 index 0000000000..37d0082ab1 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e6dfa851d8a9706ff5ac4c90b1edee3624bf31aea0974cfdd45cf1f75ab7f73 +size 74497 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2_signed.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2_signed.bcode new file mode 100644 index 0000000000..234902a333 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2_signed.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e2fd35aa39145a4dbae4d9eff653724d181074e879256b233982da34b0d1ee16 +size 66000 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2_signed.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2_signed.cbor new file mode 100644 index 0000000000..cecb1fa8ce --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct2_signed.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8821ea05f65efcc6bd67be80ac94ecfe3f4f8fa65992cbe81719c8e01ee48717 +size 74497 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched.bcode new file mode 100644 index 0000000000..7a66cf60f9 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8378a6ce7b70b9e8a9d0b242bfefcf55f4ee1df3fe87ce8d27d18db09c333b4d +size 2977 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched.cbor new file mode 100644 index 0000000000..c4709a9f94 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d75390fd4fd4484352aa2076019df44a5ceb7c835ab9f6444dbb2dba5e6b268 +size 3697 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched_signed.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched_signed.bcode new file mode 100644 index 0000000000..044cfc2673 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched_signed.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:716dc0d7ed2d136bbadb21838c99a18697abba0fc50c8f6b6f80dcec9e1ad8b6 +size 2977 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched_signed.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched_signed.cbor new file mode 100644 index 0000000000..e71df72964 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_modswitched_signed.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f1632b8cda925497a9d90f102fb0292132ffcc2fdad0604896730156ee6ec4f +size 3697 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded.bcode new file mode 100644 index 0000000000..1bf9b3e358 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc9e04bb4d92d008e01606249b955a0eab037d1d5757c5a37d65c4fd953ec14d +size 564 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded.cbor new file mode 100644 index 0000000000..efa752f341 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9651321b8c4af1bf0df369de4d427e854604ec456131f6c4948fc6a59bedf726 +size 1009 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded_signed.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded_signed.bcode new file mode 100644 index 0000000000..90e933512b --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded_signed.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cc46fa11c1c0ebb35cd93d315835f33ae3b6ef1606a37252bb95c1601b2c79ee +size 564 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded_signed.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded_signed.cbor new file mode 100644 index 0000000000..930e9b04a5 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/ct_compressed_seeded_signed.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:293e0207346f13bce6ce51b83b98351debdf8774d6e5958a82460d22bed62d4c +size 1009 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_compressed_heterogeneous_list.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_compressed_heterogeneous_list.bcode new file mode 100644 index 0000000000..ce66d6f88c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_compressed_heterogeneous_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e94dd2396b283fc379456cdfcce55cbda7e117ca1b0ebe22241489394c14c5b7 +size 1824 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_compressed_heterogeneous_list.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_compressed_heterogeneous_list.cbor new file mode 100644 index 0000000000..ed73449c32 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_compressed_heterogeneous_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:075182f7f707dae42748e8685fd673edbc041658d2b9ab197c61476256ba7be6 +size 2240 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_heterogeneous_list.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_heterogeneous_list.bcode new file mode 100644 index 0000000000..3a6d07cd55 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_heterogeneous_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fae52ee430a33ded5abd0b0e39b85ee3043c64b25950cd8048285c972abce823 +size 16672 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_heterogeneous_list.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_heterogeneous_list.cbor new file mode 100644 index 0000000000..4964a17ae3 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_heterogeneous_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:938540698c799e6b52a29f32d350293abcd3103a2ed79255efdabd1ff3b8f0d6 +size 18857 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_packed_heterogeneous_list.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_packed_heterogeneous_list.bcode new file mode 100644 index 0000000000..4d5ed4786e --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_packed_heterogeneous_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63c6da03b45d45d4b17b9493c2fdf23fb24beb80330f08f04bfd829a2a29de2b +size 16632 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_packed_heterogeneous_list.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_packed_heterogeneous_list.cbor new file mode 100644 index 0000000000..10dd08a1d2 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_packed_heterogeneous_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f6f10290d8a14c6ff42ad00f26d75572c512a6ce54584e0ad23f38aa2f02cea +size 18812 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_proven_heterogeneous_list.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_proven_heterogeneous_list.bcode new file mode 100644 index 0000000000..beeb8699e8 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_proven_heterogeneous_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:617b7963be92d1738ed48f1cc24dda73313936436107b7544f31fb13fbb2bcc1 +size 17803 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_proven_heterogeneous_list.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_proven_heterogeneous_list.cbor new file mode 100644 index 0000000000..21914efa79 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/hl_proven_heterogeneous_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d2b0a4d294832d2e192dc17dc25859a4fc86e90f6a02e8b8f7c7c1301182f72c +size 20219 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/legacy_public_key.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/legacy_public_key.bcode new file mode 100644 index 0000000000..9fc8a355ea --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/legacy_public_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:814c99341c2287831f6bae2f9023f6c94efd5eebcc0bb56161fe222b1059360f +size 73548 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/legacy_public_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/legacy_public_key.cbor new file mode 100644 index 0000000000..b89b6e998f --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/legacy_public_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6819ec3fb394ae1734b59790afee68d5c1eccd2b0d39081336839d4bd87c1755 +size 83006 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/public_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/public_key.cbor new file mode 100644 index 0000000000..2b6bd5a8d8 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/public_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22fc922125d1c4e637024e1e60aca241ce25d5711f4eb91f5a0878ad9e75f9d0 +size 37281 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/zk_pke_public_params.bcode b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/zk_pke_public_params.bcode new file mode 100644 index 0000000000..58cac0e0d1 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/zk_pke_public_params.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8266d6a67a066d8fc4293fd585ca47a2d37aaf1f92f2529188f56a5c41cee650 +size 71361608 diff --git a/utils/tfhe-backward-compat-data/data/0_8/high_level_api/zk_pke_public_params.cbor b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/zk_pke_public_params.cbor new file mode 100644 index 0000000000..bd00e9bf6d --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/high_level_api/zk_pke_public_params.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e97570c813f155afd26e67fd1ddd6da9c36ba27927f6e2afb1c98c39de051cfb +size 83628033 diff --git a/utils/tfhe-backward-compat-data/data/0_8/shortint/client_key.bcode b/utils/tfhe-backward-compat-data/data/0_8/shortint/client_key.bcode new file mode 100644 index 0000000000..31107776c7 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/shortint/client_key.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:19607a68963124293e9f6c23b1e4d1d979449dab469f56e90b1e60f062d2d567 +size 22756 diff --git a/utils/tfhe-backward-compat-data/data/0_8/shortint/client_key.cbor b/utils/tfhe-backward-compat-data/data/0_8/shortint/client_key.cbor new file mode 100644 index 0000000000..b57f46705a --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/shortint/client_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c188d9ce6b8c76048fd5bd9c4ec95baaef1163f2defd04c611fccd9de1d7978d +size 3357 diff --git a/utils/tfhe-backward-compat-data/data/0_8/shortint/ct1.bcode b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct1.bcode new file mode 100644 index 0000000000..b9a0dc42c2 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct1.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:35aa7cf9a50390a40ef6954df7ab11fa41d25147536bff4cd94fb0701ebfa5b3 +size 16492 diff --git a/utils/tfhe-backward-compat-data/data/0_8/shortint/ct1.cbor b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct1.cbor new file mode 100644 index 0000000000..2efcff747e --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct1.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf685e9f6ea5d37e7ef99e1b6f1d0a08048aedf55d0df3d0b8ed2aef8a6c22dc +size 18611 diff --git a/utils/tfhe-backward-compat-data/data/0_8/shortint/ct2.bcode b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct2.bcode new file mode 100644 index 0000000000..b325ba0c7b --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct2.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11ad79733468d9cca094a212ca28d8e483f9722f92b90bcf305c410b223ecfd0 +size 16492 diff --git a/utils/tfhe-backward-compat-data/data/0_8/shortint/ct2.cbor b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct2.cbor new file mode 100644 index 0000000000..d719f1fdf4 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/0_8/shortint/ct2.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e756b2245869ccbb924615c5b31a3046c062b7fed83a41bd4bb6e288e138299d +size 18611 diff --git a/utils/tfhe-backward-compat-data/data/1_0/high_level_api/client_key_ms_noise_reduction.bcode b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/client_key_ms_noise_reduction.bcode new file mode 100644 index 0000000000..e18d617d02 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/client_key_ms_noise_reduction.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9ba3154fe5c62a66f5e5ac470b8274c421f6eba460101d377d0a8c2f77dd5df +size 16739 diff --git a/utils/tfhe-backward-compat-data/data/1_0/high_level_api/client_key_ms_noise_reduction.cbor b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/client_key_ms_noise_reduction.cbor new file mode 100644 index 0000000000..61383e12a1 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/client_key_ms_noise_reduction.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58b3d49233372543034d927d3e8ed739433e7f849329a8e2d35e94d49d848a5c +size 2846 diff --git a/utils/tfhe-backward-compat-data/data/1_0/high_level_api/server_key_ms_noise_reduction.bcode b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/server_key_ms_noise_reduction.bcode new file mode 100644 index 0000000000..2deab58e59 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/server_key_ms_noise_reduction.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9bb8e4834fa72ac221e5e17c5881047465b01c04433d9bdfbe6495a9ef7d0b3a +size 328164 diff --git a/utils/tfhe-backward-compat-data/data/1_0/high_level_api/server_key_ms_noise_reduction.cbor b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/server_key_ms_noise_reduction.cbor new file mode 100644 index 0000000000..fd850ef9c9 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/server_key_ms_noise_reduction.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5dedbb8f84874d231ea0b0545db353b8bd67dd76316ea3779ff95a3b8d83d0b +size 377700 diff --git a/utils/tfhe-backward-compat-data/data/1_0/high_level_api/zk_pkev2_crs.bcode b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/zk_pkev2_crs.bcode new file mode 100644 index 0000000000..5bc3d7ed65 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/zk_pkev2_crs.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a399e9866ffe9110e6c42914daf246a551c06fa70f64f9b3f9b109a802db2e9d +size 5569088 diff --git a/utils/tfhe-backward-compat-data/data/1_0/high_level_api/zk_pkev2_crs.cbor b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/zk_pkev2_crs.cbor new file mode 100644 index 0000000000..12c387ebb9 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_0/high_level_api/zk_pkev2_crs.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e615cbcbe08eeaf16688f2bd8bad302b7d7f1d6fe6c0b1ca061419c9aed5f06 +size 6528206 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/client_key_with_noise_squashing.bcode b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/client_key_with_noise_squashing.bcode new file mode 100644 index 0000000000..5b360a3132 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/client_key_with_noise_squashing.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25106962325ba12671b816b79771bfc102a5d74962259a68998bf667184c1bae +size 82481 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/client_key_with_noise_squashing.cbor b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/client_key_with_noise_squashing.cbor new file mode 100644 index 0000000000..d77ab59f55 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/client_key_with_noise_squashing.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca9433f606f27550480895b75fedf3957b3cdee46089b37c7f05c957f2008294 +size 7465 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing.bcode b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing.bcode new file mode 100644 index 0000000000..03fa5b7459 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69fa342aa6cc52f4f9528b55a61bd87fcac57da5fdea87b1d6d5d05bc8ca1159 +size 2097934 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing.cbor b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing.cbor new file mode 100644 index 0000000000..a0db1f24dd --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39b04eaff98c98c0f51163a74ae821e93894988ec30128f9a4e48d7c68d3d765 +size 2368948 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing_compressed.bcode b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing_compressed.bcode new file mode 100644 index 0000000000..04879b1855 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing_compressed.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc03714323a315eb7b3c79f6fcb124dcc588bba633c389c4be89fac6adc85f7c +size 721658 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing_compressed.cbor b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing_compressed.cbor new file mode 100644 index 0000000000..612575c136 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/server_key_with_noise_squashing_compressed.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d696bafc1a0da473258d9a8826e1436e61a486d5015e802af1ff35e7d00caa0e +size 812484 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_false_ciphertext.bcode b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_false_ciphertext.bcode new file mode 100644 index 0000000000..6a53126099 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_false_ciphertext.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c486f00d1f538577613af10484f15f82b3cd374124c65d7411d9bdbed133665 +size 65656 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_false_ciphertext.cbor b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_false_ciphertext.cbor new file mode 100644 index 0000000000..2cdb8d943c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_false_ciphertext.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4f73a00be15a9da70dd08b5e575ea5a5a0fbc391d75afe2c92c0af5827e3640 +size 73898 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_true_ciphertext.bcode b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_true_ciphertext.bcode new file mode 100644 index 0000000000..cfec78318a --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_true_ciphertext.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:620b761dd3c3849d0e4f014233722af66b3529095f942b7c770ed0978f0d9f97 +size 65656 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_true_ciphertext.cbor b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_true_ciphertext.cbor new file mode 100644 index 0000000000..3e40a1a328 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_bool_true_ciphertext.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b21c9cc51ecb98e9c57e0b746bee0871e34bc6f8397ef908febcc1b2cc2ca502 +size 73900 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_signed_ciphertext.bcode b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_signed_ciphertext.bcode new file mode 100644 index 0000000000..275a6170a5 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_signed_ciphertext.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:845971c67ddff7ecb28a76fad7a87f9025b1f4da8ae074591aff37a78441f57f +size 1050152 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_signed_ciphertext.cbor b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_signed_ciphertext.cbor new file mode 100644 index 0000000000..cee0d51a65 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_signed_ciphertext.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:562016927586a61e7f2dff49cdc522812762b7ff5ec05412461d7c0a70ad7bb3 +size 1181670 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_unsigned_ciphertext.bcode b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_unsigned_ciphertext.bcode new file mode 100644 index 0000000000..6c65490c69 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_unsigned_ciphertext.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60c2e431a8595be5b21702edb455f845fdfa7a8b95760e3ced5e85e6f5a74a4c +size 1050152 diff --git a/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_unsigned_ciphertext.cbor b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_unsigned_ciphertext.cbor new file mode 100644 index 0000000000..ccd29de056 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_1/high_level_api/squashed_noise_unsigned_ciphertext.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7d444ea30f27d2f18e0589eab803821e674e6bd94f58c27f020753c32697020 +size 1181656 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key.cbor new file mode 100644 index 0000000000..ccb4fc1b9f --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:07293ca3147766029f029240b4f4464aa5a2fc123bfae4df5cf61db099d3e987 +size 3730 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_ms_mean_compensation.bcode b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_ms_mean_compensation.bcode new file mode 100644 index 0000000000..4b890a5407 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_ms_mean_compensation.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b1f1105ef2059e0173dcccbcb622f5c8b4751d955665745e9d6cc3a845bf2edb +size 16697 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_ms_mean_compensation.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_ms_mean_compensation.cbor new file mode 100644 index 0000000000..50e073c310 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_ms_mean_compensation.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34db95434b2b5de931b33b39799b27abf769fd78a1c96d240958a774dfba1195 +size 2860 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_with_noise_squashing.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_with_noise_squashing.cbor new file mode 100644 index 0000000000..7cd214b899 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/client_key_with_noise_squashing.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a65a82a2ab42acc09f8bd5c12c03069bf5b0a8b9beaa84d509bb4c18f5ed47d4 +size 14127 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_compressed_squashed_noise_ciphertext_list.bcode b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_compressed_squashed_noise_ciphertext_list.bcode new file mode 100644 index 0000000000..6e5674f239 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_compressed_squashed_noise_ciphertext_list.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9552dc89c9614e6f3ebc84e0286546ab031402fc5aaf13c43194d049f94bc75b +size 98965 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_compressed_squashed_noise_ciphertext_list.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_compressed_squashed_noise_ciphertext_list.cbor new file mode 100644 index 0000000000..7162736eac --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_compressed_squashed_noise_ciphertext_list.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e67a3223319f89ec4e9796ca4637edcfa0735f742dde16485cedc567f226784 +size 111448 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_proven_heterogeneous_list_zkv2_fasthash.bcode b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_proven_heterogeneous_list_zkv2_fasthash.bcode new file mode 100644 index 0000000000..87dc0bda8a --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_proven_heterogeneous_list_zkv2_fasthash.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e7e146bc675bc844cb4a74acb6b91a5a19cd840ceeceed64cb81c5b1dc29053 +size 18669 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_proven_heterogeneous_list_zkv2_fasthash.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_proven_heterogeneous_list_zkv2_fasthash.cbor new file mode 100644 index 0000000000..9c93b40a7e --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/hl_proven_heterogeneous_list_zkv2_fasthash.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2111afd3240ac65e6312078e2de80e8df8cbf44bf295c5615f275f7294a7beda +size 21312 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/public_key.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/public_key.cbor new file mode 100644 index 0000000000..25c096796c --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/public_key.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25f01ede3660a9b0720d0f4a80c675d4c2a8ed95574d0d07a7a1f80db254cc73 +size 37310 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/server_key_ms_mean_compensation.bcode b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/server_key_ms_mean_compensation.bcode new file mode 100644 index 0000000000..7157a0eb72 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/server_key_ms_mean_compensation.bcode @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ece05e815e2f1100a5457f17f57c21d60189aba7b8d40164d4efffdf27a7ad8 +size 328045 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/server_key_ms_mean_compensation.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/server_key_ms_mean_compensation.cbor new file mode 100644 index 0000000000..a815ba5f3a --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/server_key_ms_mean_compensation.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c4c17a64e5b5b9aa02df603f50b57b1962b75f21443686f98228ef5f4898383 +size 377585 diff --git a/utils/tfhe-backward-compat-data/data/1_3/high_level_api/zk_pke_crs.cbor b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/zk_pke_crs.cbor new file mode 100644 index 0000000000..5d67f5e4af --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/1_3/high_level_api/zk_pke_crs.cbor @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a88f022a6bb44f24f91df340521f7d242c103580b286b577f2069e733d01725 +size 6523529 diff --git a/utils/tfhe-backward-compat-data/data/high_level_api.ron b/utils/tfhe-backward-compat-data/data/high_level_api.ron new file mode 100644 index 0000000000..75057181bc --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/high_level_api.ron @@ -0,0 +1,641 @@ +[ + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlClientKey(( + test_filename: "batch_1_client_key", + parameters: ( + lwe_dimension: 887, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TUniform( + bound_log2: 46, + ), + glwe_noise_distribution: TUniform( + bound_log2: 17, + ), + pbs_base_log: 22, + pbs_level: 1, + ks_base_log: 3, + ks_level: 5, + message_modulus: 4, + ciphertext_modulus: 18446744073709551616, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -64.138, + encryption_key_choice: "big", + modulus_switch_noise_reduction_params: Standard, + ), + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlPublicKey(( + test_filename: "legacy_public_key", + client_key_filename: "client_key_for_pubkey", + compressed: false, + compact: false, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlPublicKey(( + test_filename: "compressed_legacy_public_key", + client_key_filename: "batch_1_client_key", + compressed: true, + compact: false, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlPublicKey(( + test_filename: "compact_public_key", + client_key_filename: "batch_1_client_key", + compressed: false, + compact: true, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlPublicKey(( + test_filename: "compressed_compact_public_key", + client_key_filename: "batch_1_client_key", + compressed: true, + compact: true, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlCiphertext(( + test_filename: "ct1", + key_filename: "batch_1_client_key", + compressed: false, + clear_value: 0, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlCiphertext(( + test_filename: "ct2", + key_filename: "batch_1_client_key", + compressed: false, + clear_value: 255, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlCiphertext(( + test_filename: "ct_compressed_seeded", + key_filename: "batch_1_client_key", + compressed: true, + clear_value: 255, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlCiphertext(( + test_filename: "ct_compressed_modswitched", + key_filename: "batch_1_client_key", + compressed: true, + clear_value: 255, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlSignedCiphertext(( + test_filename: "ct1_signed", + key_filename: "batch_1_client_key", + compressed: false, + clear_value: 0, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlSignedCiphertext(( + test_filename: "ct2_signed", + key_filename: "batch_1_client_key", + compressed: false, + clear_value: -127, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlSignedCiphertext(( + test_filename: "ct_compressed_seeded_signed", + key_filename: "batch_1_client_key", + compressed: true, + clear_value: 255, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlSignedCiphertext(( + test_filename: "ct_compressed_modswitched_signed", + key_filename: "batch_1_client_key", + compressed: true, + clear_value: 255, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlBoolCiphertext(( + test_filename: "bool1", + key_filename: "batch_1_client_key", + compressed: false, + clear_value: true, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlBoolCiphertext(( + test_filename: "bool2", + key_filename: "batch_1_client_key", + compressed: false, + clear_value: false, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlBoolCiphertext(( + test_filename: "compressed_seeded_bool", + key_filename: "batch_1_client_key", + compressed: true, + clear_value: true, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlBoolCiphertext(( + test_filename: "compressed_modswitched_bool", + key_filename: "batch_1_client_key", + compressed: true, + clear_value: true, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlHeterogeneousCiphertextList(( + test_filename: "hl_heterogeneous_list", + key_filename: "batch_2_client_key", + compressed: false, + proof_info: None, + clear_values: [ + 17, + 18446744073709551604, + 0, + 1, + ], + data_kinds: [ + Unsigned, + Signed, + Bool, + Bool, + ], + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlHeterogeneousCiphertextList(( + test_filename: "hl_packed_heterogeneous_list", + key_filename: "batch_2_client_key", + compressed: false, + proof_info: None, + clear_values: [ + 17, + 18446744073709551604, + 0, + 1, + ], + data_kinds: [ + Unsigned, + Signed, + Bool, + Bool, + ], + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlHeterogeneousCiphertextList(( + test_filename: "hl_compressed_heterogeneous_list", + key_filename: "batch_2_client_key", + compressed: true, + proof_info: None, + clear_values: [ + 17, + 18446744073709551604, + 0, + 1, + ], + data_kinds: [ + Unsigned, + Signed, + Bool, + Bool, + ], + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlHeterogeneousCiphertextList(( + test_filename: "hl_proven_heterogeneous_list", + key_filename: "batch_2_client_key", + compressed: false, + proof_info: Some(( + public_key_filename: "public_key", + params_filename: "zk_pke_public_params", + metadata: "drawkcab", + )), + clear_values: [ + 17, + 18446744073709551604, + 0, + 1, + ], + data_kinds: [ + Unsigned, + Signed, + Bool, + Bool, + ], + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: ZkPkePublicParams(( + test_filename: "zk_pke_public_params", + lwe_dimension: 2048, + max_num_cleartext: 16, + noise_bound: 46, + ciphertext_modulus: 18446744073709551616, + plaintext_modulus: 32, + padding_bit_count: 1, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "high_level_api", + metadata: HlClientKey(( + test_filename: "client_key_with_compression", + parameters: ( + lwe_dimension: 887, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TUniform( + bound_log2: 46, + ), + glwe_noise_distribution: TUniform( + bound_log2: 17, + ), + pbs_base_log: 22, + pbs_level: 1, + ks_base_log: 3, + ks_level: 5, + message_modulus: 4, + ciphertext_modulus: 18446744073709551616, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -64.138, + encryption_key_choice: "big", + modulus_switch_noise_reduction_params: Standard, + ), + )), + ), + ( + tfhe_version_min: "0.10", + tfhe_module: "high_level_api", + metadata: HlClientKey(( + test_filename: "client_key", + parameters: ( + lwe_dimension: 887, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TUniform( + bound_log2: 46, + ), + glwe_noise_distribution: TUniform( + bound_log2: 17, + ), + pbs_base_log: 22, + pbs_level: 1, + ks_base_log: 3, + ks_level: 5, + message_modulus: 4, + ciphertext_modulus: 18446744073709551616, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -64.138, + encryption_key_choice: "big", + modulus_switch_noise_reduction_params: Standard, + ), + )), + ), + ( + tfhe_version_min: "0.10", + tfhe_module: "high_level_api", + metadata: HlServerKey(( + test_filename: "compressed_server_key", + client_key_filename: "client_key.cbor", + compressed: true, + )), + ), + ( + tfhe_version_min: "0.10", + tfhe_module: "high_level_api", + metadata: HlServerKey(( + test_filename: "server_key_with_compression", + client_key_filename: "client_key.cbor", + 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, + )), + ), + ( + tfhe_version_min: "0.11", + tfhe_module: "high_level_api", + metadata: HlHeterogeneousCiphertextList(( + test_filename: "hl_proven_heterogeneous_list_zkv2", + key_filename: "client_key", + compressed: false, + proof_info: Some(( + public_key_filename: "public_key", + params_filename: "zk_pke_crs", + metadata: "2vdrawkcab", + )), + clear_values: [ + 17, + 18446744073709551604, + 0, + 1, + ], + data_kinds: [ + Unsigned, + Signed, + Bool, + Bool, + ], + )), + ), + ( + tfhe_version_min: "1.0", + tfhe_module: "high_level_api", + metadata: HlClientKey(( + test_filename: "client_key_ms_noise_reduction", + parameters: ( + lwe_dimension: 2, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TUniform( + bound_log2: 45, + ), + glwe_noise_distribution: TUniform( + bound_log2: 17, + ), + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 4, + ks_level: 4, + message_modulus: 4, + ciphertext_modulus: 18446744073709551616, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -129.15284804376165, + encryption_key_choice: "big", + modulus_switch_noise_reduction_params: DriftTechniqueNoiseReduction(( + modulus_switch_zeros_count: 2, + ms_bound: 288230376151711740.0, + ms_r_sigma_factor: 13.179852282053789, + ms_input_variance: 0.000000263039184094559, + )), + ), + )), + ), + ( + tfhe_version_min: "1.0", + tfhe_module: "high_level_api", + metadata: HlServerKey(( + test_filename: "server_key_ms_noise_reduction", + client_key_filename: "client_key_ms_noise_reduction.cbor", + compressed: false, + )), + ), + ( + tfhe_version_min: "1.0", + tfhe_module: "high_level_api", + metadata: ZkPkePublicParams(( + test_filename: "zk_pkev2_crs", + lwe_dimension: 2048, + max_num_cleartext: 16, + noise_bound: 46, + ciphertext_modulus: 18446744073709551616, + plaintext_modulus: 32, + padding_bit_count: 1, + )), + ), + ( + tfhe_version_min: "1.1", + tfhe_module: "high_level_api", + metadata: HlClientKey(( + test_filename: "client_key_with_noise_squashing", + parameters: ( + lwe_dimension: 2, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TUniform( + bound_log2: 45, + ), + glwe_noise_distribution: TUniform( + bound_log2: 17, + ), + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 4, + ks_level: 4, + message_modulus: 4, + ciphertext_modulus: 18446744073709551616, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -129.15284804376165, + encryption_key_choice: "big", + modulus_switch_noise_reduction_params: DriftTechniqueNoiseReduction(( + modulus_switch_zeros_count: 2, + ms_bound: 288230376151711740.0, + ms_r_sigma_factor: 13.179852282053789, + ms_input_variance: 0.000000263039184094559, + )), + ), + )), + ), + ( + tfhe_version_min: "1.1", + tfhe_module: "high_level_api", + metadata: HlServerKey(( + test_filename: "server_key_with_noise_squashing", + client_key_filename: "client_key_with_noise_squashing", + compressed: false, + )), + ), + ( + tfhe_version_min: "1.1", + tfhe_module: "high_level_api", + metadata: HlServerKey(( + test_filename: "server_key_with_noise_squashing_compressed", + client_key_filename: "client_key_with_noise_squashing", + compressed: true, + )), + ), + ( + tfhe_version_min: "1.1", + tfhe_module: "high_level_api", + metadata: HlSquashedNoiseUnsignedCiphertext(( + test_filename: "squashed_noise_unsigned_ciphertext", + key_filename: "client_key_with_noise_squashing", + clear_value: 42, + )), + ), + ( + tfhe_version_min: "1.1", + tfhe_module: "high_level_api", + metadata: HlSquashedNoiseSignedCiphertext(( + test_filename: "squashed_noise_signed_ciphertext", + key_filename: "client_key_with_noise_squashing", + clear_value: -37, + )), + ), + ( + tfhe_version_min: "1.1", + tfhe_module: "high_level_api", + metadata: HlSquashedNoiseBoolCiphertext(( + test_filename: "squashed_noise_bool_false_ciphertext", + key_filename: "client_key_with_noise_squashing", + clear_value: false, + )), + ), + ( + tfhe_version_min: "1.1", + tfhe_module: "high_level_api", + metadata: HlSquashedNoiseBoolCiphertext(( + test_filename: "squashed_noise_bool_true_ciphertext", + key_filename: "client_key_with_noise_squashing", + clear_value: true, + )), + ), + ( + tfhe_version_min: "1.3", + tfhe_module: "high_level_api", + metadata: HlHeterogeneousCiphertextList(( + test_filename: "hl_proven_heterogeneous_list_zkv2_fasthash", + key_filename: "client_key", + compressed: false, + proof_info: Some(( + public_key_filename: "public_key", + params_filename: "zk_pke_crs", + metadata: "2vdrawkcab", + )), + clear_values: [ + 17, + 18446744073709551604, + 0, + 1, + ], + data_kinds: [ + Unsigned, + Signed, + Bool, + Bool, + ], + )), + ), + ( + tfhe_version_min: "1.3", + tfhe_module: "high_level_api", + metadata: HlClientKey(( + test_filename: "client_key_ms_mean_compensation", + parameters: ( + lwe_dimension: 2, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TUniform( + bound_log2: 45, + ), + glwe_noise_distribution: TUniform( + bound_log2: 17, + ), + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 4, + ks_level: 4, + message_modulus: 4, + ciphertext_modulus: 18446744073709551616, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -129.15284804376165, + encryption_key_choice: "big", + modulus_switch_noise_reduction_params: CenteredMeanNoiseReduction, + ), + )), + ), + ( + tfhe_version_min: "1.3", + tfhe_module: "high_level_api", + metadata: HlServerKey(( + test_filename: "server_key_ms_mean_compensation", + client_key_filename: "client_key_ms_mean_compensation.cbor", + compressed: false, + )), + ), + ( + tfhe_version_min: "1.3", + tfhe_module: "high_level_api", + metadata: HlCompressedSquashedNoiseCiphertextList(( + test_filename: "hl_compressed_squashed_noise_ciphertext_list", + key_filename: "client_key_with_noise_squashing", + clear_values: [ + 54679568, + 18446744073697155244, + 12396372, + 0, + 1, + ], + data_kinds: [ + Unsigned, + Signed, + Signed, + Bool, + Bool, + ], + )), + ), +] \ No newline at end of file diff --git a/utils/tfhe-backward-compat-data/data/shortint.ron b/utils/tfhe-backward-compat-data/data/shortint.ron new file mode 100644 index 0000000000..b3ec358e42 --- /dev/null +++ b/utils/tfhe-backward-compat-data/data/shortint.ron @@ -0,0 +1,49 @@ +[ + ( + tfhe_version_min: "0.8", + tfhe_module: "shortint", + metadata: ShortintClientKey(( + test_filename: "client_key", + parameters: ( + lwe_dimension: 761, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: Gaussian( + stddev: 0.00000636835566258815, + ), + glwe_noise_distribution: Gaussian( + stddev: 0.00000000000000031529322391500584, + ), + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 3, + ks_level: 5, + message_modulus: 4, + ciphertext_modulus: 18446744073709551616, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -40.05, + encryption_key_choice: "big", + modulus_switch_noise_reduction_params: Standard, + ), + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "shortint", + metadata: ShortintCiphertext(( + test_filename: "ct1", + key_filename: "client_key", + clear_value: 0, + )), + ), + ( + tfhe_version_min: "0.8", + tfhe_module: "shortint", + metadata: ShortintCiphertext(( + test_filename: "ct2", + key_filename: "client_key", + clear_value: 3, + )), + ), +] \ No newline at end of file diff --git a/utils/tfhe-backward-compat-data/src/data_0_10.rs b/utils/tfhe-backward-compat-data/src/data_0_10.rs new file mode 100644 index 0000000000..b4960330b9 --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/data_0_10.rs @@ -0,0 +1,170 @@ +use crate::generate::{ + store_versioned_test_tfhe_0_10, TfhersVersion, VALID_TEST_PARAMS_TUNIFORM, + VALID_TEST_PARAMS_TUNIFORM_COMPRESSION, +}; +use crate::{ + HlClientKeyTest, HlServerKeyTest, TestCompressionParameterSet, TestDistribution, TestMetadata, + TestParameterSet, HL_MODULE_NAME, +}; +use std::borrow::Cow; +use std::fs::create_dir_all; +use tfhe_0_10::boolean::engine::BooleanEngine; +use tfhe_0_10::core_crypto::commons::generators::DeterministicSeeder; +use tfhe_0_10::core_crypto::commons::math::random::ActivatedRandomGenerator; +use tfhe_0_10::core_crypto::prelude::{CiphertextModulusLog, LweCiphertextCount}; +use tfhe_0_10::shortint::engine::ShortintEngine; +use tfhe_0_10::shortint::parameters::{ + CarryModulus, CiphertextModulus, ClassicPBSParameters, CompressionParameters, + DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, EncryptionKeyChoice, + GlweDimension, LweDimension, MaxNoiseLevel, MessageModulus, PBSParameters, PolynomialSize, + StandardDev, +}; +use tfhe_0_10::{CompressedServerKey, Seed}; + +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_tfhe_0_10($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() + } +} + +impl From for CompressionParameters { + fn from(value: TestCompressionParameterSet) -> Self { + let TestCompressionParameterSet { + br_level, + br_base_log, + packing_ks_level, + packing_ks_base_log, + packing_ks_polynomial_size, + packing_ks_glwe_dimension, + lwe_per_glwe, + storage_log_modulus, + packing_ks_key_noise_distribution, + } = value; + Self { + br_level: DecompositionLevelCount(br_level), + br_base_log: DecompositionBaseLog(br_base_log), + packing_ks_level: DecompositionLevelCount(packing_ks_level), + packing_ks_base_log: DecompositionBaseLog(packing_ks_base_log), + packing_ks_polynomial_size: PolynomialSize(packing_ks_polynomial_size), + packing_ks_glwe_dimension: GlweDimension(packing_ks_glwe_dimension), + lwe_per_glwe: LweCiphertextCount(lwe_per_glwe), + storage_log_modulus: CiphertextModulusLog(storage_log_modulus), + packing_ks_key_noise_distribution: packing_ks_key_noise_distribution.into(), + } + } +} + +const HL_CLIENTKEY_TEST: HlClientKeyTest = HlClientKeyTest { + test_filename: Cow::Borrowed("client_key"), + parameters: VALID_TEST_PARAMS_TUNIFORM, +}; + +const HL_COMPRESSED_SERVERKEY_TEST: HlServerKeyTest = HlServerKeyTest { + test_filename: Cow::Borrowed("compressed_server_key"), + client_key_filename: Cow::Borrowed("client_key.cbor"), + compressed: true, +}; + +const HL_SERVERKEY_WITH_COMPRESSION_TEST: HlServerKeyTest = HlServerKeyTest { + test_filename: Cow::Borrowed("server_key_with_compression"), + client_key_filename: Cow::Borrowed("client_key.cbor"), + compressed: false, +}; + +pub struct V0_10; + +impl TfhersVersion for V0_10 { + const VERSION_NUMBER: &'static str = "0.10"; + + 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 config = tfhe_0_10::ConfigBuilder::with_custom_parameters(HL_CLIENTKEY_TEST.parameters) + .enable_compression(VALID_TEST_PARAMS_TUNIFORM_COMPRESSION.into()) + .build(); + let (hl_client_key, hl_server_key) = tfhe_0_10::generate_keys(config); + let compressed_server_key = CompressedServerKey::new(&hl_client_key); + + store_versioned_test!(&hl_client_key, &dir, &HL_CLIENTKEY_TEST.test_filename); + store_versioned_test!( + &compressed_server_key, + &dir, + &HL_COMPRESSED_SERVERKEY_TEST.test_filename, + ); + store_versioned_test!( + &hl_server_key, + &dir, + &HL_SERVERKEY_WITH_COMPRESSION_TEST.test_filename, + ); + + vec![ + TestMetadata::HlClientKey(HL_CLIENTKEY_TEST), + TestMetadata::HlServerKey(HL_COMPRESSED_SERVERKEY_TEST), + TestMetadata::HlServerKey(HL_SERVERKEY_WITH_COMPRESSION_TEST), + ] + } +} diff --git a/utils/tfhe-backward-compat-data/src/data_0_11.rs b/utils/tfhe-backward-compat-data/src/data_0_11.rs new file mode 100644 index 0000000000..6b7c8cc15c --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/data_0_11.rs @@ -0,0 +1,221 @@ +use crate::generate::{ + store_versioned_auxiliary_tfhe_0_11, store_versioned_test_tfhe_0_11, TfhersVersion, PRNG_SEED, + VALID_TEST_PARAMS_TUNIFORM, +}; +use crate::{ + DataKind, HlClientKeyTest, HlHeterogeneousCiphertextListTest, PkeZkProofAuxiliaryInfo, + TestDistribution, TestMetadata, TestParameterSet, ZkPkePublicParamsTest, HL_MODULE_NAME, +}; +use std::borrow::Cow; +use std::fs::create_dir_all; +use tfhe_0_11::boolean::engine::BooleanEngine; +use tfhe_0_11::core_crypto::commons::generators::DeterministicSeeder; +use tfhe_0_11::core_crypto::commons::math::random::{DefaultRandomGenerator, RandomGenerator}; +use tfhe_0_11::core_crypto::prelude::{LweCiphertextCount, TUniform}; +use tfhe_0_11::shortint::engine::ShortintEngine; +use tfhe_0_11::shortint::parameters::{ + CarryModulus, CiphertextModulus, ClassicPBSParameters, DecompositionBaseLog, + DecompositionLevelCount, DynamicDistribution, EncryptionKeyChoice, GlweDimension, LweDimension, + MaxNoiseLevel, MessageModulus, PBSParameters, PolynomialSize, StandardDev, +}; +use tfhe_0_11::zk::{CompactPkeCrs, ZkComputeLoad, ZkMSBZeroPaddingBitCount}; +use tfhe_0_11::{ + set_server_key, ClientKey, CompactPublicKey, ProvenCompactCiphertextList, Seed, ServerKey, +}; + +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_tfhe_0_11($msg, $dir, $test_filename) + }; +} + +macro_rules! store_versioned_auxiliary { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_auxiliary_tfhe_0_11($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 as u64), + carry_modulus: CarryModulus(value.carry_modulus as u64), + max_noise_level: MaxNoiseLevel::new(value.max_noise_level as u64), + 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() + } +} + +const HL_CLIENTKEY_TEST: HlClientKeyTest = HlClientKeyTest { + test_filename: Cow::Borrowed("client_key"), + parameters: VALID_TEST_PARAMS_TUNIFORM, +}; + +// 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, +}; + +const HL_PROVEN_COMPACTLIST_TEST_ZKV2: HlHeterogeneousCiphertextListTest = + HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_proven_heterogeneous_list_zkv2"), + key_filename: HL_CLIENTKEY_TEST.test_filename, + clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + compressed: false, + proof_info: Some(PkeZkProofAuxiliaryInfo { + public_key_filename: Cow::Borrowed("public_key"), + params_filename: Cow::Borrowed("zk_pke_crs"), + metadata: Cow::Borrowed("2vdrawkcab"), + }), + }; + +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)); + + // Generate a compact public key needed to create a compact list + let config = + tfhe_0_11::ConfigBuilder::with_custom_parameters(VALID_TEST_PARAMS_TUNIFORM).build(); + let hl_client_key = ClientKey::generate(config); + let hl_server_key = ServerKey::new(&hl_client_key); + set_server_key(hl_server_key.clone()); + let compact_pub_key = CompactPublicKey::new(&hl_client_key); + + let crs = CompactPkeCrs::new( + LweDimension(ZK_PKE_CRS_TEST.lwe_dimension), + LweCiphertextCount(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,); + + // Store the associated client key to be able to decrypt the ciphertexts in the list + store_versioned_auxiliary!( + &hl_client_key, + &dir, + &HL_PROVEN_COMPACTLIST_TEST_ZKV2.key_filename + ); + + store_versioned_auxiliary!( + &compact_pub_key, + &dir, + &HL_PROVEN_COMPACTLIST_TEST_ZKV2 + .proof_info + .unwrap() + .public_key_filename + ); + + let mut proven_builder = ProvenCompactCiphertextList::builder(&compact_pub_key); + proven_builder + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2.clear_values[0] as u8) + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2.clear_values[1] as i8) + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2.clear_values[2] != 0) + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2.clear_values[3] != 0); + + let proven_list_packed = proven_builder + .build_with_proof_packed( + &crs, + HL_PROVEN_COMPACTLIST_TEST_ZKV2 + .proof_info + .unwrap() + .metadata + .as_bytes(), + ZkComputeLoad::Proof, + ) + .unwrap(); + + store_versioned_test!( + &proven_list_packed, + &dir, + &HL_PROVEN_COMPACTLIST_TEST_ZKV2.test_filename, + ); + + vec![ + TestMetadata::ZkPkePublicParams(ZK_PKE_CRS_TEST), + TestMetadata::HlHeterogeneousCiphertextList(HL_PROVEN_COMPACTLIST_TEST_ZKV2), + ] + } +} diff --git a/utils/tfhe-backward-compat-data/src/data_0_8.rs b/utils/tfhe-backward-compat-data/src/data_0_8.rs new file mode 100644 index 0000000000..b42da4616b --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/data_0_8.rs @@ -0,0 +1,685 @@ +use std::borrow::Cow; +use std::fs::create_dir_all; + +use tfhe_0_8::boolean::engine::BooleanEngine; +use tfhe_0_8::core_crypto::commons::generators::DeterministicSeeder; +use tfhe_0_8::core_crypto::commons::math::random::RandomGenerator; +use tfhe_0_8::core_crypto::prelude::{ + ActivatedRandomGenerator, CiphertextModulusLog, LweCiphertextCount, TUniform, +}; +use tfhe_0_8::integer::parameters::{ + DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, GlweDimension, + LweDimension, PolynomialSize, StandardDev, +}; +use tfhe_0_8::prelude::*; +use tfhe_0_8::shortint::engine::ShortintEngine; +use tfhe_0_8::shortint::parameters::list_compression::CompressionParameters; +use tfhe_0_8::shortint::{ + CarryModulus, CiphertextModulus, ClassicPBSParameters, EncryptionKeyChoice, MaxNoiseLevel, + MessageModulus, PBSParameters, +}; +use tfhe_0_8::zk::{CompactPkeCrs, ZkComputeLoad, ZkMSBZeroPaddingBitCount}; +use tfhe_0_8::{ + generate_keys, set_server_key, shortint, ClientKey, CompactCiphertextList, CompactPublicKey, + CompressedCiphertextListBuilder, CompressedCompactPublicKey, CompressedFheBool, + CompressedFheInt8, CompressedFheUint8, CompressedPublicKey, ConfigBuilder, FheBool, FheInt8, + FheUint8, ProvenCompactCiphertextList, PublicKey, Seed, ServerKey, +}; + +use crate::generate::{ + store_versioned_auxiliary_tfhe_0_8, store_versioned_test_tfhe_0_8, TfhersVersion, + INSECURE_SMALL_PK_TEST_PARAMS, PRNG_SEED, VALID_TEST_PARAMS, VALID_TEST_PARAMS_TUNIFORM, + VALID_TEST_PARAMS_TUNIFORM_COMPRESSION, +}; +use crate::{ + DataKind, HlBoolCiphertextTest, HlCiphertextTest, HlClientKeyTest, + HlHeterogeneousCiphertextListTest, HlPublicKeyTest, HlSignedCiphertextTest, + PkeZkProofAuxiliaryInfo, ShortintCiphertextTest, ShortintClientKeyTest, + TestCompressionParameterSet, TestDistribution, TestMetadata, TestParameterSet, + ZkPkePublicParamsTest, HL_MODULE_NAME, SHORTINT_MODULE_NAME, +}; + +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_tfhe_0_8($msg, $dir, $test_filename) + }; +} + +macro_rules! store_versioned_auxiliary { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_auxiliary_tfhe_0_8($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::TUniform(TUniform::new(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 classic_pbs: ClassicPBSParameters = value.into(); + classic_pbs.into() + } +} + +impl From for CompressionParameters { + fn from(value: TestCompressionParameterSet) -> Self { + let TestCompressionParameterSet { + br_level, + br_base_log, + packing_ks_level, + packing_ks_base_log, + packing_ks_polynomial_size, + packing_ks_glwe_dimension, + lwe_per_glwe, + storage_log_modulus, + packing_ks_key_noise_distribution, + } = value; + Self { + br_level: DecompositionLevelCount(br_level), + br_base_log: DecompositionBaseLog(br_base_log), + packing_ks_level: DecompositionLevelCount(packing_ks_level), + packing_ks_base_log: DecompositionBaseLog(packing_ks_base_log), + packing_ks_polynomial_size: PolynomialSize(packing_ks_polynomial_size), + packing_ks_glwe_dimension: GlweDimension(packing_ks_glwe_dimension), + lwe_per_glwe: LweCiphertextCount(lwe_per_glwe), + storage_log_modulus: CiphertextModulusLog(storage_log_modulus), + packing_ks_key_noise_distribution: packing_ks_key_noise_distribution.into(), + } + } +} + +// Shortint test constants +const SHORTINT_CLIENT_KEY_FILENAME: &str = "client_key"; + +const SHORTINT_CLIENTKEY_TEST: ShortintClientKeyTest = ShortintClientKeyTest { + test_filename: Cow::Borrowed(SHORTINT_CLIENT_KEY_FILENAME), + // Here we use the non TUniform params for shortint to be able to check gaussian params + parameters: VALID_TEST_PARAMS, +}; +const SHORTINT_CT1_TEST: ShortintCiphertextTest = ShortintCiphertextTest { + test_filename: Cow::Borrowed("ct1"), + key_filename: Cow::Borrowed(SHORTINT_CLIENT_KEY_FILENAME), + clear_value: 0, +}; +const SHORTINT_CT2_TEST: ShortintCiphertextTest = ShortintCiphertextTest { + test_filename: Cow::Borrowed("ct2"), + key_filename: Cow::Borrowed(SHORTINT_CLIENT_KEY_FILENAME), + clear_value: 3, +}; + +// HL test constants +// Batch 1 +const HL_CLIENT_KEY_BATCH_1_FILENAME: &str = "batch_1_client_key"; + +const HL_CLIENTKEY_TEST: HlClientKeyTest = HlClientKeyTest { + test_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + parameters: VALID_TEST_PARAMS_TUNIFORM, +}; + +// We use a client key with specific parameters for the pubkey since it can be very large +const HL_LEGACY_PUBKEY_TEST: HlPublicKeyTest = HlPublicKeyTest { + test_filename: Cow::Borrowed("legacy_public_key"), + client_key_filename: Cow::Borrowed("client_key_for_pubkey"), + compressed: false, + compact: false, +}; + +const HL_COMPRESSED_LEGACY_PUBKEY_TEST: HlPublicKeyTest = HlPublicKeyTest { + test_filename: Cow::Borrowed("compressed_legacy_public_key"), + client_key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + compact: false, +}; + +const HL_COMPACT_PUBKEY_TEST: HlPublicKeyTest = HlPublicKeyTest { + test_filename: Cow::Borrowed("compact_public_key"), + client_key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: false, + compact: true, +}; + +const HL_COMPRESSED_COMPACT_PUBKEY_TEST: HlPublicKeyTest = HlPublicKeyTest { + test_filename: Cow::Borrowed("compressed_compact_public_key"), + client_key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + compact: true, +}; + +const HL_CT1_TEST: HlCiphertextTest = HlCiphertextTest { + test_filename: Cow::Borrowed("ct1"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: false, + clear_value: 0, +}; + +const HL_CT2_TEST: HlCiphertextTest = HlCiphertextTest { + test_filename: Cow::Borrowed("ct2"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: false, + clear_value: 255, +}; + +const HL_COMPRESSED_SEEDED_CT_TEST: HlCiphertextTest = HlCiphertextTest { + test_filename: Cow::Borrowed("ct_compressed_seeded"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + clear_value: 255, +}; + +const HL_COMPRESSED_CT_MODSWITCHED_TEST: HlCiphertextTest = HlCiphertextTest { + test_filename: Cow::Borrowed("ct_compressed_modswitched"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + clear_value: 255, +}; + +const HL_SIGNED_CT1_TEST: HlSignedCiphertextTest = HlSignedCiphertextTest { + test_filename: Cow::Borrowed("ct1_signed"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: false, + clear_value: 0, +}; + +const HL_SIGNED_CT2_TEST: HlSignedCiphertextTest = HlSignedCiphertextTest { + test_filename: Cow::Borrowed("ct2_signed"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: false, + clear_value: -127, +}; + +const HL_SIGNED_COMPRESSED_SEEDED_CT_TEST: HlSignedCiphertextTest = HlSignedCiphertextTest { + test_filename: Cow::Borrowed("ct_compressed_seeded_signed"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + clear_value: 255, +}; + +const HL_SIGNED_COMPRESSED_CT_MODSWITCHED_TEST: HlSignedCiphertextTest = HlSignedCiphertextTest { + test_filename: Cow::Borrowed("ct_compressed_modswitched_signed"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + clear_value: 255, +}; + +const HL_BOOL1_TEST: HlBoolCiphertextTest = HlBoolCiphertextTest { + test_filename: Cow::Borrowed("bool1"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: false, + clear_value: true, +}; + +const HL_BOOL2_TEST: HlBoolCiphertextTest = HlBoolCiphertextTest { + test_filename: Cow::Borrowed("bool2"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: false, + clear_value: false, +}; + +const HL_COMPRESSED_BOOL_SEEDED_TEST: HlBoolCiphertextTest = HlBoolCiphertextTest { + test_filename: Cow::Borrowed("compressed_seeded_bool"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + clear_value: true, +}; + +const HL_COMPRESSED_BOOL_MODSWITCHED_TEST: HlBoolCiphertextTest = HlBoolCiphertextTest { + test_filename: Cow::Borrowed("compressed_modswitched_bool"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_1_FILENAME), + compressed: true, + clear_value: true, +}; + +// Batch 2 +const HL_CLIENT_KEY_BATCH_2_FILENAME: &str = "batch_2_client_key"; + +const HL_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_heterogeneous_list"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_2_FILENAME), + clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + compressed: false, + proof_info: None, +}; + +const HL_PACKED_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = + HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_packed_heterogeneous_list"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_2_FILENAME), + clear_values: HL_COMPACTLIST_TEST.clear_values, + data_kinds: HL_COMPACTLIST_TEST.data_kinds, + compressed: false, + proof_info: None, + }; + +const HL_COMPRESSED_LIST_TEST: HlHeterogeneousCiphertextListTest = + HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_compressed_heterogeneous_list"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_2_FILENAME), + clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + compressed: true, + proof_info: None, + }; + +const HL_PROVEN_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = + HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_proven_heterogeneous_list"), + key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_2_FILENAME), + clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + compressed: false, + proof_info: Some(PkeZkProofAuxiliaryInfo { + public_key_filename: Cow::Borrowed("public_key"), + params_filename: Cow::Borrowed("zk_pke_public_params"), + metadata: Cow::Borrowed("drawkcab"), + }), + }; + +const ZK_PKE_PUBLIC_PARAMS_TEST: ZkPkePublicParamsTest = ZkPkePublicParamsTest { + test_filename: Cow::Borrowed("zk_pke_public_params"), + 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, +}; + +const HL_CLIENT_W_COMP_KEY_BATCH_2_FILENAME: &str = "client_key_with_compression"; + +const HL_CLIENTKEY_WITH_COMPRESSION_TEST: HlClientKeyTest = HlClientKeyTest { + test_filename: Cow::Borrowed(HL_CLIENT_W_COMP_KEY_BATCH_2_FILENAME), + parameters: VALID_TEST_PARAMS_TUNIFORM, +}; + +pub struct V0_8; + +impl TfhersVersion for V0_8 { + const VERSION_NUMBER: &'static str = "0.8"; + + 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 { + let dir = Self::data_dir().join(SHORTINT_MODULE_NAME); + create_dir_all(&dir).unwrap(); + + // generate a client key + let shortint_client_key = shortint::ClientKey::new(SHORTINT_CLIENTKEY_TEST.parameters); + + store_versioned_test!( + &shortint_client_key, + &dir, + &SHORTINT_CLIENTKEY_TEST.test_filename, + ); + + // generate ciphertexts + let ct1 = shortint_client_key.encrypt(SHORTINT_CT1_TEST.clear_value); + let ct2 = shortint_client_key.encrypt(SHORTINT_CT2_TEST.clear_value); + + // Serialize them + store_versioned_test!(&ct1, &dir, &SHORTINT_CT1_TEST.test_filename); + store_versioned_test!(&ct2, &dir, &SHORTINT_CT2_TEST.test_filename); + + vec![ + TestMetadata::ShortintClientKey(SHORTINT_CLIENTKEY_TEST), + TestMetadata::ShortintCiphertext(SHORTINT_CT1_TEST), + TestMetadata::ShortintCiphertext(SHORTINT_CT2_TEST), + ] + } + + fn gen_hl_data() -> Vec { + let dir = Self::data_dir().join(HL_MODULE_NAME); + create_dir_all(&dir).unwrap(); + + let mut all_tests = vec![]; + + { + // generate keys + let config = + ConfigBuilder::with_custom_parameters(HL_CLIENTKEY_TEST.parameters).build(); + let (hl_client_key, hl_server_key) = generate_keys(config); + + // Here we use specific parameters to generate a smaller public key. + // WARNING: these parameters are completely insecure + let params_pk = INSECURE_SMALL_PK_TEST_PARAMS; + let client_key_for_pk = + ClientKey::generate(ConfigBuilder::with_custom_parameters(params_pk).build()); + + let pub_key = PublicKey::new(&client_key_for_pk); + let compressed_pub_key = CompressedPublicKey::new(&hl_client_key); + let compact_pub_key = CompactPublicKey::new(&hl_client_key); + let compressed_compact_pub_key = CompressedCompactPublicKey::new(&hl_client_key); + + store_versioned_test!(&hl_client_key, &dir, &HL_CLIENTKEY_TEST.test_filename); + + store_versioned_test!(&pub_key, &dir, &HL_LEGACY_PUBKEY_TEST.test_filename); + store_versioned_auxiliary!( + &client_key_for_pk, + &dir, + &HL_LEGACY_PUBKEY_TEST.client_key_filename, + ); + + store_versioned_test!( + &compressed_pub_key, + &dir, + &HL_COMPRESSED_LEGACY_PUBKEY_TEST.test_filename, + ); + store_versioned_test!( + &compact_pub_key, + &dir, + &HL_COMPACT_PUBKEY_TEST.test_filename, + ); + store_versioned_test!( + &compressed_compact_pub_key, + &dir, + &HL_COMPRESSED_COMPACT_PUBKEY_TEST.test_filename, + ); + + set_server_key(hl_server_key); + + // generate ciphertexts + let ct1 = FheUint8::encrypt(HL_CT1_TEST.clear_value, &hl_client_key); + let ct2 = FheUint8::encrypt(HL_CT2_TEST.clear_value, &hl_client_key); + + let ct1_signed = FheInt8::encrypt(HL_SIGNED_CT1_TEST.clear_value, &hl_client_key); + let ct2_signed = FheInt8::encrypt(HL_SIGNED_CT2_TEST.clear_value, &hl_client_key); + + let bool1 = FheBool::encrypt(HL_BOOL1_TEST.clear_value, &hl_client_key); + let bool2 = FheBool::encrypt(HL_BOOL2_TEST.clear_value, &hl_client_key); + + // Generate compressed ciphertexts + // The first one using seeded (default) method + let compressed_ct1 = CompressedFheUint8::encrypt( + HL_COMPRESSED_SEEDED_CT_TEST.clear_value, + &hl_client_key, + ); + let compressed_ct1_signed = CompressedFheInt8::encrypt( + HL_SIGNED_COMPRESSED_SEEDED_CT_TEST.clear_value, + &hl_client_key, + ); + let compressed_bool1 = CompressedFheBool::encrypt( + HL_COMPRESSED_BOOL_SEEDED_TEST.clear_value, + &hl_client_key, + ); + + // The second one using the modulus switched method + let compressed_ct2 = FheUint8::encrypt( + HL_COMPRESSED_CT_MODSWITCHED_TEST.clear_value, + &hl_client_key, + ) + .compress(); + let compressed_ct2_signed = FheInt8::encrypt( + HL_SIGNED_COMPRESSED_CT_MODSWITCHED_TEST.clear_value, + &hl_client_key, + ) + .compress(); + let compressed_bool2 = CompressedFheBool::encrypt( + HL_COMPRESSED_BOOL_MODSWITCHED_TEST.clear_value, + &hl_client_key, + ); + + // Serialize them + store_versioned_test!(&ct1, &dir, &HL_CT1_TEST.test_filename); + store_versioned_test!(&ct2, &dir, &HL_CT2_TEST.test_filename); + store_versioned_test!( + &compressed_ct1, + &dir, + &HL_COMPRESSED_SEEDED_CT_TEST.test_filename, + ); + store_versioned_test!( + &compressed_ct2, + &dir, + &HL_COMPRESSED_CT_MODSWITCHED_TEST.test_filename, + ); + + store_versioned_test!(&ct1_signed, &dir, &HL_SIGNED_CT1_TEST.test_filename); + store_versioned_test!(&ct2_signed, &dir, &HL_SIGNED_CT2_TEST.test_filename); + store_versioned_test!( + &compressed_ct1_signed, + &dir, + &HL_SIGNED_COMPRESSED_SEEDED_CT_TEST.test_filename, + ); + store_versioned_test!( + &compressed_ct2_signed, + &dir, + &HL_SIGNED_COMPRESSED_CT_MODSWITCHED_TEST.test_filename, + ); + + store_versioned_test!(&bool1, &dir, &HL_BOOL1_TEST.test_filename); + store_versioned_test!(&bool2, &dir, &HL_BOOL2_TEST.test_filename); + store_versioned_test!( + &compressed_bool1, + &dir, + &HL_COMPRESSED_BOOL_SEEDED_TEST.test_filename, + ); + store_versioned_test!( + &compressed_bool2, + &dir, + &HL_COMPRESSED_BOOL_MODSWITCHED_TEST.test_filename, + ); + + let test_batch_1 = [ + TestMetadata::HlClientKey(HL_CLIENTKEY_TEST), + TestMetadata::HlPublicKey(HL_LEGACY_PUBKEY_TEST), + TestMetadata::HlPublicKey(HL_COMPRESSED_LEGACY_PUBKEY_TEST), + TestMetadata::HlPublicKey(HL_COMPACT_PUBKEY_TEST), + TestMetadata::HlPublicKey(HL_COMPRESSED_COMPACT_PUBKEY_TEST), + TestMetadata::HlCiphertext(HL_CT1_TEST), + TestMetadata::HlCiphertext(HL_CT2_TEST), + TestMetadata::HlCiphertext(HL_COMPRESSED_SEEDED_CT_TEST), + TestMetadata::HlCiphertext(HL_COMPRESSED_CT_MODSWITCHED_TEST), + TestMetadata::HlSignedCiphertext(HL_SIGNED_CT1_TEST), + TestMetadata::HlSignedCiphertext(HL_SIGNED_CT2_TEST), + TestMetadata::HlSignedCiphertext(HL_SIGNED_COMPRESSED_SEEDED_CT_TEST), + TestMetadata::HlSignedCiphertext(HL_SIGNED_COMPRESSED_CT_MODSWITCHED_TEST), + TestMetadata::HlBoolCiphertext(HL_BOOL1_TEST), + TestMetadata::HlBoolCiphertext(HL_BOOL2_TEST), + TestMetadata::HlBoolCiphertext(HL_COMPRESSED_BOOL_SEEDED_TEST), + TestMetadata::HlBoolCiphertext(HL_COMPRESSED_BOOL_MODSWITCHED_TEST), + ]; + all_tests.extend(test_batch_1); + } + + { + // Generate a compact public key needed to create a compact list + let config = + tfhe_0_8::ConfigBuilder::with_custom_parameters(VALID_TEST_PARAMS_TUNIFORM) + .enable_compression(VALID_TEST_PARAMS_TUNIFORM_COMPRESSION.into()) + .build(); + let hl_client_key = ClientKey::generate(config); + let hl_server_key = ServerKey::new(&hl_client_key); + set_server_key(hl_server_key.clone()); + let compact_pub_key = CompactPublicKey::new(&hl_client_key); + + let mut zk_rng: RandomGenerator = + RandomGenerator::new(Seed(PRNG_SEED)); + let crs = CompactPkeCrs::new( + LweDimension(ZK_PKE_PUBLIC_PARAMS_TEST.lwe_dimension), + ZK_PKE_PUBLIC_PARAMS_TEST.max_num_cleartext, + TUniform::::new(ZK_PKE_PUBLIC_PARAMS_TEST.noise_bound as u32), + CiphertextModulus::new(ZK_PKE_PUBLIC_PARAMS_TEST.ciphertext_modulus), + ZK_PKE_PUBLIC_PARAMS_TEST.plaintext_modulus as u64, + ZkMSBZeroPaddingBitCount(ZK_PKE_PUBLIC_PARAMS_TEST.padding_bit_count as u64), + &mut zk_rng, + ) + .unwrap(); + + // Store the associated client key to be able to decrypt the ciphertexts in the list + store_versioned_auxiliary!( + &hl_client_key, + &dir, + &HL_PROVEN_COMPACTLIST_TEST.key_filename + ); + + store_versioned_auxiliary!( + &compact_pub_key, + &dir, + &HL_PROVEN_COMPACTLIST_TEST + .proof_info + .unwrap() + .public_key_filename + ); + + let mut proven_builder = ProvenCompactCiphertextList::builder(&compact_pub_key); + proven_builder + .push(HL_PROVEN_COMPACTLIST_TEST.clear_values[0] as u8) + .push(HL_PROVEN_COMPACTLIST_TEST.clear_values[1] as i8) + .push(HL_PROVEN_COMPACTLIST_TEST.clear_values[2] != 0) + .push(HL_PROVEN_COMPACTLIST_TEST.clear_values[3] != 0); + + let proven_list_packed = proven_builder + .build_with_proof_packed( + crs.public_params(), + HL_PROVEN_COMPACTLIST_TEST + .proof_info + .unwrap() + .metadata + .as_bytes(), + ZkComputeLoad::Proof, + ) + .unwrap(); + + store_versioned_test!( + crs.public_params(), + &dir, + &ZK_PKE_PUBLIC_PARAMS_TEST.test_filename, + ); + + store_versioned_test!( + &proven_list_packed, + &dir, + &HL_PROVEN_COMPACTLIST_TEST.test_filename, + ); + + // Generate heterogeneous list data + let mut compact_builder = CompactCiphertextList::builder(&compact_pub_key); + compact_builder + .push(HL_COMPACTLIST_TEST.clear_values[0] as u8) + .push(HL_COMPACTLIST_TEST.clear_values[1] as i8) + .push(HL_COMPACTLIST_TEST.clear_values[2] != 0) + .push(HL_COMPACTLIST_TEST.clear_values[3] != 0); + + let compact_list_packed = compact_builder.build_packed(); + let compact_list = compact_builder.build(); + + let mut compressed_builder = CompressedCiphertextListBuilder::new(); + compressed_builder + .push(FheUint8::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[0] as u8, + &hl_client_key, + )) + .push(FheInt8::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[1] as i8, + &hl_client_key, + )) + .push(FheBool::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[2] != 0, + &hl_client_key, + )) + .push(FheBool::encrypt( + HL_COMPRESSED_LIST_TEST.clear_values[3] != 0, + &hl_client_key, + )); + let compressed_list = compressed_builder.build().unwrap(); + + store_versioned_test!( + &compact_list_packed, + &dir, + &HL_PACKED_COMPACTLIST_TEST.test_filename, + ); + store_versioned_test!(&compact_list, &dir, &HL_COMPACTLIST_TEST.test_filename); + store_versioned_test!( + &compressed_list, + &dir, + &HL_COMPRESSED_LIST_TEST.test_filename, + ); + + store_versioned_test!( + &hl_client_key, + &dir, + &HL_CLIENTKEY_WITH_COMPRESSION_TEST.test_filename, + ); + + let test_batch_2 = [ + TestMetadata::HlHeterogeneousCiphertextList(HL_COMPACTLIST_TEST), + TestMetadata::HlHeterogeneousCiphertextList(HL_PACKED_COMPACTLIST_TEST), + TestMetadata::HlHeterogeneousCiphertextList(HL_COMPRESSED_LIST_TEST), + TestMetadata::HlHeterogeneousCiphertextList(HL_PROVEN_COMPACTLIST_TEST), + TestMetadata::ZkPkePublicParams(ZK_PKE_PUBLIC_PARAMS_TEST), + TestMetadata::HlClientKey(HL_CLIENTKEY_WITH_COMPRESSION_TEST), + ]; + + all_tests.extend(test_batch_2); + } + + all_tests + } +} diff --git a/utils/tfhe-backward-compat-data/src/data_1_0.rs b/utils/tfhe-backward-compat-data/src/data_1_0.rs new file mode 100644 index 0000000000..6a3b89e23e --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/data_1_0.rs @@ -0,0 +1,201 @@ +use crate::generate::{ + store_versioned_test_tfhe_1_0, TfhersVersion, INSECURE_SMALL_TEST_PARAMS_MS_NOISE_REDUCTION, + PRNG_SEED, VALID_TEST_PARAMS_TUNIFORM, +}; +use crate::{ + HlClientKeyTest, HlServerKeyTest, TestDistribution, TestMetadata, + TestModulusSwitchNoiseReductionParams, TestModulusSwitchType, TestParameterSet, + ZkPkePublicParamsTest, HL_MODULE_NAME, +}; +use std::borrow::Cow; +use std::fs::create_dir_all; +use tfhe_1_0::boolean::engine::BooleanEngine; +use tfhe_1_0::core_crypto::commons::generators::DeterministicSeeder; +use tfhe_1_0::core_crypto::commons::math::random::{DefaultRandomGenerator, RandomGenerator}; +use tfhe_1_0::core_crypto::prelude::{ + LweCiphertextCount, NoiseEstimationMeasureBound, RSigmaFactor, TUniform, Variance, +}; +use tfhe_1_0::shortint::engine::ShortintEngine; +use tfhe_1_0::shortint::parameters::{ + CarryModulus, CiphertextModulus, ClassicPBSParameters, DecompositionBaseLog, + DecompositionLevelCount, DynamicDistribution, EncryptionKeyChoice, GlweDimension, LweDimension, + MaxNoiseLevel, MessageModulus, ModulusSwitchNoiseReductionParams, PBSParameters, + PolynomialSize, StandardDev, +}; +use tfhe_1_0::zk::{CompactPkeCrs, ZkMSBZeroPaddingBitCount}; +use tfhe_1_0::Seed; + +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_tfhe_1_0($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 ModulusSwitchNoiseReductionParams { + fn from(value: TestModulusSwitchNoiseReductionParams) -> Self { + let TestModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count, + ms_bound, + ms_r_sigma_factor, + ms_input_variance, + } = value; + + ModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count: LweCiphertextCount(modulus_switch_zeros_count), + ms_bound: NoiseEstimationMeasureBound(ms_bound), + ms_r_sigma_factor: RSigmaFactor(ms_r_sigma_factor), + ms_input_variance: Variance(ms_input_variance), + } + } +} + +impl From for ClassicPBSParameters { + fn from(value: TestParameterSet) -> Self { + let modulus_switch_noise_reduction_params = + match value.modulus_switch_noise_reduction_params { + TestModulusSwitchType::Standard => None, + TestModulusSwitchType::DriftTechniqueNoiseReduction( + test_modulus_switch_noise_reduction_params, + ) => Some(test_modulus_switch_noise_reduction_params.into()), + TestModulusSwitchType::CenteredMeanNoiseReduction => panic!("Not supported"), + }; + + 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 as u64), + carry_modulus: CarryModulus(value.carry_modulus as u64), + max_noise_level: MaxNoiseLevel::new(value.max_noise_level as u64), + 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"), + } + }, + modulus_switch_noise_reduction_params, + } + } +} + +impl From for PBSParameters { + fn from(value: TestParameterSet) -> Self { + let tmp: ClassicPBSParameters = value.into(); + tmp.into() + } +} + +const HL_CLIENTKEY_MS_NOISE_REDUCTION_TEST: HlClientKeyTest = HlClientKeyTest { + test_filename: Cow::Borrowed("client_key_ms_noise_reduction"), + parameters: INSECURE_SMALL_TEST_PARAMS_MS_NOISE_REDUCTION, +}; + +const HL_SERVERKEY_MS_NOISE_REDUCTION_TEST: HlServerKeyTest = HlServerKeyTest { + test_filename: Cow::Borrowed("server_key_ms_noise_reduction"), + client_key_filename: Cow::Borrowed("client_key_ms_noise_reduction.cbor"), + compressed: false, +}; + +const ZK_PKEV2_CRS_TEST: ZkPkePublicParamsTest = ZkPkePublicParamsTest { + test_filename: Cow::Borrowed("zk_pkev2_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 V1_0; + +impl TfhersVersion for V1_0 { + const VERSION_NUMBER: &'static str = "1.0"; + + 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 config = tfhe_1_0::ConfigBuilder::with_custom_parameters( + HL_CLIENTKEY_MS_NOISE_REDUCTION_TEST.parameters, + ) + .build(); + + let (hl_client_key, hl_server_key) = tfhe_1_0::generate_keys(config); + + store_versioned_test!( + &hl_client_key, + &dir, + &HL_CLIENTKEY_MS_NOISE_REDUCTION_TEST.test_filename + ); + store_versioned_test!( + &hl_server_key, + &dir, + &HL_SERVERKEY_MS_NOISE_REDUCTION_TEST.test_filename, + ); + + let mut zk_rng: RandomGenerator = + RandomGenerator::new(Seed(PRNG_SEED)); + + let zkv2_crs = CompactPkeCrs::new( + LweDimension(ZK_PKEV2_CRS_TEST.lwe_dimension), + LweCiphertextCount(ZK_PKEV2_CRS_TEST.max_num_cleartext), + TUniform::::new(ZK_PKEV2_CRS_TEST.noise_bound as u32), + CiphertextModulus::new(ZK_PKEV2_CRS_TEST.ciphertext_modulus), + ZK_PKEV2_CRS_TEST.plaintext_modulus as u64, + ZkMSBZeroPaddingBitCount(ZK_PKEV2_CRS_TEST.padding_bit_count as u64), + &mut zk_rng, + ) + .unwrap(); + + store_versioned_test!(&zkv2_crs, &dir, &ZK_PKEV2_CRS_TEST.test_filename,); + + vec![ + TestMetadata::HlClientKey(HL_CLIENTKEY_MS_NOISE_REDUCTION_TEST), + TestMetadata::HlServerKey(HL_SERVERKEY_MS_NOISE_REDUCTION_TEST), + TestMetadata::ZkPkePublicParams(ZK_PKEV2_CRS_TEST), + ] + } +} diff --git a/utils/tfhe-backward-compat-data/src/data_1_1.rs b/utils/tfhe-backward-compat-data/src/data_1_1.rs new file mode 100644 index 0000000000..4cdd93a215 --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/data_1_1.rs @@ -0,0 +1,304 @@ +use crate::generate::{ + store_versioned_test_tfhe_1_1, TfhersVersion, + INSECURE_SMALL_TEST_NOISE_SQUASHING_PARAMS_MS_NOISE_REDUCTION, + INSECURE_SMALL_TEST_PARAMS_MS_NOISE_REDUCTION, +}; +use crate::{ + HlClientKeyTest, HlServerKeyTest, HlSquashedNoiseBoolCiphertextTest, + HlSquashedNoiseSignedCiphertextTest, HlSquashedNoiseUnsignedCiphertextTest, TestDistribution, + TestMetadata, TestModulusSwitchNoiseReductionParams, TestModulusSwitchType, + TestNoiseSquashingParams, TestParameterSet, HL_MODULE_NAME, +}; +use std::borrow::Cow; +use std::fs::create_dir_all; +use tfhe_1_1::boolean::engine::BooleanEngine; +use tfhe_1_1::core_crypto::commons::generators::DeterministicSeeder; +use tfhe_1_1::core_crypto::commons::math::random::DefaultRandomGenerator; +use tfhe_1_1::core_crypto::prelude::{ + LweCiphertextCount, NoiseEstimationMeasureBound, RSigmaFactor, UnsignedInteger, Variance, +}; +use tfhe_1_1::prelude::*; +use tfhe_1_1::shortint::engine::ShortintEngine; +use tfhe_1_1::shortint::parameters::{ + CarryModulus, CiphertextModulus, ClassicPBSParameters, CoreCiphertextModulus, + DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, EncryptionKeyChoice, + GlweDimension, LweDimension, MaxNoiseLevel, MessageModulus, ModulusSwitchNoiseReductionParams, + NoiseSquashingParameters, PBSParameters, PolynomialSize, StandardDev, +}; +use tfhe_1_1::{set_server_key, CompressedServerKey, FheBool, FheInt64, FheUint64, Seed}; + +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_tfhe_1_1($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 ModulusSwitchNoiseReductionParams { + fn from(value: TestModulusSwitchNoiseReductionParams) -> Self { + let TestModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count, + ms_bound, + ms_r_sigma_factor, + ms_input_variance, + } = value; + + ModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count: LweCiphertextCount(modulus_switch_zeros_count), + ms_bound: NoiseEstimationMeasureBound(ms_bound), + ms_r_sigma_factor: RSigmaFactor(ms_r_sigma_factor), + ms_input_variance: Variance(ms_input_variance), + } + } +} + +impl From for ClassicPBSParameters { + fn from(value: TestParameterSet) -> Self { + let modulus_switch_noise_reduction_params = + match value.modulus_switch_noise_reduction_params { + TestModulusSwitchType::Standard => None, + TestModulusSwitchType::DriftTechniqueNoiseReduction( + test_modulus_switch_noise_reduction_params, + ) => Some(test_modulus_switch_noise_reduction_params.into()), + TestModulusSwitchType::CenteredMeanNoiseReduction => panic!("Not supported"), + }; + + 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 as u64), + carry_modulus: CarryModulus(value.carry_modulus as u64), + max_noise_level: MaxNoiseLevel::new(value.max_noise_level as u64), + 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"), + } + }, + modulus_switch_noise_reduction_params, + } + } +} + +impl From for PBSParameters { + fn from(value: TestParameterSet) -> Self { + let tmp: ClassicPBSParameters = value.into(); + tmp.into() + } +} + +impl From for NoiseSquashingParameters { + fn from(value: TestNoiseSquashingParams) -> Self { + let TestNoiseSquashingParams { + glwe_dimension, + polynomial_size, + glwe_noise_distribution, + decomp_base_log, + decomp_level_count, + modulus_switch_noise_reduction_params, + message_modulus, + carry_modulus, + ciphertext_modulus, + } = value; + + Self { + glwe_dimension: GlweDimension(glwe_dimension), + polynomial_size: PolynomialSize(polynomial_size), + glwe_noise_distribution: glwe_noise_distribution.into(), + decomp_base_log: DecompositionBaseLog(decomp_base_log), + decomp_level_count: DecompositionLevelCount(decomp_level_count), + modulus_switch_noise_reduction_params: modulus_switch_noise_reduction_params + .map(|p| p.into()), + message_modulus: MessageModulus(message_modulus.try_into().unwrap()), + carry_modulus: CarryModulus(carry_modulus.try_into().unwrap()), + ciphertext_modulus: if ciphertext_modulus == 0 { + CoreCiphertextModulus::new_native() + } else { + CoreCiphertextModulus::try_new(ciphertext_modulus).unwrap() + }, + } + } +} + +const HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST: HlClientKeyTest = HlClientKeyTest { + test_filename: Cow::Borrowed("client_key_with_noise_squashing"), + parameters: INSECURE_SMALL_TEST_PARAMS_MS_NOISE_REDUCTION, +}; + +const HL_SERVERKEY_MS_NOISE_REDUCTION_TEST: HlServerKeyTest = HlServerKeyTest { + test_filename: Cow::Borrowed("server_key_with_noise_squashing"), + client_key_filename: HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.test_filename, + compressed: false, +}; + +const HL_SERVERKEY_MS_NOISE_REDUCTION_COMPRESSED_TEST: HlServerKeyTest = HlServerKeyTest { + test_filename: Cow::Borrowed("server_key_with_noise_squashing_compressed"), + client_key_filename: HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.test_filename, + compressed: true, +}; + +const HL_SQUASHED_NOISE_UNSIGNED_CIPHERTEXT_TEST: HlSquashedNoiseUnsignedCiphertextTest = + HlSquashedNoiseUnsignedCiphertextTest { + test_filename: Cow::Borrowed("squashed_noise_unsigned_ciphertext"), + key_filename: HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.test_filename, + clear_value: 42, + }; + +const HL_SQUASHED_NOISE_SIGNED_CIPHERTEXT_TEST: HlSquashedNoiseSignedCiphertextTest = + HlSquashedNoiseSignedCiphertextTest { + test_filename: Cow::Borrowed("squashed_noise_signed_ciphertext"), + key_filename: HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.test_filename, + clear_value: -37, + }; + +const HL_SQUASHED_NOISE_BOOL_FALSE_CIPHERTEXT_TEST: HlSquashedNoiseBoolCiphertextTest = + HlSquashedNoiseBoolCiphertextTest { + test_filename: Cow::Borrowed("squashed_noise_bool_false_ciphertext"), + key_filename: HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.test_filename, + clear_value: false, + }; + +const HL_SQUASHED_NOISE_BOOL_TRUE_CIPHERTEXT_TEST: HlSquashedNoiseBoolCiphertextTest = + HlSquashedNoiseBoolCiphertextTest { + test_filename: Cow::Borrowed("squashed_noise_bool_true_ciphertext"), + key_filename: HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.test_filename, + clear_value: true, + }; + +pub struct V1_1; + +impl TfhersVersion for V1_1 { + const VERSION_NUMBER: &'static str = "1.1"; + + 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 config = tfhe_1_1::ConfigBuilder::with_custom_parameters( + HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.parameters, + ) + .enable_noise_squashing( + INSECURE_SMALL_TEST_NOISE_SQUASHING_PARAMS_MS_NOISE_REDUCTION.into(), + ) + .build(); + + let (hl_client_key, hl_server_key) = tfhe_1_1::generate_keys(config); + + set_server_key(hl_server_key.clone()); + + let ct_unsigned = FheUint64::encrypt( + HL_SQUASHED_NOISE_UNSIGNED_CIPHERTEXT_TEST.clear_value, + &hl_client_key, + ); + let ct_signed = FheInt64::encrypt( + HL_SQUASHED_NOISE_SIGNED_CIPHERTEXT_TEST.clear_value, + &hl_client_key, + ); + let ct_false = FheBool::encrypt( + HL_SQUASHED_NOISE_BOOL_FALSE_CIPHERTEXT_TEST.clear_value, + &hl_client_key, + ); + let ct_true = FheBool::encrypt( + HL_SQUASHED_NOISE_BOOL_TRUE_CIPHERTEXT_TEST.clear_value, + &hl_client_key, + ); + + let ct_unsigned = ct_unsigned.squash_noise().unwrap(); + let ct_signed = ct_signed.squash_noise().unwrap(); + let ct_false = ct_false.squash_noise().unwrap(); + let ct_true = ct_true.squash_noise().unwrap(); + + store_versioned_test!( + &hl_client_key, + &dir, + &HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST.test_filename + ); + store_versioned_test!( + &hl_server_key, + &dir, + &HL_SERVERKEY_MS_NOISE_REDUCTION_TEST.test_filename, + ); + + store_versioned_test!( + &ct_unsigned, + &dir, + &HL_SQUASHED_NOISE_UNSIGNED_CIPHERTEXT_TEST.test_filename, + ); + store_versioned_test!( + &ct_signed, + &dir, + &HL_SQUASHED_NOISE_SIGNED_CIPHERTEXT_TEST.test_filename, + ); + store_versioned_test!( + &ct_false, + &dir, + &HL_SQUASHED_NOISE_BOOL_FALSE_CIPHERTEXT_TEST.test_filename, + ); + store_versioned_test!( + &ct_true, + &dir, + &HL_SQUASHED_NOISE_BOOL_TRUE_CIPHERTEXT_TEST.test_filename, + ); + + let compressed_hl_server_key = CompressedServerKey::new(&hl_client_key); + + store_versioned_test!( + &compressed_hl_server_key, + &dir, + &HL_SERVERKEY_MS_NOISE_REDUCTION_COMPRESSED_TEST.test_filename, + ); + + vec![ + TestMetadata::HlClientKey(HL_CLIENTKEY_WITH_NOISE_SQUASHING_TEST), + TestMetadata::HlServerKey(HL_SERVERKEY_MS_NOISE_REDUCTION_TEST), + TestMetadata::HlServerKey(HL_SERVERKEY_MS_NOISE_REDUCTION_COMPRESSED_TEST), + TestMetadata::HlSquashedNoiseUnsignedCiphertext( + HL_SQUASHED_NOISE_UNSIGNED_CIPHERTEXT_TEST, + ), + TestMetadata::HlSquashedNoiseSignedCiphertext(HL_SQUASHED_NOISE_SIGNED_CIPHERTEXT_TEST), + TestMetadata::HlSquashedNoiseBoolCiphertext( + HL_SQUASHED_NOISE_BOOL_FALSE_CIPHERTEXT_TEST, + ), + TestMetadata::HlSquashedNoiseBoolCiphertext( + HL_SQUASHED_NOISE_BOOL_TRUE_CIPHERTEXT_TEST, + ), + ] + } +} diff --git a/utils/tfhe-backward-compat-data/src/data_1_3.rs b/utils/tfhe-backward-compat-data/src/data_1_3.rs new file mode 100644 index 0000000000..342f98830f --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/data_1_3.rs @@ -0,0 +1,458 @@ +use crate::generate::{ + store_versioned_auxiliary_tfhe_1_3, store_versioned_test_tfhe_1_3, TfhersVersion, + INSECURE_SMALL_TEST_PARAMS_MS_MEAN_COMPENSATION, PRNG_SEED, VALID_TEST_PARAMS_TUNIFORM, +}; +use crate::{ + DataKind, HlClientKeyTest, HlCompressedSquashedNoiseCiphertextListTest, + HlHeterogeneousCiphertextListTest, HlServerKeyTest, PkeZkProofAuxiliaryInfo, TestDistribution, + TestMetadata, TestModulusSwitchNoiseReductionParams, TestModulusSwitchType, + TestNoiseSquashingCompressionParameters, TestNoiseSquashingParams, TestParameterSet, + ZkPkePublicParamsTest, HL_MODULE_NAME, +}; +use std::borrow::Cow; +use std::fs::create_dir_all; + +use crate::generate::{ + INSECURE_SMALL_TEST_NOISE_SQUASHING_PARAMS_MS_NOISE_REDUCTION, + INSECURE_SMALL_TEST_PARAMS_MS_NOISE_REDUCTION, TEST_PRAMS_NOISE_SQUASHING_COMPRESSION, +}; + +use tfhe_1_3::boolean::engine::BooleanEngine; +use tfhe_1_3::core_crypto::commons::generators::DeterministicSeeder; +use tfhe_1_3::core_crypto::commons::math::random::RandomGenerator; +use tfhe_1_3::core_crypto::prelude::{DefaultRandomGenerator, TUniform}; +use tfhe_1_3::prelude::*; +use tfhe_1_3::shortint::engine::ShortintEngine; +use tfhe_1_3::shortint::parameters::{ + CarryModulus, CiphertextModulus, ClassicPBSParameters, CoreCiphertextModulus, + DecompositionBaseLog, DecompositionLevelCount, DynamicDistribution, EncryptionKeyChoice, + GlweDimension, LweCiphertextCount, LweDimension, MaxNoiseLevel, MessageModulus, + ModulusSwitchNoiseReductionParams, NoiseEstimationMeasureBound, + NoiseSquashingCompressionParameters, NoiseSquashingParameters, PolynomialSize, RSigmaFactor, + StandardDev, Variance, +}; +use tfhe_1_3::shortint::prelude::ModulusSwitchType; +use tfhe_1_3::shortint::AtomicPatternParameters; +use tfhe_1_3::zk::{CompactPkeCrs, ZkComputeLoad, ZkMSBZeroPaddingBitCount}; +use tfhe_1_3::{ + set_server_key, ClientKey, CompactPublicKey, CompressedSquashedNoiseCiphertextList, FheBool, + FheInt32, FheUint32, ProvenCompactCiphertextList, Seed, ServerKey, +}; + +macro_rules! store_versioned_test { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_test_tfhe_1_3($msg, $dir, $test_filename) + }; +} + +macro_rules! store_versioned_auxiliary { + ($msg:expr, $dir:expr, $test_filename:expr $(,)? ) => { + store_versioned_auxiliary_tfhe_1_3($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 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 ModulusSwitchNoiseReductionParams { + fn from(value: TestModulusSwitchNoiseReductionParams) -> Self { + let TestModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count, + ms_bound, + ms_r_sigma_factor, + ms_input_variance, + } = value; + + ModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count: LweCiphertextCount(modulus_switch_zeros_count), + ms_bound: NoiseEstimationMeasureBound(ms_bound), + ms_r_sigma_factor: RSigmaFactor(ms_r_sigma_factor), + ms_input_variance: Variance(ms_input_variance), + } + } +} + +impl From for ModulusSwitchType { + fn from(value: TestModulusSwitchType) -> Self { + match value { + TestModulusSwitchType::Standard => ModulusSwitchType::Standard, + TestModulusSwitchType::DriftTechniqueNoiseReduction( + test_modulus_switch_noise_reduction_params, + ) => ModulusSwitchType::DriftTechniqueNoiseReduction( + test_modulus_switch_noise_reduction_params.into(), + ), + TestModulusSwitchType::CenteredMeanNoiseReduction => { + ModulusSwitchType::CenteredMeanNoiseReduction + } + } + } +} + +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 as u64), + carry_modulus: CarryModulus(value.carry_modulus as u64), + max_noise_level: MaxNoiseLevel::new(value.max_noise_level as u64), + 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"), + } + }, + modulus_switch_noise_reduction_params: value + .modulus_switch_noise_reduction_params + .into(), + } + } +} + +impl From for AtomicPatternParameters { + fn from(value: TestParameterSet) -> Self { + let classic = ClassicPBSParameters::from(value); + + classic.into() + } +} + +impl From for NoiseSquashingParameters { + fn from(value: TestNoiseSquashingParams) -> Self { + let TestNoiseSquashingParams { + glwe_dimension, + polynomial_size, + glwe_noise_distribution, + decomp_base_log, + decomp_level_count, + modulus_switch_noise_reduction_params, + message_modulus, + carry_modulus, + ciphertext_modulus, + } = value; + + Self { + glwe_dimension: GlweDimension(glwe_dimension), + polynomial_size: PolynomialSize(polynomial_size), + glwe_noise_distribution: glwe_noise_distribution.into(), + decomp_base_log: DecompositionBaseLog(decomp_base_log), + decomp_level_count: DecompositionLevelCount(decomp_level_count), + modulus_switch_noise_reduction_params: match modulus_switch_noise_reduction_params { + Some(p) => ModulusSwitchType::DriftTechniqueNoiseReduction(p.into()), + None => ModulusSwitchType::Standard, + }, + message_modulus: MessageModulus(message_modulus as u64), + carry_modulus: CarryModulus(carry_modulus as u64), + ciphertext_modulus: CoreCiphertextModulus::try_new(ciphertext_modulus).unwrap(), + } + } +} + +impl From for NoiseSquashingCompressionParameters { + fn from(value: TestNoiseSquashingCompressionParameters) -> Self { + let TestNoiseSquashingCompressionParameters { + packing_ks_level, + packing_ks_base_log, + packing_ks_polynomial_size, + packing_ks_glwe_dimension, + lwe_per_glwe, + packing_ks_key_noise_distribution, + message_modulus, + carry_modulus, + ciphertext_modulus, + } = value; + + Self { + packing_ks_level: DecompositionLevelCount(packing_ks_level), + packing_ks_base_log: DecompositionBaseLog(packing_ks_base_log), + packing_ks_polynomial_size: PolynomialSize(packing_ks_polynomial_size), + packing_ks_glwe_dimension: GlweDimension(packing_ks_glwe_dimension), + lwe_per_glwe: LweCiphertextCount(lwe_per_glwe), + packing_ks_key_noise_distribution: packing_ks_key_noise_distribution.into(), + message_modulus: MessageModulus(message_modulus as u64), + carry_modulus: CarryModulus(carry_modulus as u64), + ciphertext_modulus: CoreCiphertextModulus::try_new(ciphertext_modulus).unwrap(), + } + } +} + +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, +}; + +const HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH: HlHeterogeneousCiphertextListTest = + HlHeterogeneousCiphertextListTest { + test_filename: Cow::Borrowed("hl_proven_heterogeneous_list_zkv2_fasthash"), + key_filename: Cow::Borrowed("client_key"), + clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + compressed: false, + proof_info: Some(PkeZkProofAuxiliaryInfo { + public_key_filename: Cow::Borrowed("public_key"), + params_filename: ZK_PKE_CRS_TEST.test_filename, + metadata: Cow::Borrowed("2vdrawkcab"), + }), + }; + +const HL_CLIENTKEY_MS_MEAN_COMPENSATION: HlClientKeyTest = HlClientKeyTest { + test_filename: Cow::Borrowed("client_key_ms_mean_compensation"), + parameters: INSECURE_SMALL_TEST_PARAMS_MS_MEAN_COMPENSATION, +}; + +const HL_SERVERKEY_MS_MEAN_COMPENSATION: HlServerKeyTest = HlServerKeyTest { + test_filename: Cow::Borrowed("server_key_ms_mean_compensation"), + client_key_filename: Cow::Borrowed("client_key_ms_mean_compensation.cbor"), + compressed: false, +}; + +const HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST: HlCompressedSquashedNoiseCiphertextListTest = + HlCompressedSquashedNoiseCiphertextListTest { + test_filename: Cow::Borrowed("hl_compressed_squashed_noise_ciphertext_list"), + key_filename: Cow::Borrowed("client_key_with_noise_squashing"), + clear_values: Cow::Borrowed(&[ + 54679568u32 as u64, + -12396372i32 as u64, + 12396372i32 as u64, + false as u64, + true as u64, + ]), + data_kinds: Cow::Borrowed(&[ + DataKind::Unsigned, + DataKind::Signed, + DataKind::Signed, + DataKind::Bool, + DataKind::Bool, + ]), + }; + +pub struct V1_3; + +impl TfhersVersion for V1_3 { + const VERSION_NUMBER: &'static str = "1.3"; + + 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)); + + // Generate a compact public key needed to create a compact list + let config = + tfhe_1_3::ConfigBuilder::with_custom_parameters(VALID_TEST_PARAMS_TUNIFORM).build(); + let hl_client_key = ClientKey::generate(config); + let hl_server_key = ServerKey::new(&hl_client_key); + set_server_key(hl_server_key.clone()); + let compact_pub_key = CompactPublicKey::new(&hl_client_key); + + let crs = CompactPkeCrs::new( + LweDimension(ZK_PKE_CRS_TEST.lwe_dimension), + LweCiphertextCount(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 the crs + store_versioned_auxiliary!(&crs, &dir, &ZK_PKE_CRS_TEST.test_filename); + + // Store the associated client key to be able to decrypt the ciphertexts in the list + store_versioned_auxiliary!( + &hl_client_key, + &dir, + &HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH.key_filename + ); + + store_versioned_auxiliary!( + &compact_pub_key, + &dir, + &HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH + .proof_info + .unwrap() + .public_key_filename + ); + + let mut proven_builder = ProvenCompactCiphertextList::builder(&compact_pub_key); + proven_builder + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH.clear_values[0] as u8) + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH.clear_values[1] as i8) + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH.clear_values[2] != 0) + .push(HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH.clear_values[3] != 0); + + let proven_list_packed = proven_builder + .build_with_proof_packed( + &crs, + HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH + .proof_info + .unwrap() + .metadata + .as_bytes(), + ZkComputeLoad::Verify, + ) + .unwrap(); + + store_versioned_test!( + &proven_list_packed, + &dir, + &HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH.test_filename, + ); + + let config = tfhe_1_3::ConfigBuilder::with_custom_parameters( + HL_CLIENTKEY_MS_MEAN_COMPENSATION.parameters, + ) + .build(); + + let (hl_client_key, hl_server_key) = tfhe_1_3::generate_keys(config); + + store_versioned_test!( + &hl_client_key, + &dir, + &HL_CLIENTKEY_MS_MEAN_COMPENSATION.test_filename + ); + store_versioned_test!( + &hl_server_key, + &dir, + &HL_SERVERKEY_MS_MEAN_COMPENSATION.test_filename, + ); + + // Generate data for the squashed noise compressed ciphertext list + { + let config = tfhe_1_3::ConfigBuilder::with_custom_parameters( + INSECURE_SMALL_TEST_PARAMS_MS_NOISE_REDUCTION, + ) + .enable_noise_squashing( + INSECURE_SMALL_TEST_NOISE_SQUASHING_PARAMS_MS_NOISE_REDUCTION.into(), + ) + .enable_noise_squashing_compression(TEST_PRAMS_NOISE_SQUASHING_COMPRESSION.into()) + .build(); + let hl_client_key = ClientKey::generate(config); + let hl_server_key = ServerKey::new(&hl_client_key); + set_server_key(hl_server_key.clone()); + + let input_a = FheUint32::encrypt( + HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST.clear_values[0] as u32, + &hl_client_key, + ); + let input_b = FheInt32::encrypt( + HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST.clear_values[1] as i32, + &hl_client_key, + ); + let input_c = FheInt32::encrypt( + HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST.clear_values[2] as i32, + &hl_client_key, + ); + let input_d = FheBool::encrypt( + HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST.clear_values[3] != 0, + &hl_client_key, + ); + let input_e = FheBool::encrypt( + HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST.clear_values[4] != 0, + &hl_client_key, + ); + + let ns_a = input_a.squash_noise().unwrap(); + let ns_b = input_b.squash_noise().unwrap(); + let ns_c = input_c.squash_noise().unwrap(); + let ns_d = input_d.squash_noise().unwrap(); + let ns_e = input_e.squash_noise().unwrap(); + + let compressed_list = CompressedSquashedNoiseCiphertextList::builder() + .push(ns_a) + .push(ns_b) + .push(ns_c) + .push(ns_d) + .push(ns_e) + .build() + .unwrap(); + + store_versioned_auxiliary!( + &hl_client_key, + &dir, + &HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST.key_filename + ); + + store_versioned_test!( + &compressed_list, + &dir, + &HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST.test_filename, + ); + }; + + vec![ + TestMetadata::HlHeterogeneousCiphertextList(HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH), + TestMetadata::HlClientKey(HL_CLIENTKEY_MS_MEAN_COMPENSATION), + TestMetadata::HlServerKey(HL_SERVERKEY_MS_MEAN_COMPENSATION), + TestMetadata::HlCompressedSquashedNoiseCiphertextList( + HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST, + ), + ] + } +} diff --git a/utils/tfhe-backward-compat-data/src/generate.rs b/utils/tfhe-backward-compat-data/src/generate.rs new file mode 100644 index 0000000000..f101bfe4e1 --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/generate.rs @@ -0,0 +1,308 @@ +use std::borrow::Cow; +use std::fs::{self, File}; +use std::path::{Path, PathBuf}; + +use bincode::Options; +use serde::Serialize; +use tfhe_0_11_versionable::Versionize as VersionizeTfhe_0_11; +use tfhe_1_0_versionable::Versionize as VersionizeTfhe_1_0; +use tfhe_1_1_versionable::Versionize as VersionizeTfhe_1_1; +use tfhe_1_3_versionable::Versionize as VersionizeTfhe_1_3; +use tfhe_versionable::{Versionize as VersionizeTfhe_0_10, Versionize as VersionizeTfhe_0_8}; + +use crate::{ + data_dir, dir_for_version, TestCompressionParameterSet, TestDistribution, TestMetadata, + TestModulusSwitchNoiseReductionParams, TestModulusSwitchType, + TestNoiseSquashingCompressionParameters, TestNoiseSquashingParams, TestParameterSet, +}; + +pub const PRNG_SEED: u128 = 0xdeadbeef; + +/// Valid parameter set that can be used in tfhe operations +pub const VALID_TEST_PARAMS: TestParameterSet = TestParameterSet { + lwe_dimension: 761, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TestDistribution::Gaussian { + stddev: 6.36835566258815e-06, + }, + glwe_noise_distribution: TestDistribution::Gaussian { + stddev: 3.1529322391500584e-16, + }, + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 3, + ks_level: 5, + message_modulus: 4, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -40.05, + ciphertext_modulus: 1 << 64, + encryption_key_choice: Cow::Borrowed("big"), + modulus_switch_noise_reduction_params: TestModulusSwitchType::Standard, +}; + +pub const VALID_TEST_PARAMS_TUNIFORM: TestParameterSet = TestParameterSet { + lwe_dimension: 887, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TestDistribution::TUniform { bound_log2: 46 }, + glwe_noise_distribution: TestDistribution::TUniform { bound_log2: 17 }, + pbs_base_log: 22, + pbs_level: 1, + ks_base_log: 3, + ks_level: 5, + message_modulus: 4, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -64.138, + ciphertext_modulus: 1 << 64, + encryption_key_choice: Cow::Borrowed("big"), + modulus_switch_noise_reduction_params: TestModulusSwitchType::Standard, +}; + +/// Those parameters are insecure and are used to generate small legacy public keys +pub const INSECURE_SMALL_PK_TEST_PARAMS: TestParameterSet = TestParameterSet { + lwe_dimension: 10, + glwe_dimension: 4, + polynomial_size: 512, + lwe_noise_distribution: TestDistribution::Gaussian { + stddev: 1.499_900_593_439_687_3e-6, + }, + glwe_noise_distribution: TestDistribution::Gaussian { + stddev: 2.845267479601915e-15, + }, + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 5, + ks_level: 3, + message_modulus: 2, + carry_modulus: 2, + max_noise_level: 3, + log2_p_fail: -64.05, + ciphertext_modulus: 1 << 64, + encryption_key_choice: Cow::Borrowed("small"), + modulus_switch_noise_reduction_params: TestModulusSwitchType::Standard, +}; + +/// Those parameters are insecure and are used to generate small legacy public keys +pub const INSECURE_SMALL_TEST_PARAMS_MS_NOISE_REDUCTION: TestParameterSet = TestParameterSet { + lwe_dimension: 2, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TestDistribution::TUniform { bound_log2: 45 }, + glwe_noise_distribution: TestDistribution::TUniform { bound_log2: 17 }, + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 4, + ks_level: 4, + message_modulus: 4, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -129.15284804376165, + ciphertext_modulus: 1 << 64, + encryption_key_choice: Cow::Borrowed("big"), + modulus_switch_noise_reduction_params: TestModulusSwitchType::DriftTechniqueNoiseReduction( + TestModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count: 2, + ms_bound: 288230376151711744f64, + ms_r_sigma_factor: 13.179852282053789f64, + ms_input_variance: 2.63039184094559e-7f64, + }, + ), +}; + +/// Those parameters are insecure and are used to generate small legacy public keys +pub const INSECURE_SMALL_TEST_PARAMS_MS_MEAN_COMPENSATION: TestParameterSet = TestParameterSet { + lwe_dimension: 2, + glwe_dimension: 1, + polynomial_size: 2048, + lwe_noise_distribution: TestDistribution::TUniform { bound_log2: 45 }, + glwe_noise_distribution: TestDistribution::TUniform { bound_log2: 17 }, + pbs_base_log: 23, + pbs_level: 1, + ks_base_log: 4, + ks_level: 4, + message_modulus: 4, + carry_modulus: 4, + max_noise_level: 5, + log2_p_fail: -129.15284804376165, + ciphertext_modulus: 1 << 64, + encryption_key_choice: Cow::Borrowed("big"), + modulus_switch_noise_reduction_params: TestModulusSwitchType::CenteredMeanNoiseReduction, +}; + +/// Those parameters are insecure and are used to generate small legacy public keys +/// Got with the above parameters for noise squashing +pub const INSECURE_SMALL_TEST_NOISE_SQUASHING_PARAMS_MS_NOISE_REDUCTION: TestNoiseSquashingParams = + TestNoiseSquashingParams { + glwe_dimension: 2, + polynomial_size: 2048, + glwe_noise_distribution: TestDistribution::TUniform { bound_log2: 30 }, + decomp_base_log: 24, + decomp_level_count: 3, + modulus_switch_noise_reduction_params: Some(TestModulusSwitchNoiseReductionParams { + modulus_switch_zeros_count: 2, + ms_bound: 288230376151711744f64, + ms_r_sigma_factor: 13.179852282053789f64, + ms_input_variance: 2.63039184094559e-7f64, + }), + message_modulus: 4, + carry_modulus: 4, + // 0 interpreted as native modulus for u128 + ciphertext_modulus: 0, + }; + +pub const TEST_PRAMS_NOISE_SQUASHING_COMPRESSION: TestNoiseSquashingCompressionParameters = + TestNoiseSquashingCompressionParameters { + packing_ks_level: 1, + packing_ks_base_log: 61, + packing_ks_polynomial_size: 1024, + packing_ks_glwe_dimension: 6, + lwe_per_glwe: 128, + packing_ks_key_noise_distribution: TestDistribution::TUniform { bound_log2: 3 }, + message_modulus: 4, + carry_modulus: 4, + ciphertext_modulus: 0, // native modulus for u128 + }; + +// Compression parameters for 2_2 TUniform +pub const VALID_TEST_PARAMS_TUNIFORM_COMPRESSION: TestCompressionParameterSet = + TestCompressionParameterSet { + br_level: 1, + br_base_log: 23, + packing_ks_level: 4, + packing_ks_base_log: 4, + packing_ks_polynomial_size: 256, + packing_ks_glwe_dimension: 4, + lwe_per_glwe: 256, + storage_log_modulus: 12, + packing_ks_key_noise_distribution: TestDistribution::TUniform { bound_log2: 42 }, + }; + +/// Invalid parameter set to test the limits +pub const INVALID_TEST_PARAMS: TestParameterSet = TestParameterSet { + lwe_dimension: usize::MAX, + glwe_dimension: usize::MAX, + polynomial_size: usize::MAX, + lwe_noise_distribution: TestDistribution::Gaussian { stddev: f64::MAX }, + glwe_noise_distribution: TestDistribution::Gaussian { stddev: f64::MAX }, + pbs_base_log: usize::MAX, + pbs_level: usize::MAX, + ks_base_log: usize::MAX, + ks_level: usize::MAX, + message_modulus: usize::MAX, + carry_modulus: usize::MAX, + max_noise_level: usize::MAX, + log2_p_fail: f64::MAX, + ciphertext_modulus: u128::MAX, + encryption_key_choice: Cow::Borrowed("big"), + modulus_switch_noise_reduction_params: TestModulusSwitchType::Standard, +}; + +pub fn save_cbor>(msg: &Data, path: P) { + let path = path.as_ref(); + if path.exists() { + panic!( + "Error while saving {}, file already exists, \ + indicating an error in the test file organization.", + path.display() + ); + } + let mut file = File::create(path).unwrap(); + ciborium::ser::into_writer(msg, &mut file).unwrap(); +} + +pub fn save_bcode>(msg: &Data, path: P) { + let path = path.as_ref(); + if path.exists() { + panic!( + "Error while saving {}, file already exists, \ + indicating an error in the test file organization.", + path.display() + ); + } + + let mut file = File::create(path).unwrap(); + let options = bincode::DefaultOptions::new().with_fixint_encoding(); + options.serialize_into(&mut file, msg).unwrap(); +} + +/// Stores the test data in `dir`, encoded in both cbor and bincode, using the right +/// tfhe-versionable version +macro_rules! define_store_versioned_test_fn { + ($fn_name:ident, $versionize_trait:ident) => { + pub fn $fn_name>( + msg: &Data, + dir: P, + test_filename: &str, + ) { + let versioned = msg.versionize(); + + // Store in cbor + let filename_cbor = format!("{}.cbor", test_filename); + save_cbor(&versioned, dir.as_ref().join(filename_cbor)); + + // Store in bincode + let filename_bincode = format!("{}.bcode", test_filename); + save_bcode(&versioned, dir.as_ref().join(filename_bincode)); + } + }; +} +define_store_versioned_test_fn!(store_versioned_test_tfhe_0_8, VersionizeTfhe_0_8); +define_store_versioned_test_fn!(store_versioned_test_tfhe_0_10, VersionizeTfhe_0_10); +define_store_versioned_test_fn!(store_versioned_test_tfhe_0_11, VersionizeTfhe_0_11); +define_store_versioned_test_fn!(store_versioned_test_tfhe_1_0, VersionizeTfhe_1_0); +define_store_versioned_test_fn!(store_versioned_test_tfhe_1_1, VersionizeTfhe_1_1); +define_store_versioned_test_fn!(store_versioned_test_tfhe_1_3, VersionizeTfhe_1_3); + +/// Stores the auxiliary data in `dir`, encoded in cbor, using the right tfhe-versionable version +macro_rules! define_store_versioned_auxiliary_fn { + ($fn_name:ident, $versionize_trait:ident) => { + pub fn $fn_name>( + msg: &Data, + dir: P, + test_filename: &str, + ) { + let versioned = msg.versionize(); + + // Store in cbor + let filename_cbor = format!("{}.cbor", test_filename); + save_cbor(&versioned, dir.as_ref().join(filename_cbor)); + } + }; +} +define_store_versioned_auxiliary_fn!(store_versioned_auxiliary_tfhe_0_8, VersionizeTfhe_0_8); +define_store_versioned_auxiliary_fn!(store_versioned_auxiliary_tfhe_0_10, VersionizeTfhe_0_10); +define_store_versioned_auxiliary_fn!(store_versioned_auxiliary_tfhe_0_11, VersionizeTfhe_0_11); +define_store_versioned_auxiliary_fn!(store_versioned_auxiliary_tfhe_1_3, VersionizeTfhe_1_3); + +pub fn store_metadata>(value: &Meta, path: P) { + let serialized = ron::ser::to_string_pretty(value, ron::ser::PrettyConfig::default()).unwrap(); + fs::write(path, serialized).unwrap(); +} + +pub trait TfhersVersion { + const VERSION_NUMBER: &'static str; + + fn data_dir() -> PathBuf { + let base_data_dir = data_dir(env!("CARGO_MANIFEST_DIR")); + dir_for_version(base_data_dir, Self::VERSION_NUMBER) + } + + /// How to fix the prng seed for this version to make sure the generated testcases do not change + /// every time we run the script + fn seed_prng(seed: u128); + + /// Generates data for the "shortint" module for this version. + /// This should create tfhe-rs shortint types, versionize them and store them into the version + /// specific directory. The metadata for the generated tests should be returned in the same + /// order that the tests will be run. + fn gen_shortint_data() -> Vec; + + /// Generates data for the "high_level_api" module for this version. + /// This should create tfhe-rs HL types, versionize them and store them into the version + /// specific directory. The metadata for the generated tests should be returned in the same + /// order that the tests will be run. + fn gen_hl_data() -> Vec; +} diff --git a/utils/tfhe-backward-compat-data/src/lib.rs b/utils/tfhe-backward-compat-data/src/lib.rs new file mode 100644 index 0000000000..083cbc355f --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/lib.rs @@ -0,0 +1,542 @@ +use core::f64; +use std::borrow::Cow; +use std::path::{Path, PathBuf}; + +#[cfg(feature = "load")] +use semver::{Prerelease, Version, VersionReq}; +#[cfg(feature = "load")] +use std::fmt::Display; +use strum::Display; + +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 data_1_0; +#[cfg(feature = "generate")] +pub mod data_1_1; +#[cfg(feature = "generate")] +pub mod data_1_3; +#[cfg(feature = "generate")] +pub mod generate; +#[cfg(feature = "load")] +pub mod load; + +const DATA_DIR: &str = "data"; + +pub const SHORTINT_MODULE_NAME: &str = "shortint"; +pub const HL_MODULE_NAME: &str = "high_level_api"; +pub const ZK_MODULE_NAME: &str = "zk"; + +/// This struct re-defines tfhe-rs parameter sets but this allows to be independent of changes made +/// into the ParameterSet of tfhe-rs. +/// +/// The idea here is to define a type that is able to carry the information of the used parameters +/// without using any tfhe-rs types. +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct TestParameterSet { + pub lwe_dimension: usize, + pub glwe_dimension: usize, + pub polynomial_size: usize, + pub lwe_noise_distribution: TestDistribution, + pub glwe_noise_distribution: TestDistribution, + pub pbs_base_log: usize, + pub pbs_level: usize, + pub ks_base_log: usize, + pub ks_level: usize, + pub message_modulus: usize, + pub ciphertext_modulus: u128, + pub carry_modulus: usize, + pub max_noise_level: usize, + pub log2_p_fail: f64, + pub encryption_key_choice: Cow<'static, str>, + pub modulus_switch_noise_reduction_params: TestModulusSwitchType, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct TestModulusSwitchNoiseReductionParams { + pub modulus_switch_zeros_count: usize, + pub ms_bound: f64, + pub ms_r_sigma_factor: f64, + pub ms_input_variance: f64, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub enum TestModulusSwitchType { + Standard, + DriftTechniqueNoiseReduction(TestModulusSwitchNoiseReductionParams), + CenteredMeanNoiseReduction, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct TestNoiseSquashingParams { + pub glwe_dimension: usize, + pub polynomial_size: usize, + pub glwe_noise_distribution: TestDistribution, + pub decomp_base_log: usize, + pub decomp_level_count: usize, + pub modulus_switch_noise_reduction_params: Option, + pub message_modulus: usize, + pub carry_modulus: usize, + pub ciphertext_modulus: u128, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct TestNoiseSquashingCompressionParameters { + pub packing_ks_level: usize, + pub packing_ks_base_log: usize, + pub packing_ks_polynomial_size: usize, + pub packing_ks_glwe_dimension: usize, + pub lwe_per_glwe: usize, + pub packing_ks_key_noise_distribution: TestDistribution, + pub message_modulus: usize, + pub carry_modulus: usize, + pub ciphertext_modulus: u128, +} + +/// This struct re-defines tfhe-rs compression parameter sets but this allows to be independent of +/// changes made into the ParameterSet of tfhe-rs. +/// +/// The idea here is to define a type that is able to carry the information of the used parameters +/// without using any tfhe-rs types. +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct TestCompressionParameterSet { + pub br_level: usize, + pub br_base_log: usize, + pub packing_ks_level: usize, + pub packing_ks_base_log: usize, + pub packing_ks_polynomial_size: usize, + pub packing_ks_glwe_dimension: usize, + pub lwe_per_glwe: usize, + pub storage_log_modulus: usize, + pub packing_ks_key_noise_distribution: TestDistribution, +} + +/// Representation of a random distribution that is independent from any tfhe-rs version +#[derive(Serialize, Deserialize, Clone, Debug)] +pub enum TestDistribution { + Gaussian { stddev: f64 }, + TUniform { bound_log2: u32 }, +} + +pub fn dir_for_version>(data_dir: P, version: &str) -> PathBuf { + let mut path = data_dir.as_ref().to_path_buf(); + path.push(version.replace('.', "_")); + + path +} + +pub fn data_dir>(root: P) -> PathBuf { + let mut path = PathBuf::from(root.as_ref()); + path.push(DATA_DIR); + + path +} + +pub trait TestType { + /// The tfhe-rs module where this type reside + fn module(&self) -> String; + + /// The Type that is tested + fn target_type(&self) -> String; + + /// The name of the file to be tested, without path or extension + /// (they will be inferred) + fn test_filename(&self) -> String; + + #[cfg(feature = "load")] + fn success(&self, format: load::DataFormat) -> load::TestSuccess { + load::TestSuccess { + module: self.module(), + target_type: self.target_type(), + test_filename: self.test_filename(), + format, + } + } + + #[cfg(feature = "load")] + fn failure(&self, error: E, format: load::DataFormat) -> load::TestFailure { + load::TestFailure { + module: self.module(), + target_type: self.target_type(), + test_filename: self.test_filename(), + source_error: format!("{}", error), + format, + } + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct ShortintClientKeyTest { + pub test_filename: Cow<'static, str>, + pub parameters: TestParameterSet, +} + +impl TestType for ShortintClientKeyTest { + fn module(&self) -> String { + SHORTINT_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "ClientKey".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct ShortintCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub clear_value: u64, +} + +impl TestType for ShortintCiphertextTest { + fn module(&self) -> String { + SHORTINT_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "Ciphertext".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlClientKeyTest { + pub test_filename: Cow<'static, str>, + pub parameters: TestParameterSet, +} + +impl TestType for HlClientKeyTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "ClientKey".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlServerKeyTest { + pub test_filename: Cow<'static, str>, + pub client_key_filename: Cow<'static, str>, + pub compressed: bool, +} + +impl TestType for HlServerKeyTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "ServerKey".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlPublicKeyTest { + pub test_filename: Cow<'static, str>, + pub client_key_filename: Cow<'static, str>, + pub compressed: bool, + pub compact: bool, +} + +impl TestType for HlPublicKeyTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "PublicKey".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub compressed: bool, + pub clear_value: u64, +} + +impl TestType for HlCiphertextTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "FheUint".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlSignedCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub compressed: bool, + pub clear_value: i64, +} + +impl TestType for HlSignedCiphertextTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "FheInt".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlBoolCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub compressed: bool, + pub clear_value: bool, +} + +impl TestType for HlBoolCiphertextTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "FheBool".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Copy, Debug)] +pub enum DataKind { + Bool, + Signed, + Unsigned, +} + +/// Info needed to be able to verify a pke proven compact list +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct PkeZkProofAuxiliaryInfo { + pub public_key_filename: Cow<'static, str>, + pub params_filename: Cow<'static, str>, + pub metadata: Cow<'static, str>, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlHeterogeneousCiphertextListTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub compressed: bool, + pub proof_info: Option, + pub clear_values: Cow<'static, [u64]>, + pub data_kinds: Cow<'static, [DataKind]>, +} + +impl TestType for HlHeterogeneousCiphertextListTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "CompactCiphertextList".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlCompressedSquashedNoiseCiphertextListTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub clear_values: Cow<'static, [u64]>, + pub data_kinds: Cow<'static, [DataKind]>, +} + +impl TestType for HlCompressedSquashedNoiseCiphertextListTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "SquashedNoiseCiphertextList".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlSquashedNoiseUnsignedCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub clear_value: u64, +} + +impl TestType for HlSquashedNoiseUnsignedCiphertextTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "SquashedNoiseFheUint".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlSquashedNoiseSignedCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub clear_value: i64, +} + +impl TestType for HlSquashedNoiseSignedCiphertextTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "SquashedNoiseFheInt".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct HlSquashedNoiseBoolCiphertextTest { + pub test_filename: Cow<'static, str>, + pub key_filename: Cow<'static, str>, + pub clear_value: bool, +} + +impl TestType for HlSquashedNoiseBoolCiphertextTest { + fn module(&self) -> String { + HL_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "SquashedNoiseFheBool".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct ZkPkePublicParamsTest { + pub test_filename: Cow<'static, str>, + pub lwe_dimension: usize, + pub max_num_cleartext: usize, + pub noise_bound: usize, + pub ciphertext_modulus: u128, + pub plaintext_modulus: usize, + pub padding_bit_count: usize, +} + +impl TestType for ZkPkePublicParamsTest { + fn module(&self) -> String { + ZK_MODULE_NAME.to_string() + } + + fn target_type(&self) -> String { + "CompactPkePublicParams".to_string() + } + + fn test_filename(&self) -> String { + self.test_filename.to_string() + } +} + +#[derive(Serialize, Deserialize, Clone, Debug, Display)] +pub enum TestMetadata { + // Shortint + ShortintCiphertext(ShortintCiphertextTest), + ShortintClientKey(ShortintClientKeyTest), + + // Hl + HlCiphertext(HlCiphertextTest), + HlSignedCiphertext(HlSignedCiphertextTest), + HlBoolCiphertext(HlBoolCiphertextTest), + HlHeterogeneousCiphertextList(HlHeterogeneousCiphertextListTest), + HlClientKey(HlClientKeyTest), + HlServerKey(HlServerKeyTest), + HlPublicKey(HlPublicKeyTest), + ZkPkePublicParams(ZkPkePublicParamsTest), /* We place it in the hl folder since it is + * currently used with hl tests: */ + HlSquashedNoiseUnsignedCiphertext(HlSquashedNoiseUnsignedCiphertextTest), + HlSquashedNoiseSignedCiphertext(HlSquashedNoiseSignedCiphertextTest), + HlSquashedNoiseBoolCiphertext(HlSquashedNoiseBoolCiphertextTest), + HlCompressedSquashedNoiseCiphertextList(HlCompressedSquashedNoiseCiphertextListTest), +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Testcase { + pub tfhe_version_min: String, + pub tfhe_module: String, + pub metadata: TestMetadata, +} + +#[cfg(feature = "load")] +impl Testcase { + pub fn is_valid_for_version(&self, version: &str) -> bool { + let mut tfhe_version = Version::parse(version).unwrap(); + + // Removes the pre-release tag because matches will always return + tfhe_version.pre = Prerelease::EMPTY; + + let req = format!(">={}", self.tfhe_version_min); + let min_version = VersionReq::parse(&req).unwrap(); + + min_version.matches(&tfhe_version) + } + + pub fn skip(&self) -> load::TestSkipped { + load::TestSkipped { + module: self.tfhe_module.to_string(), + test_name: self.metadata.to_string(), + } + } +} diff --git a/utils/tfhe-backward-compat-data/src/load.rs b/utils/tfhe-backward-compat-data/src/load.rs new file mode 100644 index 0000000000..3574106baa --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/load.rs @@ -0,0 +1,152 @@ +use std::fmt::Display; +use std::fs::{self, File}; +use std::path::Path; + +use bincode::{DefaultOptions, Options}; +use serde::de::DeserializeOwned; + +use crate::{TestType, Testcase}; + +/// Loads auxiliary data that might be needed for a test (eg: a key to test a ciphertext) +/// If the path has an extension the file is loaded as is, if not it adds the .cbor extension +pub fn load_versioned_auxiliary>( + path: P, +) -> Result { + let path = path.as_ref(); + let path = match path.extension() { + Some(_) => path.to_path_buf(), + None => path.with_extension("cbor"), + }; + + let path = path.as_path(); + + let file = File::open(path) + .map_err(|e| format!("Failed to read auxiliary file {}: {}", path.display(), e))?; + ciborium::de::from_reader(file) + .map_err(|e| format!("Failed to parse auxiliary file {}: {}", path.display(), e)) +} + +#[derive(Copy, Clone, Debug)] +pub enum DataFormat { + Cbor, + Bincode, +} + +impl Display for DataFormat { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl DataFormat { + pub fn extension(&self) -> &'static str { + match self { + DataFormat::Cbor => "cbor", + DataFormat::Bincode => "bcode", + } + } + + /// Loads the file that should be tested + pub fn load_versioned_test, T: TestType>( + self, + dir: P, + test: &T, + ) -> Result { + let filename = format!("{}.{}", test.test_filename(), self.extension()); + let file = File::open(dir.as_ref().join(filename)) + .map_err(|e| test.failure(format!("Failed to read testcase: {}", e), self))?; + + match self { + Self::Cbor => ciborium::de::from_reader(file).map_err(|e| test.failure(e, self)), + Self::Bincode => { + let options = DefaultOptions::new().with_fixint_encoding(); + options + .deserialize_from(file) + .map_err(|e| test.failure(e, self)) + } + } + } +} + +pub enum TestResult { + Success(TestSuccess), + Failure(TestFailure), + Skipped(TestSkipped), +} + +impl From> for TestResult { + fn from(value: Result) -> Self { + match value { + Ok(success) => Self::Success(success), + Err(failure) => Self::Failure(failure), + } + } +} + +impl TestResult { + pub fn is_failure(&self) -> bool { + match self { + TestResult::Failure(_) => true, + TestResult::Success(_) | TestResult::Skipped(_) => false, + } + } +} + +pub struct TestFailure { + pub(crate) module: String, + pub(crate) target_type: String, + pub(crate) test_filename: String, + pub(crate) source_error: String, + pub(crate) format: DataFormat, +} + +impl Display for TestFailure { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Test: {}::{} in file {}.{}: FAILED: {}", + self.module, + self.target_type, + self.test_filename, + self.format.extension(), + self.source_error + ) + } +} + +pub struct TestSuccess { + pub(crate) module: String, + pub(crate) target_type: String, + pub(crate) test_filename: String, + pub(crate) format: DataFormat, +} + +impl Display for TestSuccess { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Test: {}::{} using file {}.{}: SUCCESS", + self.module, + self.target_type, + self.test_filename, + self.format.extension(), + ) + } +} + +pub struct TestSkipped { + pub(crate) module: String, + pub(crate) test_name: String, +} + +impl Display for TestSkipped { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Test: {}::{}: SKIPPED", self.module, self.test_name) + } +} + +pub fn load_tests_metadata>(path: P) -> Result, String> { + let serialized = + fs::read_to_string(path).map_err(|e| format!("Failed to load test metadata: {}", e))?; + ron::from_str(&serialized).map_err(|e| format!("Invalid test metadata: {}", e)) +} diff --git a/utils/tfhe-backward-compat-data/src/main.rs b/utils/tfhe-backward-compat-data/src/main.rs new file mode 100644 index 0000000000..c322fd7860 --- /dev/null +++ b/utils/tfhe-backward-compat-data/src/main.rs @@ -0,0 +1,76 @@ +use std::fs::remove_dir_all; +use std::thread; +use tfhe_backward_compat_data::data_0_10::V0_10; +use tfhe_backward_compat_data::data_0_11::V0_11; +use tfhe_backward_compat_data::data_0_8::V0_8; +use tfhe_backward_compat_data::data_1_0::V1_0; +use tfhe_backward_compat_data::data_1_1::V1_1; +use tfhe_backward_compat_data::data_1_3::V1_3; +use tfhe_backward_compat_data::generate::{store_metadata, TfhersVersion, PRNG_SEED}; +use tfhe_backward_compat_data::{data_dir, Testcase, HL_MODULE_NAME, SHORTINT_MODULE_NAME}; + +fn gen_all_data() -> Vec { + Vers::seed_prng(PRNG_SEED); + + let shortint_tests = Vers::gen_shortint_data(); + + let mut tests: Vec = shortint_tests + .iter() + .map(|metadata| Testcase { + tfhe_version_min: Vers::VERSION_NUMBER.to_string(), + tfhe_module: SHORTINT_MODULE_NAME.to_string(), + metadata: metadata.clone(), + }) + .collect(); + + let hl_tests = Vers::gen_hl_data(); + + tests.extend(hl_tests.iter().map(|metadata| Testcase { + tfhe_version_min: Vers::VERSION_NUMBER.to_string(), + tfhe_module: HL_MODULE_NAME.to_string(), + metadata: metadata.clone(), + })); + + tests +} + +fn main() { + let root_dir = env!("CARGO_MANIFEST_DIR"); + let data_dir_path = data_dir(root_dir); + remove_dir_all(&data_dir_path).unwrap(); + + let handler_v0_8 = thread::spawn(gen_all_data::); + let handler_v0_10 = thread::spawn(gen_all_data::); + let handler_v0_11 = thread::spawn(gen_all_data::); + let handler_v1_0 = thread::spawn(gen_all_data::); + let handler_v1_1 = thread::spawn(gen_all_data::); + let handler_v1_3 = thread::spawn(gen_all_data::); + + let mut testcases = vec![]; + + testcases.extend_from_slice(&handler_v0_8.join().unwrap()); + testcases.extend_from_slice(&handler_v0_10.join().unwrap()); + testcases.extend_from_slice(&handler_v0_11.join().unwrap()); + testcases.extend_from_slice(&handler_v1_0.join().unwrap()); + testcases.extend_from_slice(&handler_v1_1.join().unwrap()); + testcases.extend_from_slice(&handler_v1_3.join().unwrap()); + + let shortint_testcases: Vec = testcases + .iter() + .filter(|test| test.tfhe_module == SHORTINT_MODULE_NAME) + .cloned() + .collect(); + + store_metadata(&shortint_testcases, data_dir_path.join("shortint.ron")); + + let high_level_api_testcases: Vec = testcases + .iter() + .filter(|test| test.tfhe_module == HL_MODULE_NAME) + .cloned() + .collect(); + + store_metadata( + &high_level_api_testcases, + data_dir_path.join("high_level_api.ron"), + ); +}