Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(compute): testing chained operation calls with output labels #42

Merged
merged 32 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f832459
refactor(compute): testing chained operation calls with output labels
10d9e Oct 21, 2024
dc341e6
refactor(compute): make clippy happy
10d9e Oct 21, 2024
ca2628a
added single test case for build_and_execute_multiplication
10d9e Oct 22, 2024
e8f586c
Refactor circuit builder and add multi-multiplication test case
10d9e Oct 24, 2024
e0af533
feat(compute): initial implementation of circuit builder macro
10d9e Oct 25, 2024
0a141b0
feat(compute): implemented circuit macro builder
10d9e Oct 25, 2024
ba5c909
refactor(compute): cleanup
10d9e Oct 25, 2024
f2781ec
compute(feat): add unsigned multibit support to circuit macro
10d9e Oct 25, 2024
8942e5e
feat(compute): added if else builder in circuit macro
10d9e Oct 25, 2024
a35e4c6
fix(compute): removed superflous into() in input generation of macro
10d9e Oct 25, 2024
a64c080
refactor(compute): Refactor circuit builder macros
10d9e Oct 25, 2024
3fe0441
refactor(compute): Add multiplication circuit macro
10d9e Oct 25, 2024
9f22945
refactor(compute): Refactor circuit macro input generation
10d9e Oct 25, 2024
c82818d
refactor(compute): Refactor circuit macro input generation in compute…
10d9e Oct 25, 2024
9d8b07f
fix(compute): Fixed mux gate to observe only the LSB of the switch param
10d9e Oct 25, 2024
59400e2
refactor(circuit_macro): Comment out debug print statement in circuit…
10d9e Oct 25, 2024
3cc5ab9
Refactor circuit_macro to remove unnecessary cloning in circuit function
10d9e Oct 25, 2024
33d1459
feat(macro): Refactor circuit_macro to expose both compile and execut…
10d9e Oct 25, 2024
93a9630
feat(macro): Add types module to circuits; add support for multiline …
10d9e Oct 26, 2024
da90983
feat(macro): added support for returning boolean types
10d9e Oct 26, 2024
369049e
feat(macro): Refactor circuit_macro to use the updated CircuitBuilder…
10d9e Oct 27, 2024
4c5633f
Refactor circuit_macro to remove unnecessary cloning in circuit function
10d9e Oct 27, 2024
80c7fce
Refactor circuit_macro to remove unnecessary cloning in circuit function
10d9e Oct 27, 2024
bd0b22c
refactor: cleanup
10d9e Oct 27, 2024
5db4df9
make clippy happy
10d9e Oct 27, 2024
e3d3bec
cleanup
10d9e Oct 27, 2024
2101dea
cleanup
10d9e Oct 27, 2024
69d41c0
cleanup samples
10d9e Oct 27, 2024
3da0a2c
Refactor: Add clippy lints to circuit_macro
10d9e Oct 27, 2024
1d8f59a
feat(compute): add support for division and modulus
10d9e Oct 27, 2024
4009826
feat(macro): add supporting tests for division and modulus tests
10d9e Oct 27, 2024
0e00bd0
refactor: make clippy happy
10d9e Oct 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# will have compiled files and executables
debug/
target/
temp/

# These are backup files generated by rustfmt
**/*.rs.bk
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ resolver = "2"
members = [
"benchmark",
"compute",
"vm",
"vm",
"circuit_macro",
]

[workspace.package]
Expand Down
118 changes: 116 additions & 2 deletions benchmark/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,90 @@ fn gateway_encrypted_le() -> Result<(), Box<dyn ::std::error::Error>> {
Ok(())
}

fn tfhe_encrypted_division() -> Result<(), Box<dyn ::std::error::Error>> {
use tfhe::prelude::*;
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint128};
// Basic configuration to use homomorphic integers
let config = ConfigBuilder::default().build();

// Key generation
let (client_key, server_keys) = generate_keys(config);

let clear_a = 12345678910u128;
let clear_b = 1234;

// Encrypting the input data using the (private) client_key
let encrypted_a = FheUint128::try_encrypt(clear_a, &client_key).unwrap();
let encrypted_b = FheUint128::try_encrypt(clear_b, &client_key).unwrap();

// On the server side:
set_server_key(server_keys);

// Clear equivalent computations: 12345678910 * 1234
let encrypted_res_mul = &encrypted_a / &encrypted_b;

let clear_res: u128 = encrypted_res_mul.decrypt(&client_key);
assert_eq!(clear_res, clear_a / clear_b);

Ok(())
}

fn gateway_encrypted_division() -> Result<(), Box<dyn ::std::error::Error>> {
use compute::uint::GarbledUint128;

let clear_a = 12345678910u128;
let clear_b = 1234;

let a: GarbledUint128 = clear_a.into();
let b: GarbledUint128 = clear_b.into();

let result: u128 = (&a / &b).into();
assert_eq!(result, clear_a / clear_b);
Ok(())
}

fn tfhe_encrypted_modulus() -> Result<(), Box<dyn std::error::Error>> {
use tfhe::prelude::*;
use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheUint128};
// Basic configuration to use homomorphic integers
let config = ConfigBuilder::default().build();

// Key generation
let (client_key, server_keys) = generate_keys(config);

let clear_a = 12345678910u128;
let clear_b = 1234;

// Encrypting the input data using the (private) client_key
let encrypted_a = FheUint128::try_encrypt(clear_a, &client_key).unwrap();
let encrypted_b = FheUint128::try_encrypt(clear_b, &client_key).unwrap();

// On the server side:
set_server_key(server_keys);

// Clear equivalent computations: 12345678910 * 1234
let encrypted_res_mul = &encrypted_a % &encrypted_b;

let clear_res: u128 = encrypted_res_mul.decrypt(&client_key);
assert_eq!(clear_res, clear_a % clear_b);

Ok(())
}

fn gateway_encrypted_modulus() -> Result<(), Box<dyn ::std::error::Error>> {
use compute::uint::GarbledUint128;

let clear_a = 12345678910u128;
let clear_b = 1234;

let a: GarbledUint128 = clear_a.into();
let b: GarbledUint128 = clear_b.into();

let result: u128 = (&a % &b).into();
assert_eq!(result, clear_a % clear_b);
Ok(())
}

fn tfhe_encrypted_mux() {
use tfhe::boolean::prelude::*;
// We generate a set of client/server keys, using the default parameters:
Expand Down Expand Up @@ -711,7 +795,7 @@ fn gateway_encrypted_mux() {
let b: GarbledBoolean = bool2.into();
let c: GarbledBoolean = bool3.into();

let result = a.mux(&b, &c);
let result = GarbledBoolean::mux(&a, &b, &c);
let result: bool = result.into();
assert_eq!(result, if bool1 { bool2 } else { bool3 });
}
Expand Down Expand Up @@ -914,6 +998,32 @@ fn benchmark_tfhe_encrypted_mux(c: &mut Criterion) {
c.bench_function("tfhe_encrypted_mux", |b| b.iter(tfhe_encrypted_mux));
}

// Benchmark 35: Benchmarking benchmark_gateway_encrypted_division
fn benchmark_gateway_encrypted_division(c: &mut Criterion) {
c.bench_function("gateway_encrypted_division", |b| {
b.iter(gateway_encrypted_division)
});
}

// Benchmark 36: Benchmarking benchmark_tfhe_encrypted_division
fn benchmark_tfhe_encrypted_division(c: &mut Criterion) {
c.bench_function("tfhe_encrypted_division", |b| {
b.iter(tfhe_encrypted_division)
});
}

// Benchmark 37: Benchmarking benchmark_gateway_encrypted_modulus
fn benchmark_gateway_encrypted_modulus(c: &mut Criterion) {
c.bench_function("gateway_encrypted_modulus", |b| {
b.iter(gateway_encrypted_modulus)
});
}

// Benchmark 38: Benchmarking benchmark_tfhe_encrypted_modulus
fn benchmark_tfhe_encrypted_modulus(c: &mut Criterion) {
c.bench_function("tfhe_encrypted_modulus", |b| b.iter(tfhe_encrypted_modulus));
}

// Configure Criterion with a sample size of 10
fn custom_criterion() -> Criterion {
Criterion::default().sample_size(10)
Expand All @@ -924,9 +1034,13 @@ criterion_group!(
name = benches;
config = custom_criterion();
targets =
benchmark_gateway_encrypted_division,
benchmark_tfhe_encrypted_division,
benchmark_gateway_encrypted_modulus,
benchmark_tfhe_encrypted_modulus,

benchmark_gateway_encrypted_mux,
benchmark_tfhe_encrypted_mux,

benchmark_gateway_encrypted_addition,
benchmark_tfhe_encrypted_addition,
benchmark_gateway_encrypted_subtraction,
Expand Down
1 change: 1 addition & 0 deletions circuit_macro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
12 changes: 12 additions & 0 deletions circuit_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "circuit_macro"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
proc-macro2 = "1.0"
Loading