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

fix(integer): rotations/shifts < 2 blocks #2041

Merged
merged 1 commit into from
Feb 13, 2025
Merged

Conversation

tmontaigu
Copy link
Contributor

@tmontaigu tmontaigu commented Feb 10, 2025

This commit fixes a few bugs

  • The shift/rotate functions used when blocks encrypt a number of bits that is a power of 2 was causing a panic when working on one block.

    • Also, when the number of blocks was low (e.g 2 blocks with 2_2 params) a noise cleaning step was wrongly skipped
  • The function used when blocks encrypt non power of 2 number of bits also had a problem

The test have been updated to test with different block sizes and check the noise level

Overall these bugs only affected low block counts (e.g FheUint2, FheUint4) ciphertexts


This change is Reviewable

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

Looks good a typo and a question on the amount when len == 1

Reviewed 1 of 3 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 2 unresolved discussions


tfhe/src/integer/server_key/radix_parallel/shift.rs line 416 at r1 (raw file):

            let block = self.key.unchecked_apply_lookup_table_bivariate(
                &ct.blocks()[0],
                &amount.blocks[0],

here amount could be of length 0 (?)

Also is it certain this behaves properly if amounts is e.g. == 16 meaning the lower block == 0 (so no shift) but in practice the shift by 16 on a block of 2 bits is going to yield a 0 block or some wrapped around stuff depending on how the shift behaves ?

If it wraps around are we sure we keep enough bits in the amount block vs the number of bits in the ct block ?


tfhe/src/integer/server_key/radix_parallel/shift.rs line 448 at r1 (raw file):

        // When doing right shift of a signed ciphertext, we do an arithmetic shift
        // Thus, we need some special luts to be used on the last block
        // (which has the sign big)

sign big -> sign bits

Copy link
Contributor Author

@tmontaigu tmontaigu left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @IceTDrinker)


tfhe/src/integer/server_key/radix_parallel/shift.rs line 416 at r1 (raw file):

Previously, IceTDrinker (Arthur Meyre) wrote…

here amount could be of length 0 (?)

Also is it certain this behaves properly if amounts is e.g. == 16 meaning the lower block == 0 (so no shift) but in practice the shift by 16 on a block of 2 bits is going to yield a 0 block or some wrapped around stuff depending on how the shift behaves ?

If it wraps around are we sure we keep enough bits in the amount block vs the number of bits in the ct block ?

As this is meant for params where blocks encrypts a number of bits that is a power of 2, that means since the shift applies a modulus to the amount, only looking at the first block of the amount is fine.

The tests have a case where amount > nb bits

I added a guard for empty amounts

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

:lgtm: Thanks !

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: 2 of 3 files reviewed, all discussions resolved

This commit fixes a few bugs

* The shift/rotate functions used when blocks encrypt a number of bits
  that is a power of 2 was causing a panic when working on one block.
  - Also, when the number of blocks was low (e.g 2 blocks with 2_2
    params) a noise cleaning step was wrongly skipped

* The function used when blocks encrypt non power of 2 number of bits
  also had a problem

The test have been updated to test with different block sizes and check
the noise level

Overall these bugs only affected low block counts (e.g FheUint2,
FheUint4) ciphertexts
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @tmontaigu)

@tmontaigu tmontaigu merged commit 37934e4 into main Feb 13, 2025
149 checks passed
@tmontaigu tmontaigu deleted the tm/fix-small-shifts branch February 13, 2025 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants