OpenMined / TenSEAL

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

Large Size Ciphertext #429

Closed wzjin2017 closed 1 year ago

wzjin2017 commented 1 year ago

Description

The ciphertext is fairly large. I encrypted a tensor of 5k numbers. The ciphertext ends up being 1700MB big. The plaintext (torch tensor) I saved, however, is around 50 KB. Is this the expected behavior or am I messing up something here?

How to Reproduce

My test code goes like this.

import tenseal as ts
import torch
import pickle
import os

def context():
    context = ts.context(ts.SCHEME_TYPE.CKKS, 8192, coeff_mod_bit_sizes=[60, 40, 40, 60])
    context.global_scale = pow(2, 52)
    context.generate_galois_keys()
    return context

context = context()

plain1 = ts.plain_tensor(torch.rand(5609))
encrypted_tensor1 = ts.ckks_tensor(context, plain1)

with open('ciphertext_seal.pickle', 'wb') as handle:
    pickle.dump(encrypted_tensor1.serialize(), handle, protocol=pickle.HIGHEST_PROTOCOL)
cipher_size = os.path.getsize('ciphertext_seal.pickle')
print(cipher_size)
efriel94 commented 1 year ago

I think that is expected. It's not a bug. This is one of downsides of using HE - memory requirements blows up quite fast (depending on alot of factors such as scheme, security parameters etc)

If you require a lighter footprint you could try experimenting with using ckks_vector instead of ckks_tensor, its a 1D array rather than N-dimensional.