Skip to content

Commit 50ff6cc

Browse files
yspolyakovYuriy Polyakov
andauthored
fixes the bug with CKKS bootstrapping for N=2^17 (#1015)
Co-authored-by: Yuriy Polyakov <ypolyakod@dualitytech.com>
1 parent 2052e64 commit 50ff6cc

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

src/pke/lib/scheme/ckksrns/ckksrns-fhe.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ void FHECKKSRNS::EvalBootstrapSetup(const CryptoContextImpl<DCRTPoly>& cc, std::
181181
// Extract the modulus prior to bootstrapping
182182
double qDouble = GetBigModulus(cryptoParams);
183183

184-
int exponent{0};
185-
std::frexp(qDouble, &exponent);
186-
uint128_t factor = static_cast<uint128_t>(1) << static_cast<uint32_t>(exponent - 1);
184+
uint128_t factor = ((uint128_t)1 << (static_cast<uint32_t>(std::round(std::log2(qDouble)))));
187185
double pre = (compositeDegree > 1) ? 1.0 : qDouble / factor;
188186
double k = (cryptoParams->GetSecretKeyDist() == SPARSE_TERNARY) ? K_SPARSE : 1.0;
189187
double scaleEnc = pre / k;
@@ -311,9 +309,7 @@ void FHECKKSRNS::EvalBootstrapPrecompute(const CryptoContextImpl<DCRTPoly>& cc,
311309
// Extract the modulus prior to bootstrapping
312310
double qDouble = GetBigModulus(cryptoParams);
313311

314-
int exponent{0};
315-
std::frexp(qDouble, &exponent);
316-
uint128_t factor = static_cast<uint128_t>(1) << static_cast<uint32_t>(exponent - 1);
312+
uint128_t factor = ((uint128_t)1 << (static_cast<uint32_t>(std::round(std::log2(qDouble)))));
317313
double pre = qDouble / factor;
318314
double k = (cryptoParams->GetSecretKeyDist() == SPARSE_TERNARY) ? K_SPARSE : 1.0;
319315
double scaleEnc = (compositeDegree > 1) ? 1.0 / k : pre / k;

0 commit comments

Comments
 (0)