Attempting to use FIXEDMANUAL or FIXEDAUTO Scaling Technique

Hi, I’m new to using OpenFHE. I’m having trouble using the FIXEDMANUAL or FIXEDAUTO scaling techniques with CKKS. Maybe I’m doing something wrong with the setup or something but whenever I set the scaling technique to FIXEDMANUAL or FIXEDAUTO, creating a plaintext hangs indefinitely while it does not when the scaling technique to FLEXIBLEAUTOEXT.

Below is a code sample (running on OpenFHE v1.2.3) that shows what I mean:

#include <vector>
#include <iostream>
#include <cmath>

#include "openfhe.h"

using namespace lbcrypto;

int main() {
    int ring_dim = 1 << 14;
    int num_slots = ring_dim / 2;

    // Set up encryption parameters for CKKS
    CCParams<CryptoContextCKKSRNS> parameters;
    parameters.SetMultiplicativeDepth(1);
    parameters.SetScalingModSize(40);
    parameters.SetRingDim(ring_dim);
    parameters.SetBatchSize(num_slots);
    parameters.SetSecurityLevel(HEStd_128_classic);

    // The following lines do not work because it hangs when creating a plaintext
    parameters.SetScalingTechnique(FIXEDMANUAL); 
    // parameters.SetScalingTechnique(FIXEDAUTO);

    // The following commented out line does work, however
    // parameters.SetScalingTechnique(FLEXIBLEAUTOEXT);

    std::cout << "Generating crypto context..." << std::endl;
    // Create CryptoContext
    CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
    cc->Enable(PKE);
    cc->Enable(KEYSWITCH);
    cc->Enable(LEVELEDSHE);

    std::cout << "Generating keys..." << std::endl;
    // Generate public and secret keys
    auto keys = cc->KeyGen();
    cc->EvalMultKeyGen(keys.secretKey);

    // Scale
    double scale = pow(2.0, 40);

    // Create some plaintexts
    std::vector<double> vec1 = {1.0, 2.0, 3.0, 4.0};

    std::cout << "Creating plaintext..." << std::endl;
    // Gets stuck here when using FIXEDMANUAL scaling technique
    Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(vec1, scale);

    std::cout << "Encrypting plaintext..." << std::endl;
    // Encrypt the plaintexts
    auto ctxt1 = cc->Encrypt(keys.publicKey, ptxt1);

    std::cout << "Adding ciphertext with plaintext..." << std::endl;
    // Perform ptxt-ctxt addition
    auto ctxt_ptxt_add = cc->EvalAdd(ctxt1, ptxt1);

    std::cout << "Decrypting and printing plaintext..." << std::endl;
    // Decrypt and print results
    Plaintext result;
    cc->Decrypt(keys.secretKey, ctxt_ptxt_add, &result);
    std::cout << "ptxt-ctxt addition result: " << result->GetRealPackedValue() << std::endl;

    return 0;
}

I also noticed that the ManualRescaleDemo does not set the ScalingTechnique to FIXEDMANUAL. Am I missing something for how to use the different scaling techniques?

Why are you passing the scale here?

You should set the scale using the crypto-context parameters as follows:
parameters.SetScalingModSize(40);

Please follow the example “simple-real-numbers.cpp” to use and configure CKKS properly.

1 Like