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

bgv: Add a attribute to ciphertext to track plaintext bits #99

Closed
asraa opened this issue Aug 16, 2023 · 6 comments
Closed

bgv: Add a attribute to ciphertext to track plaintext bits #99

asraa opened this issue Aug 16, 2023 · 6 comments
Labels
dialect: bgv Issues concerning the bgv dialect

Comments

@asraa
Copy link
Collaborator

asraa commented Aug 16, 2023

In the last HEIR meeting, we noted that rather than holding onto the underlying encrypted type, that it would be more useful to keep track of the number of plaintext bits that are encoded (potentially in each slot) of a BGV ciphertext. This would make the error analysis better. Likewise, at the BGV layer, it really is no longer relevant whether something was SIMD or not - this can occur at a higher level pass.

It may also be useful to have some notions of which slots are being used? Although not sure. That can be a separate issue.

@j2kun
Copy link
Collaborator

j2kun commented Nov 28, 2023

I think we could perhaps also migrate the bgv::Ciphertext type to the lwe dialect as an RLWE ciphertext type, which does not currently exist but we want to have it there.

@Maokami
Copy link
Collaborator

Maokami commented Feb 12, 2024

I'm uncertain, but it seems that the current encoding attributes, which track plaintext bits (e.g., lwe.BitFieldEncodingAttr, lwe.polynomial_evaluation_encoding, etc.), assume that the noise part of a ciphertext starts from the least significant bit (LSB). ( upto cleartext_start bit).

However, in the BGV scheme, it seems that the noise is located at the most significant bit (MSB) of the plaintext part, as illustrated in the following image:
image

Should we change the way of these modeling?

@asraa
Copy link
Collaborator Author

asraa commented Feb 12, 2024

Should we change the way of these modeling?

Ah, I see the wording in https://github.com/google/heir/blob/main/include/Dialect/LWE/IR/LWEAttributes.td#L56-L58 implies the FV style with noise in the LSB. I don't think the attribute needs to change right now, since the attribute is only keeping track of the message bit position. The noise models specific to each scheme and the encryptions should specify / handle where the noise is added. I do think the wording should change to allow for both types.

@j2kun
Copy link
Collaborator

j2kun commented Feb 12, 2024 via email

@j2kun
Copy link
Collaborator

j2kun commented Feb 12, 2024

Taking a second look, yes I see how the docs are confusing. I think for BGV the interpretation of

#lwe_encoding = #lwe.bit_field_encoding<cleartext_start=4, cleartext_bitwidth=4>

Would be this: where n stands for noise and b for the message bits

       nn...n|bbbb
    MSB^         ^LSB

@j2kun j2kun added the dialect: bgv Issues concerning the bgv dialect label Feb 13, 2024
copybara-service bot pushed a commit that referenced this issue Feb 14, 2024
Cf. #99

PiperOrigin-RevId: 606738033
copybara-service bot pushed a commit that referenced this issue Feb 14, 2024
Cf. #99

PiperOrigin-RevId: 606974721
@j2kun
Copy link
Collaborator

j2kun commented May 23, 2024

This is fixed now since we moved BGV to use LWE types and attributes.

@j2kun j2kun closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialect: bgv Issues concerning the bgv dialect
Projects
None yet
Development

No branches or pull requests

3 participants