@@ -3,7 +3,7 @@ use bigdecimal::num_bigint::BigInt;
3
3
4
4
use fhevm_listener:: contracts:: TfheContract ;
5
5
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 } ;
7
7
8
8
9
9
use crate :: tests:: operators:: { generate_binary_test_cases, generate_unary_test_cases} ;
@@ -26,9 +26,14 @@ fn tfhe_event(data: TfheContractEvents) -> Log<TfheContractEvents> {
26
26
Log :: < TfheContractEvents > { address, data}
27
27
}
28
28
29
- fn as_scalar ( big_int : & BigInt ) -> Handle {
29
+ fn as_scalar_handle ( big_int : & BigInt ) -> Handle {
30
30
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)
32
37
}
33
38
34
39
fn to_bytes ( big_int : & BigInt ) -> Bytes {
@@ -53,7 +58,7 @@ fn binary_op_to_event(op: &BinaryOperatorTestCase, lhs: &Handle, rhs: &Handle, r
53
58
let use_bytes_when_avail = op. is_scalar && op. bits > 256 ;
54
59
let rhs_bytes = to_bytes ( & r_scalar) ;
55
60
let rhs = if op. is_scalar && op. bits <= 256 {
56
- as_scalar ( r_scalar)
61
+ as_scalar_handle ( r_scalar)
57
62
} else {
58
63
rhs. clone ( )
59
64
} ;
@@ -95,7 +100,7 @@ fn next_handle() -> Handle {
95
100
#[ allow( non_upper_case_globals) ]
96
101
static count: std:: sync:: atomic:: AtomicU64 = std:: sync:: atomic:: AtomicU64 :: new ( 1 ) ;
97
102
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 ) )
99
104
}
100
105
101
106
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
160
165
161
166
wait_until_all_ciphertexts_computed ( & app) . await ?;
162
167
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 ( ) ] ;
164
169
let resp = decrypt_ciphertexts ( & pool, 1 , decrypt_request) . await ?;
165
170
let decr_response = & resp[ 0 ] ;
166
171
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
243
248
listener_event_to_db. notify_scheduler ( ) . await ;
244
249
wait_until_all_ciphertexts_computed ( & app) . await ?;
245
250
246
- let decrypt_request = vec ! [ output_handle. to_be_bytes_vec ( ) ] ;
251
+ let decrypt_request = vec ! [ output_handle. to_vec ( ) ] ;
247
252
let resp = decrypt_ciphertexts ( & pool, 1 , decrypt_request) . await ?;
248
253
let decr_response = & resp[ 0 ] ;
249
254
println ! (
@@ -350,7 +355,7 @@ async fn test_fhe_if_then_else_events() -> Result<(), Box<dyn std::error::Error>
350
355
) ) . await ?;
351
356
listener_event_to_db. notify_scheduler ( ) . await ;
352
357
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 ( ) ] ;
354
359
let resp = decrypt_ciphertexts ( & pool, 1 , decrypt_request) . await ?;
355
360
let decr_response = & resp[ 0 ] ;
356
361
println ! (
@@ -422,7 +427,7 @@ async fn test_fhe_cast_events() -> Result<(), Box<dyn std::error::Error>> {
422
427
423
428
listener_event_to_db. notify_scheduler ( ) . await ;
424
429
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 ( ) ] ;
426
431
let resp = decrypt_ciphertexts ( & pool, 1 , decrypt_request) . await ?;
427
432
let decr_response = & resp[ 0 ] ;
428
433
@@ -486,7 +491,7 @@ async fn test_fhe_rand_events() -> Result<(), Box<dyn std::error::Error>> {
486
491
listener_event_to_db. insert_tfhe_event ( & tfhe_event (
487
492
TfheContractEvents :: FheRandBounded ( TfheContract :: FheRandBounded {
488
493
caller,
489
- upperBound : as_scalar ( & BigInt :: from ( 1 ) ) ,
494
+ upperBound : as_scalar_uint ( & BigInt :: from ( 1 ) ) ,
490
495
randType : to_ty ( rand_type) ,
491
496
seed : FixedBytes :: from ( [ 1u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 , 0u8 ] ) ,
492
497
result : output3_handle. clone ( )
@@ -496,7 +501,7 @@ async fn test_fhe_rand_events() -> Result<(), Box<dyn std::error::Error>> {
496
501
listener_event_to_db. notify_scheduler ( ) . await ;
497
502
wait_until_all_ciphertexts_computed ( & app) . await ?;
498
503
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 ( ) ] ;
500
505
let resp = decrypt_ciphertexts ( & pool, 1 , decrypt_request) . await ?;
501
506
assert_eq ! ( resp[ 0 ] . output_type, rand_type as i16 ) ;
502
507
assert_eq ! ( resp[ 1 ] . output_type, rand_type as i16 ) ;
0 commit comments