Huelse / SEAL-Python

Microsoft SEAL 4.X For Python
MIT License
321 stars 65 forks source link

"relinearize_inplace" doesn‘t work #103

Closed cs1317 closed 1 year ago

cs1317 commented 1 year ago

I tried using "relinearize_inplace" to reduce the noise, which would allow me to do more multiplications, but I found that: Whether or not to use "relinearize_inplace", I can only do up to 10 multiplications, and the reduction in noise budget is the same.Here is my code:

`from seal import *

parms = EncryptionParameters(scheme_type.bfv) poly_modulus_degree = 32768 parms.set_poly_modulus_degree(poly_modulus_degree) parms.set_coeff_modulus(CoeffModulus.BFVDefault(poly_modulus_degree)) parms.set_plain_modulus(PlainModulus.Batching(poly_modulus_degree, 60)) context = SEALContext(parms)

keygen = KeyGenerator(context) secret_key = keygen.secret_key() public_key = keygen.create_public_key() relin_keys = keygen.create_relin_keys()

encryptor = Encryptor(context, public_key) decryptor = Decryptor(context, secret_key) evaluator = Evaluator(context)

data=[2,3,4,5,6,7,8,9,10,11,12] data_encrypted=[] for d in data: data_encrypted.append(encryptor.encrypt(Plaintext(str(d))))

result=encryptor.encrypt(Plaintext('1')) for i,d in enumerate(data_encrypted): result = evaluator.multiply(result, d) evaluator.relinearize_inplace(result, relin_keys) print(decryptor.invariant_noise_budget(result))

decrypted_result=decryptor.decrypt(result) print(decrypted_result.to_string())`

Huelse commented 1 year ago

yes, the bfv scheme in SEAL cannot evaluate unlimited, you can find each ciphertext has a noise budget.