I have tried to use the SEAL variant for python (tenSEAL, here is their repo,https://github.com/OpenMined/TenSEAL/tree/main) to square a simple array. I could not get quite the result I wanted.
Here is my code:
import tenseal as ts
import numpy as np
# parameters
poly_mod_degree = 4096 # bigger means more security
coeff_mod_bit_sizes = [40, 20, 40]
# create TenSEALContext
context = ts.context(ts.SCHEME_TYPE.CKKS, poly_mod_degree, -1, coeff_mod_bit_sizes)
context.global_scale = pow(2, 21)
context
# a 2-D array example
arr = np.array([5,6,7,8,2,10]).reshape([2,3])
array([[ 5, 6, 7],
[ 8, 2, 10]])
encrypted_tensor = ts.ckks_tensor(context, arr)
result = encrypted_tensor**2
def decrypt(enc):
return enc.decrypt().tolist()
decrypt(result)
[[50.79439493138295, 73.15217478776158, 99.56040377582177],
[130.03345115244963, 8.126560454115648, 203.17401152512096]]
However, I expected my output to be like:
[[25, 36, 49],
[64, 4, 100]]
it looks like it squares the result and then multiplies it by 2? Can anyone explain in more detail why it happens?
Also, is it possible to set up lower parameters in the context, e.g. poly_mod_degree = 16 and global_scale = pow(2, 4)? I have tried it but encountered a ValueError: encryption parameters are not set correctly.