Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for public data serialization / deserialization #1119

Open
FlorentCLMichel opened this issue Nov 25, 2024 · 1 comment
Open

Support for public data serialization / deserialization #1119

FlorentCLMichel opened this issue Nov 25, 2024 · 1 comment

Comments

@FlorentCLMichel
Copy link
Contributor

FlorentCLMichel commented Nov 25, 2024

(This issue originated from discussions with @j2kun on the Python backend document; see issue #1105 . )

As far as I am aware, FHE applications are generally split between at least two parties - in the simplest case, a ‘client’ with access to secret data and a ‘server’ without access to secret data. One important source of complexity for newcomers can be to determine what information can or can't be sent to the ‘server’ without compromising the security of encrypted data. I think it would be great for HEIR to have a way to (semi-) automatically (de)serialize the data that can / needs to be exchanged between the ‘client’ and ‘server’. (See for instance this OpenFHE example or serialization in TFHE-rs.)

I'm not sure yet exactly which form it would take. Taking the first example of the Python frontend document, maybe one way to split it between client-side and server-side operations could be:

#example_client.py

# some library used for client/server communication
from some_user_lib import send_data_to_server, receive_data_from_server

@heir.compile(backend="openfhe")
def foo(a: heir.secret[heir.i32], b: heir.secret[heir.i32]):
  if a < b:
    return a
  else:
    return b - 1

key = foo.gen_keys()
enc_a = foo.encrypt_a(key.client_key, 7)
enc_b = foo.encrypt_b(key.client_key, 6)

# serialize the information the server will need (e.g. bootstrapping key, key-switching key, and LUTs for CGGI, plus the encrypted data)
serialized_server_info = key.serialize_public()
serialized_data = foo.serialize_input_ciphers([enc_a, enc_b], batch_size=1)

# send data to the server
send_data_to_server([serialized_server_info, serialized_data])

# receive data from the server and deserialize it
serialized_enc_result = receive_data_from_server()
enc_result = foo.deserialize_output_ciphers(serialized_enc_result, batch_size=1)

result = foo.decrypt_result(key.client_key, enc_result)
#example_server.py

from some_user_lib import send_data_to_client, receive_data_from_client

# Alternatively, the function body could be replaced by `pass`  if all the information required 
# to evaluate it are part of the data sent by the client
@heir.compile(backend="openfhe")
def foo(a: heir.secret[heir.i32], b: heir.secret[heir.i32]) -> heir.secret[heir.i32] :
  if a < b:
    return a
  else:
    return b - 1

serialized_server_info, serialized_data = receive_data_from_client()
server_info = foo.deserialize_server_info(serialized_server_info)
enc_a, enc_b = foo.deserialize_data(serialized_data, batch_size=1)
enc_result = foo.foo(server_info.server_keys, enc_a, enc_b)
serialized_enc_result = foo.serialize_output_ciphers([enc_a, enc_b], batch_size=1)
send_data_to_client()
Copy link

This issue has 1 outstanding TODOs:

This comment was autogenerated by todo-backlinks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant