Skip to content

Commit 39d7f74

Browse files
committed
chore: fhevm-listener, handle is bytes32
1 parent ab04f7e commit 39d7f74

File tree

4 files changed

+112
-106
lines changed

4 files changed

+112
-106
lines changed

fhevm-engine/coprocessor/src/tests/operators_from_events.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use bigdecimal::num_bigint::BigInt;
33

44
use fhevm_listener::contracts::TfheContract;
55
use fhevm_listener::contracts::TfheContract::TfheContractEvents;
6-
use fhevm_listener::database::tfhe_event_propagate::{Database as ListenerDatabase, Handle, ToType};
6+
use fhevm_listener::database::tfhe_event_propagate::{ClearConst, Database as ListenerDatabase, Handle, ToType};
77

88

99
use crate::tests::operators::{generate_binary_test_cases, generate_unary_test_cases};
@@ -26,9 +26,14 @@ fn tfhe_event(data: TfheContractEvents) -> Log<TfheContractEvents> {
2626
Log::<TfheContractEvents>{address, data}
2727
}
2828

29-
fn as_scalar(big_int: &BigInt) -> Handle {
29+
fn as_scalar_handle(big_int: &BigInt) -> Handle {
3030
let (_, bytes) = big_int.to_bytes_be();
31-
Handle::from_be_slice(&bytes)
31+
Handle::right_padding_from(&bytes)
32+
}
33+
34+
fn as_scalar_uint(big_int: &BigInt) -> ClearConst {
35+
let (_, bytes) = big_int.to_bytes_be();
36+
ClearConst::from_be_slice(&bytes)
3237
}
3338

3439
fn to_bytes(big_int: &BigInt) -> Bytes {
@@ -53,7 +58,7 @@ fn binary_op_to_event(op: &BinaryOperatorTestCase, lhs: &Handle, rhs: &Handle, r
5358
let use_bytes_when_avail = op.is_scalar && op.bits > 256;
5459
let rhs_bytes = to_bytes(&r_scalar);
5560
let rhs = if op.is_scalar && op.bits <= 256 {
56-
as_scalar(r_scalar)
61+
as_scalar_handle(r_scalar)
5762
} else {
5863
rhs.clone()
5964
};
@@ -95,7 +100,7 @@ fn next_handle() -> Handle {
95100
#[allow(non_upper_case_globals)]
96101
static count: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
97102
let v = count.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
98-
Handle::from_limbs([1, 2, 3, v])
103+
as_scalar_handle(&BigInt::from(v))
99104
}
100105

101106
async fn listener_event_to_db(app: &TestInstance) -> ListenerDatabase {
@@ -160,7 +165,7 @@ async fn test_fhe_binary_operands_events() -> Result<(), Box<dyn std::error::Err
160165

161166
wait_until_all_ciphertexts_computed(&app).await?;
162167
for (op, output_handle) in cases {
163-
let decrypt_request = vec![output_handle.to_be_bytes_vec()];
168+
let decrypt_request = vec![output_handle.to_vec()];
164169
let resp = decrypt_ciphertexts(&pool, 1, decrypt_request).await?;
165170
let decr_response = &resp[0];
166171
println!("Checking computation for binary test bits:{} op:{} is_scalar:{} lhs:{} rhs:{} output:{}",
@@ -243,7 +248,7 @@ async fn test_fhe_unary_operands_events() -> Result<(), Box<dyn std::error::Erro
243248
listener_event_to_db.notify_scheduler().await;
244249
wait_until_all_ciphertexts_computed(&app).await?;
245250

246-
let decrypt_request = vec![output_handle.to_be_bytes_vec()];
251+
let decrypt_request = vec![output_handle.to_vec()];
247252
let resp = decrypt_ciphertexts(&pool, 1, decrypt_request).await?;
248253
let decr_response = &resp[0];
249254
println!(
@@ -350,7 +355,7 @@ async fn test_fhe_if_then_else_events() -> Result<(), Box<dyn std::error::Error>
350355
)).await?;
351356
listener_event_to_db.notify_scheduler().await;
352357
wait_until_all_ciphertexts_computed(&app).await?;
353-
let decrypt_request = vec![output_handle.to_be_bytes_vec()];
358+
let decrypt_request = vec![output_handle.to_vec()];
354359
let resp = decrypt_ciphertexts(&pool, 1, decrypt_request).await?;
355360
let decr_response = &resp[0];
356361
println!(
@@ -422,7 +427,7 @@ async fn test_fhe_cast_events() -> Result<(), Box<dyn std::error::Error>> {
422427

423428
listener_event_to_db.notify_scheduler().await;
424429
wait_until_all_ciphertexts_computed(&app).await?;
425-
let decrypt_request = vec![output_handle.to_be_bytes_vec()];
430+
let decrypt_request = vec![output_handle.to_vec()];
426431
let resp = decrypt_ciphertexts(&pool, 1, decrypt_request).await?;
427432
let decr_response = &resp[0];
428433

@@ -486,7 +491,7 @@ async fn test_fhe_rand_events() -> Result<(), Box<dyn std::error::Error>> {
486491
listener_event_to_db.insert_tfhe_event(&tfhe_event(
487492
TfheContractEvents::FheRandBounded(TfheContract::FheRandBounded {
488493
caller,
489-
upperBound: as_scalar(&BigInt::from(1)),
494+
upperBound: as_scalar_uint(&BigInt::from(1)),
490495
randType: to_ty(rand_type),
491496
seed: FixedBytes::from([1u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8]),
492497
result: output3_handle.clone()
@@ -496,7 +501,7 @@ async fn test_fhe_rand_events() -> Result<(), Box<dyn std::error::Error>> {
496501
listener_event_to_db.notify_scheduler().await;
497502
wait_until_all_ciphertexts_computed(&app).await?;
498503

499-
let decrypt_request = vec![output1_handle.to_be_bytes_vec(), output2_handle.to_be_bytes_vec(), output3_handle.to_be_bytes_vec()];
504+
let decrypt_request = vec![output1_handle.to_vec(), output2_handle.to_vec(), output3_handle.to_vec()];
500505
let resp = decrypt_ciphertexts(&pool, 1, decrypt_request).await?;
501506
assert_eq!(resp[0].output_type, rand_type as i16);
502507
assert_eq!(resp[1].output_type, rand_type as i16);

0 commit comments

Comments
 (0)