chore(backward): integrate backward compat data

Code is taken from
59a6179831

Adapted to make ci work
This commit is contained in:
Nicolas Sarlin
2025-06-30 18:02:18 +02:00
committed by Nicolas Sarlin
parent 97ce0f6ecf
commit 57cbab9fe1
127 changed files with 4470 additions and 113 deletions

2
.gitattributes vendored
View File

@@ -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

View File

@@ -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 }}
# Cache key is an aggregated hash of lfs files hashes
- name: Get LFS data sha
id: hash-lfs-data
run: |
echo "BACKWARD_COMPAT_DATA_BRANCH=${PR_BRANCH}" >> "${GITHUB_ENV}"
- name: Get backward compat branch
id: backward_compat_branch
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' }}

View File

@@ -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

View File

@@ -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:

View File

@@ -18,7 +18,7 @@ members = [
]
exclude = [
"tests/backward_compatibility_tests",
"utils/tfhe-backward-compat-data",
"utils/tfhe-lints",
"apps/trivium",
]

View File

@@ -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 '"'
@@ -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,9 @@ 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)
tests/$(BACKWARD_COMPAT_DATA_DIR): clone_backward_compat_data
.PHONY: pull_backward_compat_data # Clone the data repo needed for backward compatibility tests
pull_backward_compat_data:
./scripts/pull_backward_compat_data.sh $(BACKWARD_COMPAT_DATA_DIR)
#
# Real use case examples

View File

@@ -203,7 +203,7 @@ In order to run those applications on hardware, user must build from the project
> 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:
> ```bash
> git lfs pull --include="*" --exclude=""
> git lfs pull --include="*.hpu" --exclude=""
> ```
``` 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=""
> git lfs pull --include="*.hpu" --exclude=""
> ```

View File

@@ -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)

View File

