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

Ns/rename pp crs #1760

Merged
merged 2 commits into from
Nov 8, 2024
Merged

Ns/rename pp crs #1760

merged 2 commits into from
Nov 8, 2024

Conversation

nsarlin-zama
Copy link
Contributor

closes: https://github.com/zama-ai/tfhe-rs-internal/issues/800#issue-2603108396

PR content/description

Use the CompactPkeCrs instead of the CompactPkePublicParams. It simplifies a bit the workflow for users, they generate a crs and are directly able to use it and serialize it without having to extract the params.

Having a release 0.11 in Cargo.toml was necessary to be able to update the data repo.

Check-list:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Relevant issues are marked as resolved/closed, related issues are linked in the description
  • Check for breaking changes (including serialization changes) and add them to commit message following the conventional commit specification

@nsarlin-zama nsarlin-zama added the data_PR This is a PR that needs to fetch new data for backward compat tests label Nov 7, 2024
@cla-bot cla-bot bot added the cla-signed label Nov 7, 2024
@nsarlin-zama nsarlin-zama force-pushed the ns/rename_pp_crs branch 2 times, most recently from 5926757 to 808cc7c Compare November 7, 2024 15:07
Comment on lines +141 to +143
impl Named for CompactPkeCrs {
const NAME: &'static str = "zk::CompactPkeCrs";
}
Copy link
Member

Choose a reason for hiding this comment

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

isn't this an issue for versioning if the struct is transparent ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the name is included outside of the versioned data so it has no influence on the versioning. If one day we want to modify the struct to not be transparent we will have to do a CompactPkeCrsVersions enum that starts at v1:

enum CompactPkeCrsVersions {
  V0(CompactPkePublicParams),
  V1(CompactPkeCrs)
}

Copy link
Member

Choose a reason for hiding this comment

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

ok my bad I meant if we want to safe deserialize a CompactPkeCrs from the params, it won't work because of the named impl right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the idea is to deserialize it as a CompactPkePublicParams and then convert it to a CompactPkeCrs using the From impl

Copy link
Member

Choose a reason for hiding this comment

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

could we somehow force people to always deserialize the CRS via some from/into tricks ?

Copy link
Contributor Author

@nsarlin-zama nsarlin-zama Nov 8, 2024

Choose a reason for hiding this comment

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

The problem is that since they have been serialized with NAME = "CompactPkePublicParams" it means that the output of safe_deserialize needs to be something with NAME= "CompactPkePublicParams".

We could have CompactPkeCrs::NAME = "CompactPkePublicParams", but since it's just a matter of calling .into for the user, I don't think it's worth having this discrepancy.

Copy link
Member

Choose a reason for hiding this comment

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

no yeah I agree, was just thinking out loud

Copy link
Member

Choose a reason for hiding this comment

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

or maybe a different way to write safe serialize/deserialize with a serialized type S that has Into where T is the actual type we want to use later, but that would maybe defeat the purpose of the safe serialize

// "wasm bindgen is fragile and prefers the actual type vs. Self"
#[allow(clippy::use_self)]
#[wasm_bindgen]
impl CompactPkePublicParams {
Copy link
Member

Choose a reason for hiding this comment

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

do we want to keep this on the js side ?

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 think we at least need to keep the deserialize code for backward compatibility ?

Copy link
Member

Choose a reason for hiding this comment

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

ah is it only deserialization ?

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 put on th Crs and a "deserialize_from_parameters" kind of thing ?

Copy link
Member

Choose a reason for hiding this comment

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

and on the struct itself because I guess we need it a "deserialize_into_crs"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you want to keep both ? Maybe it's better to keep it simple and have only the Crs::deserialize_from_parameters ?

Copy link
Member

Choose a reason for hiding this comment

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

sure, I'm just trying to think of users manipulating the old struct and not finding any function on it

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.

If we have functions that can create/generate the old struct we should likely mark them deprecated/remove them, wdyt ?

@nsarlin-zama
Copy link
Contributor Author

If we have functions that can create/generate the old struct we should likely mark them deprecated/remove them, wdyt ?

crs.public_params() is needed inside TFHE-rs, but maybe I can remove the pub attribute ?
However I don't know if blockchain won't need it somehow, I know that they have their own structs with Curve::G1/G2 but I don't know if they need to access points in the crs

@IceTDrinker
Copy link
Member

IceTDrinker commented Nov 8, 2024

If we have functions that can create/generate the old struct we should likely mark them deprecated/remove them, wdyt ?

crs.public_params() is needed inside TFHE-rs, but maybe I can remove the pub attribute ? However I don't know if blockchain won't need it somehow, I know that they have their own structs with Curve::G1/G2 but I don't know if they need to access points in the crs

or maybe make it borrow from the CRS ?

edit: this achieves nothing except avoiding copies

@IceTDrinker
Copy link
Member

maybe I'm wrong here, I don't have a precise enough view of the CRS and params

BREAKING_CHANGE:
- All the zk API (build_with_proof, verify, verify_and_expand,...) now take a
`CompactPkeCrs` instead of a `CompactPkePublicParams`. Serialized
`CompactPkePublicParams` from previous versions can be converted into a
`CompactPkeCrs` using `params.into()`
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.

Looks good to me !

@nsarlin-zama nsarlin-zama merged commit 6ef22e8 into main Nov 8, 2024
79 of 88 checks passed
@nsarlin-zama nsarlin-zama deleted the ns/rename_pp_crs branch November 8, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cla-signed data_PR This is a PR that needs to fetch new data for backward compat tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants