refactor(shortint): remove degree in generate_lookup_table_no_encode

This commit is contained in:
Nicolas Sarlin
2025-03-06 11:41:02 +01:00
committed by Nicolas Sarlin
parent 0e70dd3641
commit 056716fbb9
2 changed files with 30 additions and 23 deletions

View File

@@ -7,9 +7,7 @@ use crate::core_crypto::prelude::{
use crate::shortint::ciphertext::Degree;
use crate::shortint::engine::ShortintEngine;
use crate::shortint::parameters::{AtomicPatternKind, NoiseLevel};
use crate::shortint::server_key::{
apply_programmable_bootstrap_no_ms_noise_reduction, LookupTableOwned,
};
use crate::shortint::server_key::apply_programmable_bootstrap_no_ms_noise_reduction;
use crate::shortint::{PBSOrder, ServerKey};
use tfhe_csprng::seeders::Seed;
@@ -142,8 +140,7 @@ impl ServerKey {
let poly_delta = 2 * self.bootstrapping_key.polynomial_size().0 as u64 / p;
let acc: LookupTableOwned =
self.generate_lookup_table_no_encode(|x| (2 * (x / poly_delta) + 1) * delta / 2);
let acc = self.generate_lookup_table_no_encode(|x| (2 * (x / poly_delta) + 1) * delta / 2);
let out_lwe_size = self.bootstrapping_key.output_lwe_dimension().to_lwe_size();
@@ -156,7 +153,7 @@ impl ServerKey {
&self.bootstrapping_key,
&seeded,
&mut ct,
&acc.acc,
&acc,
buffers,
);
});

View File

@@ -691,29 +691,15 @@ impl ServerKey {
)
}
pub(crate) fn generate_lookup_table_no_encode<F>(&self, f: F) -> LookupTableOwned
pub(crate) fn generate_lookup_table_no_encode<F>(&self, f: F) -> GlweCiphertextOwned<u64>
where
F: Fn(u64) -> u64,
{
let mut acc = GlweCiphertext::new(
0,
let size = LookupTableSize::new(
self.bootstrapping_key.glwe_size(),
self.bootstrapping_key.polynomial_size(),
self.ciphertext_modulus,
);
fill_accumulator_no_encoding(
&mut acc,
self.bootstrapping_key.polynomial_size(),
self.bootstrapping_key.glwe_size(),
f,
);
LookupTableOwned {
acc,
// We should not rely on the degree in this case
// The degree should be set manually on the outputs of PBS by this LUT
degree: Degree::new(self.message_modulus.0 * self.carry_modulus.0 * 2),
}
generate_lookup_table_no_encode(size, self.ciphertext_modulus, f)
}
/// Given a function as input, constructs the lookup table working on the message bits
@@ -1612,6 +1598,30 @@ pub(crate) fn apply_programmable_bootstrap_no_ms_noise_reduction<InputCont, Outp
extract_lwe_sample_from_glwe_ciphertext(&glwe_out, out_buffer, MonomialDegree(0));
}
/// Generate a lookup table without any encoding specifications
///
/// It is the responsibility of the function `f` to encode the input cleartexts into valid
/// plaintexts for the parameters in use.
pub(crate) fn generate_lookup_table_no_encode<F>(
size: LookupTableSize,
ciphertext_modulus: CiphertextModulus,
f: F,
) -> GlweCiphertextOwned<u64>
where
F: Fn(u64) -> u64,
{
let mut acc = GlweCiphertext::new(
0,
size.glwe_size(),
size.polynomial_size(),
ciphertext_modulus,
);
fill_accumulator_no_encoding(&mut acc, size.polynomial_size(), size.glwe_size(), f);
acc
}
/// Generate a LUT where the output encoding is identical to the input one
pub fn generate_lookup_table<F>(
size: LookupTableSize,
ciphertext_modulus: CiphertextModulus,