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

Added SEAL library and FHE mode #41

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8f15540
Added SEAL library and FHE mode
seoyunsoo Jan 7, 2022
83f34b2
Made changes suggested by Alex
seoyunsoo Jan 14, 2022
e7cc59d
Made new fhe folder in src/target
seoyunsoo Jan 17, 2022
f644be0
Implemented the generation of the code for initializing SEAL paramete…
seoyunsoo Jan 27, 2022
cfc2235
fhe and, or, xor test cases
seoyunsoo Feb 3, 2022
ea4b7ed
Added Map operation to IR
seoyunsoo Feb 16, 2022
3c59444
Map Operation changed indices to bitvectors
seoyunsoo Feb 21, 2022
1cb736f
Merged with main
seoyunsoo Feb 21, 2022
0404c6e
Implemented typechecking for Map IR
seoyunsoo Feb 25, 2022
248d746
Updated backend to support SEAL interpreter
seoyunsoo Mar 25, 2022
a66a508
Fixed Merge Conflicts
seoyunsoo Mar 25, 2022
eb79606
Removed extraneous code
seoyunsoo Mar 25, 2022
3c3f203
Fixed linting issue
seoyunsoo Mar 25, 2022
2159c20
Added building/testing for FHE backend
seoyunsoo Mar 31, 2022
cb53d1a
Deleted extraneous content. Fixed a bug
seoyunsoo Mar 31, 2022
d30b3d4
Changed build script and ci.yml
seoyunsoo Mar 31, 2022
f127d5d
changed ci.yml
seoyunsoo Mar 31, 2022
308bcbc
changed ci.yml again
seoyunsoo Mar 31, 2022
5b1ac71
changed ci.yml again again
seoyunsoo Mar 31, 2022
d55e5a5
fixed bug in driver
seoyunsoo Mar 31, 2022
fdb91e7
fixed test inputs
seoyunsoo Mar 31, 2022
277c2c0
Merge branch 'master' into fhe
edwjchen Apr 19, 2022
afd8bf2
Added support for addition, multiplication, and simple vectorized ope…
seoyunsoo Apr 26, 2022
cdc2ea8
Merge branch 'fhe' of wys.github.com:circify/circ into fhe
seoyunsoo Apr 26, 2022
6c590db
Fixed linting issue
seoyunsoo Apr 26, 2022
94b65fd
Cleaned up directory, changed test names
seoyunsoo Apr 27, 2022
18b4112
Added test case generation for testing batched vs naive
seoyunsoo Sep 30, 2022
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
env:
CARGO_TERM_COLOR: always
ABY_SOURCE: "./../ABY"
SEAL_SOURCE: "./../SEAL"

jobs:
build:
Expand All @@ -31,7 +32,9 @@ jobs:
- name: Cache third_party build
uses: actions/cache@v2
with:
path: ${ABY_SOURCE}/build
path: |
${ABY_SOURCE}/build
${SEAL_SOURCE}/build
key: ${{ runner.os }}
- name: Check
run: python3 driver.py --check
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
Northrim marked this conversation as resolved.
Show resolved Hide resolved
Northrim marked this conversation as resolved.
Show resolved Hide resolved
"cmake.configureOnOpen": false
}
63 changes: 56 additions & 7 deletions Cargo.lock

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

18 changes: 17 additions & 1 deletion driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def verify_path_empty(path) -> bool:
if verify_path_empty(ABY_SOURCE):
subprocess.run(["git", "clone", "https://github.com/edwjchen/ABY.git", ABY_SOURCE])
subprocess.run(["./scripts/build_aby.zsh"])
if f == "seal":
if verify_path_empty(SEAL_SOURCE):
subprocess.run(["git", "clone", "https://github.com/Northrim/SEAL.git", SEAL_SOURCE])
subprocess.run(["./scripts/build_seal.zsh"])

