Skip to content

Commit

Permalink
More tests for einputs
Browse files Browse the repository at this point in the history
  • Loading branch information
david-zk committed Sep 9, 2024
1 parent 55dcd6c commit ad917d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
23 changes: 21 additions & 2 deletions fhevm-engine/coprocessor/src/tests/inputs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::str::FromStr;

use tfhe::integer::U256;
use tonic::metadata::MetadataValue;

use crate::{db_queries::query_tenant_keys, server::coprocessor::{fhevm_coprocessor_client::FhevmCoprocessorClient, DebugDecryptRequest, InputToUpload, InputUploadBatch}, tests::utils::{default_api_key, default_tenant_id, setup_test_app}};
Expand Down Expand Up @@ -28,6 +29,12 @@ async fn test_fhe_inputs() -> Result<(), Box<dyn std::error::Error>> {
.push(2u16)
.push(3u32)
.push(4u64)
.push(5u128)
// TODO: 160 bits test
.push(U256::from(7u32))
// .push(StaticUnsignedBigInt::<8>::from(8u32))
// .push(StaticUnsignedBigInt::<16>::from(9u32))
// .push(StaticUnsignedBigInt::<32>::from(10u32))
.build();

let serialized = bincode::serialize(&the_list).unwrap();
Expand All @@ -51,7 +58,7 @@ async fn test_fhe_inputs() -> Result<(), Box<dyn std::error::Error>> {

let first_resp = &resp.upload_responses[0];

assert_eq!(first_resp.input_handles.len(), 5);
assert_eq!(first_resp.input_handles.len(), 7);

let mut decr_handles: Vec<Vec<u8>> = Vec::new();
for handle in &first_resp.input_handles {
Expand All @@ -67,7 +74,9 @@ async fn test_fhe_inputs() -> Result<(), Box<dyn std::error::Error>> {
);
let resp = client.debug_decrypt_ciphertext(decrypt_request).await?;
let resp = resp.get_ref();
assert_eq!(resp.values.len(), 5);
assert_eq!(resp.values.len(), 7);
// TODO: add ebytes support, we only support 256 bits max
// assert_eq!(resp.values.len(), 10);

assert_eq!(resp.values[0].output_type, 0);
assert_eq!(resp.values[0].value, "false");
Expand All @@ -79,6 +88,16 @@ async fn test_fhe_inputs() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(resp.values[3].value, "3");
assert_eq!(resp.values[4].output_type, 5);
assert_eq!(resp.values[4].value, "4");
assert_eq!(resp.values[5].output_type, 6);
assert_eq!(resp.values[5].value, "5");
assert_eq!(resp.values[6].output_type, 8);
assert_eq!(resp.values[6].value, "7");
// assert_eq!(resp.values[7].output_type, 9);
// assert_eq!(resp.values[7].value, "8");
// assert_eq!(resp.values[8].output_type, 10);
// assert_eq!(resp.values[8].value, "9");
// assert_eq!(resp.values[9].output_type, 11);
// assert_eq!(resp.values[9].value, "10");

Ok(())
}
Expand Down
22 changes: 11 additions & 11 deletions fhevm-engine/fhevm-engine-common/src/tfhe_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ pub fn perform_fhe_operation(
}
SupportedFheOperations::FheCast => match (&input_operands[0], &input_operands[1]) {
(SupportedFheCiphertexts::FheBool(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2070,7 +2070,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheUint8(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2122,7 +2122,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheUint16(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2174,7 +2174,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheUint32(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2226,7 +2226,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheUint64(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2278,7 +2278,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheUint128(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2330,7 +2330,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheUint160(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2382,7 +2382,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheUint256(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2434,7 +2434,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheBytes64(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2486,7 +2486,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheBytes128(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down Expand Up @@ -2538,7 +2538,7 @@ pub fn perform_fhe_operation(
}
}
(SupportedFheCiphertexts::FheBytes256(inp), SupportedFheCiphertexts::Scalar(op)) => {
let (l, h) = op.to_low_high_u128();
let (l, _) = op.to_low_high_u128();
let l = l as i16;
let type_id = input_operands[0].type_num();
if l == type_id {
Expand Down

0 comments on commit ad917d1

Please sign in to comment.