# Crashes with specific parameter setting in CKKS

**URL:** <https://openfhe.discourse.group/t/crashes-with-specific-parameter-setting-in-ckks/1252>\
**Category:** Library Questions\
**Created:** [May 8, 2024, 2:01am UTC](https://openfhe.discourse.group/t/crashes-with-specific-parameter-setting-in-ckks/1252 "2024-05-08T02:01:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyerinpark](https://avatars.discourse-cdn.com/v4/letter/h/bc79bd/32.png) [@hyerinpark](https://openfhe.discourse.group/u/hyerinpark)\
**Post date:** [May 8, 2024, 2:01am UTC](https://openfhe.discourse.group/t/crashes-with-specific-parameter-setting-in-ckks/1252/1 "2024-05-08T02:01:06Z")

</div>

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).

1. 

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.

```auto
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;
}

```

1. 

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.

```auto
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!

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [May 8, 2024, 12:56pm UTC](https://openfhe.discourse.group/t/crashes-with-specific-parameter-setting-in-ckks/1252/2 "2024-05-08T12:56:41Z")

</div>

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](https://github.com/openfheorg/openfhe-development/pull/736), and this will be merged into main soon.

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [May 8, 2024, 11:24pm UTC](https://openfhe.discourse.group/t/crashes-with-specific-parameter-setting-in-ckks/1252/3 "2024-05-08T23:24:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hyerinpark](https://avatars.discourse-cdn.com/v4/letter/h/bc79bd/32.png) [@hyerinpark](https://openfhe.discourse.group/u/hyerinpark)\
**Post date:** [May 9, 2024, 2:47am UTC](https://openfhe.discourse.group/t/crashes-with-specific-parameter-setting-in-ckks/1252/4 "2024-05-09T02:47:53Z")

</div>

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…

```auto
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;
}

```

```auto
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;
}

```

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [May 9, 2024, 9:29pm UTC](https://openfhe.discourse.group/t/crashes-with-specific-parameter-setting-in-ckks/1252/5 "2024-05-09T21:29:57Z")

</div>

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.
