chore(hl): add a feature for extended types

This commit is contained in:
Nicolas Sarlin
2025-03-03 16:02:02 +01:00
committed by Nicolas Sarlin
parent e6e7081c7c
commit 10b82141eb
14 changed files with 3013 additions and 1335 deletions

View File

@@ -350,6 +350,9 @@ clippy_integer: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
--features=integer,experimental \
-p $(TFHE_SPEC) -- --no-deps -D warnings
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
--features=integer,experimental,extended-types \
-p $(TFHE_SPEC) -- --no-deps -D warnings
.PHONY: clippy # Run clippy lints enabling the boolean, shortint, integer
clippy: install_rs_check_toolchain
@@ -388,10 +391,10 @@ clippy_c_api: install_rs_check_toolchain
.PHONY: clippy_js_wasm_api # Run clippy lints enabling the boolean, shortint, integer and the js wasm API
clippy_js_wasm_api: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,zk-pok \
--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 \
-p $(TFHE_SPEC) -- --no-deps -D warnings
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api \
--features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,extended-types \
-p $(TFHE_SPEC) -- --no-deps -D warnings
.PHONY: clippy_tasks # Run clippy lints on helper tasks crate.
@@ -407,10 +410,10 @@ clippy_trivium: install_rs_check_toolchain
.PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.)
clippy_all_targets: install_rs_check_toolchain
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats \
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats,extended-types \
-p $(TFHE_SPEC) -- --no-deps -D warnings
RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats,experimental \
--features=boolean,shortint,integer,internal-keycache,zk-pok,strings,pbs-stats,extended-types,experimental \
-p $(TFHE_SPEC) -- --no-deps -D warnings
.PHONY: clippy_tfhe_csprng # Run clippy lints on tfhe-csprng
@@ -529,7 +532,7 @@ build_web_js_api: install_rs_build_toolchain install_wasm_pack
cd tfhe && \
RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \
wasm-pack build --release --target=web \
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types
.PHONY: build_web_js_api_parallel # Build the js API targeting the web browser with parallelism support
build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack
@@ -537,7 +540,7 @@ build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack
rustup component add rust-src --toolchain $(RS_CHECK_TOOLCHAIN) && \
RUSTFLAGS="$(WASM_RUSTFLAGS) -C target-feature=+atomics,+bulk-memory" rustup run $(RS_CHECK_TOOLCHAIN) \
wasm-pack build --release --target=web \
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api,zk-pok \
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api,zk-pok,extended-types \
-Z build-std=panic_abort,std && \
find pkg/snippets -type f -iname workerHelpers.js -exec sed -i "s|const pkg = await import('..\/..\/..');|const pkg = await import('..\/..\/..\/tfhe.js');|" {} \;
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
cd tfhe && \
RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \
wasm-pack build --release --target=nodejs \
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok
-- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types
.PHONY: build_tfhe_csprng # Build tfhe_csprng
build_tfhe_csprng: install_rs_build_toolchain

View File

@@ -92,6 +92,9 @@ internal-keycache = ["dep:fs2"]
gpu = ["dep:tfhe-cuda-backend"]
zk-pok = ["dep:tfhe-zk-pok"]
# Adds more FheUint/FheInt types to the HL
extended-types = []
pbs-stats = []
noise-asserts = []

View File

