-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Implement Relinearization operation of BFV Scheme #3977
Implement Relinearization operation of BFV Scheme #3977
Conversation
Check out this pull request on Review Jupyter notebook visual diffs & provide feedback on notebooks. Powered by ReviewNB |
Codecov Report
@@ Coverage Diff @@
## master #3977 +/- ##
==========================================
- Coverage 94.88% 94.76% -0.13%
==========================================
Files 202 203 +1
Lines 20853 21038 +185
==========================================
+ Hits 19786 19936 +150
- Misses 1067 1102 +35
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing to see the BFV scheme now working, looking forward to the tensor type!
temp_poly_ptr, encrypted_ptr[j], key_mod[j], self.poly_modulus | ||
) | ||
|
||
return CipherText(ct[:-1], param_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current algorithm only apply for length 3 ciphertexts, right? So we can explicitly specify ct[0:2]
to make it clear here
def _get_sk_power_2(self, sk): | ||
sk_power_2 = [] | ||
for i in range(len(self._coeff_modulus)): | ||
sk_power_2.append( | ||
poly_mul_mod(sk[i], sk[i], self._coeff_modulus[i], self._poly_modulus) | ||
) | ||
return sk_power_2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've seen this method in quite some places, can we factorize it and provide it in utils maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is used in decrypter and here but I modified it from the other one. it only gives the power of 2 and the decryptors calculate any power given to it. I can get this done later because merging both to the same function will require changing indexes at various positions.😅
test/torch/tensors/test_fv.py
Outdated
@pytest.mark.parametrize( | ||
"val", [(0), (1), (-1), (100), (1000), (-1000), (-99)], | ||
) | ||
def test_fv_relin(val): | ||
ctx = Context(EncryptionParams(128, CoeffModulus().create(128, [40, 40]), 64)) | ||
keygenerator = KeyGenerator(ctx) | ||
keys = keygenerator.keygen() | ||
relin_key = keygenerator.get_relin_keys() | ||
encoder = IntegerEncoder(ctx) | ||
encryptor = Encryptor(ctx, keys[1]) # keys[1] = public_key | ||
decryptor = Decryptor(ctx, keys[0]) # keys[0] = secret_key | ||
evaluator = Evaluator(ctx) | ||
|
||
op = encryptor.encrypt(encoder.encode(val)) | ||
temp_prod = evaluator.mul(op, op) | ||
relin_prod = evaluator.relin(temp_prod, relin_key) | ||
assert len(temp_prod.data) - 1 == len(relin_prod.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add more tests, ones that do multiple mul and relin, and others that check the failure for len 2 and >3 ciphertexts?
with pytest.raises(Warning): | ||
evaluator.relin(op1, relin_key) # Ciphertext size 2 | ||
|
||
with pytest.raises(Exception): | ||
evaluator.relin(evaluator.mul(temp_prod, val1), relin_key) # Ciphertext size 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We doesn't need to run this on every values, I think you can separate this into a different test with a single value
415bd7f
to
3b1aa9a
Compare
Description
Closes #3662 #3791
Implementing Relin Key and Relinearization operation for the FV scheme. So that we can decrement the size of ciphertexts if needed. Mainly required after multiplication operation.
Affected Dependencies
None
How has this been tested?
Added tests for the relinearization operation.
Checklist