Huelse / SEAL-Python

Microsoft SEAL 4.X For Python
MIT License
317 stars 66 forks source link

Getting logs of errors from SEAL #124

Open arituerto opened 2 days ago

arituerto commented 2 days ago

Type I'm having issues when encrypting vectors that I cannot reproduce in my development machine.

Describe I have a small piece of software that used Python-SEAL. Everything works fine but when I move to a different machine software stops working, I cannot create keys nor encrypt a vector when I provide keys created in my machine. Software simply stops without any error and I cannot reproduce in my dev machine. Is there any way of enabling logs for SEAL?

Thanks in advance!

Huelse commented 2 days ago

Can you provide a code case and the system environment? This library should throw std errors like in C++.

arituerto commented 2 hours ago

I have a class that controls all SEAL related stuff. There, all the seal objects are created, initialized so they can be used when needed:

params = seal.EncryptionParameters(seal_scheme_type)
params.set_poly_modulus_degree(poly_modulus_degree)
if coeff_modulus is not None:
    params.set_coeff_modulus(coeff_modulus)
else:
    params.set_coeff_modulus(
        seal.CoeffModulus.BFVDefault(poly_modulus_degree))
if plain_modulus is not None:
    params.set_plain_modulus(plain_modulus)
else:
    params.set_plain_modulus(
        seal.PlainModulus.Batching(poly_modulus_degree, plain_modulus_bit_size))
self.__context = context = seal.SEALContext(params)
logging.info("Context created and set")
self.__batch_encoder = seal.BatchEncoder(self.__context)
logging.info("BatchEncoder created")
self.__evaluator = seal.Evaluator(self.__context)
logging.info("Evaluator created")

Encryptor is initialized with a public key read from file:

self.__encryptor = seal.Encryptor(self.__context, public_key)

Process method is the one doing the encryption, it receives a vector and tries to encrypt it

def process(self, vector_id:  np.Array):
        pod_vector = [np.int64(0.) for i in range(
            int(self.__batch_encoder.slot_count() / 2))]
        for i, v in enumerate(vector_id):
            pod_vector[i] = np.int64(self.__precision * v)
        logging.debug("Pod vector computed")
        plain_vector = self.__batch_encoder.encode(pod_vector)
        logging.debug("Vector encoded")
        encrypted_vector = self.__encryptor.encrypt(plain_vector)
        logging.debug("Vector encrypted")

Last log is never reached, program stops with no message, no raised exception, nothing.

I have tested the code both in linux (ubuntu 22.04 and windows 11) and it works in both (Processor: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz 2.42 GHz). The computer where things are failing is an i7 with the same windows.

I checked SEAL code and didn't find any std error code, just throwing c++ exceptions.