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

feat(tfhe): add safe deserialiation #572

Merged
merged 7 commits into from
Oct 5, 2023
Merged

Conversation

mayeul-zama
Copy link
Contributor

Some tests will need to be added

@github-actions
Copy link

@slab-ci cpu_fast_test

@IceTDrinker
Copy link
Member

please don't request reviews on draft PRs :) reduces the inbox github noise

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from 63cabe6 to 03bf39d Compare September 22, 2023 10:07
@github-actions
Copy link

@slab-ci cpu_fast_test

tfhe/Cargo.toml Outdated Show resolved Hide resolved
@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from 03bf39d to aa5a479 Compare September 27, 2023 14:22
@github-actions
Copy link

@slab-ci cpu_fast_test

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from aa5a479 to 7896560 Compare September 27, 2023 14:52
@github-actions
Copy link

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks !

tfhe/src/core_crypto/commons/parameters.rs Outdated Show resolved Hide resolved
tfhe/src/conformance.rs Show resolved Hide resolved
tfhe/src/safe_serialization.rs Outdated Show resolved Hide resolved
tfhe/src/safe_serialization.rs Outdated Show resolved Hide resolved
tfhe/src/safe_serialization.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/parameters/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/parameters/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/parameters/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/parameters/mod.rs Outdated Show resolved Hide resolved
tfhe/src/integer/ciphertext/mod.rs Outdated Show resolved Hide resolved
@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from 7896560 to ce3ed52 Compare September 28, 2023 13:26
@github-actions
Copy link

@slab-ci cpu_fast_test

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from ce3ed52 to 665f7ce Compare September 28, 2023 13:26
@github-actions
Copy link

@slab-ci cpu_fast_test

1 similar comment
@github-actions
Copy link

@slab-ci cpu_fast_test

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from 1a34ad4 to e121038 Compare September 28, 2023 15:29
@github-actions
Copy link

@slab-ci cpu_fast_test

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from e121038 to 571d1ee Compare September 29, 2023 14:27
@github-actions
Copy link

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First batch of comment on the updated PR, haven't checked the tests for now

tfhe/src/shortint/parameters/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/parameters/mod.rs Outdated Show resolved Hide resolved
tfhe/src/conformance.rs Outdated Show resolved Hide resolved
tfhe/src/core_crypto/algorithms/glwe_sample_extraction.rs Outdated Show resolved Hide resolved
tfhe/src/core_crypto/algorithms/glwe_sample_extraction.rs Outdated Show resolved Hide resolved
tfhe/src/core_crypto/fft_impl/fft64/crypto/wop_pbs/mod.rs Outdated Show resolved Hide resolved
tfhe/src/lib.rs Outdated

pub mod conformance;

pub trait Named {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer not having anything other than modules and imports in the root lib.rs, not sure if there are some conventions around that in rust

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can create a module named but I don't see the benefit as it would only be 3 lines long

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be part of the safe_deserialization ? as it's used by it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but it forces the impl Named to be behing a #[cfg(safe-deserialization)] which is why I put it out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm how bad does it complicate things ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not too bad

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would https://doc.rust-lang.org/std/any/fn.type_name.html be an alternative to having a custom Named trait ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the page you linked

This is intended for diagnostic use. The exact contents and format of the string returned are not specified,

it was the first solution but did not seem robust

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and also just moving the struct from one module to another would change the string thus breaking serialization

tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
tfhe/src/safe_serialization.rs Outdated Show resolved Hide resolved
tfhe/src/safe_serialization.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
use super::*;
use crate::conformance::ParameterSetConformant;
use crate::core_crypto::prelude::UnsignedInteger;
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's plan adding more tests later down the line using the create_parameterized_test pattern from elsewhere in the crate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see the benefit to hav this test with many parameter sets (except if they increase coverage, for exemple by using a non native modulus)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just a matter of completeness :)

plus the macro instantiation of tests is really not that bad

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from 410e8f0 to f9d5a4b Compare October 3, 2023 08:37
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there, we are down to the last details, thanks a lot for all the work up to this point !

tfhe/src/core_crypto/algorithms/glwe_sample_extraction.rs Outdated Show resolved Hide resolved
tfhe/src/core_crypto/algorithms/misc.rs Outdated Show resolved Hide resolved
use super::*;
use crate::conformance::ParameterSetConformant;
use crate::core_crypto::prelude::UnsignedInteger;
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just a matter of completeness :)

plus the macro instantiation of tests is really not that bad

tfhe/src/safe_deserialization.rs Outdated Show resolved Hide resolved
tfhe/src/safe_deserialization.rs Outdated Show resolved Hide resolved
tfhe/src/safe_deserialization.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Show resolved Hide resolved
@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from f9d5a4b to ec9df18 Compare October 3, 2023 17:10
@github-actions
Copy link

github-actions bot commented Oct 3, 2023

@slab-ci cpu_fast_test

@IceTDrinker
Copy link
Member

btw have you made progress on having the HL part in the C API ?

Comment on lines +39 to +45
options
.with_limit(VERSION_LENGTH_LIMIT)
.serialize_into::<_, String>(&mut writer, &SERIALIZATION_VERSION.to_owned())?;

options
.with_limit(TYPE_NAME_LENGTH_LIMIT)
.serialize_into::<_, String>(&mut writer, &T::NAME.to_owned())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these .to_owned() ? passign the &'static str should work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For deserialization, I think we have to use the String type
I'm not sure a serialized &str is guaranted to be deserializable as a String which is why I did it this way

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from ec9df18 to 4531f3a Compare October 4, 2023 11:30
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

@slab-ci cpu_fast_test

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from 4531f3a to fe48db0 Compare October 4, 2023 13:05
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

@slab-ci cpu_fast_test

@mayeul-zama mayeul-zama force-pushed the mz/safe_deserialization branch from fe48db0 to 57f954d Compare October 4, 2023 15:01
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right let's start with this, thanks a lot for the work !

@github-actions
Copy link

github-actions bot commented Oct 4, 2023

Pull Request has been approved 🎉
Launching full test suite...
@slab-ci cpu_test
@slab-ci cpu_integer_test
@slab-ci cpu_multi_bit_test
@slab-ci cpu_wasm_test
@slab-ci csprng_randomness_testing

@mayeul-zama mayeul-zama merged commit 492d348 into main Oct 5, 2023
20 checks passed
@mayeul-zama mayeul-zama deleted the mz/safe_deserialization branch October 5, 2023 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants