in src/hit/api/evaluator/scaleestimator.cpp [120:140]
void ScaleEstimator::update_max_log_scale(const CKKSCiphertext &ct) {
// update the estimated_max_log_scale_
auto scale_exp = static_cast<int>(round(log2(ct.scale()) / context->log_scale()));
if (scale_exp != 1 && scale_exp != 2) {
LOG_AND_THROW_STREAM("Internal error: scale_exp is not 1 or 2: got "
<< scale_exp << ". "
<< "HIT ciphertext scale is " << log2(ct.scale()) << " bits, and nominal scale is "
<< context->log_scale() << " bits");
}
if (scale_exp > ct.he_level()) {
auto estimated_scale = (PLAINTEXT_LOG_MAX - log2(l_inf_norm(ct.raw_pt))) / (scale_exp - ct.he_level());
{
scoped_lock lock(mutex_);
estimated_max_log_scale_ = min(estimated_max_log_scale_, estimated_scale);
}
} else if (scale_exp == ct.he_level() && log2(l_inf_norm(ct.raw_pt)) > PLAINTEXT_LOG_MAX) {
LOG_AND_THROW_STREAM("The maximum value in the plaintext is "
<< log2(l_inf_norm(ct.raw_pt)) << " bits which exceeds SEAL's capacity of "
<< PLAINTEXT_LOG_MAX << " bits. Overflow is imminent.");
}
}