# Why does decryption of a fresh ciphertext, or a single EvalMul using a plaintext and a fresh ciphertext, result in NaN?

**URL:** <https://openfhe.discourse.group/t/why-does-decryption-of-a-fresh-ciphertext-or-a-single-evalmul-using-a-plaintext-and-a-fresh-ciphertext-result-in-nan/2163>\
**Category:** Library Questions\
**Created:** [September 7, 2025, 12:17am UTC](https://openfhe.discourse.group/t/why-does-decryption-of-a-fresh-ciphertext-or-a-single-evalmul-using-a-plaintext-and-a-fresh-ciphertext-result-in-nan/2163 "2025-09-07T00:17:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![YKSK](https://avatars.discourse-cdn.com/v4/letter/y/76d3ee/32.png) [@YKSK](https://openfhe.discourse.group/u/YKSK)\
**Post date:** [September 7, 2025, 12:17am UTC](https://openfhe.discourse.group/t/why-does-decryption-of-a-fresh-ciphertext-or-a-single-evalmul-using-a-plaintext-and-a-fresh-ciphertext-result-in-nan/2163/1 "2025-09-07T00:17:11Z")

</div>

I have a question regarding the Python wrapper for OpenFHE (version 0.8.4).  
I encountered an issue.

The problem is that the result of decrypting a fresh ciphertext, or of decrypting a ciphertext that has been through a single EvalMul using a plaintext and a fresh ciphertext, sometimes becomes “NaN” after performing certain operations over the ciphertext space (these operations resulted in a RuntimeError: “The decryption failed because the approximation error is too high. Check the parameters.”).

Specifically, when decrypting `a_pt` inside a loop, I noticed that it sometimes produces the correct values, but at unpredictable iterations, the decryption output suddenly becomes NaN:

### 

a = [1] \* batch\_size  
a\_pt = cc.MakeCKKSPackedPlaintext(a)  
a\_ct = cc.Encrypt(keys.publicKey, a\_pt)

dim = 2 \*\* 8

for i in tqdm(range(dim)):  
temp\_pt = cc.Decrypt(keys.secretKey, a\_ct)  
temp = temp\_pt.GetCKKSPackedValue()  
print(temp[:4])

### 

Interestingly, if I restart the computer and run the same loop, the output is always correct without producing NaN.

I would like to ask why this kind of error occurs.

The exact code is as follows::

#######

import Receiver  
from openfhe import \*  
from tqdm.notebook import tqdm

mult\_depth = 41  
scale\_mod\_size = 59  
batch\_size = (131072 \>\> 1)  
ring\_dim = 131072

parameters = CCParamsCKKSRNS()  
parameters.SetMultiplicativeDepth(mult\_depth)  
parameters.SetScalingModSize(scale\_mod\_size)  
parameters.SetBatchSize(batch\_size)  
parameters.SetScalingTechnique(FLEXIBLEAUTOEXT)  
parameters.SetRingDim(ring\_dim)  
parameters.SetSecurityLevel(HEStd\_128\_classic)  
parameters.SetExecutionMode(EXEC\_EVALUATION)

cc = GenCryptoContext(parameters)

cc.Enable(PKESchemeFeature.PKE)  
cc.Enable(PKESchemeFeature.KEYSWITCH)  
cc.Enable(PKESchemeFeature.LEVELEDSHE)  
cc.Enable(PKESchemeFeature.ADVANCEDSHE)

keys = cc.KeyGen()  
cc.EvalMultKeyGen(keys.secretKey)

a = [1] \* batch\_size  
b = [2] \* batch\_size

a\_pt = cc.MakeCKKSPackedPlaintext(a)

b\_pt = cc.MakeCKKSPackedPlaintext(b)

a\_ct = cc.Encrypt(keys.publicKey, a\_pt)  
b\_ct = cc.Encrypt(keys.publicKey, b\_pt)

dim = 2 \*\* 8

for i in tqdm(range(dim)):  
temp\_pt = cc.Decrypt(keys.secretKey,a\_ct)  
temp = temp\_pt.GetCKKSPackedValue()  
print(temp[:4])

for i in tqdm(range(dim)):  
temp\_ct = cc.EvalMult(a\_ct, b\_ct)  
temp\_pt = cc.Decrypt(keys.secretKey,temp\_ct)  
temp = temp\_pt.GetCKKSPackedValue()  
print(temp[:4])

print(“End”)

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [September 9, 2025, 7:08pm UTC](https://openfhe.discourse.group/t/why-does-decryption-of-a-fresh-ciphertext-or-a-single-evalmul-using-a-plaintext-and-a-fresh-ciphertext-result-in-nan/2163/2 "2025-09-09T19:08:17Z")

</div>

I ran your code on my machine with `OpenFHE-Python v1.4.0` and I did not face any issues.  
You might be running out of memory on your machine. The cryptographic parameters are unnecessarily set very large. That might be causing some memory issues on your system.

You do not need that high multiplicative depth for the computation in your code. Accordingly, you do not need a large ring dimension.

---

<div class="post-metadata">

**Author:** ![YKSK](https://avatars.discourse-cdn.com/v4/letter/y/76d3ee/32.png) [@YKSK](https://openfhe.discourse.group/u/YKSK)\
**Post date:** [September 22, 2025, 8:50pm UTC](https://openfhe.discourse.group/t/why-does-decryption-of-a-fresh-ciphertext-or-a-single-evalmul-using-a-plaintext-and-a-fresh-ciphertext-result-in-nan/2163/3 "2025-09-22T20:50:27Z")

</div>

Yes, I understand that I used a high multiplicative depth.  
I used it because I needed that depth to perform certain operations over the ciphertext space before NaN values appeared.

Actually, I was able to resolve this issue by updating the library to version 1.3.0.

Thank you very much for your response!
