OpenMined / TenSEAL

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

Side effect and wrong result of a simple mul operation #354

Open Kirija opened 3 years ago

Kirija commented 3 years ago

Hi, on tenseal 0.3.4, a simple mul operation leads to the operands being overwritten

import tenseal as ts
import math

# Setup TenSEAL context
context = ts.context(
            ts.SCHEME_TYPE.CKKS,
            poly_modulus_degree=8192,
            coeff_mod_bit_sizes=[60, 40, 40, 60]
          )
context.generate_galois_keys()
context.global_scale = 2**40

x    = ts.ckks_vector(context, [4])
y    = ts.ckks_vector(context, [0.5])

print("Before mul X=",x.decrypt()," scale=",math.log(x.ciphertext()[0].scale,2))
print("Before mul Y=",y.decrypt()," scale=",math.log(y.ciphertext()[0].scale,2))

x=x.mul(y)

print("After  mul X=",x.decrypt()," scale=",math.log(x.ciphertext()[0].scale,2))
print("After  mul Y=",y.decrypt()," scale=",math.log(y.ciphertext()[0].scale,2))

Results in : Before mul X= [4.000000000647424] scale= 40.0 Before mul Y= [0.5000000001644422] scale= 40.0 After mul X= [-3.9069508659243407e-10] scale= 40.0 After mul Y= [-1.8427671583511186e-09] scale= 40.0

Dont know what's wrong but its serious !

bcebere commented 3 years ago

Hello,

Could you please test this using TenSEAL 0.3.6? If the problem persists, please also mention your OS and Python version. Thanks!

Kirija commented 3 years ago

Hi, Thanks for your reply. I'm on a M1 Mac, OS 11.6 Big Sur, Python is 3.9.6, packaged by conda-forge . Unfortunately no, I can't switch to 3.6 because cpu_features does not compile on anything else than an intel processor on MacOS, yet. Cheers