google / heir

A compiler for homomorphic encryption
https://heir.dev/
Apache License 2.0
292 stars 44 forks source link

bgv : Add a verifier for Rotate #287

Closed Maokami closed 9 months ago

Maokami commented 9 months ago

I believe there should be a check ensuring that the dimension of the ciphertext, which serves as the operand of rotation, is two.

Justification:

However, due to my lack of HE knowledge, I don't know why the rotation doesn't work when the dimension of ciphertext is greater than 2. Let me know if anyone knows!

j2kun commented 9 months ago

I will summarize the work needed to do this in HEIR, in case you are looking to dip your feet into the coding. A high-level explanation of how verifiers work is here.

asraa commented 9 months ago

Let me know if anyone knows!

While I don't think it's theoretically impossible to apply a galois rotation on a length 3 ciphertext, I think the reason both implementations avoid doing so is because the Galois Keys are computed to switch the ciphertext from being encrypted from a key (1, s^i) to a (1, s). If the ciphertext has length 3, then I'm not sure why there aren't static size checks, but the key switching matrix would only apply to the first two polys of the ciphertext and then probably leave an incorrect result.

Maokami commented 9 months ago

@j2kun @asraa Thank you for the pointers and explanations!

Before I start writing verifiers, I believe it's essential to establish the specification of the operations.

Based on this issue and this conversation, it's challenging to determine which inputs are valid for each operation of the HE schemes. In this case, should we really reject cases where c.dim != 2 in rotate(c)? As @asraa pointed out, theoretically speaking, isn't it valid operation?

One viable option is to follow the lead of existing libraries. For rotations, to the best of my knowledge, SEAL, OpenFHE, and Lattigo all prohibit the case where c.dim != 2. Would it be acceptable to create a verifier based on these criteria?

j2kun commented 9 months ago

I think prohibiting c.dim != 2 is acceptable. And generally speaking, my philosophy of software design is that it's better to start with a strict definition and relax it or generalize it only once you have a good reason to.

j2kun commented 9 months ago

Thanks again @Maokami! Please let me know if there is any other topic you want to work on in the project. I'm happy to help.

Maokami commented 9 months ago

Thank you for your help! I'll take a closer look at the project to see if there's any other stuff I can contribute.