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

CKKS: Generate Scheme Param #1400

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

Conversation

ZenithalHourlyRate
Copy link
Collaborator

In a similar style with #1379.

CKKS noise analysis is not as suggestive as BGV, which only gives the precision info, while the later can be used for determining overflow or not (correctness). So we may only support user providing the the default scale and the first mod size and we generate the parameter for them.

There are many scale-related techniques like #1169 (comment) and #1169 (comment). This PR only serves as a baseline for making the pipeline work, as it just generates the primes in an increasing order without caring the scaling factor. These management passes should be implemented later.

I put the parameter generation process in secret-to-ckks. As we are not using noise model (so not validate-noise), we do not have other pass to put it.

The CKKS SchemeParamAttr is for later integration like the Lattigo CKKS backend #1382.

lib/Dialect/CKKS/IR/CKKSAttributes.td Outdated Show resolved Hide resolved
Copy link
Collaborator

@j2kun j2kun Feb 14, 2025

Choose a reason for hiding this comment

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

A lot of stuff in this file looks copied from BGV/Params.cpp. Maybe extract the prime generation to a new library in lib/Utils/NumberTheory.{h,cpp}? Or maybe a new Utils lib in lib/Parameters that includes the prime generation and the other common functions like computeDnum and computeRingDim and the HEStd_128_classic

Then it seems a large part of getConcreteSchemeParams is also copied. Because that function is so large, it's hard for me to see what differs between the BGV/CKKS versions of it. It seems like the only difference is logDefaultScale replaced plaintextModulus, and logDefaultScale is passed through while plaintextModulus is used as the first prime. It might be worth abstracting the common parts so they can be reused to make it easier to keep the two implementations in sync and also to show the differences between them more clearly. It's not clear to me what's the right way to do this, though. Is it possible to have a baseline RLWE parameter generation that is agnostic of BGV/CKKS or provides configurable options, and then modify/pass particular options to do the CKKS/BGV specific parts? Or maybe the subroutines used in both can be extracted without too much loss of clarity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now I separate them into

  • RLWESecurityParams, including the HEStd_128_classic (updated to the recent "Security guidelines for implementing homomorphic encryption") and computeRingDim
  • RLWEParams, for common fields and the prime generation
  • {BGV/CKKS}/Params, for special field for BGV/CKKS

For now I think it is OK as we are only making the pipeline work. In the future for CKKS there might be a different prime generation process living in CKKS/Params.cpp because Openfhe has a level specific scaling factor and to maintain that Openfhe uses a carefully designed algorithm in "Approximate Homomorphic Encryption with Reduced Approximation Error"

Copy link
Collaborator

@j2kun j2kun left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@j2kun j2kun added the pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull_ready Indicates whether a PR is ready to pull. The copybara worker will import for internal testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants