Serialization/deserialization
Last updated
Was this helpful?
Last updated
Was this helpful?
This document explains the serialization
and deserialization
features that are useful to send data to a server to perform the computations.
TFHE-rs uses the framework and implements Serde's Serialize
and Deserialize
traits.
To serialize the data, you need to choose a . In the following example, we use for its binary format.
Here is a full example:
When dealing with sensitive types, it's important to implement safe serialization and safe deserialization functions to prevent runtime errors and enhance security. The safe serialization and deserialization use bincode
internally.
The safe deserialization must take the output of a safe-serialization as input. During the process, the following validation occurs:
Type match: deserializing type A
from a serialized type B
raises an error indicating "On deserialization, expected type A, got type B".
Version compatibility: deserializing type A
of a newer version (for example, version 0.2) from a serialized type A
of an older version (for example, version 0.1) raises an error indicating "On deserialization, expected serialization version 0.2, got version 0.1".
Parameter compatibility: deserializing an object of type A
with one set of crypto parameters from an object of type A
with another set of crypto parameters raises an error indicating "Deserialized object of type A not conformant with given parameter set"
If both parameter sets have the same LWE dimension for ciphertexts, a ciphertext from param 1 may not fail this deserialization check with param 2.
This check can't distinguish ciphertexts/server keys from independent client keys with the same parameters.
This check is meant to prevent runtime errors in server homomorphic operations by checking that server keys and ciphertexts are compatible with the same parameter set.
You can use the standalone is_conformant
method to check parameter compatibility. Besides, the safe_deserialize_conformant
function includes the parameter compatibility check, and the safe_deserialize
function does not include the compatibility check.
Size limit: both serialization and deserialization processes expect a size limit (measured in bytes) for the serialized data:
On serialization, an error is raised if the serialized output exceeds the specific limit.
On deserialization, an error is raised if the serialized input exceeds the specific limit.
This feature aims to gracefully return an error in case of an attacker trying to cause an out-of-memory error on deserialization.
Here is an example:
You can combine this serialization/deserialization feature with the feature by using the safe_serialize_versioned
and safe_deserialize_conformant_versioned
functions.