Save encrypted values in Python

Hello. I have been playing around with the Concrete python libraries (Numpy and ML) and despite what is said in this question on this same forum I tested that it is possible to manually call the encrypt, run and decrypt steps separately (see the basic example from the Concrete-numpy documentation).

From the example:

# this will encrypt arguments that require encryption and pack all arguments
# as well as public materials (public keys)
public_args = circuit.encrypt(3, 4)
# this will run the encrypted computation using public materials and inputs provided
encrypted_result =
# the execution returns the encrypted result which can later be decrypted
decrypted_result = circuit.decrypt(encrypted_result)

Using the Concrete library in Rust I was able to save and later retrieve encrypted values in files or different data structures (via bincode serialization), but this is not possible using the Python libraries. Exploring the code I saw that it is not possible to pickle those values since the mlir package is compiled. This is the error I’m facing:

TypeError: cannot pickle 'mlir._mlir_libs._concretelang._compiler.PublicArguments' object

What I want to do is run inference on encrypted inputs, but getting the encrypted inputs from other source.

Is there any workaround to get those values? Should I wait until the next library release?

Please let me know if I’m doing something wrong. Thank you.

Hello @alberto

I am going to try to answer for CN team since they are in vacation.

First: yes, as explained in the question you link, it is not possible to call the encrypt / run / decrypt in Concrete-ML. It will be possible to have the separated APIs in Concrete-ML in the next release.

Now, you’re right, Concrete-Numpy is always a step in advance, since Concrete-ML is built on top of Concrete-Numpy. So yes, as you say, in CN, you have the encrypt, run and decrypt APIs.

In the next releases of Concrete-Numpy and Concrete-ML (this summer), you will have complete examples of a client & server protocol, possibly on different machines, which will allow you to do exactly what you want. Certainly you can build workarounds in the meantime, but it may be simpler & safer to just wait for the next release for this part, if it does not block you.


1 Like

Hello @benoit,

Thanks for your quick response. Probably there are workarounds, but I guess they would require memory management or similar complex methods. I agree that it is simpler and safer to wait, hopefully this summer the next release of both libraries is released .

Thank you all for your hard work!

Hello @alberto

Adding to what @benoit already said, you can currently serialize both an encryption, and the result of an execution, to be able to send those between different parties. We implement the serialize/unserialize methods for that. However, calling unserialize requires passing the client parameters object, which can be found under the FHECircuit object as _client_parameters.

This will be much simpler in the next release, but you should at least work around it for now.

1 Like

Hello @ayoub,

Thank you very much for your reponse. Sorry, but where can I find the serialize/unserialize functions in python implementation? I am not able to find them.

These are methods implemented on the objects that are returned by encrypt or run. For example, you would do:

public_args = circuit.encrypt(3, 4)
serialized = public_args.serialize()

Thank you @ayoub, but that returns the following error:

Traceback (most recent call last):
  File "", line 48, in <module>
    serialized = public_args.serialize()
AttributeError: 'PublicArguments' object has no attribute 'serialize'

I’m using the latest version of concrete-numpy and the example from the documentation. I’m doing something wrong?

Sorry @alberto but I was wrong about the version I was assuming to be the latest released. This workaround isn’t available currently unfortunately. So you shouldn’t worry about this workaround, because next release is going to have a clear API for your usecase.

Don’t worry @ayoub, thanks anyway for your help. I hope the next version will be released soon!