OpenMined/TenSEAL

(enc_vector1 + plain_vector1) not equal to enc(vector1 + vector1)

HaonanYuan opened this issue · 0 comments

Question

(enc_vector1 + plain_vector1) not equal to enc(vector1 + vector1)

Further Information

I am trying to calculate an encrypted vector mul plain matrix, and this encrypted vector is equal to an encrypted vector add a plain vector. However, I find there is a wired thing that (Enc(a) + b).mm(User_B) is not equal to Enc(a + b).mm(User_B). The test code is shown below.

Screenshots

plain_matrix = np.array([[0.0, 0.0, 0.0, 0.0],
                         [0.0, 0.0, 0.0, 0.0],
                         [0.0, 0.0, 0.0, 0.0],
                         [0.0, 10.0, 0.0, 0.0]])

plain_vector = np.array([0.1, 237874.552365, 0.000000002, 1])
plain_vector_1 = np.array([0.1, 237874.552365, 0.000000002, 1])

plain_res = np.dot(plain_matrix, plain_vector + plain_vector_1)

enc_vector = ts.ckks_vector(context, plain_vector)
enc_vector_1 = ts.ckks_vector(context, plain_vector_1)

enc_vector_2 = enc_vector + enc_vector_1
enc_vector_3 = enc_vector + plain_vector_1

enc_res_1 = enc_vector_2.mm(plain_matrix.T)
enc_res_2 = enc_vector_3.mm(plain_matrix.T)

res_1 = enc_res_1.decrypt()
res_2 = enc_res_2.decrypt()

print(plain_res)
print(res_1)
print(res_2)

result

[ 0. 0. 0. 4757491.0473]
[2.655831578605229e-10, -5.912459528628605e-10, -1.994569202300637e-09, 4757497.852951228]
[6.590880511287327e-10, 3.316680605596568e-09, -2.8285272646509907e-09, 2378748.926475601]