Skip to content

Commit

Permalink
Fix LUTs in helm.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jimouris committed Jun 5, 2023
1 parent 6aa5370 commit fd8ced0
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 218 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helm"
description = "HELM: Homomorphic Evaluation with Lookup table Memoization"
description = "HELM: Homomorphic Evaluation with EDA-driven Logic Minimization"
version = "0.1.0"
edition = "2021"
authors = ["Dimitris Mouris <[email protected]>", "Charles Gouert <[email protected]>"]
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,32 @@ git clone --recurse-submodules [email protected]:TrustworthyComputing/helm.git
```

### Build & Run

Compile and run the tests:
```shell
cargo build --release
cargo test --release
```

HELM has two modes: "gates"-mode and "LUTs"-mode. HELM automatically detects if
a LUTs or a gates circuit has been provided as input. Below are two examples:

Example in "gates"-mode:
```shell
cargo run --bin helm --release -- \
--input ./hdl-benchmarks/processed-netlists/s27.v
cargo run --bin helm --release -- \
--input ./hdl-benchmarks/processed-netlists/2-bit-adder.v \
--wires ./hdl-benchmarks/test-cases/2-bit-adder.inputs.csv
```

Example in "LUTs"-mode:
```shell
cargo run --bin helm --release -- \
--input ./hdl-benchmarks/processed-netlists/8-bit-adder-lut-3-1.v \
--wires hdl-benchmarks/test-cases/8-bit-adder.inputs.csv
```

### Example of an ISCAS'85 circuit
If a circuit is in the [netlists](./hdl-benchmarks/netlists/) directory but not
in the [processed-netlists](./hdl-benchmarks/processed-netlists/), run the
Expand Down
56 changes: 17 additions & 39 deletions src/bin/helm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@ use debug_print::debug_println;
use helm::{ascii, circuit, circuit::EvalCircuit, verilog_parser};
use std::{collections::HashMap, time::Instant};
use termion::color;
use tfhe::{
boolean::prelude::*,
integer::{
wopbs::WopbsKey as WopbsKeyInt, ClientKey as ClientKeyInt, ServerKey as ServerKeyInt,
},
shortint::{
parameters::{
parameters_wopbs_message_carry::WOPBS_PARAM_MESSAGE_1_CARRY_1,
PARAM_MESSAGE_1_CARRY_1,
PARAM_MESSAGE_3_CARRY_0,
},
wopbs::WopbsKey as WopbsKeyShortInt,
},
};
use tfhe::{boolean::prelude::*, shortint::parameters::PARAM_MESSAGE_3_CARRY_0};

fn parse_args() -> (String, usize, bool, HashMap<String, bool>) {
let matches = Command::new("HELM")
.about("HELM: Homomorphic Evaluation with Lookup table Memoization")
.about("HELM: Homomorphic Evaluation with EDA-driven Logic Minimization")
.arg(
Arg::new("input")
.long("input")
Expand Down Expand Up @@ -75,12 +62,7 @@ fn parse_args() -> (String, usize, bool, HashMap<String, bool>) {
}
};

(
file_name.to_string(),
num_cycles,
verbose,
input_wire_map,
)
(file_name.to_string(), num_cycles, verbose, input_wire_map)
}

fn main() {
Expand Down Expand Up @@ -133,6 +115,12 @@ fn main() {

// Encrypted Evaluation
if !has_luts {
println!(
"{} -- Gates mode -- {}",
color::Fg(color::LightYellow),
color::Fg(color::Reset)
);

// Gate mode
let mut start = Instant::now();
let (client_key, server_key) = gen_keys();
Expand Down Expand Up @@ -168,28 +156,18 @@ fn main() {
start.elapsed().as_secs_f64()
);
} else {
println!(
"{} -- LUTs mode -- {}",
color::Fg(color::LightYellow),
color::Fg(color::Reset)
);

// LUT mode
let mut start = Instant::now();
let (client_key_shortint, server_key_shortint) =
tfhe::shortint::gen_keys(PARAM_MESSAGE_1_CARRY_1); // single bit ctxt
let client_key = ClientKeyInt::from(client_key_shortint.clone());
let server_key = ServerKeyInt::from_shortint(&client_key, server_key_shortint.clone());
let wopbs_key_shortint = WopbsKeyShortInt::new_wopbs_key(
&client_key_shortint,
&server_key_shortint,
&&WOPBS_PARAM_MESSAGE_1_CARRY_1,
);
let wopbs_key = WopbsKeyInt::from(wopbs_key_shortint.clone());
let (client_key, server_key) = tfhe::shortint::gen_keys(PARAM_MESSAGE_3_CARRY_0); // single bit ctxt
let mut circuit = circuit::LutCircuit::new(client_key, server_key, circuit_ptxt);
println!("KeyGen done in {} seconds.", start.elapsed().as_secs_f64());

let mut circuit = circuit::HighPrecisionLutCircuit::new(
wopbs_key_shortint,
wopbs_key,
client_key.clone(),
server_key,
circuit_ptxt,
);

// Client encrypts their inputs
start = Instant::now();
let mut enc_wire_map =
Expand Down
Loading

0 comments on commit fd8ced0

Please sign in to comment.