OpenMined / TenSEAL

A library for doing homomorphic encryption operations on tensors
Apache License 2.0
837 stars 158 forks source link

Changing of rescale policy not permitted #323

Open Kirija opened 3 years ago

Kirija commented 3 years ago

Description

Changing online the rescaling leads to completely wrong results

How to Reproduce

`import tenseal as ts import numpy as np

bits_scale = 26 coeff_mod_bit_sizes = [31] + [bits_scale] 24 + [31] context = ts.context( ts.SCHEME_TYPE.CKKS, poly_modulus_degree=81924, # 8192 coeff_mod_bit_sizes=coeff_mod_bit_sizes, )

context.auto_rescale = False context.auto_mod_switch = True context.generate_galois_keys() context.global_scale = pow(2, bits_scale)

x = np.random.random(8).astype(np.float32) x_cryp = ts.ckks_tensor(context, x) x_cryp = x_cryp 1 context.auto_rescale = True x_cryp = x_cryp 1 y_cryp = x_cryp.decrypt() y = np.asarray(y_cryp.tolist()) if((x==y).all()) : print("Good") else : print("Not good") print("x=",x) print("y=",y) You will see that y and x are completely different. If you remove the intermediatecontext.auto_rescale = True` it's ok.

Expected Behavior

I expect x and y to be approx-equals