Skip to content

Commit

Permalink
feat(wasm): add missing push_u{512,1024,2048}
Browse files Browse the repository at this point in the history
This adds the missing push functions for some big
uint type that the fhEVM needs
  • Loading branch information
tmontaigu committed Aug 16, 2024
1 parent febaf12 commit 53d159a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
9 changes: 8 additions & 1 deletion tfhe/js_on_wasm_tests/test-hlapi-signed.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ test('hlapi_public_key_encrypt_decrypt_int256_small', (t) => {
});



//////////////////////////////////////////////////////////////////////////////
/// 32 bits compact
//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -423,12 +422,14 @@ test('hlapi_compact_ciphertext_list', (t) => {
let clear_i32 = -3284;
let clear_bool = true;
let clear_u256 = generateRandomBigInt(256);
let clear_u2048 = generateRandomBigInt(2048);

let builder = CompactCiphertextList.builder(publicKey);
builder.push_u2(clear_u2);
builder.push_i32(clear_i32);
builder.push_boolean(clear_bool);
builder.push_u256(clear_u256);
builder.push_u2048(clear_u2048);
let list = builder.build();

let serialized = list.safe_serialize(BigInt(10000000));
Expand All @@ -455,6 +456,12 @@ test('hlapi_compact_ciphertext_list', (t) => {
expander.get_uint256(3).decrypt(clientKey),
clear_u256,
);

assert.deepStrictEqual(
expander.get_uint2048(4).decrypt(clientKey),
clear_u2048,
);

});

test('hlapi_compact_ciphertext_list_with_proof', (t) => {
Expand Down
29 changes: 28 additions & 1 deletion tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,33 @@ impl CompactCiphertextListBuilder {
})
}

#[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(|| {
Expand Down Expand Up @@ -1018,7 +1045,7 @@ macro_rules! define_expander_get_method {
};
}
define_expander_get_method!(
unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 256 }
unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 256, 512, 1024, 2048 }
);
define_expander_get_method!(
signed: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128, 160, 256 }
Expand Down

0 comments on commit 53d159a

Please sign in to comment.