Hello OpenFHE Team,
I’ve encountered an incorrect result in the library and wanted to report it.
Here is a minimal snippet of the code that reproduces the issue:
#include "openfhe.h"
using namespace lbcrypto;
using namespace std;
int main(void)
{
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetScalingTechnique(NORESCALE);
CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
cc->Enable(PKE);
cc->Enable(LEVELEDSHE);
KeyPair<DCRTPoly> keyPair;
keyPair = cc->KeyGen();
cc->EvalMultKeyGen(keyPair.secretKey);
size_t slots(8);
vector<complex<double>> tmp_vec_(8);
Plaintext tmp;
Ciphertext<DCRTPoly> x;
double yP;
int c;
vector<double> tmp_vec_1 = {0.2, 0.4, 0.6, 0.8, 1.0};
tmp = cc->MakeCKKSPackedPlaintext(tmp_vec_1);
x = cc->Encrypt(keyPair.publicKey, tmp);
// After this multiplication, the following addition doesn't work
x = cc->EvalMult(x, tmp);
// Result : x = 0.04000 0.16000 0.36000 0.64000 1.00000
cc->Decrypt(keyPair.secretKey, x, &tmp);
tmp_vec_ = tmp->GetCKKSPackedValue();
for (int64_t tmp_i = 0; tmp_i < 5; ++tmp_i)
{
cout << fixed << setprecision(5) << real(tmp_vec_[tmp_i]) << " ";
}
cout << endl;
vector<double> tmp_vec_5(slots, 1.0);
tmp = cc->MakeCKKSPackedPlaintext(tmp_vec_5);
x = cc->EvalAdd(x, tmp);
// Result : x = 0.04000 0.16000 0.36000 0.64000 1.00000
cc->Decrypt(keyPair.secretKey, x, &tmp);
tmp_vec_ = tmp->GetCKKSPackedValue();
for (int64_t tmp_i = 0; tmp_i < 5; ++tmp_i)
{
cout << fixed << setprecision(5) << real(tmp_vec_[tmp_i]) << " ";
}
cout << endl;
return 0;
}
When executed on the latest version ( OpenFHE v1.1.4), the result is following:
0.04000 0.16000 0.36000 0.64000 1.00000
0.04000 0.16000 0.36000 0.64000 1.00000 <- this is weird
It looks like EvalAdd doesn’t work after EvalMult.
I guess the problem lies in using the NORESCALE scaling technique in CKKS, which does make sense to me because rescaling is a core operation in CKKS.
However, if I understood correctly, I gently suggest that prohibiting the use of NORESCALE mode in the CKKS scheme might be better.
Thank you!