# install python requirements
subprocess.run(["pip3", "install", "-r", "requirements.txt"])
Expand Down Expand Up @@ -76,6 +80,12 @@ def build(features):
if "smt" in features and "zok" in features:
subprocess.run(["./scripts/build_mpc_zokrates_test.zsh"], check=True)
subprocess.run(["./scripts/build_aby.zsh"], check=True)
if "seal" in features:
if "c" in features:
subprocess.run(["./scripts/build_fhe_c_test.zsh"], check=True)
if "smt" in features and "zok" in features:
subprocess.run(["./scripts/build_fhe_zokrates_test.zsh"], check=True)
subprocess.run(["./scripts/build_seal.zsh"], check=True)

def test(features):
"""
Expand All @@ -101,6 +111,8 @@ def test(features):
if "zok" in features and "smt" in features:
if "aby" in features:
subprocess.run(["python3", "./scripts/aby_tests/zokrates_test_aby.py"], check=True)
if "seal" in features:
subprocess.run(["python3", "./scripts/seal_tests/zokrates_test_seal.py"], check=True)
if "lp" in features:
subprocess.run(["./scripts/test_zok_to_ilp.zsh"], check=True)
if "r1cs" in features:
Expand All @@ -111,6 +123,8 @@ def test(features):
if "c" in features:
if "aby" in features:
subprocess.run(["python3", "./scripts/aby_tests/c_test_aby.py"], check=True)
if "seal" in features:
subprocess.run(["python3", "./scripts/seal_tests/c_test_seal.py"], check=True)

def benchmark(features):
mode = load_mode()
Expand Down Expand Up @@ -165,6 +179,8 @@ def clean(features):
print("cleaning!")
if "aby" in features:
subprocess.run(["./scripts/clean_aby.zsh"])
if "seal" in features:
subprocess.run(["./scripts/clean_seal.zsh"])
subprocess.run(["rm", "-rf", "scripts/aby_tests/__pycache__"])
subprocess.run(["rm", "-rf", "P", "V", "pi", "perf.data perf.data.old flamegraph.svg"])

Expand Down Expand Up @@ -210,7 +226,7 @@ def verify_feature(f):
parser.add_argument("-m", "--mode", type=str, help="set `debug` or `release` mode")
parser.add_argument("-A", "--all_features", action="store_true", help="set all features on")
parser.add_argument("-L", "--list_features", action="store_true", help="print active features")
parser.add_argument("-F", "--features", nargs="+", help="set features on <aby, c, lp, r1cs, smt, zok>, reset features with -F none")
parser.add_argument("-F", "--features", nargs="+", help="set features on <aby, c, lp, r1cs, seal, smt, zok>, reset features with -F none")
parser.add_argument("--benchmark", action="store_true", help="build benchmarks")
parser.add_argument("extra", metavar="PASS_THROUGH_ARGS", nargs=argparse.REMAINDER, help="Extra arguments for --flamegraph. Prefix with --")
args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions examples/C/fhe/unit_tests/arithmetic_tests/add.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b) {
return a + b;
}
3 changes: 3 additions & 0 deletions examples/C/fhe/unit_tests/arithmetic_tests/mult.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b) {
return a * b;
}
3 changes: 3 additions & 0 deletions examples/C/fhe/unit_tests/arithmetic_tests/mult_add_pub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b, __attribute__((public)) int v) {
return a * b + v;
}
5 changes: 5 additions & 0 deletions examples/C/fhe/unit_tests/boolean_tests/boolean_and.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdbool.h>

bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b) {
return a && b;
}
5 changes: 5 additions & 0 deletions examples/C/fhe/unit_tests/boolean_tests/boolean_equals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdbool.h>

bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b) {
return a == b;
}
5 changes: 5 additions & 0 deletions examples/C/fhe/unit_tests/boolean_tests/boolean_or.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdbool.h>

bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b) {
return a || b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b, __attribute__((private(1))) int c) {
return a + b + c;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdbool.h>

bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b, __attribute__((private(1))) bool c) {
return a && b && c;
}
2 changes: 2 additions & 0 deletions examples/ZoKrates/fhe/unit_tests/arithmetic_tests/add.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private u32 a, private u32 b) -> u32:
return a + b
2 changes: 2 additions & 0 deletions examples/ZoKrates/fhe/unit_tests/arithmetic_tests/mult.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private u32 a, private u32 b) -> u32:
return a * b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def main(private u32 a, private u32 b, public u32 v) -> u32:
return a * b + v
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private bool a, private bool b) -> bool:
return a && b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private bool a, private bool b) -> bool:
return a == b
2 changes: 2 additions & 0 deletions examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_or.zok
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private bool a, private bool b) -> bool:
return a || b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private u32 a, private u32 b, private u32 c) -> u32:
return a + b + c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def main(private bool a, private bool b, private bool c) -> bool:
return a && b && c
13 changes: 13 additions & 0 deletions examples/circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use circ::ir::{
term::extras::Letified,
};
use circ::target::aby::trans::to_aby;
use circ::target::fhe::trans::to_fhe;
#[cfg(feature = "lp")]
use circ::target::ilp::trans::to_ilp;
#[cfg(feature = "r1cs")]
Expand Down Expand Up @@ -101,6 +102,7 @@ enum Backend {
},
Smt {},
Ilp {},
Fhe {},
Mpc {
#[structopt(long, default_value = "hycc", name = "cost_model")]
cost_model: String,
Expand Down Expand Up @@ -187,6 +189,7 @@ fn main() {
Backend::Ilp { .. } => Mode::Opt,
Backend::Mpc { .. } => Mode::Mpc(options.parties),
Backend::Smt { .. } => Mode::Proof,
Backend::Fhe { .. } => Mode::Fhe,
};
let language = determine_language(&options.frontend.language, &options.path);
let cs = match language {
Expand Down Expand Up @@ -246,6 +249,7 @@ fn main() {
],
// vec![Opt::Sha, Opt::ConstantFold, Opt::Mem, Opt::ConstantFold],
),
Mode::Fhe => opt(cs, vec![Opt::ConstantFold]),
Mode::Proof | Mode::ProofOfHighValue(_) => opt(
cs,
vec![
Expand Down Expand Up @@ -384,6 +388,15 @@ fn main() {
todo!()
}
}
Backend::Fhe { .. } => {
println!("Converting to fhe");
let lang_str = match language {
DeterminedLanguage::C => "c".to_string(),
DeterminedLanguage::Zsharp => "zok".to_string(),
_ => panic!("Language isn't supported by FHE backend: {:#?}", language),
};
to_fhe(cs, &path_buf, &lang_str);
}
#[cfg(not(feature = "smt"))]
Backend::Smt { .. } => {
panic!("Missing feature: smt");
Expand Down
40 changes: 40 additions & 0 deletions scripts/build_fhe_c_test.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env zsh

set -ex

disable -r time

# cargo build --release --features c --example circ

BIN=./target/release/examples/circ
export CARGO_MANIFEST_DIR=$(pwd)

case "$OSTYPE" in
darwin*)
alias measure_time="gtime --format='%e seconds %M kB'"
;;
linux*)
alias measure_time="time --format='%e seconds %M kB'"
;;
esac

function fhe_test {
cpath=$1
RUST_BACKTRACE=1 measure_time $BIN $cpath fhe
}

# build boolean tests
fhe_test ./examples/C/fhe/unit_tests/boolean_tests/boolean_and.c
fhe_test ./examples/C/fhe/unit_tests/boolean_tests/boolean_or.c
fhe_test ./examples/C/fhe/unit_tests/boolean_tests/boolean_equals.c

# build nary boolean tests
fhe_test ./examples/C/fhe/unit_tests/nary_boolean_tests/nary_boolean_and.c

# build arithmetic tests
fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/add.c
fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/mult.c
fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/mult_add_pub.c

# build nary arithmetic tests
fhe_test ./examples/C/fhe/unit_tests/nary_arithmetic_tests/nary_arithmetic_add.c
Loading