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): fix max_noise_level to keep space for carry #1632

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ where
ks_level: wopbs_params.ks_level,
message_modulus: wopbs_params.message_modulus,
carry_modulus: wopbs_params.carry_modulus,
max_noise_level: crate::shortint::parameters::MaxNoiseLevel::from_msg_carry_modulus(
max_noise_level: crate::shortint::parameters::MaxNoiseLevel::integer_radix_server_key(
wopbs_params.message_modulus,
wopbs_params.carry_modulus,
),
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ where
ks_level: wopbs_params.ks_level,
message_modulus: wopbs_params.message_modulus,
carry_modulus: wopbs_params.carry_modulus,
max_noise_level: crate::shortint::parameters::MaxNoiseLevel::from_msg_carry_modulus(
max_noise_level: crate::shortint::parameters::MaxNoiseLevel::integer_radix_server_key(
wopbs_params.message_modulus,
wopbs_params.carry_modulus,
),
Expand Down
28 changes: 22 additions & 6 deletions tfhe/src/integer/server_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::integer::client_key::ClientKey;
use crate::shortint::ciphertext::{Degree, MaxDegree};
/// Error returned when the carry buffer is full.
pub use crate::shortint::CheckError;
use crate::shortint::{CarryModulus, MessageModulus, PBSParameters};
use crate::shortint::{CarryModulus, MaxNoiseLevel, MessageModulus, PBSParameters};
pub use radix::scalar_mul::ScalarMultiplier;
pub use radix::scalar_sub::TwosComplementNegation;
pub use radix_parallel::{MatchValues, MiniUnsignedInteger, Reciprocable};
Expand Down Expand Up @@ -51,26 +51,42 @@ impl MaxDegree {
message_modulus: MessageModulus,
carry_modulus: CarryModulus,
) -> Self {
let full_max_degree = message_modulus.0 * carry_modulus.0 - 1;
let full_max_degree = Self::from_msg_carry_modulus(message_modulus, carry_modulus).get();

let carry_max_degree = carry_modulus.0 - 1;

// We want to be have a margin to add a carry from another block
Self::new(full_max_degree - carry_max_degree)
}
}

impl MaxDegree {
/// Compute the [`MaxDegree`] for an integer server key (compressed or uncompressed).
/// This is tailored for [`CrtCiphertext`](`crate::integer::CrtCiphertext`) and not compatible
/// for use with [`RadixCiphertext`](`crate::integer::RadixCiphertext`).
fn integer_crt_server_key(
message_modulus: MessageModulus,
carry_modulus: CarryModulus,
) -> Self {
let full_max_degree = message_modulus.0 * carry_modulus.0 - 1;
Self::from_msg_carry_modulus(message_modulus, carry_modulus)
}
}

Self::new(full_max_degree)
impl MaxNoiseLevel {
/// Compute the [`MaxNoiseLevel`] for an integer server key (compressed or uncompressed).
/// To allow carry propagation between shortint blocks in a
/// [`RadixCiphertext`](`crate::integer::RadixCiphertext`) (which includes adding the extracted
/// carry from one shortint block to the next block), this formula provisions space to add a
/// carry.
pub(crate) fn integer_radix_server_key(
message_modulus: MessageModulus,
carry_modulus: CarryModulus,
) -> Self {
let full_max_noise_level =
Self::from_msg_carry_modulus(message_modulus, carry_modulus).get();

let carry_max_noise_level = 1;

// We want to be have a margin to add a carry from another block
Self::new(full_max_noise_level - carry_max_noise_level)
}
}

Expand Down
Loading