I want to know how the multiplicationDepth affects the number of EvalMult(ciphertext, plaintext).
I set the multiplicationDepth = n. After performing n+1 plaintext-ciphertext multiplications, the result decrypted is 0.
So I want to know if I can perform more plaintext-ciphertext multiplications when I set the depth to n. Or how to set the scale factor?(The question seems to be similiar to About CKKS cipher-plain multiplication - FHE Questions - OpenFHE).
Here is a example.
using Ctx = lbcrypto::Ciphertext<lbcrypto::DCRTPoly>;
using Ptx = lbcrypto::Plaintext;
uint32_t multDepth = 2;
uint32_t scaleModSize = 40;
uint32_t batchSize = 128;
ScalingTechnique rescaleTech = FIXEDMANUAL;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetMultiplicativeDepth(multDepth);
parameters.SetScalingModSize(scaleModSize);
parameters.SetBatchSize(batchSize);
parameters.SetScalingTechnique(rescaleTech);
CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
cc->Enable(PKE);
cc->Enable(KEYSWITCH);
cc->Enable(LEVELEDSHE);
auto keys = cc->KeyGen();
cc->EvalMultKeyGen(keys.secretKey);
std::vector<double> x1 = {0.25, 0.5, 1.0, 2.0, 4.0};
std::vector<double> x2 = {4, 2, 1, 0.5, 0.25};
Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(x1);
Plaintext ptxt2 = cc->MakeCKKSPackedPlaintext(x2);
auto c1 = cc->Encrypt(keys.publicKey, ptxt1);
auto c2 = cc->Encrypt(keys.publicKey, ptxt2);
Ctx c3 = c1;
Ptx ptx3;
for (size_t i = 1; i < 5; ++i)
{
c3 = cc->EvalMult(c3, ptxt2);
cc->Decrypt(keys.secretKey, c3, &ptx3);
ptx3->SetLength(8);
std::cout << ptx3 << std::endl;
}
The output is
(1, 1, 1, 1, 1, 1.28776e-09, -5.05258e-10, -1.68733e-09, … ); Estimated precision: 30 bits
(4, 2, 1, 0.5, 0.25, -3.02947e-10, 8.86368e-10, -1.30289e-09, … ); Estimated precision: 29 bits
(3.51656e-06, 6.46768e-06, 8.11758e-07, 3.00899e-06, 2.803e-06, 9.14237e-07, 9.56325e-07, 4.59316e-06, … ); Estimated precision: 28 bits
(-3.45635e-10, 2.75771e-10, 1.30282e-10, -3.34742e-11, -1.57894e-10, -1.17082e-10, -2.21638e-10, 9.24746e-11, … ); Estimated precision: 31 bits