Rename noise_margin

This commit is contained in:
Rick Weber
2022-02-01 17:22:03 -08:00
parent 03b120e824
commit fc63ba110b
12 changed files with 68 additions and 74 deletions

View File

@@ -228,7 +228,7 @@ fn compile_fhe_programs() -> (CompiledFheProgram, CompiledFheProgram, CompiledFh
// pass these parameters when compiling the other FHE programs so they are compatible.
let mul_program = Compiler::with_fhe_program(mul)
// We need to make the noise margin large enough so we can do a few repeated calculations.
.noise_margin_bits(32)
.additional_noise_budget(32)
.plain_modulus_constraint(PlainModulusConstraint::Raw(1_000_000))
.compile()
.unwrap();

View File

@@ -220,7 +220,7 @@ fn compile_fhe_programs() -> (
// pass these parameters when compiling the other FHE programs so they are compatible.
let add_program = Compiler::with_fhe_program(add)
// We need to make the noise margin large enough so we can do a few repeated calculations.
.noise_margin_bits(32)
.additional_noise_budget(32)
.plain_modulus_constraint(PlainModulusConstraint::Raw(1_000_000))
.compile()
.unwrap();

View File

@@ -173,7 +173,6 @@ fn run_fhe<F, T, U>(
{
let start = Instant::now();
let fhe_program = Compiler::with_fhe_program(c)
.noise_margin_bits(20)
.plain_modulus_constraint(plain_modulus)
.compile()
.unwrap();

View File

@@ -157,7 +157,6 @@ fn main() {
// suitable for use with Batched types. The 24 denotes the minimum precision of the plain
// modulus.
let fhe_program = Compiler::with_fhe_program(dot_product)
.noise_margin_bits(30)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(24))
.compile()
.unwrap();

View File

@@ -27,30 +27,26 @@ fn simple_multiply(a: Cipher<Signed>, b: Cipher<Signed>) -> Cipher<Signed> {
fn main() {
/*
* Compile the FHE program we previously declared. We specify the plain-text modulus is 600,
* meaning that if our calculatations ever result in a value greater than 600, we'll
* encounter overflow. Since 5 * 15 = 75 < 600, we have plenty of headroom and won't encounter
* this issue.
*
* Homomorphic operations introduce noise into ciphertexts. Too much noise results in
* garbled messages upon decryption. Homomorphic encryption schemes have a number of parameters
* that impact how quickly the noise grows. While some parameters result in less noise, such parameters
* tend to result in slower computation. Hence, there's a tradeoff to make; ideally you pick
* the smallest parameters that work in your application.
*
* Sunscreen allows experts to explicitly set the scheme parameters, but the default behavior
* is to let the compiler run your FHE program a number of times with different parameters and measure
* the resulting noise.
*
* We set the noise margin bits parameter to 5, which means Sunscreen must retain 5 bits or more
* of noise margin in every output ciphertext in order to use a given set of parameters.
*
* Afterwards, we simply compile and assert the compilation succeeds by calling unwrap. Compilation
* returns the compiled FHE program and parameters.
*/
* Compile the FHE program we previously declared. We specify the plain-text modulus is 600,
* meaning that if our calculatations ever result in a value greater than 600, we'll
* encounter overflow. Since 5 * 15 = 75 < 600, we have plenty of headroom and won't encounter
* this issue.
*
* Homomorphic operations introduce noise into ciphertexts. Too much noise results in
* garbled messages upon decryption. Homomorphic encryption schemes have a number of parameters
* that impact how quickly the noise grows. While some parameters result in less noise, such parameters
* tend to result in slower computation. Hence, there's a tradeoff to make; ideally you pick
* the smallest parameters that work in your application.
*
* Sunscreen allows experts to explicitly set the scheme parameters, but the default behavior
* is to let the compiler run your FHE program a number of times with different parameters and measure
* the resulting noise.
* Afterwards, we simply compile and assert the compilation succeeds by calling unwrap. Compilation
* returns the compiled FHE program and parameters.
*/
let fhe_program = Compiler::with_fhe_program(simple_multiply)
.plain_modulus_constraint(PlainModulusConstraint::Raw(600))
.noise_margin_bits(5)
.compile()
.unwrap();

View File

@@ -58,7 +58,7 @@ where
params_mode: ParamsMode::Search,
plain_modulus_constraint: None,
security_level: SecurityLevel::TC128,
noise_margin: 10,
noise_margin: 20,
}
}
@@ -100,7 +100,7 @@ where
/**
* The minimum number of bits of noise budget the search algorithm will leave for all outputs.
*/
pub fn noise_margin_bits(mut self, noise_margin: u32) -> Self {
pub fn additional_noise_budget(mut self, noise_margin: u32) -> Self {
self.noise_margin = noise_margin;
self
}

View File

@@ -17,7 +17,7 @@
//! fn main() {
//! let fhe_program = Compiler::with_fhe_program(simple_multiply)
//! .plain_modulus_constraint(PlainModulusConstraint::Raw(600))
//! .noise_margin_bits(5)
//! .additional_noise_budget(5)
//! .compile()
//! .unwrap();
//!

View File

@@ -12,7 +12,7 @@ type CipherFractional = Cipher<Fractional<64>>;
fn compile<F: FheProgramFn>(c: F) -> CompiledFheProgram {
Compiler::with_fhe_program(c)
.noise_margin_bits(30)
.additional_noise_budget(30)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap()
@@ -333,7 +333,7 @@ fn can_div_cipher_const() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(100000))
.compile()
.unwrap();
@@ -374,7 +374,7 @@ fn can_negate() {
}
let fhe_program = Compiler::with_fhe_program(neg)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(100000))
.compile()
.unwrap();

View File

@@ -14,7 +14,7 @@ fn can_encode_rational_numbers() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -51,7 +51,7 @@ fn can_add_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -82,7 +82,7 @@ fn can_add_cipher_plain() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -112,7 +112,7 @@ fn can_add_plain_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -142,7 +142,7 @@ fn can_add_cipher_literal() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -171,7 +171,7 @@ fn can_add_literal_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -207,7 +207,7 @@ fn can_sub_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -238,7 +238,7 @@ fn can_sub_cipher_plain() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -268,7 +268,7 @@ fn can_sub_plain_cipher() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -299,7 +299,7 @@ fn can_sub_cipher_literal() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -328,7 +328,7 @@ fn can_sub_literal_cipher() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -364,7 +364,7 @@ fn can_mul_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -395,7 +395,7 @@ fn can_mul_cipher_plain() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -425,7 +425,7 @@ fn can_mul_plain_cipher() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -456,7 +456,7 @@ fn can_mul_cipher_literal() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -485,7 +485,7 @@ fn can_mul_literal_cipher() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -521,7 +521,7 @@ fn can_div_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(div)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -552,7 +552,7 @@ fn can_div_cipher_plain() {
}
let fhe_program = Compiler::with_fhe_program(div)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -582,7 +582,7 @@ fn can_div_plain_cipher() {
}
let fhe_program = Compiler::with_fhe_program(div)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -613,7 +613,7 @@ fn can_div_cipher_literal() {
}
let fhe_program = Compiler::with_fhe_program(div)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -642,7 +642,7 @@ fn can_div_literal_cipher() {
}
let fhe_program = Compiler::with_fhe_program(div)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -678,7 +678,7 @@ fn can_neg_cipher() {
}
let fhe_program = Compiler::with_fhe_program(neg)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();

View File

@@ -21,7 +21,7 @@ fn can_add_cipher_plain() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -51,7 +51,7 @@ fn can_add_plain_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -81,7 +81,7 @@ fn can_add_cipher_literal() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -109,7 +109,7 @@ fn can_add_literal_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -144,7 +144,7 @@ fn can_sub_cipher_plain() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -174,7 +174,7 @@ fn can_sub_plain_cipher() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -204,7 +204,7 @@ fn can_sub_cipher_literal() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -232,7 +232,7 @@ fn can_sub_literal_cipher() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -267,7 +267,7 @@ fn can_mul_cipher_plain() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -297,7 +297,7 @@ fn can_mul_plain_cipher() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -327,7 +327,7 @@ fn can_mul_cipher_literal() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();
@@ -355,7 +355,7 @@ fn can_mul_literal_cipher() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();

View File

@@ -21,7 +21,7 @@ fn can_swap_rows_cipher() {
}
let fhe_program = Compiler::with_fhe_program(swap_rows)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(0))
.compile()
.unwrap();
@@ -62,7 +62,7 @@ fn can_rotate_left_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(0))
.compile()
.unwrap();
@@ -100,7 +100,7 @@ fn can_rotate_right_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(0))
.compile()
.unwrap();
@@ -138,7 +138,7 @@ fn can_add_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(add)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(0))
.compile()
.unwrap();
@@ -178,7 +178,7 @@ fn can_sub_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(sub)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(0))
.compile()
.unwrap();
@@ -218,7 +218,7 @@ fn can_mul_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(0))
.compile()
.unwrap();
@@ -258,7 +258,7 @@ fn can_neg_cipher_cipher() {
}
let fhe_program = Compiler::with_fhe_program(mul)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::BatchingMinimum(0))
.compile()
.unwrap();

View File

@@ -8,7 +8,7 @@ fn can_encrypt_decrypt() {
}
let fhe_program = Compiler::with_fhe_program(foo)
.noise_margin_bits(5)
.additional_noise_budget(5)
.plain_modulus_constraint(PlainModulusConstraint::Raw(500))
.compile()
.unwrap();