Skip to content

Commit e0dbb55

Browse files
committed
Added unit tests and changed version to 3.5.3
1 parent 46a2487 commit e0dbb55

3 files changed

Lines changed: 73 additions & 15 deletions

File tree

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# List of Changes
22

3+
## Version 3.5.3
4+
5+
### Bug fixes
6+
7+
- Fixed a bug in `seal::util::IterTuple<...>` where a part of the `value_type` was constructed incorrectly.
8+
- Fixed a bug in `Evaluator::mod_switch_drop_to_next` that caused non-inplace modulus switching to fail [(Issue 179)](https://github.com/microsoft/SEAL/issues/179). Thanks s0l0ist!
9+
310
## Version 3.5.2
411

512
### Bug fixes

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.12)
1111
# 4. SEAL C++ tests #
1212
###################################################
1313

14-
project(SEAL VERSION 3.5.2 LANGUAGES CXX C)
14+
project(SEAL VERSION 3.5.3 LANGUAGES CXX C)
1515

1616
# Check operating system: for Windows, use Visual Studio solution/project files.
1717
if(MSVC)

native/tests/seal/evaluator.cpp

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ namespace sealtest
21782178
evaluator.relinearize_inplace(encrypted1, rlk);
21792179
evaluator.rescale_to_next_inplace(encrypted1);
21802180

2181-
// check correctness of modulo switching
2181+
// check correctness of modulus switching
21822182
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);
21832183

21842184
decryptor.decrypt(encrypted1, plainRes);
@@ -2246,7 +2246,7 @@ namespace sealtest
22462246
evaluator.relinearize_inplace(encrypted1, rlk);
22472247
evaluator.rescale_to_next_inplace(encrypted1);
22482248

2249-
// check correctness of modulo switching
2249+
// check correctness of modulus switching
22502250
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);
22512251

22522252
decryptor.decrypt(encrypted1, plainRes);
@@ -2318,7 +2318,7 @@ namespace sealtest
23182318
auto target_parms = context->first_context_data()->next_context_data()->next_context_data()->parms_id();
23192319
evaluator.rescale_to_inplace(encrypted1, target_parms);
23202320

2321-
// check correctness of modulo switching
2321+
// check correctness of modulus switching
23222322
ASSERT_TRUE(encrypted1.parms_id() == target_parms);
23232323

23242324
decryptor.decrypt(encrypted1, plainRes);
@@ -2367,7 +2367,7 @@ namespace sealtest
23672367
// Relinearize now
23682368
evaluator.relinearize_inplace(encrypted1, rlk);
23692369

2370-
// check correctness of modulo switching
2370+
// check correctness of modulus switching
23712371
ASSERT_TRUE(encrypted1.parms_id() == target_parms);
23722372

23732373
decryptor.decrypt(encrypted1, plainRes);
@@ -2431,7 +2431,7 @@ namespace sealtest
24312431
evaluator.relinearize_inplace(encrypted, rlk);
24322432
evaluator.rescale_to_next_inplace(encrypted);
24332433

2434-
// check correctness of modulo switching
2434+
// check correctness of modulus switching
24352435
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);
24362436

24372437
decryptor.decrypt(encrypted, plainRes);
@@ -2490,7 +2490,7 @@ namespace sealtest
24902490
evaluator.relinearize_inplace(encrypted, rlk);
24912491
evaluator.rescale_to_next_inplace(encrypted);
24922492

2493-
// check correctness of modulo switching
2493+
// check correctness of modulus switching
24942494
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);
24952495

24962496
decryptor.decrypt(encrypted, plainRes);
@@ -2508,7 +2508,7 @@ namespace sealtest
25082508
{
25092509
EncryptionParameters parms(scheme_type::CKKS);
25102510
{
2511-
// modulo switching without rescaling for random vectors
2511+
// modulus switching without rescaling for random vectors
25122512
size_t slot_size = 64;
25132513
parms.set_poly_modulus_degree(slot_size * 2);
25142514
parms.set_coeff_modulus(CoeffModulus::Create(slot_size * 2, { 60, 60, 60, 60, 60 }));
@@ -2547,9 +2547,26 @@ namespace sealtest
25472547
// check correctness of encryption
25482548
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());
25492549

2550+
// Not inplace
2551+
Ciphertext destination;
2552+
evaluator.mod_switch_to_next(encrypted, destination);
2553+
2554+
// check correctness of modulus switching
2555+
ASSERT_TRUE(destination.parms_id() == next_parms_id);
2556+
2557+
decryptor.decrypt(destination, plainRes);
2558+
encoder.decode(plainRes, output);
2559+
2560+
for (size_t i = 0; i < slot_size; i++)
2561+
{
2562+
auto tmp = abs(input[i].real() - output[i].real());
2563+
ASSERT_TRUE(tmp < 0.5);
2564+
}
2565+
2566+
// Inplace
25502567
evaluator.mod_switch_to_next_inplace(encrypted);
25512568

2552-
// check correctness of modulo switching
2569+
// check correctness of modulus switching
25532570
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);
25542571

25552572
decryptor.decrypt(encrypted, plainRes);
@@ -2563,7 +2580,7 @@ namespace sealtest
25632580
}
25642581
}
25652582
{
2566-
// modulo switching without rescaling for random vectors
2583+
// modulus switching without rescaling for random vectors
25672584
size_t slot_size = 32;
25682585
parms.set_poly_modulus_degree(slot_size * 2);
25692586
parms.set_coeff_modulus(CoeffModulus::Create(slot_size * 2, { 40, 40, 40, 40, 40 }));
@@ -2602,9 +2619,26 @@ namespace sealtest
26022619
// check correctness of encryption
26032620
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());
26042621

2622+
// Not inplace
2623+
Ciphertext destination;
2624+
evaluator.mod_switch_to_next(encrypted, destination);
2625+
2626+
// check correctness of modulus switching
2627+
ASSERT_TRUE(destination.parms_id() == next_parms_id);
2628+
2629+
decryptor.decrypt(destination, plainRes);
2630+
encoder.decode(plainRes, output);
2631+
2632+
for (size_t i = 0; i < slot_size; i++)
2633+
{
2634+
auto tmp = abs(input[i].real() - output[i].real());
2635+
ASSERT_TRUE(tmp < 0.5);
2636+
}
2637+
2638+
// Inplace
26052639
evaluator.mod_switch_to_next_inplace(encrypted);
26062640

2607-
// check correctness of modulo switching
2641+
// check correctness of modulus switching
26082642
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);
26092643

26102644
decryptor.decrypt(encrypted, plainRes);
@@ -2618,7 +2652,7 @@ namespace sealtest
26182652
}
26192653
}
26202654
{
2621-
// modulo switching without rescaling for random vectors
2655+
// modulus switching without rescaling for random vectors
26222656
size_t slot_size = 32;
26232657
parms.set_poly_modulus_degree(128);
26242658
parms.set_coeff_modulus(CoeffModulus::Create(128, { 40, 40, 40, 40, 40 }));
@@ -2657,9 +2691,26 @@ namespace sealtest
26572691
// check correctness of encryption
26582692
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());
26592693

2694+
// Not inplace
2695+
Ciphertext destination;
2696+
evaluator.mod_switch_to_next(encrypted, destination);
2697+
2698+
// check correctness of modulus switching
2699+
ASSERT_TRUE(destination.parms_id() == next_parms_id);
2700+
2701+
decryptor.decrypt(destination, plainRes);
2702+
encoder.decode(plainRes, output);
2703+
2704+
for (size_t i = 0; i < slot_size; i++)
2705+
{
2706+
auto tmp = abs(input[i].real() - output[i].real());
2707+
ASSERT_TRUE(tmp < 0.5);
2708+
}
2709+
2710+
// Inplace
26602711
evaluator.mod_switch_to_next_inplace(encrypted);
26612712

2662-
// check correctness of modulo switching
2713+
// check correctness of modulus switching
26632714
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);
26642715

26652716
decryptor.decrypt(encrypted, plainRes);
@@ -2738,7 +2789,7 @@ namespace sealtest
27382789
evaluator.relinearize_inplace(encrypted1, rlk);
27392790
evaluator.rescale_to_next_inplace(encrypted1);
27402791

2741-
// check correctness of modulo switching with rescaling
2792+
// check correctness of modulus switching with rescaling
27422793
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);
27432794

27442795
// move enc3 to the level of enc1 * enc2
@@ -2821,7 +2872,7 @@ namespace sealtest
28212872
evaluator.relinearize_inplace(encrypted1, rlk);
28222873
evaluator.rescale_to_next_inplace(encrypted1);
28232874

2824-
// check correctness of modulo switching with rescaling
2875+
// check correctness of modulus switching with rescaling
28252876
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);
28262877

28272878
// move enc3 to the level of enc1 * enc2

0 commit comments

Comments
 (0)