OpenFHE Rescaling with Issues after scheme switching with CKKS and TFHE/FHEW

Hi all, I’m stuck with weird rescaling error when using OpenFHE CKKS.

After multiplying an encrypted index gotten from EvalMaxSchemeSwitching by some plaintext and accumulating results, decryption fails consistently. Below is a function that replicates my task.

Ctext readData(Ctext &encryptedInput, int vecSize){
vecSize = nextPowerOf2(vecSize);
vector<double>datasV = {1, 2, 3, 7, 1, 2, 3, 5};
int dataSize = nextPowerOf2(datasV.size());
Ptext encodeData = context->MakeCKKSPackedPlaintext(datasV, 1, 1, nullptr, dataSize);
auto ccLWE = context->GetBinCCForSchemeSwitch();
auto pLWE = ccLWE->GetMaxPlaintextSpace().ConvertToInt();
vector<Ctext> cinVec = context->EvalMaxSchemeSwitching(encryptedInput, keyPair.publicKey, vecSize, vecSize, pLWE, 1.0);
Ctext cIndex = cinVec[1];


// cout << "encryptedInput --- Rescaling Factor: "<< encryptedInput->GetScalingFactor() << " -- Level: " << encryptedInput->GetLevel() << endl; 
// cout << "cIndex --- Rescaling Factor: "<< cIndex->GetScalingFactor() << " -- Level: " << cIndex->GetLevel() << endl; 

vector<Ctext> products;
vector<double> zeros(dataSize, 0);
zeros[0] = 1.0;
Ptext cleaning_mask = context->MakeCKKSPackedPlaintext(zeros, 1, cIndex->GetLevel(), nullptr, vecSize); 

for(int i=0; i<dataSize; i++){
    Ctext tempIn = context->EvalMult(cIndex, cleaning_mask);
    Ctext repeated = repeatEncryptedValue(tempIn, dataSize);
    // cout << "repeated --- Rescaling Factor: "<< repeated->GetScalingFactor() << " -- Level: " << repeated->GetLevel() << endl; 

    // encodeData->SetScalingFactor(repeated->GetScalingFactor());
    Ctext info = context->EvalMult(repeated, encodeData);
    products.push_back(info);
    
    cIndex = context->EvalRotate(cIndex, 1);
}
Ctext result = context->EvalAddMany(products);
return result;

}

I have already tried many alternative solutions such as Ptext encodeData = context->MakeCKKSPackedPlaintext(datasV, 1, encryptedInput->GetLevel(), nullptr, dataSize), encodeData->SetScalingFactor(repeated->GetScalingFactor()) etc.

In the “SetScalingFactor” case, I can atlease decrypt but the results are close to 0 for every all elements (garbage)
[ (1.19387e-11,0) (3.73468e-11,0) (3.42138e-11,0) (9.11236e-11,0) (1.19387e-11,0) (3.73468e-11,0) (3.42138e-11,0) (9.11236e-11,0) ]

other relevant information. If I uncomment the prints, I get the following scaling factors and ciphertext levels.

encryptedInput — Rescaling Factor: 4.72238e+21 – Level: 2
cIndex — Rescaling Factor: 4.72238e+21 – Level: 14
repeated — Rescaling Factor: 4.72226e+21 – Level: 15

Any assistance on how to fix this issue will be greatly appreciated.

Please provide a minimum working example that can be compiled and run, which includes the cryptocontext parameters, all inputs, etc.

Also, not only the level is relevant, but the degree of the scaling noise as well. Moreover, if you manually set the scaling factor without correctly adjusting, more error is introduced.

Thank you so much for your feedback.

I changed the value of the multiplication depth to 2 and it works.

Initially I kept it at zero as I wasn’t expecting to do any Bootstrapping thus thought that was fine all along.