Skip to content

Commit

Permalink
Added unit tests and changed version to 3.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlaine committed May 31, 2020
1 parent 46a2487 commit e0dbb55
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# List of Changes

## Version 3.5.3

### Bug fixes

- Fixed a bug in `seal::util::IterTuple<...>` where a part of the `value_type` was constructed incorrectly.
- 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!

## Version 3.5.2

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.12)
# 4. SEAL C++ tests #
###################################################

project(SEAL VERSION 3.5.2 LANGUAGES CXX C)
project(SEAL VERSION 3.5.3 LANGUAGES CXX C)

# Check operating system: for Windows, use Visual Studio solution/project files.
if(MSVC)
Expand Down
79 changes: 65 additions & 14 deletions native/tests/seal/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ namespace sealtest
evaluator.relinearize_inplace(encrypted1, rlk);
evaluator.rescale_to_next_inplace(encrypted1);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);

decryptor.decrypt(encrypted1, plainRes);
Expand Down Expand Up @@ -2246,7 +2246,7 @@ namespace sealtest
evaluator.relinearize_inplace(encrypted1, rlk);
evaluator.rescale_to_next_inplace(encrypted1);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);

decryptor.decrypt(encrypted1, plainRes);
Expand Down Expand Up @@ -2318,7 +2318,7 @@ namespace sealtest
auto target_parms = context->first_context_data()->next_context_data()->next_context_data()->parms_id();
evaluator.rescale_to_inplace(encrypted1, target_parms);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted1.parms_id() == target_parms);

decryptor.decrypt(encrypted1, plainRes);
Expand Down Expand Up @@ -2367,7 +2367,7 @@ namespace sealtest
// Relinearize now
evaluator.relinearize_inplace(encrypted1, rlk);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted1.parms_id() == target_parms);

decryptor.decrypt(encrypted1, plainRes);
Expand Down Expand Up @@ -2431,7 +2431,7 @@ namespace sealtest
evaluator.relinearize_inplace(encrypted, rlk);
evaluator.rescale_to_next_inplace(encrypted);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);

decryptor.decrypt(encrypted, plainRes);
Expand Down Expand Up @@ -2490,7 +2490,7 @@ namespace sealtest
evaluator.relinearize_inplace(encrypted, rlk);
evaluator.rescale_to_next_inplace(encrypted);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);

decryptor.decrypt(encrypted, plainRes);
Expand All @@ -2508,7 +2508,7 @@ namespace sealtest
{
EncryptionParameters parms(scheme_type::CKKS);
{
// modulo switching without rescaling for random vectors
// modulus switching without rescaling for random vectors
size_t slot_size = 64;
parms.set_poly_modulus_degree(slot_size * 2);
parms.set_coeff_modulus(CoeffModulus::Create(slot_size * 2, { 60, 60, 60, 60, 60 }));
Expand Down Expand Up @@ -2547,9 +2547,26 @@ namespace sealtest
// check correctness of encryption
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());

// Not inplace
Ciphertext destination;
evaluator.mod_switch_to_next(encrypted, destination);

// check correctness of modulus switching
ASSERT_TRUE(destination.parms_id() == next_parms_id);

decryptor.decrypt(destination, plainRes);
encoder.decode(plainRes, output);

for (size_t i = 0; i < slot_size; i++)
{
auto tmp = abs(input[i].real() - output[i].real());
ASSERT_TRUE(tmp < 0.5);
}

// Inplace
evaluator.mod_switch_to_next_inplace(encrypted);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);

decryptor.decrypt(encrypted, plainRes);
Expand All @@ -2563,7 +2580,7 @@ namespace sealtest
}
}
{
// modulo switching without rescaling for random vectors
// modulus switching without rescaling for random vectors
size_t slot_size = 32;
parms.set_poly_modulus_degree(slot_size * 2);
parms.set_coeff_modulus(CoeffModulus::Create(slot_size * 2, { 40, 40, 40, 40, 40 }));
Expand Down Expand Up @@ -2602,9 +2619,26 @@ namespace sealtest
// check correctness of encryption
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());

// Not inplace
Ciphertext destination;
evaluator.mod_switch_to_next(encrypted, destination);

// check correctness of modulus switching
ASSERT_TRUE(destination.parms_id() == next_parms_id);

decryptor.decrypt(destination, plainRes);
encoder.decode(plainRes, output);

for (size_t i = 0; i < slot_size; i++)
{
auto tmp = abs(input[i].real() - output[i].real());
ASSERT_TRUE(tmp < 0.5);
}

// Inplace
evaluator.mod_switch_to_next_inplace(encrypted);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);

decryptor.decrypt(encrypted, plainRes);
Expand All @@ -2618,7 +2652,7 @@ namespace sealtest
}
}
{
// modulo switching without rescaling for random vectors
// modulus switching without rescaling for random vectors
size_t slot_size = 32;
parms.set_poly_modulus_degree(128);
parms.set_coeff_modulus(CoeffModulus::Create(128, { 40, 40, 40, 40, 40 }));
Expand Down Expand Up @@ -2657,9 +2691,26 @@ namespace sealtest
// check correctness of encryption
ASSERT_TRUE(encrypted.parms_id() == context->first_parms_id());

// Not inplace
Ciphertext destination;
evaluator.mod_switch_to_next(encrypted, destination);

// check correctness of modulus switching
ASSERT_TRUE(destination.parms_id() == next_parms_id);

decryptor.decrypt(destination, plainRes);
encoder.decode(plainRes, output);

for (size_t i = 0; i < slot_size; i++)
{
auto tmp = abs(input[i].real() - output[i].real());
ASSERT_TRUE(tmp < 0.5);
}

// Inplace
evaluator.mod_switch_to_next_inplace(encrypted);

// check correctness of modulo switching
// check correctness of modulus switching
ASSERT_TRUE(encrypted.parms_id() == next_parms_id);

decryptor.decrypt(encrypted, plainRes);
Expand Down Expand Up @@ -2738,7 +2789,7 @@ namespace sealtest
evaluator.relinearize_inplace(encrypted1, rlk);
evaluator.rescale_to_next_inplace(encrypted1);

// check correctness of modulo switching with rescaling
// check correctness of modulus switching with rescaling
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);

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

// check correctness of modulo switching with rescaling
// check correctness of modulus switching with rescaling
ASSERT_TRUE(encrypted1.parms_id() == next_parms_id);

// move enc3 to the level of enc1 * enc2
Expand Down

0 comments on commit e0dbb55

Please sign in to comment.