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

feat(integer): improve shift/rotate by encrypted amount #1647

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

tmontaigu
Copy link
Contributor

This commit does a few things:

  • Changes the BitExtractor to use many_lut to reduce number of PBS done
  • Add blocks rotation/shift operation
  • Implement a new algorithm for bit shift/rotation by encrypted amounts
  • Add support bit shift/rotation for 1_1 parameters (as result of adding block shift/rotation)

The gist of the new bit shift/rotation is to use the same idea as the scalar version where we first shift blocks between adjacent blocks, then use a rotation of blocks.

Doing this requires to do a division and modulo operation:

let (shift_within_blocks, block_rotations) =
  (amount / bits_per_block, amount % bits_per_block)

When amount is clear this operation is simple, when amount is encrypted then is harder (bits_per_block is always clear). However, when bits_per_block is a power of 2 (e.g 1, 2, 4) / and % can be made by shifting and bit-masking, which are simple operations.

This means the new algorithm is only compatible with 1_1, 2_2, 4_4 but not 3_3.
The new algorithm improves the latency as well as the throughput as it requires less PBS in total

closes: please link all relevant issues

PR content/description

Check-list:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Relevant issues are marked as resolved/closed, related issues are linked in the description
  • Check for breaking changes (including serialization changes) and add them to commit message following the conventional commit specification

@cla-bot cla-bot bot added the cla-signed label Oct 7, 2024
@tmontaigu tmontaigu requested a review from nsarlin-zama October 8, 2024 11:36
@tmontaigu tmontaigu force-pushed the tm/faster-shift branch 2 times, most recently from f273633 to 1bcfce3 Compare October 10, 2024 08:50
Copy link
Contributor

@nsarlin-zama nsarlin-zama left a comment

Choose a reason for hiding this comment

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

Good for me !

This commit does a few things:
* Changes the BitExtractor to use many_lut to reduce number of PBS
  done
* Add blocks rotation/shift operation
* Implement a new algorithm for bit shift/rotation by encrypted amounts
* Add support bit shift/rotation for 1_1 parameters (as result of adding
  block shift/rotation)

The gist of the new bit shift/rotation is to use the same idea as the scalar
version where we first shift blocks between adjacent blocks,
then use a rotation of blocks.

Doing this requires to do a division and modulo operation:
```rust
let (shift_within_blocks, block_rotations) =
  (amount / bits_per_block, amount % bits_per_block)
```
When `amount` is clear this operation is simple, when `amount` is
encrypted then is harder (`bits_per_block` is always clear).
However, when bits_per_block is a power of 2 (e.g 1, 2, 4) `/` and `%`
can be made by shifting and bit-masking, which are simple operations.

This means the new algorithm is only compatible with 1_1, 2_2, 4_4 but
not 3_3.
The new algorithm improves the latency as well as the throughput as
it requires less PBS in total
@zama-bot zama-bot removed the approved label Oct 11, 2024
@tmontaigu tmontaigu self-assigned this Oct 11, 2024
@tmontaigu tmontaigu merged commit ac71973 into main Oct 14, 2024
86 checks passed
@tmontaigu tmontaigu deleted the tm/faster-shift branch October 14, 2024 07: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