@@ -59,6 +59,8 @@ fn gen_c_api() {
"gpu",
#[cfg(feature = "zk-pok")]
"zk-pok",
#[cfg(feature = "extended-types")]
"extended-types",
];
let parse_expand_vec = if parse_expand_features_vec.is_empty() {

View File

@@ -61,6 +61,7 @@ pub enum FheTypes {
Type_FheInt1024 = 32,
Type_FheInt2048 = 33,
// Extended types
Type_FheUint24 = 34,
Type_FheUint40 = 35,
Type_FheUint48 = 36,

View File

@@ -634,6 +634,47 @@ mod tests {
}
}
#[cfg(feature = "extended-types")]
#[test]
fn test_compact_list_extended_types() {
let config = crate::ConfigBuilder::default().build();
let ck = crate::ClientKey::generate(config);
let sk = crate::ServerKey::new(&ck);
let pk = crate::CompactPublicKey::new(&ck);
set_server_key(sk);
let compact_list = CompactCiphertextList::builder(&pk)
.push_with_num_bits(-17i64, 40)
.unwrap()
.push_with_num_bits(3u8, 24)
.unwrap()
.build_packed();
let serialized = bincode::serialize(&compact_list).unwrap();
let compact_list: CompactCiphertextList = bincode::deserialize(&serialized).unwrap();
let expander = compact_list.expand().unwrap();
{
let a: crate::FheInt40 = expander.get(0).unwrap().unwrap();
let b: crate::FheUint24 = expander.get(1).unwrap().unwrap();
let a: i64 = a.decrypt(&ck);
assert_eq!(a, -17);
let b: u8 = b.decrypt(&ck);
assert_eq!(b, 3);
}
{
// Incorrect type
assert!(expander.get::<FheUint32>(0).is_err());
// Correct type but wrong number of bits
assert!(expander.get::<FheInt64>(0).is_err());
}
}
#[test]
fn test_compact_list_with_casting() {
let config = crate::ConfigBuilder::with_custom_parameters(

View File

@@ -1,21 +1,32 @@
expand_pub_use_fhe_type!(
pub use unsigned{
FheUint2, FheUint4, FheUint6, FheUint8, FheUint10, FheUint12, FheUint14, FheUint16,
FheUint24, FheUint32, FheUint40, FheUint48, FheUint56, FheUint64, FheUint72, FheUint80,
FheUint88, FheUint96, FheUint104, FheUint112, FheUint120, FheUint128, FheUint136,
FheUint144, FheUint152, FheUint160, FheUint168, FheUint176, FheUint184, FheUint192,
FheUint200, FheUint208, FheUint216, FheUint224, FheUint232, FheUint240, FheUint248,
FheUint256, FheUint512, FheUint1024, FheUint2048,
FheUint32, FheUint64, FheUint128, FheUint160, FheUint256, FheUint512, FheUint1024,
FheUint2048,
};
);
#[cfg(feature = "extended-types")]
expand_pub_use_fhe_type!(
pub use unsigned{
FheUint24, FheUint40, FheUint48, FheUint56, FheUint72, FheUint80,FheUint88, FheUint96,
FheUint104, FheUint112, FheUint120, FheUint136, FheUint144, FheUint152, FheUint168,
FheUint176, FheUint184, FheUint192, FheUint200, FheUint208, FheUint216, FheUint224,
FheUint232, FheUint240, FheUint248,
};
);
expand_pub_use_fhe_type!(
pub use signed{
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24,
FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96,
FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160,
FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224,
FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048,
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32,
FheInt64, FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048,
};
);
#[cfg(feature = "extended-types")]
expand_pub_use_fhe_type!(
pub use signed{
FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80, FheInt88, FheInt96, FheInt104,
FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184,
FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248,
};
);

View File

@@ -17,10 +17,15 @@ pub(in crate::high_level_api) use inner::{RadixCiphertext, RadixCiphertextVersio
expand_pub_use_fhe_type!(
pub use static_{
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24,
FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96,
FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160,
FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224,
FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32,
FheInt64,FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048
};
);
#[cfg(feature = "extended-types")]
expand_pub_use_fhe_type!(
pub use static_{
FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80, FheInt88, FheInt96, FheInt104,
FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184,
FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248
};
);

File diff suppressed because it is too large Load Diff

View File

@@ -95,180 +95,30 @@ static_int_type! {
}
}
static_int_type! {
Signed {
num_bits: 24,
}
}
static_int_type! {
Signed {
num_bits: 32,
}
}
static_int_type! {
Signed {
num_bits: 40,
}
}
static_int_type! {
Signed {
num_bits: 48,
}
}
static_int_type! {
Signed {
num_bits: 56,
}
}
static_int_type! {
Signed {
num_bits: 64,
}
}
static_int_type! {
Signed {
num_bits: 72,
}
}
static_int_type! {
Signed {
num_bits: 80,
}
}
static_int_type! {
Signed {
num_bits: 88,
}
}
static_int_type! {
Signed {
num_bits: 96,
}
}
static_int_type! {
Signed {
num_bits: 104,
}
}
static_int_type! {
Signed {
num_bits: 112,
}
}
static_int_type! {
Signed {
num_bits: 120,
}
}
static_int_type! {
Signed {
num_bits: 128,
}
}
static_int_type! {
Signed {
num_bits: 136,
}
}
static_int_type! {
Signed {
num_bits: 144,
}
}
static_int_type! {
Signed {
num_bits: 152,
}
}
static_int_type! {
Signed {
num_bits: 160,
}
}
static_int_type! {
Signed {
num_bits: 168,
}
}
static_int_type! {
Signed {
num_bits: 176,
}
}
static_int_type! {
Signed {
num_bits: 184,
}
}
static_int_type! {
Signed {
num_bits: 192,
}
}
static_int_type! {
Signed {
num_bits: 200,
}
}
static_int_type! {
Signed {
num_bits: 208,
}
}
static_int_type! {
Signed {
num_bits: 216,
}
}
static_int_type! {
Signed {
num_bits: 224,
}
}
static_int_type! {
Signed {
num_bits: 232,
}
}
static_int_type! {
Signed {
num_bits: 240,
}
}
static_int_type! {
Signed {
num_bits: 248,
}
}
static_int_type! {
Signed {
num_bits: 256,
@@ -292,3 +142,161 @@ static_int_type! {
num_bits: 2048,
}
}
#[cfg(feature = "extended-types")]
pub use extended::*;
#[cfg(feature = "extended-types")]
mod extended {
use super::*;
static_int_type! {
Signed {
num_bits: 24,
}
}
static_int_type! {
Signed {
num_bits: 40,
}
}
static_int_type! {
Signed {
num_bits: 48,
}
}
static_int_type! {
Signed {
num_bits: 56,
}
}
static_int_type! {
Signed {
num_bits: 72,
}
}
static_int_type! {
Signed {
num_bits: 80,
}
}
static_int_type! {
Signed {
num_bits: 88,
}
}
static_int_type! {
Signed {
num_bits: 96,
}
}
static_int_type! {
Signed {
num_bits: 104,
}
}
static_int_type! {
Signed {
num_bits: 112,
}
}
static_int_type! {
Signed {
num_bits: 120,
}
}
static_int_type! {
Signed {
num_bits: 136,
}
}
static_int_type! {
Signed {
num_bits: 144,
}
}
static_int_type! {
Signed {
num_bits: 152,
}
}
static_int_type! {
Signed {
num_bits: 168,
}
}
static_int_type! {
Signed {
num_bits: 176,
}
}
static_int_type! {
Signed {
num_bits: 184,
}
}
static_int_type! {
Signed {
num_bits: 192,
}
}
static_int_type! {
Signed {
num_bits: 200,
}
}
static_int_type! {
Signed {
num_bits: 208,
}
}
static_int_type! {
Signed {
num_bits: 216,
}
}
static_int_type! {
Signed {
num_bits: 224,
}
}
static_int_type! {
Signed {
num_bits: 232,
}
}
static_int_type! {
Signed {
num_bits: 240,
}
}
static_int_type! {
Signed {
num_bits: 248,
}
}
}

View File

@@ -3,11 +3,17 @@ pub use base::{FheUint, FheUintId};
expand_pub_use_fhe_type!(
pub use static_{
FheUint2, FheUint4, FheUint6, FheUint8, FheUint10, FheUint12, FheUint14, FheUint16,
FheUint24, FheUint32, FheUint40, FheUint48, FheUint56, FheUint64, FheUint72, FheUint80,
FheUint88, FheUint96, FheUint104, FheUint112, FheUint120, FheUint128, FheUint136,
FheUint144, FheUint152, FheUint160, FheUint168, FheUint176, FheUint184, FheUint192,
FheUint200, FheUint208, FheUint216, FheUint224, FheUint232, FheUint240, FheUint248,
FheUint256, FheUint512, FheUint1024, FheUint2048,
FheUint32, FheUint64, FheUint128, FheUint160, FheUint256, FheUint512, FheUint1024,
FheUint2048,
};
);
#[cfg(feature = "extended-types")]
expand_pub_use_fhe_type!(
pub use static_{
FheUint24, FheUint40, FheUint48, FheUint56, FheUint72, FheUint80, FheUint88, FheUint96,
FheUint104, FheUint112, FheUint120, FheUint136, FheUint144, FheUint152, FheUint168,
FheUint176, FheUint184, FheUint192, FheUint200, FheUint208, FheUint216, FheUint224,
FheUint232, FheUint240, FheUint248,
};
);

File diff suppressed because it is too large Load Diff

View File

@@ -96,180 +96,30 @@ static_int_type! {
}
}
static_int_type! {
Unsigned {
num_bits: 24,
}
}
static_int_type! {
Unsigned {
num_bits: 32,
}
}
static_int_type! {
Unsigned {
num_bits: 40,
}
}
static_int_type! {
Unsigned {
num_bits: 48,
}
}
static_int_type! {
Unsigned {
num_bits: 56,
}
}
static_int_type! {
Unsigned {
num_bits: 64,
}
}
static_int_type! {
Unsigned {
num_bits: 72,
}
}
static_int_type! {
Unsigned {
num_bits: 80,
}
}
static_int_type! {
Unsigned {
num_bits: 88,
}
}
static_int_type! {
Unsigned {
num_bits: 96,
}
}
static_int_type! {
Unsigned {
num_bits: 104,
}
}
static_int_type! {
Unsigned {
num_bits: 112,
}
}
static_int_type! {
Unsigned {
num_bits: 120,
}
}
static_int_type! {
Unsigned {
num_bits: 128,
}
}
static_int_type! {
Unsigned {
num_bits: 136,
}
}
static_int_type! {
Unsigned {
num_bits: 144,
}
}
static_int_type! {
Unsigned {
num_bits: 152,
}
}
static_int_type! {
Unsigned {
num_bits: 160,
}
}
static_int_type! {
Unsigned {
num_bits: 168,
}
}
static_int_type! {
Unsigned {
num_bits: 176,
}
}
static_int_type! {
Unsigned {
num_bits: 184,
}
}
static_int_type! {
Unsigned {
num_bits: 192,
}
}
static_int_type! {
Unsigned {
num_bits: 200,
}
}
static_int_type! {
Unsigned {
num_bits: 208,
}
}
static_int_type! {
Unsigned {
num_bits: 216,
}
}
static_int_type! {
Unsigned {
num_bits: 224,
}
}
static_int_type! {
Unsigned {
num_bits: 232,
}
}
static_int_type! {
Unsigned {
num_bits: 240,
}
}
static_int_type! {
Unsigned {
num_bits: 248,
}
}
static_int_type! {
Unsigned {
num_bits: 256,
@@ -293,3 +143,161 @@ static_int_type! {
num_bits: 2048,
}
}
#[cfg(feature = "extended-types")]
pub use extended::*;
#[cfg(feature = "extended-types")]
mod extended {
use super::*;
static_int_type! {
Unsigned {
num_bits: 24,
}
}
static_int_type! {
Unsigned {
num_bits: 40,
}
}
static_int_type! {
Unsigned {
num_bits: 48,
}
}
static_int_type! {
Unsigned {
num_bits: 56,
}
}
static_int_type! {
Unsigned {
num_bits: 72,
}
}
static_int_type! {
Unsigned {
num_bits: 80,
}
}
static_int_type! {
Unsigned {
num_bits: 88,
}
}
static_int_type! {
Unsigned {
num_bits: 96,
}
}
static_int_type! {
Unsigned {
num_bits: 104,
}
}
static_int_type! {
Unsigned {
num_bits: 112,
}
}
static_int_type! {
Unsigned {
num_bits: 120,
}
}
static_int_type! {
Unsigned {
num_bits: 136,
}
}
static_int_type! {
Unsigned {
num_bits: 144,
}
}
static_int_type! {
Unsigned {
num_bits: 152,
}
}
static_int_type! {
Unsigned {
num_bits: 168,
}
}
static_int_type! {
Unsigned {
num_bits: 176,
}
}
static_int_type! {
Unsigned {
num_bits: 184,
}
}
static_int_type! {
Unsigned {
num_bits: 192,
}
}
static_int_type! {
Unsigned {
num_bits: 200,
}
}
static_int_type! {
Unsigned {
num_bits: 208,
}
}
static_int_type! {
Unsigned {
num_bits: 216,
}
}
static_int_type! {
Unsigned {
num_bits: 224,
}
}
static_int_type! {
Unsigned {
num_bits: 232,
}
}
static_int_type! {
Unsigned {
num_bits: 240,
}
}
static_int_type! {
Unsigned {
num_bits: 248,
}
}
}

View File

@@ -65,20 +65,29 @@ pub use keys::{
mod tests;
pub use crate::high_level_api::booleans::{CompressedFheBool, FheBool, FheBoolConformanceParams};
#[cfg(feature = "extended-types")]
expand_pub_use_fhe_type!(
pub use crate::high_level_api::integers{
FheUint24, FheUint40, FheUint48, FheUint56, FheUint72, FheUint80,FheUint88, FheUint96,
FheUint104, FheUint112, FheUint120, FheUint136, FheUint144, FheUint152, FheUint168,
FheUint176, FheUint184, FheUint192, FheUint200, FheUint208, FheUint216, FheUint224,
FheUint232, FheUint240, FheUint248,
FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80,FheInt88, FheInt96, FheInt104,
FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184,
FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248,
};
);
expand_pub_use_fhe_type!(
pub use crate::high_level_api::integers{
FheUint2, FheUint4, FheUint6, FheUint8, FheUint10, FheUint12, FheUint14, FheUint16,
FheUint24, FheUint32, FheUint40, FheUint48, FheUint56, FheUint64, FheUint72, FheUint80,
FheUint88, FheUint96, FheUint104, FheUint112, FheUint120, FheUint128, FheUint136,
FheUint144, FheUint152, FheUint160, FheUint168, FheUint176, FheUint184, FheUint192,
FheUint200, FheUint208, FheUint216, FheUint224, FheUint232, FheUint240, FheUint248,
FheUint256, FheUint512, FheUint1024, FheUint2048,
FheUint32, FheUint64, FheUint128, FheUint160, FheUint256, FheUint512, FheUint1024,
FheUint2048,
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24,
FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96,
FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160,
FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224,
FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048
FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32,
FheInt64, FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048,
};
);
pub use array::{

View File

@@ -322,6 +322,82 @@ macro_rules! create_wrapper_type_non_native_type (
}
);
create_wrapper_type_non_native_type!(
{
type_name: FheUint128,
compressed_type_name: CompressedFheUint128,
proven_type: ProvenFheUint128,
rust_type: u128,
},
{
type_name: FheUint160,
compressed_type_name: CompressedFheUint160,
proven_type: ProvenFheUint160,
rust_type: U256,
},
{
type_name: FheUint256,
compressed_type_name: CompressedFheUint256,
proven_type: ProvenFheUint256,
rust_type: U256,
},
{
type_name: FheUint512,
compressed_type_name: CompressedFheUint512,
proven_type: ProvenFheUint512,
rust_type: U512,
},
{
type_name: FheUint1024,
compressed_type_name: CompressedFheUint1024,
proven_type: ProvenFheUint1024,
rust_type: U1024,
},
{
type_name: FheUint2048,
compressed_type_name: CompressedFheUint2048,
proven_type: ProvenFheUint2048,
rust_type: U2048,
},
{
type_name: FheInt128,
compressed_type_name: CompressedFheInt128,
proven_type: ProvenFheInt128,
rust_type: i128,
},
{
type_name: FheInt160,
compressed_type_name: CompressedFheInt160,
proven_type: ProvenFheInt160,
rust_type: I256,
},
{
type_name: FheInt256,
compressed_type_name: CompressedFheInt256,
proven_type: ProvenFheInt256,
rust_type: I256,
},
{
type_name: FheInt512,
compressed_type_name: CompressedFheInt512,
proven_type: ProvenFheInt512,
rust_type: I512,
},
{
type_name: FheInt1024,
compressed_type_name: CompressedFheInt1024,
proven_type: ProvenFheInt1024,
rust_type: I1024,
},
{
type_name: FheInt2048,
compressed_type_name: CompressedFheInt2048,
proven_type: ProvenFheInt2048,
rust_type: I2048,
},
);
#[cfg(feature = "extended-types")]
create_wrapper_type_non_native_type!(
{
type_name: FheUint72,
@@ -365,12 +441,6 @@ create_wrapper_type_non_native_type!(
proven_type: ProvenFheUint120,
rust_type: u128,
},
{
type_name: FheUint128,
compressed_type_name: CompressedFheUint128,
proven_type: ProvenFheUint128,
rust_type: u128,
},
{
type_name: FheUint136,
compressed_type_name: CompressedFheUint136,
@@ -389,12 +459,6 @@ create_wrapper_type_non_native_type!(
proven_type: ProvenFheUint152,
rust_type: U256,
},
{
type_name: FheUint160,
compressed_type_name: CompressedFheUint160,
proven_type: ProvenFheUint160,
rust_type: U256,
},
{
type_name: FheUint168,
compressed_type_name: CompressedFheUint168,
@@ -461,30 +525,6 @@ create_wrapper_type_non_native_type!(
proven_type: ProvenFheUint248,
rust_type: U256,
},
{
type_name: FheUint256,
compressed_type_name: CompressedFheUint256,
proven_type: ProvenFheUint256,
rust_type: U256,
},
{
type_name: FheUint512,
compressed_type_name: CompressedFheUint512,
proven_type: ProvenFheUint512,
rust_type: U512,
},
{
type_name: FheUint1024,
compressed_type_name: CompressedFheUint1024,
proven_type: ProvenFheUint1024,
rust_type: U1024,
},
{
type_name: FheUint2048,
compressed_type_name: CompressedFheUint2048,
proven_type: ProvenFheUint2048,
rust_type: U2048,
},
// Signed
{
type_name: FheInt72,
@@ -528,12 +568,6 @@ create_wrapper_type_non_native_type!(
proven_type: ProvenFheInt120,
rust_type: i128,
},
{
type_name: FheInt128,
compressed_type_name: CompressedFheInt128,
proven_type: ProvenFheInt128,
rust_type: i128,
},
{
type_name: FheInt136,
compressed_type_name: CompressedFheInt136,
@@ -552,12 +586,6 @@ create_wrapper_type_non_native_type!(
proven_type: ProvenFheInt152,
rust_type: I256,
},
{
type_name: FheInt160,
compressed_type_name: CompressedFheInt160,
proven_type: ProvenFheInt160,
rust_type: I256,
},
{
type_name: FheInt168,
compressed_type_name: CompressedFheInt168,
@@ -624,30 +652,6 @@ create_wrapper_type_non_native_type!(
proven_type: ProvenFheInt248,
rust_type: I256,
},
{
type_name: FheInt256,
compressed_type_name: CompressedFheInt256,
proven_type: ProvenFheInt256,
rust_type: I256,
},
{
type_name: FheInt512,
compressed_type_name: CompressedFheInt512,
proven_type: ProvenFheInt512,
rust_type: I512,
},
{
type_name: FheInt1024,
compressed_type_name: CompressedFheInt1024,
proven_type: ProvenFheInt1024,
rust_type: I1024,
},
{
type_name: FheInt2048,
compressed_type_name: CompressedFheInt2048,
proven_type: ProvenFheInt2048,
rust_type: I2048,
},
);
// We use this macro to define wasm wrapper for
@@ -832,6 +836,58 @@ macro_rules! create_wrapper_type_that_has_native_type (
}
);
#[cfg(feature = "extended-types")]
create_wrapper_type_that_has_native_type!(
{
type_name: FheUint24,
compressed_type_name: CompressedFheUint24,
proven_type: ProvenFheUint24,
native_type: u32,
},
{
type_name: FheUint40,
compressed_type_name: CompressedFheUint40,
proven_type: ProvenFheUint40,
native_type: u64,
},
{
type_name: FheUint48,
compressed_type_name: CompressedFheUint48,
proven_type: ProvenFheUint48,
native_type: u64,
},
{
type_name: FheUint56,
compressed_type_name: CompressedFheUint56,
proven_type: ProvenFheUint56,
native_type: u64,
},
{
type_name: FheInt24,
compressed_type_name: CompressedFheInt24,
proven_type: ProvenFheInt24,
native_type: i32,
},
{
type_name: FheInt40,
compressed_type_name: CompressedFheInt40,
proven_type: ProvenFheInt40,
native_type: i64,
},
{
type_name: FheInt48,
compressed_type_name: CompressedFheInt48,
proven_type: ProvenFheInt48,
native_type: i64,
},
{
type_name: FheInt56,
compressed_type_name: CompressedFheInt56,
proven_type: ProvenFheInt56,
native_type: i64,
},
);
create_wrapper_type_that_has_native_type!(
{
type_name: FheBool,
@@ -887,43 +943,18 @@ create_wrapper_type_that_has_native_type!(
proven_type: ProvenFheUint16,
native_type: u16,
},
{
type_name: FheUint24,
compressed_type_name: CompressedFheUint24,
proven_type: ProvenFheUint24,
native_type: u32,
},
{
type_name: FheUint32,
compressed_type_name: CompressedFheUint32,
proven_type: ProvenFheUint32,
native_type: u32,
},
{
type_name: FheUint40,
compressed_type_name: CompressedFheUint40,
proven_type: ProvenFheUint40,
native_type: u64,
},
{
type_name: FheUint48,
compressed_type_name: CompressedFheUint48,
proven_type: ProvenFheUint48,
native_type: u64,
},
{
type_name: FheUint56,
compressed_type_name: CompressedFheUint56,
proven_type: ProvenFheUint56,
native_type: u64,
},
{
type_name: FheUint64,
compressed_type_name: CompressedFheUint64,
proven_type: ProvenFheUint64,
native_type: u64,
},
// Signed
{
type_name: FheInt2,
compressed_type_name: CompressedFheInt2,
@@ -972,36 +1003,12 @@ create_wrapper_type_that_has_native_type!(
proven_type: ProvenFheInt16,
native_type: i16,
},
{
type_name: FheInt24,
compressed_type_name: CompressedFheInt24,
proven_type: ProvenFheInt24,
native_type: i32,
},
{
type_name: FheInt32,
compressed_type_name: CompressedFheInt32,
proven_type: ProvenFheInt32,
native_type: i32,
},
{
type_name: FheInt40,
compressed_type_name: CompressedFheInt40,
proven_type: ProvenFheInt40,
native_type: i64,
},
{
type_name: FheInt48,
compressed_type_name: CompressedFheInt48,
proven_type: ProvenFheInt48,
native_type: i64,
},
{
type_name: FheInt56,
compressed_type_name: CompressedFheInt56,
proven_type: ProvenFheInt56,
native_type: i64,
},
{
type_name: FheInt64,
compressed_type_name: CompressedFheInt64,
@@ -1243,6 +1250,14 @@ macro_rules! define_builder_push_method {
};
}
#[cfg(feature = "extended-types")]
define_builder_push_method!(unsigned: {
24 <= u32,
40 <= u64,
48 <= u64,
56 <= u64,
});
define_builder_push_method!(unsigned: {
2 <= u8,
4 <= u8,
@@ -1252,14 +1267,18 @@ define_builder_push_method!(unsigned: {
12 <= u16,
14 <= u16,
16 <= u16,
24 <= u32,
32 <= u32,
40 <= u64,
48 <= u64,
56 <= u64,
64 <= u64,
});
#[cfg(feature = "extended-types")]
define_builder_push_method!(signed: {
24 <= i32,
40 <= i64,
48 <= i64,
56 <= i64,
});
define_builder_push_method!(signed: {
2 <= i8,
4 <= i8,
@@ -1269,14 +1288,160 @@ define_builder_push_method!(signed: {
12 <= i16,
14 <= i16,
16 <= i16,
24 <= i32,
32 <= i32,
40 <= i64,
48 <= i64,
56 <= i64,
64 <= i64,
});
#[wasm_bindgen]
impl CompactCiphertextListBuilder {
#[wasm_bindgen]
pub fn push_u128(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = u128::try_from(value).map_err(into_js_error)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u160(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U256::try_from(value)?;
self.0.push_with_num_bits(value, 160)?;
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u256(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U256::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u512(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U512::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u1024(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U1024::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u2048(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U2048::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i128(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = i128::try_from(value).map_err(into_js_error)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i160(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I256::try_from(value)?;
self.0.push_with_num_bits(value, 160)?;
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i256(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I256::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i512(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I512::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i1024(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I1024::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i2048(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I2048::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_boolean(&mut self, value: bool) -> Result<(), JsError> {
catch_panic(|| {
self.0.push(value);
})
}
#[wasm_bindgen]
pub fn build(&self) -> Result<CompactCiphertextList, JsError> {
catch_panic(|| {
let inner = self.0.build();
CompactCiphertextList(inner)
})
}
#[wasm_bindgen]
pub fn build_packed(&self) -> Result<CompactCiphertextList, JsError> {
catch_panic(|| {
let inner = self.0.build_packed();
CompactCiphertextList(inner)
})
}
#[cfg(feature = "zk-pok")]
pub fn build_with_proof_packed(
&self,
crs: &CompactPkeCrs,
metadata: &[u8],
compute_load: ZkComputeLoad,
) -> Result<ProvenCompactCiphertextList, JsError> {
catch_panic_result(|| {
self.0
.build_with_proof_packed(&crs.0, metadata, compute_load.into())
.map_err(into_js_error)
.map(ProvenCompactCiphertextList)
})
}
}
#[cfg(feature = "extended-types")]
#[wasm_bindgen]
impl CompactCiphertextListBuilder {
#[wasm_bindgen]
@@ -1342,15 +1507,6 @@ impl CompactCiphertextListBuilder {
})
}
#[wasm_bindgen]
pub fn push_u128(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = u128::try_from(value).map_err(into_js_error)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u136(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
@@ -1378,15 +1534,6 @@ impl CompactCiphertextListBuilder {
})
}
#[wasm_bindgen]
pub fn push_u160(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U256::try_from(value)?;
self.0.push_with_num_bits(value, 160)?;
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u168(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
@@ -1486,42 +1633,6 @@ impl CompactCiphertextListBuilder {
})
}
#[wasm_bindgen]
pub fn push_u256(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U256::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u512(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U512::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u1024(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U1024::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_u2048(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = U2048::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i72(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
@@ -1585,15 +1696,6 @@ impl CompactCiphertextListBuilder {
})
}
#[wasm_bindgen]
pub fn push_i128(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = i128::try_from(value).map_err(into_js_error)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i136(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
@@ -1621,15 +1723,6 @@ impl CompactCiphertextListBuilder {
})
}
#[wasm_bindgen]
pub fn push_i160(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I256::try_from(value)?;
self.0.push_with_num_bits(value, 160)?;
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i168(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
@@ -1728,80 +1821,6 @@ impl CompactCiphertextListBuilder {
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i256(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I256::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i512(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I512::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i1024(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I1024::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_i2048(&mut self, value: JsValue) -> Result<(), JsError> {
catch_panic_result(|| {
let value = I2048::try_from(value)?;
self.0.push(value);
Ok(())
})
}
#[wasm_bindgen]
pub fn push_boolean(&mut self, value: bool) -> Result<(), JsError> {
catch_panic(|| {
self.0.push(value);
})
}
#[wasm_bindgen]
pub fn build(&self) -> Result<CompactCiphertextList, JsError> {
catch_panic(|| {
let inner = self.0.build();
CompactCiphertextList(inner)
})
}
#[wasm_bindgen]
pub fn build_packed(&self) -> Result<CompactCiphertextList, JsError> {
catch_panic(|| {
let inner = self.0.build_packed();
CompactCiphertextList(inner)
})
}
#[cfg(feature = "zk-pok")]
pub fn build_with_proof_packed(
&self,
crs: &CompactPkeCrs,
metadata: &[u8],
compute_load: ZkComputeLoad,
) -> Result<ProvenCompactCiphertextList, JsError> {
catch_panic_result(|| {
self.0
.build_with_proof_packed(&crs.0, metadata, compute_load.into())
.map_err(into_js_error)
.map(ProvenCompactCiphertextList)
})
}
}
/// Helper macro to define get methods for the expander
@@ -1860,15 +1879,25 @@ macro_rules! define_expander_get_method {
}
};
}
#[cfg(feature = "extended-types")]
define_expander_get_method!(
unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120,
128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256,
512, 1024, 2048 }
unsigned: { 24, 40, 48, 56, 72, 80, 88, 96, 104, 112, 120, 136, 144, 152, 168, 176, 184,
192, 200, 208, 216, 224, 232, 240, 248, 256 }
);
define_expander_get_method!(
signed: { 2, 4, 6, 8, 10, 12, 14, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120,
128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256,
512, 1024, 2048 }
unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 512, 1024, 2048 }
);
#[cfg(feature = "extended-types")]
define_expander_get_method!(
signed: { 24, 40, 48, 56, 72, 80, 88, 96, 104, 112, 120, 136, 144, 152, 168, 176, 184, 192,
200, 208, 216, 224, 232, 240, 248 }
);
define_expander_get_method!(
signed: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 256, 512, 1024, 2048 }
);
#[wasm_bindgen]