Skip to content

Commit

Permalink
fix: correctly set degree
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi committed Nov 20, 2024
1 parent 9059dde commit d640dce
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tfhe/src/integer/server_key/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::ServerKey;
use crate::integer::ciphertext::boolean_value::BooleanBlock;
use crate::integer::ciphertext::IntegerRadixCiphertext;
use crate::shortint::server_key::LookupTableOwned;
use crate::shortint::Ciphertext;
use crate::shortint::{ciphertext::Degree, Ciphertext};

/// Used for compare_blocks_with_zero
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -407,8 +407,9 @@ impl<'a> Comparator<'a> {

let maybe_lhs = self.server_key.key.apply_lookup_table(&lhs_block, lhs_lut);
let maybe_rhs = self.server_key.key.apply_lookup_table(&rhs_block, rhs_lut);

let r = self.server_key.key.unchecked_add(&maybe_lhs, &maybe_rhs);
let mut r = self.server_key.key.unchecked_add(&maybe_lhs, &maybe_rhs);
// Either maybe_lhs or maybe_rhs is zero, which means that the degree is tighter.
r.degree = Degree::new(self.server_key.message_modulus().0 - 1);
result.push(r);
}

Expand Down
16 changes: 16 additions & 0 deletions tfhe/src/integer/server_key/radix/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::integer::keycache::KEY_CACHE;
use crate::integer::server_key::radix_parallel::tests_cases_unsigned::*;
use crate::integer::server_key::radix_parallel::tests_unsigned::test_add::smart_add_test;
use crate::integer::server_key::radix_parallel::tests_unsigned::test_comparison::test_unchecked_minmax;
use crate::integer::server_key::radix_parallel::tests_unsigned::test_neg::smart_neg_test;
use crate::integer::server_key::radix_parallel::tests_unsigned::test_slice::{
default_scalar_bitslice_assign_test, default_scalar_bitslice_test,
Expand Down Expand Up @@ -117,6 +118,16 @@ create_parametrized_test_classical_params!(integer_default_scalar_slice);
create_parametrized_test_classical_params!(integer_default_scalar_slice_assign);
create_parametrized_test_classical_params!(integer_smart_scalar_slice);
create_parametrized_test_classical_params!(integer_smart_scalar_slice_assign);
create_parametrized_test!(integer_unchecked_min {
coverage => {
COVERAGE_PARAM_MESSAGE_2_CARRY_2_KS_PBS
},
no_coverage => {
PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64,
PARAM_MESSAGE_3_CARRY_3_KS_PBS_GAUSSIAN_2M64,
PARAM_MESSAGE_4_CARRY_4_KS_PBS_GAUSSIAN_2M64
}
});

fn integer_encrypt_decrypt(param: ClassicPBSParameters) {
let (cks, _) = KEY_CACHE.get_from_params(param, IntegerKeyKind::Radix);
Expand Down Expand Up @@ -800,3 +811,8 @@ fn integer_smart_scalar_slice_assign(param: ClassicPBSParameters) {
let executor = CpuFunctionExecutor::new(&ServerKey::smart_scalar_bitslice_assign);
smart_scalar_bitslice_assign_test(param, executor);
}

fn integer_unchecked_min(param: ClassicPBSParameters) {
let executor = CpuFunctionExecutor::new(&ServerKey::unchecked_min);
test_unchecked_minmax(param, 2, executor, std::cmp::min::<u64>);
}
2 changes: 1 addition & 1 deletion tfhe/src/shortint/ciphertext/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl MaxDegree {
}
}

/// This tracks the number of operations that has been done.
/// The maximum value a given ciphertext can have. This helps with optimizations.
#[derive(
Debug, PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Serialize, Deserialize, Versionize,
)]
Expand Down

0 comments on commit d640dce

Please sign in to comment.