@@ -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

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
if [ $# -lt 1 ]; then
echo "invalid arguments, usage:\n"
echo "$0 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
git lfs pull --include="$1/*" --exclude="*.hpu"

View File

@@ -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> {

View File

@@ -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"

View File

@@ -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<M: TestedModule>(base_dir: &Path) -> Vec<TestResult> {
// 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
}

View File

@@ -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"]

View File

@@ -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<TestMetadata> {
// ...
// 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<TestSuccess, TestFailure> {
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<P: AsRef<Path>>(
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.

View File

@@ -0,0 +1,2 @@
[files]
extend-exclude = ["*.cbor"]

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e431d4f131647646961ed1ab1cc880fd61f15f83348d2ae1b8f442ee7e75fc1e
size 32106

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e8cb90afb13749e5c9cf5cf2756bfde435bd92f664c5e65ad9cc4bc908eb36ab
size 4950

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ca23804965ad52b18c4c55e092c7f8fb9155d7118eff45bb5eaffa769d671a3a
size 79479387

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3fb66b429b3fc8bb722e5161b84aac0e71a528bd457089adafe4e527dc6a53ab
size 89414885

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fb1e0dd0d081b34f2819d216028777b26a38e161055bfd15d20b3d5e2ad5446e
size 281931995

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a6549ea09324d0d9cccee89b21eb85982fa1bf41cf21873fda78939f06e1613b
size 324955532

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0665c8fd54940bb07b3b77520666840c8b5c24be1e5a09ba45bdedb1c064dc72
size 3578

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:15bbcc8caf2de5bfaf8c19f84f380664e92094b49f5f0728d08abb8d781d03c3
size 19241

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d70134cca9b2a0e68cc4b147a0177e6475831dda57e58405323c8a0f58cc5506
size 21985

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:25f01ede3660a9b0720d0f4a80c675d4c2a8ed95574d0d07a7a1f80db254cc73
size 37310

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a399e9866ffe9110e6c42914daf246a551c06fa70f64f9b3f9b109a802db2e9d
size 5569088

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8e615cbcbe08eeaf16688f2bd8bad302b7d7f1d6fe6c0b1ca061419c9aed5f06
size 6528206

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:146d966218f0f778b9293839215a232e141ec0199779425660229ab98028b805
size 23766

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:47a478a96630436611d31d6a79c0bde8749a980d99a079af60b5e4e9c37cdc6d
size 3578

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:71db61e78f0d276e865346970bd8deea122e0f46e195a7ac274bdc3c05d3dd42
size 4950

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cc7a4ab83002e4683189ad424287d76ff56c5ff1d840cd837f8164ab9f51f73f
size 16516

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ea98b569589885bebb74328e59b085d785370b4df15bd0292acf301de90db03c
size 18651

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:dd15a41d66f3e31fbe22cae273923faa3490388337262b1e177bfc7d47cade54
size 16516

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:368460a46dd08f30a9bf9d86832fe250f419e8dbbe4c77e7581e22c7529836a8
size 18651

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bf4b2e7f41739279478ef97b66c3b6ecc31d18579d9124c644893e8551f4ee68
size 2696

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a151f56655e58ba7acda326e95eea7a7189f116f59641de6c049b8e3047092a9
size 32106

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:71db61e78f0d276e865346970bd8deea122e0f46e195a7ac274bdc3c05d3dd42
size 4950

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:12021e06a8bfc377d88c32a584008bddff31ad54f17b30452af2203bd53f0f0b
size 32952

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b976505df0bc4b475bb34636f86acc03a3568644cba96ecaaedb149c179093b9
size 37281

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0d2cc68b39fc2529bb9115eca21dd7f94c87e2f71a7ca0a9a0c3ceddf4a76a31
size 16588

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2b17d65d770f29860c37967caf803486b4d06ec56ae047b9477277936bcbdda7
size 18893

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8aa5e8c7b74078e2a8d86cea8824cfa438974a795da47f5f0d9c4c3c8e865d87
size 1050440

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:50c30df30f274cb44940049b47515a764dcabfc4d3a4e014222262c500aefa67
size 1182066

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4c1bc3c59328d829b8b91fda11b10542066d73502df89a35adcad94770a121eb
size 156

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:840a8de5a8453b4155e6717a8e9726ae9ca205c9849ceafb5eb2d8a5a0dc4c01
size 276

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fc5a5a7730bf3c9d88c179b9ac660936da62c36a8f4ec2a4339402ac6f640da2
size 156

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6e6a55d561f1d4e4702944ccfb3f79fd7663fc6ad986b46ee0d508453bcfb9c9
size 276

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1fd37585babb5df46a7f3fb59ec40a481ee5bd7997ea26cd0551752ea29119a7
size 66000

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:51c71499c8318d8206206ff7b4e97750c3e2c22e79792c16c20c72b214f45a0f
size 74497

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9d1b2cf05880a7aaee6cc5eda9d8e6c4a1a7985dbe3a709beb3d47b5514c833f
size 66000

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:09f81282b98ac41860ab7629d481e7979a62d834189f7c48c04ebf0d8525e244
size 74497

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cbaf57d728f9061ada49adab6b892283ac26d143ddfe40e5bfd0023042336edd
size 66000

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6e6dfa851d8a9706ff5ac4c90b1edee3624bf31aea0974cfdd45cf1f75ab7f73
size 74497

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e2fd35aa39145a4dbae4d9eff653724d181074e879256b233982da34b0d1ee16
size 66000

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8821ea05f65efcc6bd67be80ac94ecfe3f4f8fa65992cbe81719c8e01ee48717
size 74497

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8378a6ce7b70b9e8a9d0b242bfefcf55f4ee1df3fe87ce8d27d18db09c333b4d
size 2977

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8d75390fd4fd4484352aa2076019df44a5ceb7c835ab9f6444dbb2dba5e6b268
size 3697

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:716dc0d7ed2d136bbadb21838c99a18697abba0fc50c8f6b6f80dcec9e1ad8b6
size 2977

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0f1632b8cda925497a9d90f102fb0292132ffcc2fdad0604896730156ee6ec4f
size 3697

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cc9e04bb4d92d008e01606249b955a0eab037d1d5757c5a37d65c4fd953ec14d
size 564

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9651321b8c4af1bf0df369de4d427e854604ec456131f6c4948fc6a59bedf726
size 1009

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cc46fa11c1c0ebb35cd93d315835f33ae3b6ef1606a37252bb95c1601b2c79ee
size 564

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:293e0207346f13bce6ce51b83b98351debdf8774d6e5958a82460d22bed62d4c
size 1009

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e94dd2396b283fc379456cdfcce55cbda7e117ca1b0ebe22241489394c14c5b7
size 1824

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:075182f7f707dae42748e8685fd673edbc041658d2b9ab197c61476256ba7be6
size 2240

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fae52ee430a33ded5abd0b0e39b85ee3043c64b25950cd8048285c972abce823
size 16672

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:938540698c799e6b52a29f32d350293abcd3103a2ed79255efdabd1ff3b8f0d6
size 18857

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:63c6da03b45d45d4b17b9493c2fdf23fb24beb80330f08f04bfd829a2a29de2b
size 16632

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2f6f10290d8a14c6ff42ad00f26d75572c512a6ce54584e0ad23f38aa2f02cea
size 18812

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:617b7963be92d1738ed48f1cc24dda73313936436107b7544f31fb13fbb2bcc1
size 17803

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d2b0a4d294832d2e192dc17dc25859a4fc86e90f6a02e8b8f7c7c1301182f72c
size 20219

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:814c99341c2287831f6bae2f9023f6c94efd5eebcc0bb56161fe222b1059360f
size 73548

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6819ec3fb394ae1734b59790afee68d5c1eccd2b0d39081336839d4bd87c1755
size 83006

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:22fc922125d1c4e637024e1e60aca241ce25d5711f4eb91f5a0878ad9e75f9d0
size 37281

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8266d6a67a066d8fc4293fd585ca47a2d37aaf1f92f2529188f56a5c41cee650
size 71361608

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e97570c813f155afd26e67fd1ddd6da9c36ba27927f6e2afb1c98c39de051cfb
size 83628033

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:19607a68963124293e9f6c23b1e4d1d979449dab469f56e90b1e60f062d2d567
size 22756

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c188d9ce6b8c76048fd5bd9c4ec95baaef1163f2defd04c611fccd9de1d7978d
size 3357

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:35aa7cf9a50390a40ef6954df7ab11fa41d25147536bff4cd94fb0701ebfa5b3
size 16492

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bf685e9f6ea5d37e7ef99e1b6f1d0a08048aedf55d0df3d0b8ed2aef8a6c22dc
size 18611

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:11ad79733468d9cca094a212ca28d8e483f9722f92b90bcf305c410b223ecfd0
size 16492

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e756b2245869ccbb924615c5b31a3046c062b7fed83a41bd4bb6e288e138299d
size 18611

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a9ba3154fe5c62a66f5e5ac470b8274c421f6eba460101d377d0a8c2f77dd5df
size 16739

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:58b3d49233372543034d927d3e8ed739433e7f849329a8e2d35e94d49d848a5c
size 2846

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9bb8e4834fa72ac221e5e17c5881047465b01c04433d9bdfbe6495a9ef7d0b3a
size 328164

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b5dedbb8f84874d231ea0b0545db353b8bd67dd76316ea3779ff95a3b8d83d0b
size 377700

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a399e9866ffe9110e6c42914daf246a551c06fa70f64f9b3f9b109a802db2e9d
size 5569088

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8e615cbcbe08eeaf16688f2bd8bad302b7d7f1d6fe6c0b1ca061419c9aed5f06
size 6528206

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:25106962325ba12671b816b79771bfc102a5d74962259a68998bf667184c1bae
size 82481

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ca9433f606f27550480895b75fedf3957b3cdee46089b37c7f05c957f2008294
size 7465

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:69fa342aa6cc52f4f9528b55a61bd87fcac57da5fdea87b1d6d5d05bc8ca1159
size 2097934

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:39b04eaff98c98c0f51163a74ae821e93894988ec30128f9a4e48d7c68d3d765
size 2368948

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bc03714323a315eb7b3c79f6fcb124dcc588bba633c389c4be89fac6adc85f7c
size 721658

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d696bafc1a0da473258d9a8826e1436e61a486d5015e802af1ff35e7d00caa0e
size 812484

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3c486f00d1f538577613af10484f15f82b3cd374124c65d7411d9bdbed133665
size 65656

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e4f73a00be15a9da70dd08b5e575ea5a5a0fbc391d75afe2c92c0af5827e3640
size 73898

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:620b761dd3c3849d0e4f014233722af66b3529095f942b7c770ed0978f0d9f97
size 65656

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b21c9cc51ecb98e9c57e0b746bee0871e34bc6f8397ef908febcc1b2cc2ca502
size 73900

View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:845971c67ddff7ecb28a76fad7a87f9025b1f4da8ae074591aff37a78441f57f
size 1050152

Some files were not shown because too many files have changed in this diff Show More