Implement CKKS in HEIR
This tracking issue is for the implementation of (at least one variant of) the CKKS FHE scheme as lowering passes in HEIR. This implementation is generally happening inside lib/Dialect/LWE/Conversions/LWEToPolynomial/LWEToPolynomial.cpp
Still TODO:
- Relinearize, basis conversion, key switch: https://github.com/google/heir/issues/2650
- Rotate
- Level_reduce/rescale
- Bootstrap
Done:
- Encrypt/decrypt
- Add/Sub/AddPlain/SubPlain
- Mul (without relinearize)
Hello @j2kun , I am interested to contribute to this issue. I have good working knowledge of MLIR Compiler Infrastructure (Custom Dialect, Ops, Pass Infrastructure, Traits, Pattern Rewrites/OpRewrite pattern in dialect conversion and FileChecks).
I expect some time to get famiiar with the codebase(1 week maybe?). So do let me know if there is some timeline in mind to close this issue.
Let me know if I can start with the above. Thanks!
Hello @j2kun , I am interested to contribute to this issue. I have good working knowledge of MLIR Compiler Infrastructure (Custom Dialect, Ops, Pass Infrastructure, Traits, Pattern Rewrites/OpRewrite pattern in dialect conversion and FileChecks).
I expect some time to get famiiar with the codebase(1 week maybe?). So do let me know if there is some timeline in mind to close this issue.
Let me know if I can start with the above. Thanks!
This issue requires a rather deep expertise in cryptography. Are you familiar with the CKKS homomorphic encryption scheme? If you haven't implemented it before in a software library, this issue may be a poor starter ticket.
If you are serious about contributing, consider attending office hours, with the calendar at https://heir.dev/community
Hello @j2kun , I am interested to contribute to this issue. I have good working knowledge of MLIR Compiler Infrastructure (Custom Dialect, Ops, Pass Infrastructure, Traits, Pattern Rewrites/OpRewrite pattern in dialect conversion and FileChecks). I expect some time to get famiiar with the codebase(1 week maybe?). So do let me know if there is some timeline in mind to close this issue. Let me know if I can start with the above. Thanks!
This issue requires a rather deep expertise in cryptography. Are you familiar with the CKKS homomorphic encryption scheme? If you haven't implemented it before in a software library, this issue may be a poor starter ticket.
If you are serious about contributing, consider attending office hours, with the calendar at https://heir.dev/community
I have theoretical understanding of the CKKS algorithm, but I have not implemented it seriously from scratch. I see this issue as an opportunity to learn the same and contribute to the repository using my MLIR Skills. However that being said, I will try my best to attend the office hour meetings to get an idea on how to get started on starter issues.
Done:
- Encrypt/decrypt
Are we sure this is actually done for CKKS? See this thread on discord
EDIT: pretty sure it's not, there's even a TODO and a (rather old) issue
- #882
Yes, agreed, though the BFV encryption is similar enough to CKKS, I think there are probably some gaps there. The existing code is at https://github.com/google/heir/blob/10fb051d3fb9ea507ddf700d746a93c1ca95b671/lib/Dialect/LWE/Conversions/LWEToPolynomial/LWEToPolynomial.cpp#L162
Hello everyone. It's been quite a while since I've contributed to HEIR but I have some time on my hands and am still interested in CKKS in particular, and at least parts of this sound doable to me.
E.g. taking rotation: This would presumably involve adding a lowering from ckks.rotate to LWE and from there to some new polynomial operation for Galois automorphisms, right?
@Time0o welcome back! Yes, I believe we would need one or more new ops at the LWE level for this to target when lowering ckks.rotate, and then we have been testing these by lowering all the way to polynomial which further lowers to LLVM and can be executed using llvm_runner_test.
Since the implementation of an automorphism involves a key switching, I would encourage you to take a look at how relinearization is lowered already (Cf. https://github.com/google/heir/blob/b36935c042e8d8557a4cca3a08f23055f637f3b4/lib/Dialect/LWE/IR/LWEOps.td#L370) and you may be able to reuse some or all of those components.
CC @crockeea who may have done some partial work here I'm not aware of, or otherwise have opinions about the right organization.
And FYI, I will probably be ramping up on this area of the codebase over the next month or so. I plan to start by reviewing the relin/key_switch lowerings and adding more robust end-to-end testing just so I can understand it better.
I have not done any work on automorphisms themselves, but the keyswitch logic should be essentially complete. The only thing you might need is a CKKS-level op for "linearKeySwitch" or similar, since all we have right now is relinearize, which requires a quadratic ciphertext.
Since the implementation of an automorphism involves a key switching
Automorphisms are typically paired with a keyswitch, but I wouldn't say that automorphisms involve/require a keyswitch. There are many reasons that you want these to be separate ops (e.g., for hoisting).