chore: update br_rerand_dp_ks_ms test to take metaparameters

This commit is contained in:
Arthur Meyre
2025-11-18 14:29:48 +01:00
committed by IceTDrinker
parent a72de66744
commit d68645c493

View File

@@ -29,19 +29,17 @@ use crate::shortint::engine::ShortintEngine;
use crate::shortint::key_switching_key::{KeySwitchingKeyBuildHelper, KeySwitchingKeyView}; use crate::shortint::key_switching_key::{KeySwitchingKeyBuildHelper, KeySwitchingKeyView};
use crate::shortint::list_compression::{CompressionPrivateKeys, DecompressionKey}; use crate::shortint::list_compression::{CompressionPrivateKeys, DecompressionKey};
use crate::shortint::parameters::test_params::{ use crate::shortint::parameters::test_params::{
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
}; };
use crate::shortint::parameters::{ use crate::shortint::parameters::{
AtomicPatternParameters, CarryModulus, CompactCiphertextListExpansionKind, AtomicPatternParameters, CarryModulus, CompactCiphertextListExpansionKind,
CompactPublicKeyEncryptionParameters, CompressionParameters, CompactPublicKeyEncryptionParameters, CompressionParameters, MetaParameters,
ShortintCompactCiphertextListCastingMode, ShortintKeySwitchingParameters, ShortintCompactCiphertextListCastingMode, ShortintKeySwitchingParameters,
}; };
use crate::shortint::public_key::compact::{CompactPrivateKey, CompactPublicKey}; use crate::shortint::public_key::compact::{CompactPrivateKey, CompactPublicKey};
use crate::shortint::server_key::tests::noise_distribution::utils::noise_simulation::NoiseSimulationModulus; use crate::shortint::server_key::tests::noise_distribution::utils::noise_simulation::NoiseSimulationModulus;
use crate::shortint::server_key::tests::parameterized_test::create_parameterized_test;
use crate::shortint::server_key::ServerKey; use crate::shortint::server_key::ServerKey;
use crate::shortint::PaddingBit; use crate::shortint::PaddingBit;
use rayon::prelude::*; use rayon::prelude::*;
@@ -589,22 +587,26 @@ fn encrypt_br_rerand_dp_ks_any_ms_pfail_helper(
after_ms after_ms
} }
fn noise_check_encrypt_br_rerand_dp_ks_ms_noise<P>( fn noise_check_encrypt_br_rerand_dp_ks_ms_noise(meta_params: MetaParameters) {
params: P, let (params, cpk_params, rerand_ksk_params, compression_params) = {
mut cpk_params: CompactPublicKeyEncryptionParameters, let compute_params = meta_params.compute_parameters;
rerand_ksk_params: ShortintKeySwitchingParameters, let dedicated_cpk_params = meta_params.dedicated_compact_public_key_parameters.unwrap();
compression_params: CompressionParameters, // To avoid the expand logic of shortint which would force a keyswitch + LUT eval after
) where // expand
P: Into<AtomicPatternParameters>, let cpk_params = {
{ let mut cpk_params = dedicated_cpk_params.pke_params;
let params: AtomicPatternParameters = params.into(); cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
compute_params.encryption_key_choice().into_pbs_order(),
);
cpk_params
};
// To avoid the expand logic of shortint which would force a keyswitch + LUT eval after expand (
let cpk_params = { compute_params,
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting( cpk_params,
params.encryption_key_choice().into_pbs_order(), dedicated_cpk_params.re_randomization_parameters.unwrap(),
); meta_params.compression_parameters.unwrap(),
cpk_params )
}; };
let cpk_private_key = CompactPrivateKey::new(cpk_params); let cpk_private_key = CompactPrivateKey::new(cpk_params);
@@ -786,49 +788,35 @@ fn noise_check_encrypt_br_rerand_dp_ks_ms_noise<P>(
assert!(before_ms_normality.null_hypothesis_is_valid && after_ms_is_ok); assert!(before_ms_normality.null_hypothesis_is_valid && after_ms_is_ok);
} }
#[test] create_parameterized_test!(noise_check_encrypt_br_rerand_dp_ks_ms_noise {
fn test_noise_check_encrypt_br_rerand_dp_ks_ms_noise_test_param_message_2_carry_2_ks_pbs_tuniform_2m128( TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
) { TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
noise_check_encrypt_br_rerand_dp_ks_ms_noise( });
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
)
}
#[test] fn noise_check_encrypt_br_rerand_dp_ks_ms_pfail(meta_params: MetaParameters) {
fn test_noise_check_encrypt_br_rerand_dp_ks_ms_noise_test_param_message_2_carry_2_ks32_tuniform_2m128( let (params, cpk_params, rerand_ksk_params, compression_params) = {
) { let compute_params = meta_params.compute_parameters;
noise_check_encrypt_br_rerand_dp_ks_ms_noise( let dedicated_cpk_params = meta_params.dedicated_compact_public_key_parameters.unwrap();
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128, // To avoid the expand logic of shortint which would force a keyswitch + LUT eval after
TEST_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, // expand
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, let cpk_params = {
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, let mut cpk_params = dedicated_cpk_params.pke_params;
) cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
} compute_params.encryption_key_choice().into_pbs_order(),
);
cpk_params
};
fn noise_check_encrypt_br_rerand_dp_ks_ms_pfail<P>( (
params: P, compute_params,
mut cpk_params: CompactPublicKeyEncryptionParameters, cpk_params,
rerand_ksk_params: ShortintKeySwitchingParameters, dedicated_cpk_params.re_randomization_parameters.unwrap(),
compression_params: CompressionParameters, meta_params.compression_parameters.unwrap(),
) where )
P: Into<AtomicPatternParameters> + Copy,
{
// To avoid the expand logic of shortint which would force a keyswitch + LUT eval after
// expand
let cpk_params = {
let params: AtomicPatternParameters = params.into();
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
params.encryption_key_choice().into_pbs_order(),
);
cpk_params
}; };
let (pfail_test_meta, params, compression_params) = { let (pfail_test_meta, params, compression_params) = {
let mut ap_params: AtomicPatternParameters = params.into(); let mut ap_params = params;
let original_message_modulus = ap_params.message_modulus(); let original_message_modulus = ap_params.message_modulus();
let original_carry_modulus = ap_params.carry_modulus(); let original_carry_modulus = ap_params.carry_modulus();
@@ -907,44 +895,31 @@ fn noise_check_encrypt_br_rerand_dp_ks_ms_pfail<P>(
pfail_check(&pfail_test_meta, test_result); pfail_check(&pfail_test_meta, test_result);
} }
#[test] create_parameterized_test!(noise_check_encrypt_br_rerand_dp_ks_ms_pfail {
fn test_noise_check_encrypt_br_rerand_dp_ks_ms_pfail_test_param_message_2_carry_2_ks_pbs_tuniform_2m128( TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
) { TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
noise_check_encrypt_br_rerand_dp_ks_ms_pfail( });
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
)
}
#[test] fn sanity_check_encrypt_br_rerand_dp_ks_ms_pbs(meta_params: MetaParameters) {
fn test_noise_check_encrypt_br_rerand_dp_ks_ms_pfail_test_param_message_2_carry_2_ks32_tuniform_2m128( let (params, cpk_params, rerand_ksk_params, compression_params) = {
) { let compute_params = meta_params.compute_parameters;
noise_check_encrypt_br_rerand_dp_ks_ms_pfail( let dedicated_cpk_params = meta_params.dedicated_compact_public_key_parameters.unwrap();
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128, // To avoid the expand logic of shortint which would force a keyswitch + LUT eval after
TEST_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, // expand
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, let cpk_params = {
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128, let mut cpk_params = dedicated_cpk_params.pke_params;
) cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
} compute_params.encryption_key_choice().into_pbs_order(),
);
cpk_params
};
fn sanity_check_encrypt_br_rerand_dp_ks_ms_pbs<P>( (
params: P, compute_params,
mut cpk_params: CompactPublicKeyEncryptionParameters, cpk_params,
rerand_ksk_params: ShortintKeySwitchingParameters, dedicated_cpk_params.re_randomization_parameters.unwrap(),
compression_params: CompressionParameters, meta_params.compression_parameters.unwrap(),
) where )
P: Into<AtomicPatternParameters>,
{
let params: AtomicPatternParameters = params.into();
// To avoid the expand logic of shortint which would force a keyswitch + LUT eval after expand
let cpk_params = {
cpk_params.expansion_kind = CompactCiphertextListExpansionKind::NoCasting(
params.encryption_key_choice().into_pbs_order(),
);
cpk_params
}; };
let cpk_private_key = CompactPrivateKey::new(cpk_params); let cpk_private_key = CompactPrivateKey::new(cpk_params);
@@ -1081,24 +1056,7 @@ fn sanity_check_encrypt_br_rerand_dp_ks_ms_pbs<P>(
} }
} }
#[test] create_parameterized_test!(sanity_check_encrypt_br_rerand_dp_ks_ms_pbs {
fn test_sanity_check_encrypt_br_rerand_dp_ks_ms_pbs_noise_test_param_message_2_carry_2_ks_tuniform_2m128( TEST_META_PARAM_CPU_2_2_KS_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
) { TEST_META_PARAM_CPU_2_2_KS32_PBS_PKE_TO_SMALL_ZKV2_TUNIFORM_2M128,
sanity_check_encrypt_br_rerand_dp_ks_ms_pbs( });
TEST_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
)
}
#[test]
fn test_sanity_check_encrypt_br_rerand_dp_ks_ms_pbs_noise_test_param_message_2_carry_2_ks32_tuniform_2m128(
) {
sanity_check_encrypt_br_rerand_dp_ks_ms_pbs(
TEST_PARAM_MESSAGE_2_CARRY_2_KS32_PBS_TUNIFORM_2M128,
TEST_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_PARAM_KEYSWITCH_PKE_TO_BIG_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
TEST_COMP_PARAM_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M128,
)
}