CKKS deserialisation

Hi all,

I’m trying to deserialize a CKKS ciphertext to a JSON string and I receive the following error:

Blockquote
Trying to save an unregistered polymorphic type (lbcrypto::CryptoParametersCKKSRNS).
Make sure your type is registered with CEREAL_REGISTER_TYPE and that the archive you are using was included (and registered with CEREAL_REGISTER_ARCHIVE) prior to calling CEREAL_REGISTER_TYPE.
If your type is already registered and you still see this error, you may need to use CEREAL_REGISTER_DYNAMIC_INIT.

I read this post and this post but I wasn’t able to find a solution.

Thank you!

Please include your code

TIC(t);
    std::vector<Ciphertext<DCRTPoly>> ciphertexts;
    for(int idx = 0; idx < plaintexts.size(); idx++) {
        Ciphertext<DCRTPoly> ciphertext= cc->Encrypt(publicKey, plaintexts[idx]);
        std::string jsonCiphertext = Serial::SerializeToString(ciphertext);
        std::cout << jsonCiphertext << std::endl;
        ciphertexts.push_back(ciphertext);
    }
    processingTime = TOC(t);

Hmm, that’s interesting why it’s not working… Please follow How to create a Minimal, Reproducible Example and I’ll dig more into it.

Thank you!

Thank you for your quick reply. Here is the complete code (it’s made from the original example)

#include "openfhe.h"

using namespace lbcrypto;

int main() {

    uint32_t multDepth = 1;
    uint32_t scaleModSize = 50;
    uint32_t batchSize = 8;
    CCParams<CryptoContextCKKSRNS> parameters;
    parameters.SetMultiplicativeDepth(multDepth);
    parameters.SetScalingModSize(scaleModSize);
    parameters.SetBatchSize(batchSize);

    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> x = {0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0};
    Plaintext ptxt = cc->MakeCKKSPackedPlaintext(x);
    auto c = cc->Encrypt(keys.publicKey, ptxt);
    std::string jsonCiphertext = Serial::SerializeToString(c);
    std::cout << jsonCiphertext << std::endl;
    return 0;
}


I serialize like this:

Serial::SerializeToFile(filename, v, SerType::BINARY);

where filename is a std::string and v is a Ciphertext<DCRTPoly>, then de-serialization as follows:

Ciphertext<DCRTPoly> result;

if (!Serial::DeserializeFromFile(filename, result, SerType::BINARY))
    cerr << "Could not find \"" << filename << "\"" << endl;

and it works like a charm. I am using CKKS, too.

Thank you!

I modified the code and the error still persists. Here is the update:

#include "openfhe.h"

using namespace lbcrypto;

int main() {

    uint32_t multDepth = 1;
    uint32_t scaleModSize = 50;
    uint32_t batchSize = 8;
    CCParams<CryptoContextCKKSRNS> parameters;
    parameters.SetMultiplicativeDepth(multDepth);
    parameters.SetScalingModSize(scaleModSize);
    parameters.SetBatchSize(batchSize);

    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> x = {0.25, 0.5, 0.75, 1.0, 2.0, 3.0, 4.0, 5.0};
    Plaintext ptxt = cc->MakeCKKSPackedPlaintext(x);
    Ciphertext<DCRTPoly> c = cc->Encrypt(keys.publicKey, ptxt);
    std::string filename = "output.txt";
    Serial::SerializeToFile(filename, c, SerType::BINARY);
    return 0;
}

@miiip Please look at OpenFHE serialization examples, e.g., https://github.com/openfheorg/openfhe-development/blob/main/src/pke/examples/simple-integers-serial.cpp. When serialization is needed, several header files with suffix “-ser.h” need to be included. Otherwise, the errors like the ones you listed appear. The last header file is scheme-specific (you would need to replace bfvrns with ckksrns).

1 Like