Commit 549c0210 authored by Jakub Klemsa's avatar Jakub Klemsa
Browse files

README, cleanup.

parent 2f138b89
......@@ -2,12 +2,12 @@
# TFHE Parameter Testing Suite
This tool serves for a (semi-)automatic TFHE parameter generation.
TODO add link to whitepaper.
Read more in our [whitepaper](./assets/abstract.pdf).
**Requirements**: `rust` compiler, `ruby` interpreter, `gnuplot`, recommended OS is Ubuntu 20.04 or similar.
## Provide Input Parameters
## Gather & Setup Input Parameters
Depending on the target application of TFHE, three input parameters must be provided to our tool:
......@@ -15,6 +15,8 @@ Depending on the target application of TFHE, three input parameters must be prov
- cleartext space bit-precision $\pi$, and
- parameterized bound on the number of homomorphic addition/scalar multiplication operations before the sample gets bootstrapped, denoted by $2^{2\Delta}$.
These, and a couple of other parameters, can be set up in [`setup.yaml`](./setup.yaml), which can be initialized as a copy of [`setup.yaml.template`](./setup.yaml.template).
### Security Level $\lambda$
......@@ -24,12 +26,12 @@ $$ -\log(\alpha) \approx s_\lambda n $$
E.g., for $\lambda = 128$, the estimated value is $s_\lambda = 0.0235$.
The pair of constants $(\lambda, s_\lambda)$ shall be accomodated in the `LAMBDA_S_LAMBDAs` constant in `src/constants_param_ranges.rs`.
The pair of constants $(\lambda, s_\lambda)$ shall be set in the `lambda_s_lambdas` field of [`setup.yaml`](./setup.yaml).
### Cleartext Bit-Precision $\pi$
The desired bit-size the cleartext space shall be indicated in the first field in the `PI_POW_2DELTAs` constant in `src/constants_param_ranges.rs`.
The desired bit-size the cleartext space shall be given as the first element in the `pi_pow_2deltas` field of [`setup.yaml`](./setup.yaml).
### Homomorphic Operations Bound
......@@ -40,26 +42,32 @@ $$ 2^{2\Delta} = \sum w_i^2 $$
where $w_i$ are respective integer weights of a homomorphic sum $\sum w_i c_i$ of samples $c_i$.
The parameter $2^{2\Delta}$ shall be given in the second field in the `PI_POW_2DELTAs` constant in `src/constants_param_ranges.rs`.
The parameter $2^{2\Delta}$ shall be given as the second element in the `pi_pow_2deltas` field of [`setup.yaml`](./setup.yaml).
## Generate the Params!
Now it's time to run the generation tool with
Other experiment parameters can be set in `setup.yaml` (number of runs, number of top parameter sets considered; explained in the whitepaper).
In the search mode, run the generation tool with
$ make run-numerical
The results are written into the folder `results-noises_numerical` (TODO might be needed to be created manually before running the tool) into a YAML file `results_lambda-<lambda>_pi-<pi>_qw-<2^2Delta>.yaml`.
In this file, several parameters are identified (with the default setting).
In the manual mode, provide your parameters in the `MAN_PARAMS` constant in [`src/manual_params.rs`](.src/manual_params.rs) and run the generation tool with
$ make run-manual
The results are written into the folder [`results-noises_numerical`](./results-noises_numerical) (TODO might be needed to be created manually before running the tool) into a YAML file `results_lambda-<lambda>_pi-<pi>_qw-<2^2Delta>.yaml`, where the parameter sets are sorted by the expected time from the fastest.
In this file, many parameters are written (self-explanatory).
## Process Results
To visualize the parameters obtained, navigate to `scripts/process-results` and run
To visualize the parameters obtained, navigate to [`scripts/process-results`](./scripts/process-results) and run
$ ./process-results.rb <lambda> <pi> <2^2Delta> <mode: n|m (numerical | manual)>
The results can be found in the `out_numerical` folder.
The results can be found in the [`out_numerical`](./scripts/process-results/out_numerical) folder.
### How It Looks
......@@ -67,4 +75,4 @@ The results can be found in the `out_numerical` folder.
In the resulting graph, one can find the best parameters of her/his choice!
N.b., an important parameter denoted by $\eta$ expresses the percentage of the maximum error bound consumed by $3\sigma$ of the noise.
![results](assets/results.png)
![results](./assets/results.png)
......@@ -339,3 +339,73 @@ pub const MAN_PARAMS: [[Params; 3]; 4] = [
// 80-bit, pi = 2, qw = 3 (for ternary gates in binary TFHE)
//~ [
//~ ],
//~ /// Trivial Paramter Set
//~ #[allow(dead_code)]
//~ pub const PARMXX__TRIVIAL: Params = Params {
//~ lambda: 5,
//~ s_lambda: 0.42, // 112: 0.0275; 80: 0.0380; 128: 0.0235
//~ bit_precision: 2,
//~ quad_weight: 2,
//~ lwe_params: LWEParams {
//~ dimension: 64,
//~ log2_std_dev: -8,
//~ },
//~ rlwe_params: RLWEParams {
//~ polynomial_size: 256,
//~ dimension: 1,
//~ log2_std_dev: -10,
//~ },
//~ bs_base_log: 2,
//~ bs_level: 2,
//~ ks_base_log: 1,
//~ ks_level: 3,
//~ v0_corr: 0.0,
//~ };
//~ /// TFHE Parameter Set A (90-bit security)
//~ #[allow(dead_code)]
//~ pub const PARM90__PI_2__D_02__A: Params = Params {
//~ lambda: 90,
//~ s_lambda: 0.42, // 112: 0.0275; 80: 0.0380; 128: 0.0235
//~ bit_precision: 3, // other params correspond with pi = 2, one more bit is needed to simulate logic operations, which work with halves
//~ quad_weight: 2,
//~ lwe_params: LWEParams {
//~ dimension: 400,
//~ log2_std_dev: -13, // -13.31,
//~ },
//~ rlwe_params: RLWEParams {
//~ polynomial_size: 1024,
//~ dimension: 1,
//~ log2_std_dev: -31, // -31.20,
//~ },
//~ bs_base_log: 15,
//~ bs_level: 1,
//~ ks_base_log: 1,
//~ ks_level: 11,
//~ v0_corr: 0.0,
//~ };
//~ /// TFHE Parameter Set B (90-bit security)
//~ #[allow(dead_code)]
//~ pub const PARM90__PI_2__D_03__B: Params = Params {
//~ lambda: 90,
//~ s_lambda: 0.42, // 112: 0.0275; 80: 0.0380; 128: 0.0235
//~ bit_precision: 3, // other params correspond with pi = 2, one more bit is needed to simulate logic operations, which work with halves
//~ quad_weight: 3,
//~ lwe_params: LWEParams {
//~ dimension: 420,
//~ log2_std_dev: -13, // -13.61,
//~ },
//~ rlwe_params: RLWEParams {
//~ polynomial_size: 1024,
//~ dimension: 1,
//~ log2_std_dev: -32, // -32.53,
//~ },
//~ bs_base_log: 16,
//~ bs_level: 1,
//~ ks_base_log: 1,
//~ ks_level: 11,
//~ v0_corr: 0.0,
//~ };
......@@ -36,26 +36,6 @@ pub struct Params {
impl Params {
// sample output in YAML:
//
// ---
// - :lambda: 90
// :pi: 2
// :_2Delta: 3
// :xy:
// - 1
// - 3
// :abcd:
// - 2
// - 1
// - 3
// - 2
// :N: 1024
// - :lambda: 90
// :pi: 2
// :_2Delta: 3
// ...
pub fn to_yaml(&self, lvl: usize) -> String {
let ind = " ".repeat(lvl);
format!("{}:lambda: {}\n{}:pi: {}\n{}:_2Delta: {}\n{}:N: {}\n{}:n: {}\n{}:k: {}\n{}:gamma: {}\n{}:l: {}\n{}:kappa: {}\n{}:t: {}\n{}:logAKSn: {}\n{}:logABKnn: {}\n{}:v0_corr: {}", // - :lambda_in: {}\n ... \n :est_lambda: {}
......@@ -243,76 +223,3 @@ impl fmt::Debug for Params {
)
}
}
// =============================================================================
/// Trivial Paramter Set
#[allow(dead_code)]
pub const PARMXX__TRIVIAL: Params = Params {
lambda: 5,
s_lambda: 0.42, // 112: 0.0275; 80: 0.0380; 128: 0.0235
bit_precision: 2,
quad_weight: 2,
lwe_params: LWEParams {
dimension: 64,
log2_std_dev: -8,
},
rlwe_params: RLWEParams {
polynomial_size: 256,
dimension: 1,
log2_std_dev: -10,
},
bs_base_log: 2,
bs_level: 2,
ks_base_log: 1,
ks_level: 3,
v0_corr: 0.0,
};
/// TFHE Parameter Set A (90-bit security)
#[allow(dead_code)]
pub const PARM90__PI_2__D_02__A: Params = Params {
lambda: 90,
s_lambda: 0.42, // 112: 0.0275; 80: 0.0380; 128: 0.0235
bit_precision: 3, // other params correspond with pi = 2, one more bit is needed to simulate logic operations, which work with halves
quad_weight: 2,
lwe_params: LWEParams {
dimension: 400,
log2_std_dev: -13, // -13.31,
},
rlwe_params: RLWEParams {
polynomial_size: 1024,
dimension: 1,
log2_std_dev: -31, // -31.20,
},
bs_base_log: 15,
bs_level: 1,
ks_base_log: 1,
ks_level: 11,
v0_corr: 0.0,
};
/// TFHE Parameter Set B (90-bit security)
#[allow(dead_code)]
pub const PARM90__PI_2__D_03__B: Params = Params {
lambda: 90,
s_lambda: 0.42, // 112: 0.0275; 80: 0.0380; 128: 0.0235
bit_precision: 3, // other params correspond with pi = 2, one more bit is needed to simulate logic operations, which work with halves
quad_weight: 3,
lwe_params: LWEParams {
dimension: 420,
log2_std_dev: -13, // -13.61,
},
rlwe_params: RLWEParams {
polynomial_size: 1024,
dimension: 1,
log2_std_dev: -32, // -32.53,
},
bs_base_log: 16,
bs_level: 1,
ks_base_log: 1,
ks_level: 11,
v0_corr: 0.0,
};
......@@ -4,6 +4,7 @@ use crate::params::*;
pub const TORUS_SIZE_B: usize = 8;
pub const MB_TO_B: usize = 1_000_000;
//TODO enable in setup.yaml
pub const KS_KSK_RATIO: f64 = 0.37; // 80 2 3
//~ pub const KS_KSK_RATIO: f64 = 0.36; // 128 2 3
//~ pub const KS_KSK_RATIO: f64 = 0.40; // -- 5 20
......@@ -26,6 +27,7 @@ impl Params {
((self.lwe_params.dimension + 1) * self.ks_level * self.rlwe_params.polynomial_size * TORUS_SIZE_B) as f64 / MB_TO_B as f64
}
//TODO enable in setup.yaml
fn brot_bk_ratio(&self) -> f64 {
//~ // for Concrete on Argentera:
//~ match self.bs_level {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment