Skip to content

Commit 10b8214

Browse files
committed
chore(hl): add a feature for extended types
1 parent e6e7081 commit 10b8214

File tree

14 files changed

+2971
-1293
lines changed

14 files changed

+2971
-1293
lines changed

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ clippy_integer: install_rs_check_toolchain
350350
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
351351
--features=integer,experimental \
352352
-p $(TFHE_SPEC) -- --no-deps -D warnings
353+
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
354+
--features=integer,experimental,extended-types \
355+
-p $(TFHE_SPEC) -- --no-deps -D warnings
353356

354357
.PHONY: clippy # Run clippy lints enabling the boolean, shortint, integer
355358
clippy: install_rs_check_toolchain
@@ -388,10 +391,10 @@ clippy_c_api: install_rs_check_toolchain
388391
.PHONY: clippy_js_wasm_api # Run clippy lints enabling the boolean, shortint, integer and the js wasm API
389392
clippy_js_wasm_api: install_rs_check_toolchain
390393
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
391-
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,zk-pok \
394+
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,zk-pok,extended-types \
392395
-p $(TFHE_SPEC) -- --no-deps -D warnings
393396
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
394-
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api \
397+
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,extended-types \
395398
-p $(TFHE_SPEC) -- --no-deps -D warnings
396399

397400
.PHONY: clippy_tasks # Run clippy lints on helper tasks crate.
@@ -407,10 +410,10 @@ clippy_trivium: install_rs_check_toolchain
407410
.PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.)
408411
clippy_all_targets: install_rs_check_toolchain
409412
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
410-
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats \
413+
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats,extended-types \
411414
-p $(TFHE_SPEC) -- --no-deps -D warnings
412415
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
413-
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats,experimental \
416+
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats,extended-types,experimental \
414417
-p $(TFHE_SPEC) -- --no-deps -D warnings
415418

416419
.PHONY: clippy_tfhe_csprng # Run clippy lints on tfhe-csprng
@@ -529,15 +532,15 @@ build_web_js_api: install_rs_build_toolchain install_wasm_pack
529532
cd tfhe && \
530533
RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \
531534
wasm-pack build --release --target=web \
532-
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok
535+
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types
533536

534537
.PHONY: build_web_js_api_parallel # Build the js API targeting the web browser with parallelism support
535538
build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack
536539
cd tfhe && \
537540
rustup component add rust-src --toolchain $(RS_CHECK_TOOLCHAIN) && \
538541
RUSTFLAGS="$(WASM_RUSTFLAGS) -C target-feature=+atomics,+bulk-memory" rustup run $(RS_CHECK_TOOLCHAIN) \
539542
wasm-pack build --release --target=web \
540-
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api,zk-pok \
543+
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api,zk-pok,extended-types \
541544
-Z build-std=panic_abort,std && \
542545
find pkg/snippets -type f -iname workerHelpers.js -exec sed -i "s|const pkg = await import('..\/..\/..');|const pkg = await import('..\/..\/..\/tfhe.js');|" {} \;
543546
jq '.files += ["snippets"]' tfhe/pkg/package.json > tmp_pkg.json && mv -f tmp_pkg.json tfhe/pkg/package.json
@@ -547,7 +550,7 @@ build_node_js_api: install_rs_build_toolchain install_wasm_pack
547550
cd tfhe && \
548551
RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \
549552
wasm-pack build --release --target=nodejs \
550-
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok
553+
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types
551554

552555
.PHONY: build_tfhe_csprng # Build tfhe_csprng
553556
build_tfhe_csprng: install_rs_build_toolchain

tfhe/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ internal-keycache = ["dep:fs2"]
9292
gpu = ["dep:tfhe-cuda-backend"]
9393
zk-pok = ["dep:tfhe-zk-pok"]
9494

95+
# Adds more FheUint/FheInt types to the HL
96+
extended-types = []
97+
9598
pbs-stats = []
9699
noise-asserts = []
97100

tfhe/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ fn gen_c_api() {
5959
"gpu",
6060
#[cfg(feature = "zk-pok")]
6161
"zk-pok",
62+
#[cfg(feature = "extended-types")]
63+
"extended-types",
6264
];
6365

6466
let parse_expand_vec = if parse_expand_features_vec.is_empty() {

tfhe/src/c_api/high_level_api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub enum FheTypes {
6161
Type_FheInt1024 = 32,
6262
Type_FheInt2048 = 33,
6363

64+
// Extended types
6465
Type_FheUint24 = 34,
6566
Type_FheUint40 = 35,
6667
Type_FheUint48 = 36,

tfhe/src/high_level_api/compact_list.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,47 @@ mod tests {
634634
}
635635
}
636636

637+
#[cfg(feature = "extended-types")]
638+
#[test]
639+
fn test_compact_list_extended_types() {
640+
let config = crate::ConfigBuilder::default().build();
641+
642+
let ck = crate::ClientKey::generate(config);
643+
let sk = crate::ServerKey::new(&ck);
644+
let pk = crate::CompactPublicKey::new(&ck);
645+
646+
set_server_key(sk);
647+
648+
let compact_list = CompactCiphertextList::builder(&pk)
649+
.push_with_num_bits(-17i64, 40)
650+
.unwrap()
651+
.push_with_num_bits(3u8, 24)
652+
.unwrap()
653+
.build_packed();
654+
655+
let serialized = bincode::serialize(&compact_list).unwrap();
656+
let compact_list: CompactCiphertextList = bincode::deserialize(&serialized).unwrap();
657+
let expander = compact_list.expand().unwrap();
658+
659+
{
660+
let a: crate::FheInt40 = expander.get(0).unwrap().unwrap();
661+
let b: crate::FheUint24 = expander.get(1).unwrap().unwrap();
662+
663+
let a: i64 = a.decrypt(&ck);
664+
assert_eq!(a, -17);
665+
let b: u8 = b.decrypt(&ck);
666+
assert_eq!(b, 3);
667+
}
668+
669+
{
670+
// Incorrect type
671+
assert!(expander.get::<FheUint32>(0).is_err());
672+
673+
// Correct type but wrong number of bits
674+
assert!(expander.get::<FheInt64>(0).is_err());
675+
}
676+
}
677+
637678
#[test]
638679
fn test_compact_list_with_casting() {
639680
let config = crate::ConfigBuilder::with_custom_parameters(

tfhe/src/high_level_api/integers/mod.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
expand_pub_use_fhe_type!(
22
pub use unsigned{
33
FheUint2, FheUint4, FheUint6, FheUint8, FheUint10, FheUint12, FheUint14, FheUint16,
4-
FheUint24, FheUint32, FheUint40, FheUint48, FheUint56, FheUint64, FheUint72, FheUint80,
5-
FheUint88, FheUint96, FheUint104, FheUint112, FheUint120, FheUint128, FheUint136,
6-
FheUint144, FheUint152, FheUint160, FheUint168, FheUint176, FheUint184, FheUint192,
7-
FheUint200, FheUint208, FheUint216, FheUint224, FheUint232, FheUint240, FheUint248,
8-
FheUint256, FheUint512, FheUint1024, FheUint2048,
4+
FheUint32, FheUint64, FheUint128, FheUint160, FheUint256, FheUint512, FheUint1024,
5+
FheUint2048,
6+
};
7+
);
8+
#[cfg(feature = "extended-types")]
9+
expand_pub_use_fhe_type!(
10+
pub use unsigned{
11+
FheUint24, FheUint40, FheUint48, FheUint56, FheUint72, FheUint80,FheUint88, FheUint96,
12+
FheUint104, FheUint112, FheUint120, FheUint136, FheUint144, FheUint152, FheUint168,
13+
FheUint176, FheUint184, FheUint192, FheUint200, FheUint208, FheUint216, FheUint224,
14+
FheUint232, FheUint240, FheUint248,
915
};
1016
);
1117

1218
expand_pub_use_fhe_type!(
1319
pub use signed{
14-
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24,
15-
FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96,
16-
FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160,
17-
FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224,
18-
FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048,
20+
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32,
21+
FheInt64, FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048,
22+
};
23+
);
24+
#[cfg(feature = "extended-types")]
25+
expand_pub_use_fhe_type!(
26+
pub use signed{
27+
FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80, FheInt88, FheInt96, FheInt104,
28+
FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184,
29+
FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248,
1930
};
2031
);
2132

tfhe/src/high_level_api/integers/signed/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ pub(in crate::high_level_api) use inner::{RadixCiphertext, RadixCiphertextVersio
1717

1818
expand_pub_use_fhe_type!(
1919
pub use static_{
20-
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24,
21-
FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96,
22-
FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160,
23-
FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224,
24-
FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048
20+
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32,
21+
FheInt64,FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048
22+
};
23+
);
24+
#[cfg(feature = "extended-types")]
25+
expand_pub_use_fhe_type!(
26+
pub use static_{
27+
FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80, FheInt88, FheInt96, FheInt104,
28+
FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184,
29+
FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248
2530
};
2631
);

0 commit comments

Comments
 (0)