diff --git a/shell_encryption/error_params.h b/shell_encryption/error_params.h index bf4fa13..0dd9499 100644 --- a/shell_encryption/error_params.h +++ b/shell_encryption/error_params.h @@ -71,7 +71,8 @@ class ErrorParams { // decomposition modulus. int num_digits = (log_decomposition_modulus + log_modulus_ - 1) / log_decomposition_modulus; - int decomposition_modulus = 1 << log_decomposition_modulus; + double decomposition_modulus = static_cast( + static_cast(1) << log_decomposition_modulus); return (8.0 / sqrt(3.0)) * ExportDoubleT() * num_digits * sigma_ * dimension_ * decomposition_modulus * num_components; } diff --git a/shell_encryption/error_params_test.cc b/shell_encryption/error_params_test.cc index 2f1b39d..7f62dfa 100644 --- a/shell_encryption/error_params_test.cc +++ b/shell_encryption/error_params_test.cc @@ -219,6 +219,29 @@ TYPED_TEST(ErrorParamsTest, RelinearizationErrorScalesWithNumComponents) { } } +// Test that the relinearization error can be computed when +// log_decomposition_modulus is equal to log(modulus) which is the largest +// possible value. +TYPED_TEST(ErrorParamsTest, + RelinearizationErrorForLargeLogDecompositionModulus) { + for (const auto& params : + rlwe::testing::ContextParameters::Value()) { + ASSERT_OK_AND_ASSIGN(auto context, + rlwe::RlweContext::Create(params)); + const int k_decomposition_modulus = + context->GetModulusParams()->log_modulus; + constexpr int k_num_components = 2; + // When log_decomposition_modulus = log(modulus), we are effectively + // not decomposing the ciphertext coefficients, and so the error can be + // much larger than the ciphertext modulus. In practice, we would never use + // such a large decomposition modulus, but we test it here to make sure the + // error computation does not fail. + EXPECT_GT(context->GetErrorParams()->B_relinearize(k_num_components, + k_decomposition_modulus), + 0.0); + } +} + } // namespace #endif // RLWE_ERROR_PARAMS_TEST_H_