Crashes with specific parameter setting in CKKS

Hello,

I want to report out two CKKS cases that produce the crash, floating point exception (core dump), on the latest version (v1.1.4).

I am not very confident whether this parameter setting is a valid setting or not, but I guess at least this crash is not expected one.

int main(void)
{
  CCParams<CryptoContextCKKSRNS> parameters;
  parameters.SetRingDim(32768);
  parameters.SetMultiplicativeDepth(19);
  parameters.SetPlaintextModulus(65537);
  parameters.SetFirstModSize(23);
  parameters.SetScalingModSize(22);

  CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
  cc->Enable(PKE);
  cc->Enable(KEYSWITCH);
  cc->Enable(LEVELEDSHE);

  return 0;
}

For this second code example, it looks similar with the first one. But one different thing is that this one additionally includes SetSecurityLevel, and if I remove it, then it terminates with an exception OpenFHEException. So I carefully guess that setting the security level as HEStd_NotSet might be the problem in this case.

int main(void)
{
  CCParams<CryptoContextCKKSRNS> parameters;
  parameters.SetRingDim(32768);
  parameters.SetMultiplicativeDepth(16);
  parameters.SetPlaintextModulus(65537);
  parameters.SetFirstModSize(50);
  parameters.SetScalingModSize(50);
  parameters.SetSecurityLevel(HEStd_NotSet);

  CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
  cc->Enable(PKE);
  cc->Enable(KEYSWITCH);
  cc->Enable(LEVELEDSHE);

  return 0;
}

Could you please check out these unexpected behaviors?

Thank you for your attention!

For the CKKS scheme, the plaintext modulus should not be set. We have added scheme validators recently in the dev branch, see 710 validate parameters for cryptocontext generation by dsuponitskiy · Pull Request #736 · openfheorg/openfhe-development · GitHub, and this will be merged into main soon.

As @andreea.alexandru pointed out, both configurations are invalid. Please try to run your code using the dev branch, and you should get proper exceptions there. This code will be merged to main (as part of releasing v1.1.5) later this month.

Thank you for the replies!

I’ve checked the PR that you mentioned.

However, I want to point out that even though I delete the SetPlaintextModulus in both example, they keep crash as before.

Here’s the modified examples. (just deleted the line with setting plaintext modulus from the original examples)
These still make crashes…

int main(void)
{
  CCParams<CryptoContextCKKSRNS> parameters;
  parameters.SetRingDim(32768);
  parameters.SetMultiplicativeDepth(19);
  parameters.SetFirstModSize(23);
  parameters.SetScalingModSize(22);

  CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
  cc->Enable(PKE);
  cc->Enable(KEYSWITCH);
  cc->Enable(LEVELEDSHE);

  return 0;
}
int main(void)
{
  CCParams<CryptoContextCKKSRNS> parameters;
  parameters.SetRingDim(32768);
  parameters.SetMultiplicativeDepth(16);
  parameters.SetFirstModSize(50);
  parameters.SetScalingModSize(50);
  parameters.SetSecurityLevel(HEStd_NotSet);

  CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
  cc->Enable(PKE);
  cc->Enable(KEYSWITCH);
  cc->Enable(LEVELEDSHE);

  return 0;
}

Thank you for providing the modified examples! I suspect this is happening because the chosen parameter values (small mod sizes, large depths, small difference between firstmod and scalingmod) cause repeated primes for the ciphertext moduli. We will be looking into this to ensure we throw a more descriptive exception when this happens. In general, mod sizes under 30 are very small and don’t offer good precision.