OpenMined / TenSEAL

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

failed to serialize the context #452

Open xuefeng-xu opened 1 year ago

xuefeng-xu commented 1 year ago

Description

Failed to serialize the context when setting the params like this, see the code below.

How to Reproduce

import tenseal as ts

ctx = ts.context(ts.SCHEME_TYPE.CKKS,
                 poly_modulus_degree=32768,
                 coeff_mod_bit_sizes=[35]+[27]*15+[35])
ctx.global_scale = pow(2, 27)
ctx.generate_galois_keys()
ctx.make_context_public()

s = ctx.serialize()

Screenshots

macOS

[libprotobuf ERROR /Users/xxf/code/TenSEAL/build/temp.macosx-11.1-arm64-cpython-38/_deps/protocolbuffers_protobuf-src/src/google/protobuf/message_lite.cc:487] tenseal.TenSEALContextProto exceeded maximum protobuf size of 2GB: 2240338979
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    s = ctx.serialize()
  File "/Users/xxf/miniconda3/envs/ph/lib/python3.8/site-packages/tenseal/enc_context.py", line 189, in serialize
    return self.data.serialize(
ValueError: failed to save proto

Ubuntu

[libprotobuf ERROR /__w/TenSEAL/TenSEAL/build/temp.linux-x86_64-cpython-38/_deps/protocolbuffers_protobuf-src/src/google/protobuf/message_lite.cc:487] tenseal.TenSEALContextProto exceeded maximum protobuf size of 2GB: 2240318631
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    s = ctx.serialize()
  File "/home/xxf/miniconda3/envs/ph/lib/python3.8/site-packages/tenseal/enc_context.py", line 189, in serialize
    return self.data.serialize(
ValueError: failed to save proto

System Information

Additional Context

To increase the multiplication depth, the param coeff_mod_bit_sizes is set like this.