Skip to content

Commit dfffd1d

Browse files
committed
refactor(backward_compat): change clear_values to be i64 instead of u64
i64 is a bit more natural for storing negative/positive Only the ron file needed an update as it stores values as text the binary files use the same binary repr as Rust (two's complement) so they don't need to change as the binary pattern is the same
1 parent 31aac3e commit dfffd1d

File tree

8 files changed

+35
-35
lines changed

8 files changed

+35
-35
lines changed

tests/backward_compatibility/high_level_api.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub fn test_hl_heterogeneous_ciphertext_list_elements<CtList: CiphertextList>(
256256

257257
fn verify_expanded_values<CtList>(
258258
list: &CtList,
259-
clear_values: &[u64],
259+
clear_values: &[i64],
260260
data_kinds: &[DataKind],
261261
key: &ClientKey,
262262
) -> Result<(), String>
@@ -327,13 +327,14 @@ where
327327

328328
/// Shared core for seeded compact ciphertext list backward compat tests.
329329
/// When `zk_proof_info` is `Some`, operates in ZK (proven) mode; otherwise plain mode.
330+
#[allow(clippy::too_many_arguments)]
330331
fn test_hl_seeded_compact_list_core<T: TestType>(
331332
dir: &Path,
332333
test: &T,
333334
format: DataFormat,
334335
key_filename: &str,
335336
public_key_filename: &str,
336-
clear_values: &[u64],
337+
clear_values: &[i64],
337338
data_kinds: &[DataKind],
338339
seed: &[u8],
339340
zk_proof_info: Option<&ZkProofAuxiliaryInfo>,
@@ -960,21 +961,20 @@ pub fn test_hl_compressed_squashed_noise_ciphertext_list(
960961
}
961962

962963
for i in 0..list.len() {
963-
let decrypted = match test.data_kinds[i] {
964+
let decrypted: i64 = match test.data_kinds[i] {
964965
DataKind::Unsigned => {
965966
let ct: SquashedNoiseFheUint = list.get(i).unwrap().unwrap();
966967
let clear: u64 = ct.decrypt(&key);
967-
clear
968+
clear as i64
968969
}
969970
DataKind::Signed => {
970971
let ct: SquashedNoiseFheInt = list.get(i).unwrap().unwrap();
971-
let clear: i64 = ct.decrypt(&key);
972-
clear as u64
972+
ct.decrypt(&key)
973973
}
974974
DataKind::Bool => {
975975
let ct: SquashedNoiseFheBool = list.get(i).unwrap().unwrap();
976976
let clear: bool = ct.decrypt(&key);
977-
clear as u64
977+
clear as i64
978978
}
979979
};
980980

utils/tfhe-backward-compat-data/crates/generate_0_11/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const HL_PROVEN_COMPACTLIST_TEST_ZKV2: HlHeterogeneousCiphertextListTest =
4444
HlHeterogeneousCiphertextListTest {
4545
test_filename: Cow::Borrowed("hl_proven_heterogeneous_list_zkv2"),
4646
key_filename: HL_CLIENTKEY_TEST.test_filename,
47-
clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]),
47+
clear_values: Cow::Borrowed(&[17u8 as i64, -12i8 as i64, false as i64, true as i64]),
4848
data_kinds: Cow::Borrowed(&[
4949
DataKind::Unsigned,
5050
DataKind::Signed,

utils/tfhe-backward-compat-data/crates/generate_0_8/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const HL_CLIENT_KEY_BATCH_2_FILENAME: &str = "batch_2_client_key";
170170
const HL_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest = HlHeterogeneousCiphertextListTest {
171171
test_filename: Cow::Borrowed("hl_heterogeneous_list"),
172172
key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_2_FILENAME),
173-
clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]),
173+
clear_values: Cow::Borrowed(&[17u8 as i64, -12i8 as i64, false as i64, true as i64]),
174174
data_kinds: Cow::Borrowed(&[
175175
DataKind::Unsigned,
176176
DataKind::Signed,
@@ -195,7 +195,7 @@ const HL_COMPRESSED_LIST_TEST: HlHeterogeneousCiphertextListTest =
195195
HlHeterogeneousCiphertextListTest {
196196
test_filename: Cow::Borrowed("hl_compressed_heterogeneous_list"),
197197
key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_2_FILENAME),
198-
clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]),
198+
clear_values: Cow::Borrowed(&[17u8 as i64, -12i8 as i64, false as i64, true as i64]),
199199
data_kinds: Cow::Borrowed(&[
200200
DataKind::Unsigned,
201201
DataKind::Signed,
@@ -210,7 +210,7 @@ const HL_PROVEN_COMPACTLIST_TEST: HlHeterogeneousCiphertextListTest =
210210
HlHeterogeneousCiphertextListTest {
211211
test_filename: Cow::Borrowed("hl_proven_heterogeneous_list"),
212212
key_filename: Cow::Borrowed(HL_CLIENT_KEY_BATCH_2_FILENAME),
213-
clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]),
213+
clear_values: Cow::Borrowed(&[17u8 as i64, -12i8 as i64, false as i64, true as i64]),
214214
data_kinds: Cow::Borrowed(&[
215215
DataKind::Unsigned,
216216
DataKind::Signed,

utils/tfhe-backward-compat-data/crates/generate_1_3/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const HL_PROVEN_COMPACTLIST_TEST_ZKV2_FASTHASH: HlHeterogeneousCiphertextListTes
4242
HlHeterogeneousCiphertextListTest {
4343
test_filename: Cow::Borrowed("hl_proven_heterogeneous_list_zkv2_fasthash"),
4444
key_filename: Cow::Borrowed("client_key"),
45-
clear_values: Cow::Borrowed(&[17u8 as u64, -12i8 as u64, false as u64, true as u64]),
45+
clear_values: Cow::Borrowed(&[17u8 as i64, -12i8 as i64, false as i64, true as i64]),
4646
data_kinds: Cow::Borrowed(&[
4747
DataKind::Unsigned,
4848
DataKind::Signed,
@@ -74,11 +74,11 @@ const HL_COMPRESSED_SQUASHED_NOISE_CIPHERTEXT_LIST: HlCompressedSquashedNoiseCip
7474
test_filename: Cow::Borrowed("hl_compressed_squashed_noise_ciphertext_list"),
7575
key_filename: Cow::Borrowed("client_key_with_noise_squashing"),
7676
clear_values: Cow::Borrowed(&[
77-
54679568u32 as u64,
78-
-12396372i32 as u64,
79-
12396372i32 as u64,
80-
false as u64,
81-
true as u64,
77+
54679568u32 as i64,
78+
-12396372i32 as i64,
79+
12396372i32 as i64,
80+
false as i64,
81+
true as i64,
8282
]),
8383
data_kinds: Cow::Borrowed(&[
8484
DataKind::Unsigned,

utils/tfhe-backward-compat-data/crates/generate_1_5/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const HL_PROVEN_COMPACTLIST_TEST_ZKV2: HlHeterogeneousCiphertextListTest =
4141
HlHeterogeneousCiphertextListTest {
4242
test_filename: Cow::Borrowed("hl_proven_list_zkv2_1_5"),
4343
key_filename: Cow::Borrowed("client_key_for_zk"),
44-
clear_values: Cow::Borrowed(&[17u8 as u64]),
44+
clear_values: Cow::Borrowed(&[17u8 as i64]),
4545
data_kinds: Cow::Borrowed(&[DataKind::Unsigned]),
4646
compressed: false,
4747
proof_info: Some(PkeZkProofAuxiliaryInfo {

utils/tfhe-backward-compat-data/crates/generate_1_6/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use tfhe::shortint::engine::ShortintEngine;
1212
use tfhe::xof_key_set::CompressedXofKeySet;
1313
use tfhe::zk::{CompactPkeCrs, ZkComputeLoad};
1414
use tfhe::{
15-
set_server_key, ClientKey, CompactCiphertextList, CompactPublicKey, CompressedCompactPublicKey,
16-
CompressedServerKey, ProvenCompactCiphertextList, Seed, ServerKey, Tag,
15+
ClientKey, CompactCiphertextList, CompactPublicKey, CompressedCompactPublicKey,
16+
CompressedServerKey, ProvenCompactCiphertextList, Seed, ServerKey, Tag, set_server_key,
1717
};
1818
use tfhe_backward_compat_data::generate::*;
1919
use tfhe_backward_compat_data::*;
@@ -36,7 +36,7 @@ const HL_SEEDED_COMPACT_LIST_TEST: HlSeededCompactCiphertextListTest =
3636
test_filename: Cow::Borrowed("hl_seeded_compact_list"),
3737
key_filename: Cow::Borrowed("seeded_client_key"),
3838
public_key_filename: Cow::Borrowed("seeded_compact_public_key"),
39-
clear_values: Cow::Borrowed(&[17u64, 255u64, 0u64]),
39+
clear_values: Cow::Borrowed(&[17, -1, 0]),
4040
data_kinds: Cow::Borrowed(&[DataKind::Unsigned, DataKind::Signed, DataKind::Bool]),
4141
seed: Cow::Borrowed(SEEDED_COMPACT_LIST_SEED),
4242
};
@@ -50,7 +50,7 @@ const HL_SEEDED_PROVEN_COMPACT_LIST_TEST: HlSeededProvenCompactCiphertextListTes
5050
params_filename: Cow::Borrowed("seeded_proven_zk_pke_crs"),
5151
metadata: Cow::Borrowed("backward_compat_seeded"),
5252
},
53-
clear_values: Cow::Borrowed(&[17u64, 255u64, 0u64]),
53+
clear_values: Cow::Borrowed(&[17, -1, 0]),
5454
data_kinds: Cow::Borrowed(&[DataKind::Unsigned, DataKind::Signed, DataKind::Bool]),
5555
seed: Cow::Borrowed(SEEDED_COMPACT_LIST_SEED),
5656
};

utils/tfhe-backward-compat-data/data/high_level_api.ron

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
proof_info: None,
199199
clear_values: [
200200
17,
201-
18446744073709551604,
201+
-12,
202202
0,
203203
1,
204204
],
@@ -220,7 +220,7 @@
220220
proof_info: None,
221221
clear_values: [
222222
17,
223-
18446744073709551604,
223+
-12,
224224
0,
225225
1,
226226
],
@@ -242,7 +242,7 @@
242242
proof_info: None,
243243
clear_values: [
244244
17,
245-
18446744073709551604,
245+
-12,
246246
0,
247247
1,
248248
],
@@ -268,7 +268,7 @@
268268
)),
269269
clear_values: [
270270
17,
271-
18446744073709551604,
271+
-12,
272272
0,
273273
1,
274274
],
@@ -398,7 +398,7 @@
398398
)),
399399
clear_values: [
400400
17,
401-
18446744073709551604,
401+
-12,
402402
0,
403403
1,
404404
],
@@ -571,7 +571,7 @@
571571
)),
572572
clear_values: [
573573
17,
574-
18446744073709551604,
574+
-12,
575575
0,
576576
1,
577577
],
@@ -630,7 +630,7 @@
630630
key_filename: "client_key_with_noise_squashing",
631631
clear_values: [
632632
54679568,
633-
18446744073697155244,
633+
-12396372,
634634
12396372,
635635
0,
636636
1,
@@ -892,7 +892,7 @@
892892
public_key_filename: "seeded_compact_public_key",
893893
clear_values: [
894894
17,
895-
255,
895+
-1,
896896
0,
897897
],
898898
data_kinds: [
@@ -933,7 +933,7 @@
933933
),
934934
clear_values: [
935935
17,
936-
255,
936+
-1,
937937
0,
938938
],
939939
data_kinds: [

utils/tfhe-backward-compat-data/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ pub struct HlHeterogeneousCiphertextListTest {
547547
pub key_filename: Cow<'static, str>,
548548
pub compressed: bool,
549549
pub proof_info: Option<PkeZkProofAuxiliaryInfo>,
550-
pub clear_values: Cow<'static, [u64]>,
550+
pub clear_values: Cow<'static, [i64]>,
551551
pub data_kinds: Cow<'static, [DataKind]>,
552552
}
553553

@@ -570,7 +570,7 @@ pub struct HlSeededCompactCiphertextListTest {
570570
pub test_filename: Cow<'static, str>,
571571
pub key_filename: Cow<'static, str>,
572572
pub public_key_filename: Cow<'static, str>,
573-
pub clear_values: Cow<'static, [u64]>,
573+
pub clear_values: Cow<'static, [i64]>,
574574
pub data_kinds: Cow<'static, [DataKind]>,
575575
pub seed: Cow<'static, [u8]>,
576576
}
@@ -595,7 +595,7 @@ pub struct HlSeededProvenCompactCiphertextListTest {
595595
pub key_filename: Cow<'static, str>,
596596
pub public_key_filename: Cow<'static, str>,
597597
pub proof_info: ZkProofAuxiliaryInfo,
598-
pub clear_values: Cow<'static, [u64]>,
598+
pub clear_values: Cow<'static, [i64]>,
599599
pub data_kinds: Cow<'static, [DataKind]>,
600600
pub seed: Cow<'static, [u8]>,
601601
}
@@ -618,7 +618,7 @@ impl TestType for HlSeededProvenCompactCiphertextListTest {
618618
pub struct HlCompressedSquashedNoiseCiphertextListTest {
619619
pub test_filename: Cow<'static, str>,
620620
pub key_filename: Cow<'static, str>,
621-
pub clear_values: Cow<'static, [u64]>,
621+
pub clear_values: Cow<'static, [i64]>,
622622
pub data_kinds: Cow<'static, [DataKind]>,
623623
}
624624

0 commit comments

Comments
 (0)