openfhe-development icon indicating copy to clipboard operation
openfhe-development copied to clipboard

Serialization/deserialization of CryptoContext fails with openfhe

Open shaih opened this issue 8 months ago • 3 comments

Trying to serialize/de-serialize the cryptocontext with Serial::SerializeToFile(filename, cc, SerType::BINARY) or Serial::DeserializeFromFile(filename, cc, SerType::BINARY)) fails with the following error message:

terminate called after throwing an instance of 'cereal::Exception'
  what():  Trying to load 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.

[cereal-bug.cpp.txt](https://github.com/user-attachments/files/20431954/cereal-bug.cpp.txt)

shaih avatar May 25 '25 17:05 shaih

@shaih Could you provide a minimal working example as I do not have any issues with serialization/deserialization in v1.3. For instance, the following example runs fine on my machine: https://github.com/openfheorg/openfhe-development/blob/main/src/pke/examples/simple-real-numbers-serial.cpp This example does both serialization and deserialization of cryptocontext for CKKS. I also suggest making sure that all serialization header files are included in the code throwing the exception:

// header files needed for serialization
#include "ciphertext-ser.h"
#include "cryptocontext-ser.h"
#include "key/key-ser.h"
#include "scheme/ckksrns/ckksrns-ser.h"

yspolyakov avatar May 25 '25 18:05 yspolyakov

I uploaded an example with the initial issue, see https://github.com/user-attachments/files/20431954/cereal-bug.cpp.txt.

Yes, adding these header files solved the issue, thanks.

Generally, having a program relying on header files should cause compilation failure, not runtime failure. I still think that managing to compile and link a program that would fail at runtime due to missing header files should be considered a bug.

shaih avatar May 31 '25 14:05 shaih

@shaih I agree it should be treated as a bug. We will try to address it as part of v1.3.1. @dsuponitskiy will look into this.

yspolyakov avatar Jun 02 '25 14:06 yspolyakov