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(ntt-bnf) Add back&Forth ntt implementation #2148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Bapt-Roux
Copy link

@Bapt-Roux Bapt-Roux commented Mar 3, 2025

PR content/description

New Pbs implementation based on NTT.
This implementation work on 2**k modulus and used modswitch before and after every cmux. It mimics the HW implementation

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][conventional-breaking]

Copy link

github-actions bot commented Mar 4, 2025

⚠️ This PR contains unsigned commits. To get your PR merged, please sign those commits (git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch (git push --force-with-lease).

If you're new to commit signing, there are different ways to set it up:

Sign commits with gpg

Follow the steps below to set up commit signing with gpg:

  1. Generate a GPG key
  2. Add the GPG key to your GitHub account
  3. Configure git to use your GPG key for commit signing
Sign commits with ssh-agent

Follow the steps below to set up commit signing with ssh-agent:

  1. Generate an SSH key and add it to ssh-agent
  2. Add the SSH key to your GitHub account
  3. Configure git to use your SSH key for commit signing
Sign commits with 1Password

You can also sign commits using 1Password, which lets you sign commits with biometrics without the signing key leaving the local 1Password process.

Learn how to use 1Password to sign your commits.

Watch the demo

@Bapt-Roux
Copy link
Author

Test of ntt-bnf failed after the rebase on last main version.
Indeed, it seems that the noise reduction used for power of two ciphertext clash with ntt-bnf implementation.
This error wasn't seen in the original branch (i.e. hw-team) since we use another modswitch implementation

@Bapt-Roux
Copy link
Author

After a review, the issue isn't link to changes in decomposition but to some part not correctly retrieved from our hw-team branch.
Indeed, with the ntt-bnf implementation, the BSK is generated on a power of two modulus and thus need to be modswitch and correctly aligned before going in the Ntt domain.
Thus, some modifications were made in lwe_bootstrap_key_conversion.rs to correctly handle the BSK conversion.

@Bapt-Roux Bapt-Roux force-pushed the br/ntt-bnf branch 2 times, most recently from 62276c7 to aa607fa Compare March 20, 2025 18:03
This implementation work on 2**k modulus and used modswitch before and
after every cmux. It mimics the HW implementation

Also modified the bootstrapping key conversion to correctly work with
ciphertext_modulus that is a power of two and with width != of native
one
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.

Haven't had time to review the mod switching part, but it seems to have lots of moving parts in different places, there are changes I disagree with on entities, some nits for now, as said haven't had time to review the interesting content of the PR yet

/// Handle modswitch and bit-align
// This part of the code is duplicated within hpu/entities. Indeed, this ntt fix have lot of chance
// to never reach main. And we don't want to have Hpu to depends on it
impl Ntt64View<'_> {
Copy link
Member

Choose a reason for hiding this comment

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

can be part of the impl block below

@@ -321,7 +321,7 @@ where
{
data: C,
polynomial_size: PolynomialSize,
ciphertext_modulus: CiphertextModulus<C::Element>,
pub(crate) ciphertext_modulus: CiphertextModulus<C::Element>,
Copy link
Member

Choose a reason for hiding this comment

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

no, there should be an accessor for this field, it stays private, otherwise anybody can mutate it and make inconsistent entities

impl Ntt64View<'_> {
/// This function switches modulus for a slice of coefficients
/// From: user domain (i.e. pow2 modulus)
/// To: ntt domain ( i.e. prime modulus)
Copy link
Member

Choose a reason for hiding this comment

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

nit: ( i.e. -> (i.e. there is an extraneous space

Comment on lines +87 to +88
/// From: ntt domain ( i.e. prime modulus)
/// To: user domain (i.e. pow2 modulus)
Copy link
Member

Choose a reason for hiding this comment

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

nit: ( i.e. -> (i.e. there is an extraneous space
also can align as above

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.

2 participants