concrete_boolean/parameters/mod.rs
1//! The cryptographic parameter set.
2//!
3//! This module provides the structure containing the cryptographic parameters required for the
4//! homomorphic evaluation of Boolean circuit as well as a list of secure cryptographic parameter
5//! sets.
6//!
7//! Two parameter sets are provided:
8//! * `concrete_boolean::parameters::DEFAULT_PARAMETERS`
9//! * `concrete_boolean::parameters::TFHE_LIB_PARAMETERS`
10//!
11//! They ensure the correctness of the Boolean circuit evaluation result (up to a certain
12//! probability) along with 128-bits of security.
13//!
14//! The two parameter sets offer a trade-off in terms of execution time versus error probability.
15//! The `DEFAULT_PARAMETERS` set offers better performances on homomorphic circuit evaluation
16//! with an higher probability error in comparison with the `TFHE_LIB_PARAMETERS`.
17//! Note that if you desire, you can also create your own set of parameters.
18//! This is an unsafe operation as failing to properly fix the parameters will potentially result
19//! with an incorrect and/or insecure computation.
20// TODO: speak about the lattice estimator and give the explicit used commit for the parameters
21
22pub use concrete_core::prelude::{
23 DecompositionBaseLog, DecompositionLevelCount, GlweDimension, LweDimension, PolynomialSize,
24 StandardDev,
25};
26use serde::{Deserialize, Serialize};
27
28/// A set of cryptographic parameters for homomorphic Boolean circuit evaluation.
29#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
30pub struct BooleanParameters {
31 pub lwe_dimension: LweDimension,
32 pub glwe_dimension: GlweDimension,
33 pub polynomial_size: PolynomialSize,
34 pub lwe_modular_std_dev: StandardDev,
35 pub glwe_modular_std_dev: StandardDev,
36 pub pbs_base_log: DecompositionBaseLog,
37 pub pbs_level: DecompositionLevelCount,
38 pub ks_base_log: DecompositionBaseLog,
39 pub ks_level: DecompositionLevelCount,
40}
41
42impl BooleanParameters {
43 /// Constructs a new set of parameters for boolean circuit evaluation.
44 ///
45 /// # Safety
46 ///
47 /// This function is unsafe, as failing to fix the parameters properly would yield incorrect
48 /// and insecure computation. Unless you are a cryptographer who really knows the impact of each
49 /// of those parameters, you __must__ stick with the provided parameters [`DEFAULT_PARAMETERS`]
50 /// and [`TFHE_LIB_PARAMETERS`], which both offer correct results with 128 bits of security.
51 #[allow(clippy::too_many_arguments)]
52 pub unsafe fn new_insecure(
53 lwe_dimension: LweDimension,
54 glwe_dimension: GlweDimension,
55 polynomial_size: PolynomialSize,
56 lwe_modular_std_dev: StandardDev,
57 glwe_modular_std_dev: StandardDev,
58 pbs_base_log: DecompositionBaseLog,
59 pbs_level: DecompositionLevelCount,
60 ks_base_log: DecompositionBaseLog,
61 ks_level: DecompositionLevelCount,
62 ) -> BooleanParameters {
63 BooleanParameters {
64 lwe_dimension,
65 glwe_dimension,
66 polynomial_size,
67 lwe_modular_std_dev,
68 glwe_modular_std_dev,
69 pbs_base_log,
70 pbs_level,
71 ks_level,
72 ks_base_log,
73 }
74 }
75}
76
77/// Default parameter set.
78///
79/// This parameter set ensures 128-bits of security, and a probability of error is upper-bounded by
80/// $2^{-25}$. The secret keys generated with this parameter set are uniform binary.
81/// This parameter set allows to evaluate faster Boolean circuits than the `TFHE_LIB_PARAMETERS`
82/// one.
83pub const DEFAULT_PARAMETERS: BooleanParameters = BooleanParameters {
84 lwe_dimension: LweDimension(586),
85 glwe_dimension: GlweDimension(2),
86 polynomial_size: PolynomialSize(512),
87 lwe_modular_std_dev: StandardDev(0.000_092_511_997_467_675_6), // 2^{-13.4}
88 glwe_modular_std_dev: StandardDev(0.000_000_034_233_878_701_836_9), // 2^{-24.8}
89 pbs_base_log: DecompositionBaseLog(8),
90 pbs_level: DecompositionLevelCount(2),
91 ks_base_log: DecompositionBaseLog(2),
92 ks_level: DecompositionLevelCount(5),
93};
94
95/// Parameter set used in [TFHE library](https://tfhe.github.io/tfhe/) for 128-bits of security.
96///
97/// Details about this set are provided
98/// [here](https://github.com/tfhe/tfhe/blob/master/src/libtfhe/tfhe_gate_bootstrapping.cpp).
99/// The secret keys generated with this parameter set are uniform binary.
100/// This parameter set ensures a probability of error is upper-bounded by $2^{-165}$.
101pub const TFHE_LIB_PARAMETERS: BooleanParameters = BooleanParameters {
102 lwe_dimension: LweDimension(630),
103 glwe_dimension: GlweDimension(1),
104 polynomial_size: PolynomialSize(1024),
105 lwe_modular_std_dev: StandardDev(0.000_043_158_372_875_155_5), // 2^{-14.5}
106 glwe_modular_std_dev: StandardDev(0.000_000_034_233_878_701_836_9), // 2^{-24.8}
107 pbs_base_log: DecompositionBaseLog(7),
108 pbs_level: DecompositionLevelCount(3),
109 ks_base_log: DecompositionBaseLog(2),
110 ks_level: DecompositionLevelCount(8),
111};