From 8f15540509918923326dfbb1fb57f9531715c9e0 Mon Sep 17 00:00:00 2001 From: William Seo Date: Fri, 7 Jan 2022 23:04:47 +0000 Subject: [PATCH 01/21] Added SEAL library and FHE mode --- .gitmodules | 3 +++ examples/circ.rs | 6 ++++++ src/front/zokrates/mod.rs | 15 ++++++++++++++- third_party/SEAL | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) create mode 160000 third_party/SEAL diff --git a/.gitmodules b/.gitmodules index baae91ffd..3a2758e60 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "third_party/ABY"] path = third_party/ABY url = https://github.com/edwjchen/ABY.git +[submodule "third_party/SEAL"] + path = third_party/SEAL + url = git@github.com:microsoft/SEAL.git diff --git a/examples/circ.rs b/examples/circ.rs index 77651c41d..7a43be8c7 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -87,6 +87,7 @@ enum Backend { Smt {}, Ilp {}, Mpc {}, + Fhe {}, } arg_enum! { @@ -156,6 +157,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 { @@ -178,6 +180,7 @@ fn main() { }; let cs = match mode { Mode::Opt => opt(cs, vec![Opt::ScalarizeVars, Opt::ConstantFold]), + Mode::Fhe => opt(cs, vec![]), Mode::Mpc(_) => opt( cs, vec![Opt::ScalarizeVars], @@ -300,5 +303,8 @@ fn main() { todo!() } } + Backend::Fhe { .. } => { + todo!() + } } } diff --git a/src/front/zokrates/mod.rs b/src/front/zokrates/mod.rs index b27725c9f..588882dc1 100644 --- a/src/front/zokrates/mod.rs +++ b/src/front/zokrates/mod.rs @@ -54,6 +54,8 @@ pub struct Inputs { pub enum Mode { /// Generating an MPC circuit. Inputs are public or private (to a party in 1..N). Mpc(u8), + /// Generating an FHE circuit using the SEAL library. + Fhe, /// Generating for a proof circuit. Inputs are public of private (to the prover). Proof, /// Generating for an optimization circuit. Inputs are existentially quantified. @@ -71,6 +73,7 @@ impl Display for Mode { &Mode::Proof => write!(f, "proof"), &Mode::Opt => write!(f, "opt"), &Mode::ProofOfHighValue(v) => write!(f, "proof_of_high_value({})", v), + &Mode::Fhe => write!(f, "fhe"), } } } @@ -520,6 +523,16 @@ impl<'ast> ZGen<'ast> { }; self.circ.cir_ctx().cs.borrow_mut().outputs.push(cmp); } + Mode::Fhe => { + let ret_term = r.unwrap_term(); + let ret_terms = ret_term.terms(); + self.circ + .cir_ctx() + .cs + .borrow_mut() + .outputs + .extend(ret_terms); + } } } } @@ -527,7 +540,7 @@ impl<'ast> ZGen<'ast> { match visibility { None | Some(ast::Visibility::Public(_)) => PUBLIC_VIS.clone(), Some(ast::Visibility::Private(private)) => match self.mode { - Mode::Proof | Mode::Opt | Mode::ProofOfHighValue(_) => { + Mode::Fhe | Mode::Proof | Mode::Opt | Mode::ProofOfHighValue(_) => { if private.number.is_some() { self.err( format!( diff --git a/third_party/SEAL b/third_party/SEAL new file mode 160000 index 000000000..88bbc51dd --- /dev/null +++ b/third_party/SEAL @@ -0,0 +1 @@ +Subproject commit 88bbc51dd684b82a781312ff04abd235c060163e From 83f34b2bf661d19adb37df18805a27e13dec8344 Mon Sep 17 00:00:00 2001 From: William Seo Date: Fri, 14 Jan 2022 00:25:00 +0000 Subject: [PATCH 02/21] Made changes suggested by Alex --- .gitmodules | 2 +- examples/circ.rs | 3 +-- src/front/zokrates/mod.rs | 12 +----------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/.gitmodules b/.gitmodules index 3a2758e60..a1c157083 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,4 @@ url = https://github.com/edwjchen/ABY.git [submodule "third_party/SEAL"] path = third_party/SEAL - url = git@github.com:microsoft/SEAL.git + url = https://github.com/microsoft/SEAL.git diff --git a/examples/circ.rs b/examples/circ.rs index 7a43be8c7..7b7b6abf7 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -180,8 +180,7 @@ fn main() { }; let cs = match mode { Mode::Opt => opt(cs, vec![Opt::ScalarizeVars, Opt::ConstantFold]), - Mode::Fhe => opt(cs, vec![]), - Mode::Mpc(_) => opt( + Mode::Mpc(_) | Mode::Fhe => opt( cs, vec![Opt::ScalarizeVars], // vec![Opt::Sha, Opt::ConstantFold, Opt::Mem, Opt::ConstantFold], diff --git a/src/front/zokrates/mod.rs b/src/front/zokrates/mod.rs index 588882dc1..6f3741106 100644 --- a/src/front/zokrates/mod.rs +++ b/src/front/zokrates/mod.rs @@ -477,7 +477,7 @@ impl<'ast> ZGen<'ast> { } if let Some(r) = self.circ.exit_fn() { match self.mode { - Mode::Mpc(_) => { + Mode::Mpc(_) | Mode::Fhe => { let ret_term = r.unwrap_term(); let ret_terms = ret_term.terms(); self.circ @@ -523,16 +523,6 @@ impl<'ast> ZGen<'ast> { }; self.circ.cir_ctx().cs.borrow_mut().outputs.push(cmp); } - Mode::Fhe => { - let ret_term = r.unwrap_term(); - let ret_terms = ret_term.terms(); - self.circ - .cir_ctx() - .cs - .borrow_mut() - .outputs - .extend(ret_terms); - } } } } From e7cc59d676c839f79ba22cdf25b74b65a5f7bc20 Mon Sep 17 00:00:00 2001 From: William Seo Date: Mon, 17 Jan 2022 17:39:13 +0000 Subject: [PATCH 03/21] Made new fhe folder in src/target --- examples/circ.rs | 4 +- src/target/fhe/mod.rs | 31 ++++++++++ src/target/fhe/trans.rs | 125 ++++++++++++++++++++++++++++++++++++++++ src/target/mod.rs | 1 + 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/target/fhe/mod.rs create mode 100644 src/target/fhe/trans.rs diff --git a/examples/circ.rs b/examples/circ.rs index 7b7b6abf7..8ab739cb6 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -303,7 +303,9 @@ fn main() { } } Backend::Fhe { .. } => { - todo!() + println!("Converting to fhe"); + let fhe = to_fhe(cs); + write_fhe_exec(fhe, path_buf); } } } diff --git a/src/target/fhe/mod.rs b/src/target/fhe/mod.rs new file mode 100644 index 000000000..f672b6485 --- /dev/null +++ b/src/target/fhe/mod.rs @@ -0,0 +1,31 @@ +//! FHE +pub mod trans; + +#[derive(Clone, Debug)] +/// ABY Circuit +/// The ABY Circuit consists of three Vec: setup, circ, and closer +/// *setup* holds code for initializing the ABY party, sharing scheme, and input values +/// *circs* holds the lowered code from the IR to ABY Circuits +/// *output* holds the code for printing the output value +pub struct FHE { + setup: Vec, + circs: Vec, + output: Vec, +} + +impl Default for FHE { + fn default() -> Self { + Self::new() + } +} + +impl FHE { + /// Initialize FHE circuit + pub fn new() -> Self { + FHE { + setup: Vec::new(), + circs: Vec::new(), + output: Vec::new(), + } + } +} \ No newline at end of file diff --git a/src/target/fhe/trans.rs b/src/target/fhe/trans.rs new file mode 100644 index 000000000..04fe25e30 --- /dev/null +++ b/src/target/fhe/trans.rs @@ -0,0 +1,125 @@ +//! Lowering IR to FHE + +use crate::ir::term::*; +use crate::target::fhe::*; + +#[derive(Clone)] +enum EmbeddedTerm { + Bool(String), + Bv(String), +} + +struct ToFHE { + fhe: FHE, + md: ComputationMetadata, + inputs: TermMap>, + cache: TermMap, +} + +impl ToFHE { + fn new(metadata: ComputationMetadata) -> Self { + Self { + fhe: FHE::new(), + md: metadata, + inputs: TermMap::new(), + cache: TermMap::new(), + } + } + + ///Initialize ciphertext and plaintext inputs + fn init_inputs(&mut self) { + // let mut ciphtertext_inputs = TermSet::new(); + // let mut plaintext_inputs = TermSet::new(); + todo!(); + } + + /// Given term `t`, type-check `t` is of type Bool and return the variable name for + /// `t` + fn get_bool(&self, t: &Term) -> String { + match self + .cache + .get(t) + .unwrap_or_else(|| panic!("Missing wire for {:?}", t)) + { + EmbeddedTerm::Bool(b) => b.clone(), + _ => panic!("Non-bool for {:?}", t), + } + } + + fn embed_bool(&mut self, t: Term) -> String { + //TODO Matching stuff + self.get_bool(&t) + } + + /// Given term `t`, type-check `t` is of type Bv and return the variable name for + /// `t` + fn get_bv(&self, t: &Term) -> String { + match self + .cache + .get(t) + .unwrap_or_else(|| panic!("Missing wire for {:?}", t)) + { + EmbeddedTerm::Bv(b) => b.clone(), + _ => panic!("Non-bv for {:?}", t), + } + } + + fn embed_bv(&mut self, t: Term) -> String { + //TODO Matching Stuff + self.get_bv(&t) + } + + fn format_output_circuit(&self, circ: String) -> String { + format!( + "TODO: {} \n", + circ + ) + } + + fn embed(&mut self, t: Term) -> String { + let mut circ = String::new(); + for c in PostOrderIter::new(t.clone()){ + println!("Embedding: {:?}", c); + match check(&c) { + Sort::Bool => { + circ = self.embed_bool(c); + } + Sort::BitVector(_) => { + circ = self.embed_bv(c); + } + e => panic!("Unsupported sort in embed: {:?}", e), + } + } + self.format_output_circuit(circ) + } + + /// Given a term `t`, lower `t` to FHE Circuits + fn lower(&mut self, t: Term) { + let circ = self.embed(t); + self.fhe.circs.push(circ); + } +} + +/// Convert this (IR) `ir` to FHE. +pub fn to_aby(ir: Computation) -> FHE { + let Computation { + outputs: terms, + metadata: md, + values: _, + } = ir.clone(); + + let mut converter = ToFHE::new(md); + + for t in terms { + println!("Terms: {}", t); + converter.lower(t.clone()); + } + + // Iterating and lowering the terms populates self.inputs, which + // are the input parameters for the FHE circuit. + // Call init_inputs here after self.inputs is populated. + converter.init_inputs(); + + converter.fhe + +} \ No newline at end of file diff --git a/src/target/mod.rs b/src/target/mod.rs index 824bf6bb4..75fd7244e 100644 --- a/src/target/mod.rs +++ b/src/target/mod.rs @@ -4,3 +4,4 @@ pub mod aby; pub mod ilp; pub mod r1cs; pub mod smt; +pub mod fhe; \ No newline at end of file From f644be097d8427aad02d03b08d5bcb5a5e74a258 Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 27 Jan 2022 22:46:30 +0000 Subject: [PATCH 04/21] Implemented the generation of the code for initializing SEAL parameters, encryption, making the server function call, decryption. --- .../fhe/unit_tests/boolean_tests/fhe_and.zok | 2 + examples/circ.rs | 5 +- scripts/build_fhe_zokrates.zsh | 26 +++ src/front/zokrates/mod.rs | 2 +- src/ir/term/mod.rs | 3 + src/target/fhe/mod.rs | 39 +++- src/target/fhe/output.rs | 64 +++++++ src/target/fhe/trans.rs | 169 +++++++++++++++++- third_party/SEAL_templates/cpp_template.txt | 22 +++ 9 files changed, 313 insertions(+), 19 deletions(-) create mode 100644 examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok create mode 100755 scripts/build_fhe_zokrates.zsh create mode 100644 src/target/fhe/output.rs create mode 100644 third_party/SEAL_templates/cpp_template.txt diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok new file mode 100644 index 000000000..9c34cea90 --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok @@ -0,0 +1,2 @@ +def main(private bool a, bool b) -> bool: + return a \ No newline at end of file diff --git a/examples/circ.rs b/examples/circ.rs index 8ab739cb6..aa60b4d25 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -14,7 +14,9 @@ use circ::ir::{ term::extras::Letified, }; use circ::target::aby::output::write_aby_exec; +use circ::target::fhe::output::write_fhe_exec; use circ::target::aby::trans::to_aby; +use circ::target::fhe::trans::to_fhe; use circ::target::ilp::trans::to_ilp; use circ::target::r1cs::bellman::parse_instance; use circ::target::r1cs::opt::reduce_linearities; @@ -180,11 +182,12 @@ fn main() { }; let cs = match mode { Mode::Opt => opt(cs, vec![Opt::ScalarizeVars, Opt::ConstantFold]), - Mode::Mpc(_) | Mode::Fhe => opt( + Mode::Mpc(_) => opt( cs, vec![Opt::ScalarizeVars], // vec![Opt::Sha, Opt::ConstantFold, Opt::Mem, Opt::ConstantFold], ), + Mode::Fhe => opt(cs, vec![Opt::ConstantFold]), Mode::Proof | Mode::ProofOfHighValue(_) => opt( cs, vec![ diff --git a/scripts/build_fhe_zokrates.zsh b/scripts/build_fhe_zokrates.zsh new file mode 100755 index 000000000..c43728333 --- /dev/null +++ b/scripts/build_fhe_zokrates.zsh @@ -0,0 +1,26 @@ +#!/usr/bin/env zsh + +set -ex + +disable -r time + +cargo build --release --example circ + +BIN=./target/release/examples/circ + +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 { + zpath=$1 + RUST_BACKTRACE=1 measure_time $BIN $zpath fhe +} + +# build fhe boolean tests +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok \ No newline at end of file diff --git a/src/front/zokrates/mod.rs b/src/front/zokrates/mod.rs index 6f3741106..12dc4b41e 100644 --- a/src/front/zokrates/mod.rs +++ b/src/front/zokrates/mod.rs @@ -534,7 +534,7 @@ impl<'ast> ZGen<'ast> { if private.number.is_some() { self.err( format!( - "Party number found, but we're generating a {} circuit", + ", but we're generating a {} circuit", self.mode ), &private.span, diff --git a/src/ir/term/mod.rs b/src/ir/term/mod.rs index 8f2c3506f..180ac08e3 100644 --- a/src/ir/term/mod.rs +++ b/src/ir/term/mod.rs @@ -1393,6 +1393,9 @@ impl std::iter::Iterator for PostOrderIter { /// A party identifier pub type PartyId = u8; +/// Ciphertext/Plaintext identifier +pub type EncStatus = bool; + #[derive(Clone, Debug, Default)] /// An IR constraint system. pub struct ComputationMetadata { diff --git a/src/target/fhe/mod.rs b/src/target/fhe/mod.rs index f672b6485..a47f7bf26 100644 --- a/src/target/fhe/mod.rs +++ b/src/target/fhe/mod.rs @@ -1,16 +1,35 @@ //! FHE pub mod trans; +pub mod output; #[derive(Clone, Debug)] -/// ABY Circuit -/// The ABY Circuit consists of three Vec: setup, circ, and closer -/// *setup* holds code for initializing the ABY party, sharing scheme, and input values -/// *circs* holds the lowered code from the IR to ABY Circuits -/// *output* holds the code for printing the output value +/// FHE program +/// The FHE program consists of two functions: main, and server_call +/// +/// int main(): Acts as the client. +/// - Sets up the seal parameters +/// - Encrypts the private inputs +/// - Calls the server({params}) with the ctext and ptext parameters +/// - Decrypts the output from the server call +/// - Runs post computations +/// +/// Ciphertext server(): Acts as the server +/// - Runs computations on homomorphically encrypted inputs +/// +/// The FHE program consists of 5 Vec: +/// header_inputs, server, setup, call_inputs, and post_computation +/// +/// *header_inputs* holds the code of the input list for the header of server() +/// *server* holds the lowered code from the IR to FHE, which is the body of server() +/// *setup* holds the code for setting up SEAL params and encrypted data in main() +/// *call_inputs* holds the code of the input list for the call to server() in main() +/// *post_computation* holds the code that runs after the server() output has been decrypted pub struct FHE { + header_inputs: Vec, + server: Vec, setup: Vec, - circs: Vec, - output: Vec, + call_inputs: Vec, + post_computation: Vec, } impl Default for FHE { @@ -23,9 +42,11 @@ impl FHE { /// Initialize FHE circuit pub fn new() -> Self { FHE { + header_inputs: Vec::new(), + server: Vec::new(), setup: Vec::new(), - circs: Vec::new(), - output: Vec::new(), + call_inputs: Vec::new(), + post_computation: Vec::new(), } } } \ No newline at end of file diff --git a/src/target/fhe/output.rs b/src/target/fhe/output.rs new file mode 100644 index 000000000..3b5b4e157 --- /dev/null +++ b/src/target/fhe/output.rs @@ -0,0 +1,64 @@ +//! Utility functions to write compiler output to FHE + +use crate::target::fhe::*; +use std::fs; +//use std::fs::{File, OpenOptions}; +//use std::io::{prelude::*, BufRead, BufReader}; +use std::path::Path; +use std::path::PathBuf; + +/// Given PathBuf `path_buf`, return the filename of the path +fn get_filename(path_buf: PathBuf) -> String { + Path::new(&path_buf.iter().last().unwrap().to_os_string()) + .file_stem() + .unwrap() + .to_os_string() + .into_string() + .unwrap() +} + +/// In ABY examples, remove the existing directory and create a directory +/// in order to write the new test case +fn create_dir_in_seal(filename: &str) { + let path = format!("third_party/SEAL/native/examples/{}", filename); + let _ = fs::remove_dir_all(&path); + fs::create_dir_all(format!("{}/common", path)).expect("Failed to create directory"); +} + +/// Using the cpp_template.txt, write the .cpp file for the new test case +fn write_circ_file(filename: &str, header_inputs: &str, server: &str, + setup: &str, call_inputs: &str, post_computation: &str) { + let template = fs::read_to_string("third_party/SEAL_templates/cpp_template.txt") + .expect("Unable to read file"); + let path = format!( + "third_party/SEAL/native/examples/{}/common/{}.cpp", + filename, filename + ); + + fs::write( + &path, + template + .replace("{header_inputs}", header_inputs) + .replace("{server}", server) + .replace("{setup}", setup) + .replace("{call_inputs}", call_inputs) + .replace("{post_computation}", post_computation), + ) + .expect("Failed to write to cpp file"); +} + +/// Write cpp output from translation later to FHE +pub fn write_fhe_exec(fhe: FHE, path_buf: PathBuf) { + let filename = get_filename(path_buf); + create_dir_in_seal(&filename); + //update_cmake_file(&filename); + //write_test_cmake_file(&filename); + //write_test_file(&filename); + //write_h_file(&filename); + write_circ_file(&filename, + &fhe.header_inputs.join(""), + &fhe.server.join("\n\t"), + &fhe.setup.join("\n\t"), + &fhe.call_inputs.join(""), + &fhe.post_computation.join("\n\t")); +} diff --git a/src/target/fhe/trans.rs b/src/target/fhe/trans.rs index 04fe25e30..d4ecb795e 100644 --- a/src/target/fhe/trans.rs +++ b/src/target/fhe/trans.rs @@ -1,5 +1,6 @@ //! Lowering IR to FHE +//use crate::front::datalog::Inputs; use crate::ir::term::*; use crate::target::fhe::*; @@ -12,7 +13,7 @@ enum EmbeddedTerm { struct ToFHE { fhe: FHE, md: ComputationMetadata, - inputs: TermMap>, + inputs: TermMap, cache: TermMap, } @@ -26,11 +27,118 @@ impl ToFHE { } } + fn get_var_name(t: Term) -> String { + match &t.op { + Op::Var(name, _) => name.to_string(), + _ => panic!("Term {} is not of type Var", t), + } + } + + /// Parse variable name from IR representation of a variable + fn parse_var_name(&self, full_name: String) -> String { + let parsed: Vec = full_name.split('_').map(str::to_string).collect(); + if parsed.len() < 2 { + panic!("Invalid variable name: {}", full_name); + } + parsed[parsed.len() - 2].to_string() + } + + + //Writes code for setting up SEAL on the client side. + fn setup_seal(&mut self) { + let poly_mod_deg = 4096; + let plaintext_mod = 1024; + + self.fhe.setup.push(format!( + "EncryptionParameters parms(scheme_type::bfv);\n\t\ + size_t poly_modulus_degree = {};\n\t\ + parms.set_poly_modulus_degree(poly_modulus_degree);\n\t\ + parms.set_coeff_modulus(CoeffModulus::BFVDefault(poly_modulus_degree));\n\t\ + parms.set_plain_modulus({});\n\t\ + SEALContext context(parms);\n\t\ + \n\t\ + KeyGenerator keygen(context);\n\t\ + SecretKey secret_key = keygen.secret_key();\n\t\ + PublicKey public_key;\n\t\ + keygen.create_public_key(public_key);\n\t\ + Encryptor encryptor(context, public_key);\n\t\ + Evaluator evaluator(context);\n\t\ + Decryptor decryptor(context, secret_key);", + poly_mod_deg.to_string(), + plaintext_mod.to_string() + )); + } + + //Writes the header for the server_call function in fhe.server + //Writes the call to server_call with the parameters in fhe.client + fn add_server_call(&mut self, ptext_in: TermSet, ctext_in: TermSet){ + for t in ptext_in.iter() { + let name = ToFHE::get_var_name(t.clone()); + self.fhe.header_inputs.push(format!("Plaintext {}_plain, ", name)); + self.fhe.call_inputs.push(format!("{}_plain, ", name)); + } + + for t in ctext_in.iter() { + let name = ToFHE::get_var_name(t.clone()); + self.fhe.header_inputs.push(format!("Ciphertext_encrypted {}, ", name)); + self.fhe.call_inputs.push(format!("{}_encrypted, ", name)); + } + + match self.fhe.header_inputs.pop() { + Some(mut input) => { + input.pop(); + input.pop(); + self.fhe.header_inputs.push(input); + }, + None => panic!("Vector should not be empty."), + } + + match self.fhe.call_inputs.pop() { + Some(mut input) => { + input.pop(); + input.pop(); + self.fhe.call_inputs.push(input); + }, + None => panic!("Vector should not be empty."), + } + } + + //Writes to fhe.client the computation that runs after the server call + //ie. Decryption + fn add_post_computation(&mut self) { + self.fhe.post_computation.push( + "cout << output_decrypted.to_string() << endl;".to_string()); + } + ///Initialize ciphertext and plaintext inputs fn init_inputs(&mut self) { - // let mut ciphtertext_inputs = TermSet::new(); - // let mut plaintext_inputs = TermSet::new(); - todo!(); + let mut ptext_inputs = TermSet::new(); + let mut ctext_inputs = TermSet::new(); + + self.setup_seal(); + + // Parse input parameters from command line as uint32_t variables + // Initialize _____ + for (t, encrypted) in self.inputs.iter() { + let name = ToFHE::get_var_name(t.clone()); + self.fhe.setup.push(format!( + "Plaintext {}_plain(uint64_to_hex_string(std::atoi(params[\"{}\"].c_str())));", + name, + self.parse_var_name(name.to_string()) + )); + if *encrypted { + self.fhe.setup.push(format!( + "Ciphertext {}_encrypted;\n\tencryptor.encrypt({}_plain, {}_encrypted);", + name, name, name + )); + ctext_inputs.insert(t.clone()); + } + else { + ptext_inputs.insert(t.clone()); + } + } + self.add_server_call(ptext_inputs, ctext_inputs); + self.add_post_computation(); } /// Given term `t`, type-check `t` is of type Bool and return the variable name for @@ -47,7 +155,29 @@ impl ToFHE { } fn embed_bool(&mut self, t: Term) -> String { - //TODO Matching stuff + match &t.op { + Op::Var(name, Sort::Bool) => { + if !self.inputs.contains_key(&t){ + match *self.md.input_vis.get(name).unwrap(){ + None => self.inputs.insert(t.clone(), false), + Some(_) => self.inputs.insert(t.clone() , true) + }; + } + if !self.cache.contains_key(&t) { + self.cache + .insert(t.clone(), EmbeddedTerm::Bool(format!("s_{}", name))); + } + } + Op::Const(Value::Bool(b)) => { + self.cache.insert( + t.clone(), + EmbeddedTerm::Bool(format!( + "{}", *b + )) + ); + } + _ => panic!("Non-field in embed_bool: {:?}", t) + } self.get_bool(&t) } @@ -65,7 +195,30 @@ impl ToFHE { } fn embed_bv(&mut self, t: Term) -> String { - //TODO Matching Stuff + match &t.op { + Op::Var(name, Sort::BitVector(_)) => { + if !self.inputs.contains_key(&t){ + match *self.md.input_vis.get(name).unwrap(){ + None => self.inputs.insert(t.clone(), false), + Some(_) => self.inputs.insert(t.clone() , true) + }; + } + if !self.cache.contains_key(&t) { + self.cache + .insert(t.clone(), EmbeddedTerm::Bv(format!("s_{}", name))); + } + } + Op::Const(Value::BitVector(b)) => { + self.cache.insert( + t.clone(), + EmbeddedTerm::Bool(format!( + "{}", *b + )) + ); + } + _ => {panic!("Non-field in embed_bv: {:?}", t);} + } + self.get_bv(&t) } @@ -96,12 +249,12 @@ impl ToFHE { /// Given a term `t`, lower `t` to FHE Circuits fn lower(&mut self, t: Term) { let circ = self.embed(t); - self.fhe.circs.push(circ); + self.fhe.server.push(circ); } } /// Convert this (IR) `ir` to FHE. -pub fn to_aby(ir: Computation) -> FHE { +pub fn to_fhe(ir: Computation) -> FHE { let Computation { outputs: terms, metadata: md, diff --git a/third_party/SEAL_templates/cpp_template.txt b/third_party/SEAL_templates/cpp_template.txt new file mode 100644 index 000000000..281154513 --- /dev/null +++ b/third_party/SEAL_templates/cpp_template.txt @@ -0,0 +1,22 @@ +#include "examples.h" + +using namespace std; +using namespace seal; + +Ciphertext server({header_inputs}){ + {server} +} + +int main() { + {setup} + + Ciphertext output_encrypted = server({call_inputs}); + + Plaintext output_plain; + decryptor.decrypt(output, output_plain); + + {post_computation} + + + return 0; +} \ No newline at end of file From cfc2235d66d3234bcab8c62e36dbdd3894876306 Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 3 Feb 2022 20:47:42 +0000 Subject: [PATCH 05/21] fhe and, or, xor test cases --- examples/ZoKrates/fhe/inputs/fhe_and.txt | 3 + .../fhe/unit_tests/boolean_tests/fhe_and.zok | 4 +- scripts/build_fhe_zokrates.zsh | 5 +- src/target/fhe/mod.rs | 2 + src/target/fhe/output.rs | 8 +- src/target/fhe/trans.rs | 256 ++++++++++++++---- third_party/SEAL_templates/cpp_template.txt | 11 +- 7 files changed, 220 insertions(+), 69 deletions(-) create mode 100644 examples/ZoKrates/fhe/inputs/fhe_and.txt diff --git a/examples/ZoKrates/fhe/inputs/fhe_and.txt b/examples/ZoKrates/fhe/inputs/fhe_and.txt new file mode 100644 index 000000000..3bfeac0d0 --- /dev/null +++ b/examples/ZoKrates/fhe/inputs/fhe_and.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +c 1 \ No newline at end of file diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok index 9c34cea90..025fa0597 100644 --- a/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok +++ b/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok @@ -1,2 +1,2 @@ -def main(private bool a, bool b) -> bool: - return a \ No newline at end of file +def main(private bool a, private bool b) -> bool: + return a || b \ No newline at end of file diff --git a/scripts/build_fhe_zokrates.zsh b/scripts/build_fhe_zokrates.zsh index c43728333..752b32544 100755 --- a/scripts/build_fhe_zokrates.zsh +++ b/scripts/build_fhe_zokrates.zsh @@ -19,8 +19,9 @@ esac function fhe_test { zpath=$1 - RUST_BACKTRACE=1 measure_time $BIN $zpath fhe + ipath=$2 + RUST_BACKTRACE=1 measure_time $BIN $zpath --inputs $ipath fhe } # build fhe boolean tests -fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok \ No newline at end of file +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok ./examples/ZoKrates/fhe/inputs/fhe_and.txt \ No newline at end of file diff --git a/src/target/fhe/mod.rs b/src/target/fhe/mod.rs index a47f7bf26..313de188a 100644 --- a/src/target/fhe/mod.rs +++ b/src/target/fhe/mod.rs @@ -30,6 +30,7 @@ pub struct FHE { setup: Vec, call_inputs: Vec, post_computation: Vec, + main_inputs: Vec, } impl Default for FHE { @@ -47,6 +48,7 @@ impl FHE { setup: Vec::new(), call_inputs: Vec::new(), post_computation: Vec::new(), + main_inputs: Vec::new(), } } } \ No newline at end of file diff --git a/src/target/fhe/output.rs b/src/target/fhe/output.rs index 3b5b4e157..2c48af4c1 100644 --- a/src/target/fhe/output.rs +++ b/src/target/fhe/output.rs @@ -27,7 +27,7 @@ fn create_dir_in_seal(filename: &str) { /// Using the cpp_template.txt, write the .cpp file for the new test case fn write_circ_file(filename: &str, header_inputs: &str, server: &str, - setup: &str, call_inputs: &str, post_computation: &str) { + setup: &str, call_inputs: &str, post_computation: &str, main_inputs: &str) { let template = fs::read_to_string("third_party/SEAL_templates/cpp_template.txt") .expect("Unable to read file"); let path = format!( @@ -42,7 +42,8 @@ fn write_circ_file(filename: &str, header_inputs: &str, server: &str, .replace("{server}", server) .replace("{setup}", setup) .replace("{call_inputs}", call_inputs) - .replace("{post_computation}", post_computation), + .replace("{post_computation}", post_computation) + .replace("{main_inputs}", main_inputs), ) .expect("Failed to write to cpp file"); } @@ -60,5 +61,6 @@ pub fn write_fhe_exec(fhe: FHE, path_buf: PathBuf) { &fhe.server.join("\n\t"), &fhe.setup.join("\n\t"), &fhe.call_inputs.join(""), - &fhe.post_computation.join("\n\t")); + &fhe.post_computation.join("\n\t"), + &fhe.main_inputs.join("")); } diff --git a/src/target/fhe/trans.rs b/src/target/fhe/trans.rs index d4ecb795e..ad32dc966 100644 --- a/src/target/fhe/trans.rs +++ b/src/target/fhe/trans.rs @@ -3,27 +3,32 @@ //use crate::front::datalog::Inputs; use crate::ir::term::*; use crate::target::fhe::*; +use fxhash::FxHashMap; #[derive(Clone)] enum EmbeddedTerm { - Bool(String), - Bv(String), + Bool(String, bool), + Bv(String, bool), } struct ToFHE { fhe: FHE, md: ComputationMetadata, inputs: TermMap, + input_map: Option>, cache: TermMap, + term_cnt: i32, } impl ToFHE { - fn new(metadata: ComputationMetadata) -> Self { + fn new(metadata: ComputationMetadata, values:Option>) -> Self { Self { fhe: FHE::new(), md: metadata, inputs: TermMap::new(), + input_map: values, cache: TermMap::new(), + term_cnt: 0, } } @@ -33,16 +38,69 @@ impl ToFHE { _ => panic!("Term {} is not of type Var", t), } } + + fn get_term_name(&mut self) -> String{ + format!("term_{}", self.term_cnt) + } + + fn inc_term(&mut self) { + self.term_cnt += 1; + } - /// Parse variable name from IR representation of a variable - fn parse_var_name(&self, full_name: String) -> String { - let parsed: Vec = full_name.split('_').map(str::to_string).collect(); - if parsed.len() < 2 { - panic!("Invalid variable name: {}", full_name); + fn value_to_hex_poly(&self, val: &Value) -> String { + match *val { + Value::Bool(true) => "1".to_string(), + Value::Bool(false) => "0".to_string(), + _ => panic!("TODO: Unimplemented"), } - parsed[parsed.len() - 2].to_string() } + /// Handles the inputs to the main function. + /// If an input's value is provided in the input file, it is initialized + /// accordingly within the main function + /// Otherwise, it is listed as an input to the main function + fn handle_main_inputs(&mut self) { + match &self.input_map { + Some (map) => { + for (t, _) in self.inputs.iter() { + let name = ToFHE::get_var_name(t.clone()); + match map.get(&name) { + Some(val) => { //TODO: change val to hex polynomial format + self.fhe.setup.push(format!( + "Plaintext {}_plain(\"{}\");", + name, self.value_to_hex_poly(val) + )); + } + None => { + self.fhe.main_inputs.push(format!( + "Plaintext {}, ", + name + )); + } + } + } + }, + None => { + for (t, _) in self.inputs.iter() { + let name = ToFHE::get_var_name(t.clone()); + self.fhe.main_inputs.push(format!( + "Plaintext {}, ", + name + )); + } + } + } + + match self.fhe.main_inputs.pop() { + Some(mut input) => { + input.pop(); + input.pop(); + self.fhe.main_inputs.push(input); + }, + None => (), + } + + } //Writes code for setting up SEAL on the client side. fn setup_seal(&mut self) { @@ -74,32 +132,14 @@ impl ToFHE { fn add_server_call(&mut self, ptext_in: TermSet, ctext_in: TermSet){ for t in ptext_in.iter() { let name = ToFHE::get_var_name(t.clone()); - self.fhe.header_inputs.push(format!("Plaintext {}_plain, ", name)); - self.fhe.call_inputs.push(format!("{}_plain, ", name)); + self.fhe.header_inputs.push(format!(", Plaintext {}_plain", name)); + self.fhe.call_inputs.push(format!(", {}_plain", name)); } for t in ctext_in.iter() { let name = ToFHE::get_var_name(t.clone()); - self.fhe.header_inputs.push(format!("Ciphertext_encrypted {}, ", name)); - self.fhe.call_inputs.push(format!("{}_encrypted, ", name)); - } - - match self.fhe.header_inputs.pop() { - Some(mut input) => { - input.pop(); - input.pop(); - self.fhe.header_inputs.push(input); - }, - None => panic!("Vector should not be empty."), - } - - match self.fhe.call_inputs.pop() { - Some(mut input) => { - input.pop(); - input.pop(); - self.fhe.call_inputs.push(input); - }, - None => panic!("Vector should not be empty."), + self.fhe.header_inputs.push(format!(", Ciphertext {}_encrypted", name)); + self.fhe.call_inputs.push(format!(", {}_encrypted", name)); } } @@ -107,7 +147,7 @@ impl ToFHE { //ie. Decryption fn add_post_computation(&mut self) { self.fhe.post_computation.push( - "cout << output_decrypted.to_string() << endl;".to_string()); + "cout << \"Output Value: \" << output_plain.to_string() << endl;".to_string()); } ///Initialize ciphertext and plaintext inputs @@ -117,15 +157,11 @@ impl ToFHE { self.setup_seal(); - // Parse input parameters from command line as uint32_t variables - // Initialize _____ + self.handle_main_inputs(); + + // Encrypt necessary terms for (t, encrypted) in self.inputs.iter() { let name = ToFHE::get_var_name(t.clone()); - self.fhe.setup.push(format!( - "Plaintext {}_plain(uint64_to_hex_string(std::atoi(params[\"{}\"].c_str())));", - name, - self.parse_var_name(name.to_string()) - )); if *encrypted { self.fhe.setup.push(format!( "Ciphertext {}_encrypted;\n\tencryptor.encrypt({}_plain, {}_encrypted);", @@ -147,13 +183,82 @@ impl ToFHE { match self .cache .get(t) - .unwrap_or_else(|| panic!("Missing wire for {:?}", t)) + .unwrap_or_else(|| panic!("Missing expression for {:?}", t)) { - EmbeddedTerm::Bool(b) => b.clone(), + EmbeddedTerm::Bool(b, _) => b.clone(), _ => panic!("Non-bool for {:?}", t), } } + fn get_enc_status(&self, t: &Term) -> bool { + match self + .cache + .get(t) + .unwrap_or_else(|| panic!("Missing expression for {:?}", t)) + { + EmbeddedTerm::Bool(_, e) => e.clone(), + EmbeddedTerm::Bv(_, e) => e.clone() + } + } + + fn embed_bool_and(&mut self, a: String, a_enc: bool, b: String, b_enc: bool, term: String) { + self.fhe.server.push(format!("Ciphertext {};", term)); + self.fhe.server.push( + match (a_enc, b_enc) { + (true, true) => + format!("evaluator.multiply({}, {}, {});", a, b, term), + (true, false) => + format!("evaluator.multiply_plain({}, {}, {});", a, b, term), + (false, true) => + format!("evaluator.multiply_plain({}, {}, {});", b, a, term), + (false, false) => + format!("encryptor.encrypt({}, {})\n\tevaluator.multiply_plain_inplace({}, {});", + a, term, term, b) + } + ); + } + + fn embed_bool_or(&mut self, a: String, a_enc: bool, b: String, b_enc: bool, term: String) { + self.fhe.server.push("Ciphertext prod;".to_string()); + + self.fhe.server.push( + match (a_enc, b_enc) { + (true, true) => + format!("evaluator.multiply({}, {}, prod);", a, b), + (true, false) => + format!("evaluator.multiply_plain({}, {}, prod);", a, b), + (false, true) => + format!("evaluator.multiply_plain({}, {}, prod);", b, a), + (false, false) => + format!("encryptor.encrypt({}, prod)\n\tevaluator.multiply_plain_inplace(prod, {});", + a, b) + } + ); + + self.fhe.server.push(format!("Ciphertext {};", term)); + + self.fhe.server.push( + match (a_enc, b_enc) { + (true, true) => + format!("evaluator.add({}, {}, {});", a, b, term), + (true, false) => + format!("evaluator.add_plain({}, {}, {});", a, b, term), + (false, true) => + format!("evaluator.add_plain({}, {}, {});", b, a, term), + (false, false) => + format!("encryptor.encrypt({}, {})\n\tevaluator.add_plain_inplace({}, {});", + a, term, term, b) + } + ); + + self.fhe.server.push(format!("evaluator.sub_inplace({}, prod);", term)); + } + + fn embed_bool_xor(&mut self, a: String, a_enc: bool, b: String, b_enc: bool, term: String) { + self.embed_bool_or(a, a_enc, b, b_enc, term.clone()); + self.fhe.server.push(format!("evaluator.sub_inplace({}, prod);", term)); + } + fn embed_bool(&mut self, t: Term) -> String { match &t.op { Op::Var(name, Sort::Bool) => { @@ -164,18 +269,46 @@ impl ToFHE { }; } if !self.cache.contains_key(&t) { - self.cache - .insert(t.clone(), EmbeddedTerm::Bool(format!("s_{}", name))); + match *self.md.input_vis.get(name).unwrap(){ + None => self.cache + .insert(t.clone(), + EmbeddedTerm::Bool(format!("{}_plain", name), false)), + Some (_) => self.cache + .insert(t.clone(), + EmbeddedTerm::Bool(format!("{}_encrypted", name), true)) + }; } } Op::Const(Value::Bool(b)) => { self.cache.insert( t.clone(), - EmbeddedTerm::Bool(format!( - "{}", *b - )) + EmbeddedTerm::Bool(format!("{}", *b), false) ); } + Op::BoolNaryOp(o) => { + let a_circ = self.get_bool(&t.cs[0]); + let b_circ = self.get_bool(&t.cs[1]); + + let term = self.get_term_name(); + self.inc_term(); + + match o { + BoolNaryOp::And => { + self.embed_bool_and(a_circ, self.get_enc_status(&t.cs[0]), + b_circ, self.get_enc_status(&t.cs[1]), term.clone()); + } + BoolNaryOp::Or => { + self.embed_bool_or(a_circ, self.get_enc_status(&t.cs[0]), + b_circ, self.get_enc_status(&t.cs[1]), term.clone()); + } + BoolNaryOp::Xor => { + self.embed_bool_xor(a_circ, self.get_enc_status(&t.cs[0]), + b_circ, self.get_enc_status(&t.cs[1]), term.clone()); + } + } + self.cache.insert(t.clone(), + EmbeddedTerm::Bool(term, true)); + } _ => panic!("Non-field in embed_bool: {:?}", t) } self.get_bool(&t) @@ -189,7 +322,7 @@ impl ToFHE { .get(t) .unwrap_or_else(|| panic!("Missing wire for {:?}", t)) { - EmbeddedTerm::Bv(b) => b.clone(), + EmbeddedTerm::Bv(b, _) => b.clone(), _ => panic!("Non-bv for {:?}", t), } } @@ -204,16 +337,20 @@ impl ToFHE { }; } if !self.cache.contains_key(&t) { - self.cache - .insert(t.clone(), EmbeddedTerm::Bv(format!("s_{}", name))); + match *self.md.input_vis.get(name).unwrap(){ + None => self.cache + .insert(t.clone(), + EmbeddedTerm::Bv(format!("{}_plain", name), false)), + Some (_) => self.cache + .insert(t.clone(), + EmbeddedTerm::Bv(format!("{}_encrypted", name), true)) + }; } } Op::Const(Value::BitVector(b)) => { self.cache.insert( t.clone(), - EmbeddedTerm::Bool(format!( - "{}", *b - )) + EmbeddedTerm::Bool(format!("{}", *b), false) ); } _ => {panic!("Non-field in embed_bv: {:?}", t);} @@ -222,9 +359,9 @@ impl ToFHE { self.get_bv(&t) } - fn format_output_circuit(&self, circ: String) -> String { + fn format_output_circuit(&self, circ: String) -> String { //TODO format!( - "TODO: {} \n", + "{}", circ ) } @@ -246,10 +383,13 @@ impl ToFHE { self.format_output_circuit(circ) } - /// Given a term `t`, lower `t` to FHE Circuits + /// Given a term `t`, lower `t` to FHE program fn lower(&mut self, t: Term) { let circ = self.embed(t); - self.fhe.server.push(circ); + self.fhe.server.push(format!( + "return {};", + circ + )); } } @@ -258,10 +398,10 @@ pub fn to_fhe(ir: Computation) -> FHE { let Computation { outputs: terms, metadata: md, - values: _, + values, } = ir.clone(); - let mut converter = ToFHE::new(md); + let mut converter = ToFHE::new(md, values); for t in terms { println!("Terms: {}", t); diff --git a/third_party/SEAL_templates/cpp_template.txt b/third_party/SEAL_templates/cpp_template.txt index 281154513..57b05c30b 100644 --- a/third_party/SEAL_templates/cpp_template.txt +++ b/third_party/SEAL_templates/cpp_template.txt @@ -3,17 +3,20 @@ using namespace std; using namespace seal; -Ciphertext server({header_inputs}){ +Ciphertext server(SEALContext context, PublicKey public_key{header_inputs}){ + Evaluator evaluator(context); + Encryptor encrypto(context, public_key); + Plaintext plain_one("1"); {server} } -int main() { +int main({main_inputs}) { {setup} - Ciphertext output_encrypted = server({call_inputs}); + Ciphertext output_encrypted = server(context, public_key{call_inputs}); Plaintext output_plain; - decryptor.decrypt(output, output_plain); + decryptor.decrypt(output_encrypted, output_plain); {post_computation} From 3c59444ad7c6879e5dacff1f401315cdec1b47eb Mon Sep 17 00:00:00 2001 From: William Seo Date: Mon, 21 Feb 2022 20:13:07 +0000 Subject: [PATCH 06/21] Map Operation changed indices to bitvectors --- src/ir/term/mod.rs | 99 ++++++++++++++++++++------------------------- src/ir/term/test.rs | 22 ++++++++++ 2 files changed, 66 insertions(+), 55 deletions(-) diff --git a/src/ir/term/mod.rs b/src/ir/term/mod.rs index d094aeb85..f8f2f9376 100644 --- a/src/ir/term/mod.rs +++ b/src/ir/term/mod.rs @@ -1122,35 +1122,17 @@ impl Value { /// Evaluate the term `t`, using variable values in `h`. pub fn eval(t: &Term, h: &FxHashMap) -> Value { - let mut vs = TermMap::::new(); + let ref mut vs = TermMap::::new(); for c in PostOrderIter::new(t.clone()) { - let v = eval_helper(vs.clone(), h, c.clone()); - vs.insert(c, v); //TODO: Should the insert happen here + eval_value(vs, h, c.clone()); } vs.get(t).unwrap().clone() } -#[macro_export] -/// Make a term. -/// -/// Syntax: -/// -/// * without children: `term![OP]` -/// * with children: `term![OP; ARG0, ARG1, ... ]` -/// * Note the semi-colon -macro_rules! term { - ($x:expr) => { - leaf_term($x) - }; - ($x:expr; $($y:expr),+) => { - term($x, vec![$($y),+]) - }; -} - /// Helper function for eval function. Handles a single term -fn eval_helper(vs: HConMap, Value>, - h: &FxHashMap, c: HConsed) -> Value { - match &c.op { +fn eval_value(vs: &mut HConMap, Value>, + h: &FxHashMap, c: HConsed) -> Value{ + let v = match &c.op { Op::Var(n, _) => h .get(n) .unwrap_or_else(|| panic!("Missing var: {} in {:?}", n, h)) @@ -1311,48 +1293,55 @@ fn eval_helper(vs: HConMap, Value>, a.clone().select(i) } Op::Map(op) => { - let mut term_vecs = Vec::new(); - match op.arity() { - None => unimplemented!("Unexpected # of inputs for map {:?}", op), - Some(x) => { - for i in 0..x { - let arr = vs.get(&c.cs[i]).unwrap().as_array().clone(); - let mut arr_terms = Vec::new(); - for j in 0..(arr.size) { - let jval = &Value::Int(Integer::from(j)); - let term = leaf_term(Op::Const(arr.clone().select(jval))); - arr_terms.push(term); - } - term_vecs.push(arr_terms); - } + let arg_cnt = c.cs.len(); + let arr_size = vs.get(&c.cs[0]).unwrap().as_array().size; + let mut term_vecs = vec![Vec::new(); arr_size]; + //2D vector: term_vecs[i] will store a vector of all the i-th index + // entries of the array arguments + + //Value::BitVector(BitVector::new(uint.into(),width,)) + for i in 0..arg_cnt { + let arr = vs.get(&c.cs[i]).unwrap().as_array().clone(); + for j in 0..arr_size { + let jval = &Value::BitVector(BitVector::new(Integer::from(j), 32)); + let term = leaf_term(Op::Const(arr.clone().select(jval))); + term_vecs[j].push(term); } } - + //Cloning the first arg just for formatting let mut res = vs.get(&c.cs[0]).unwrap().as_array().clone(); - - for i in 0..(term_vecs[0].len()) { - let t = match op.arity() { - Some(1) => { - term![(**op).clone(); term_vecs[0][i].clone()] - }, - Some(2) => { - term![(**op).clone(); term_vecs[0][i].clone(), term_vecs[1][i].clone()] - }, - Some(3) => { - term![(**op).clone(); term_vecs[0][i].clone(), term_vecs[1][i].clone(), term_vecs[2][i].clone()] - }, - _ => unimplemented!("Unexpected # of inputs for map {:?}", op), - }; - let val = eval_helper(vs.clone(), h, t); - res.map.insert(Value::Int(Integer::from(i)), val); + for i in 0..arr_size { + let t = term((**op).clone(), term_vecs[i].clone()); + let val = eval_value(vs, h, t); + res.map.insert(Value::BitVector(BitVector::new(Integer::from(i), 32)), val); } Value::Array(res) } o => unimplemented!("eval: {:?}", o), - } + }; + vs.insert(c, v.clone()); + + v //println!("Eval {}\nAs {}", c, v); } +#[macro_export] +/// Make a term. +/// +/// Syntax: +/// +/// * without children: `term![OP]` +/// * with children: `term![OP; ARG0, ARG1, ... ]` +/// * Note the semi-colon +macro_rules! term { + ($x:expr) => { + leaf_term($x) + }; + ($x:expr; $($y:expr),+) => { + term($x, vec![$($y),+]) + }; +} + /// Make an array from a sequence of terms. /// /// Requires diff --git a/src/ir/term/test.rs b/src/ir/term/test.rs index 069565b28..3032d70b6 100644 --- a/src/ir/term/test.rs +++ b/src/ir/term/test.rs @@ -3,6 +3,7 @@ use super::*; use crate::target::r1cs::trans::test::bv; +use fxhash::FxHashMap; #[test] fn eq() { @@ -14,6 +15,27 @@ fn eq() { assert!(u != w); } +#[test] +fn map_eq_test() { + let a1 = + make_array(Sort::BitVector(32), Sort::Bool, + vec![bool(true), bool(false), bool(true), bool(false)]); + let a2 = + make_array(Sort::BitVector(32), Sort::Bool, + vec![bool(true), bool(false), bool(true), bool(false)]); + let t = term![Op::Map(Box::new(Op::Eq)); a1, a2]; + + eval(&t, &FxHashMap::default()); + assert!(true); + + //println!("Value is : {}", val); + + //let res = get_value(t) + //let ans = true + //assert true + +} + mod type_ { use super::*; From 0404c6e3959e67d98a981983c48ad74f6df0ec30 Mon Sep 17 00:00:00 2001 From: William Seo Date: Fri, 25 Feb 2022 01:51:01 +0000 Subject: [PATCH 07/21] Implemented typechecking for Map IR --- src/front/zsharp/mod.rs | 4 +- src/ir/term/test.rs | 19 +- src/ir/term/ty.rs | 373 +++++++++++++++++++++++++--------------- 3 files changed, 256 insertions(+), 140 deletions(-) diff --git a/src/front/zsharp/mod.rs b/src/front/zsharp/mod.rs index 4f5eb1dad..47d6f9601 100644 --- a/src/front/zsharp/mod.rs +++ b/src/front/zsharp/mod.rs @@ -626,7 +626,7 @@ impl<'ast> ZGen<'ast> { } if let Some(r) = self.circ_exit_fn() { match self.mode { - Mode::Mpc(_) => { + Mode::Mpc(_) | Mode::Fhe => { let ret_term = r.unwrap_term(); let ret_terms = ret_term.terms(); self.circ @@ -686,7 +686,7 @@ impl<'ast> ZGen<'ast> { match visibility { None | Some(ast::Visibility::Public(_)) => PUBLIC_VIS, Some(ast::Visibility::Private(private)) => match self.mode { - Mode::Proof | Mode::Opt | Mode::ProofOfHighValue(_) => { + Mode::Fhe | Mode::Proof | Mode::Opt | Mode::ProofOfHighValue(_) => { if private.number.is_some() { self.err( format!( diff --git a/src/ir/term/test.rs b/src/ir/term/test.rs index 3032d70b6..75b79ffdb 100644 --- a/src/ir/term/test.rs +++ b/src/ir/term/test.rs @@ -19,17 +19,28 @@ fn eq() { fn map_eq_test() { let a1 = make_array(Sort::BitVector(32), Sort::Bool, - vec![bool(true), bool(false), bool(true), bool(false)]); + vec![bool(true), bool(true), bool(false), bool(false)]); let a2 = make_array(Sort::BitVector(32), Sort::Bool, vec![bool(true), bool(false), bool(true), bool(false)]); let t = term![Op::Map(Box::new(Op::Eq)); a1, a2]; - eval(&t, &FxHashMap::default()); - assert!(true); + let val = eval(&t, &FxHashMap::default()); + println!("Value is: {}", val); + + let a1 = + make_array(Sort::BitVector(32), Sort::BitVector(4), + vec![bv(0b0001, 4), bv(0b0010, 4), bv(0b0011, 4), bv(0b0100, 4)]); + + let a2 = + make_array(Sort::BitVector(32), Sort::BitVector(4), + vec![bv(0b0001, 4), bv(0b0100, 4), bv(0b1001, 4), bv(0b0000, 4)]); - //println!("Value is : {}", val); + let t_eq = term![Op::Map(Box::new(Op::Eq)); a1.clone(), a2.clone()]; + let t_add = term![Op::Map(Box::new(BV_ADD)); a1.clone(), a2.clone()]; + println!("MAP EQ Value is: {}", eval(&t_eq, &FxHashMap::default())); + println!("MAP ADD Value is: {}", eval(&t_add, &FxHashMap::default())) //let res = get_value(t) //let ans = true //assert true diff --git a/src/ir/term/ty.rs b/src/ir/term/ty.rs index 63cd26c6f..972f05189 100644 --- a/src/ir/term/ty.rs +++ b/src/ir/term/ty.rs @@ -128,6 +128,53 @@ pub fn check_raw(t: &Term) -> Result { } } Op::Update(_i) => Ok(check_raw(&t.cs[0])?), + Op::Map(op) => { + let arg_cnt = t.cs.len(); + let mut dterm_cs = Vec::new(); + + let mut key_sort = Sort::Bool; + let mut size = 0; + let mut error = None; + + match arrmap_or(&check_raw(&t.cs[0])?, "map") + { + Ok((k,_,s,)) => { + key_sort = k.clone(); + size = s.clone(); + }, + Err(e) => { + error = Some(e); + } + } + + for i in 0..arg_cnt { + match array_or(&check_raw(&t.cs[i])?, "map inputs") { + Ok((_,v)) => { + dterm_cs.push(v.default_term()); + } + Err(e) => { + error = Some(e); + } + } + } + + match error { + Some(e) => { + Err(e) + } + None => { + let dummy_term = term((**op).clone(), dterm_cs); + let res_sort = check_raw(&dummy_term) + .map(|val_sort| + Sort::Array(Box::new(key_sort), Box::new(val_sort), size)); + + match res_sort { + Ok(s) => Ok(s), + _ => Err(TypeErrorReason::Custom("map failed".to_string())) + } + } + } + } o => Err(TypeErrorReason::Custom(format!("other operator: {}", o))), }; let mut term_tys = TERM_TYPES.write().unwrap(); @@ -140,6 +187,187 @@ pub fn check_raw(t: &Term) -> Result { Ok(ty) } + +/// Helper functio for rec_check_raw +/// Type-check given term which is expressed as +/// An operation and the sorts of its children +pub fn rec_check_raw_helper(oper: &Op, a: &[&Sort]) -> Result { + match (oper, a) { + (Op::Eq, &[a, b]) => eq_or(a, b, "=").map(|_| Sort::Bool), + (Op::Ite, &[&Sort::Bool, b, c]) => eq_or(b, c, "ITE").map(|_| b.clone()), + (Op::Var(_, s), &[]) => Ok(s.clone()), + (Op::Const(c), &[]) => Ok(c.sort()), + (Op::BvBinOp(_), &[a, b]) => { + let ctx = "bv binary op"; + bv_or(a, ctx) + .and_then(|_| eq_or(a, b, ctx)) + .map(|_| a.clone()) + } + (Op::BvBinPred(_), &[a, b]) => { + let ctx = "bv binary predicate"; + bv_or(a, ctx) + .and_then(|_| eq_or(a, b, ctx)) + .map(|_| Sort::Bool) + } + (Op::BvNaryOp(_), a) => { + let ctx = "bv nary op"; + all_eq_or(a.iter().cloned(), ctx) + .and_then(|t| bv_or(t, ctx)) + .map(|a| a.clone()) + } + (Op::BvUnOp(_), &[a]) => bv_or(a, "bv unary op").map(|a| a.clone()), + (Op::BoolToBv, &[Sort::Bool]) => Ok(Sort::BitVector(1)), + (Op::BvExtract(high, low), &[Sort::BitVector(w)]) => { + if low <= high && high < w { + Ok(Sort::BitVector(high - low + 1)) + } else { + Err(TypeErrorReason::OutOfBounds(format!( + "Cannot slice from {} to {} in a bit-vector of width {}", + high, low, w + ))) + } + } + (Op::BvConcat, a) => a + .iter() + .try_fold(0, |w, x| match x { + Sort::BitVector(ww) => Ok(w + ww), + s => Err(TypeErrorReason::ExpectedBv((*s).clone(), "concat")), + }) + .map(Sort::BitVector), + (Op::BvSext(a), &[Sort::BitVector(b)]) => Ok(Sort::BitVector(a + b)), + (Op::PfToBv(a), &[Sort::Field(_)]) => Ok(Sort::BitVector(*a)), + (Op::BvUext(a), &[Sort::BitVector(b)]) => Ok(Sort::BitVector(a + b)), + (Op::Implies, &[a, b]) => { + let ctx = "bool binary op"; + bool_or(a, ctx) + .and_then(|_| eq_or(a, b, ctx)) + .map(|_| a.clone()) + } + (Op::BoolNaryOp(_), a) => { + let ctx = "bool nary op"; + all_eq_or(a.iter().cloned(), ctx) + .and_then(|t| bool_or(t, ctx)) + .map(|a| a.clone()) + } + (Op::Not, &[a]) => bool_or(a, "bool unary op").map(|a| a.clone()), + (Op::BvBit(i), &[Sort::BitVector(w)]) => { + if i < w { + Ok(Sort::Bool) + } else { + Err(TypeErrorReason::OutOfBounds(format!( + "Cannot get bit {} of a {}-bit bit-vector", + i, w + ))) + } + } + (Op::BoolMaj, &[a, b, c]) => { + let ctx = "bool majority"; + bool_or(a, ctx) + .and_then(|_| bool_or(b, ctx).and_then(|_| bool_or(c, ctx))) + .map(|c| c.clone()) + } + (Op::FpBinOp(_), &[a, b]) => { + let ctx = "fp binary op"; + fp_or(a, ctx) + .and_then(|_| eq_or(a, b, ctx)) + .map(|_| a.clone()) + } + (Op::FpBinPred(_), &[a, b]) => { + let ctx = "fp binary predicate"; + fp_or(a, ctx) + .and_then(|_| eq_or(a, b, ctx)) + .map(|_| Sort::Bool) + } + (Op::FpUnOp(_), &[a]) => fp_or(a, "fp unary op").map(|a| a.clone()), + (Op::FpUnPred(_), &[a]) => fp_or(a, "fp unary predicate").map(|_| Sort::Bool), + (Op::BvToFp, &[Sort::BitVector(64)]) => Ok(Sort::F64), + (Op::BvToFp, &[Sort::BitVector(32)]) => Ok(Sort::F64), + (Op::UbvToFp(64), &[a]) => bv_or(a, "ubv-to-fp").map(|_| Sort::F64), + (Op::UbvToFp(32), &[a]) => bv_or(a, "ubv-to-fp").map(|_| Sort::F32), + (Op::SbvToFp(64), &[a]) => bv_or(a, "sbv-to-fp").map(|_| Sort::F64), + (Op::SbvToFp(32), &[a]) => bv_or(a, "sbv-to-fp").map(|_| Sort::F32), + (Op::FpToFp(64), &[a]) => fp_or(a, "fp-to-fp").map(|_| Sort::F64), + (Op::FpToFp(32), &[a]) => fp_or(a, "fp-to-fp").map(|_| Sort::F32), + (Op::PfNaryOp(_), a) => { + let ctx = "pf nary op"; + all_eq_or(a.iter().cloned(), ctx) + .and_then(|t| pf_or(t, ctx)) + .map(|a| a.clone()) + } + (Op::UbvToPf(m), &[a]) => bv_or(a, "sbv-to-fp").map(|_| Sort::Field(m.clone())), + (Op::PfUnOp(_), &[a]) => pf_or(a, "pf unary op").map(|a| a.clone()), + (Op::Select, &[Sort::Array(k, v, _), a]) => { + eq_or(k, a, "select").map(|_| (**v).clone()) + } + (Op::Store, &[Sort::Array(k, v, n), a, b]) => eq_or(k, a, "store") + .and_then(|_| eq_or(v, b, "store")) + .map(|_| Sort::Array(k.clone(), v.clone(), *n)), + (Op::Tuple, a) => Ok(Sort::Tuple(a.iter().map(|a| (*a).clone()).collect())), + (Op::Field(i), &[a]) => tuple_or(a, "tuple field access").and_then(|t| { + if i < &t.len() { + Ok(t[*i].clone()) + } else { + Err(TypeErrorReason::OutOfBounds(format!( + "index {} in tuple of sort {}", + i, a + ))) + } + }), + (Op::Update(i), &[a, b]) => tuple_or(a, "tuple field update").and_then(|t| { + if i < &t.len() { + eq_or(&t[*i], b, "tuple update")?; + Ok(a.clone()) + } else { + Err(TypeErrorReason::OutOfBounds(format!( + "index {} in tuple of sort {}", + i, a + ))) + } + }), + (Op::Map(op), a) => { + //TODO: + // Check that key sorts are the same across all arrays + // Get the value sorts of the argument arrays + // recursively call helper to get value type of mapped array + // then return Ok(...) + let arg_cnt = a.len(); + + let key_sort = match a[0].clone() { + Sort::Array(k,_,_) => { + *k.clone() + }, + s => + return Err(TypeErrorReason::ExpectedArray(s.clone(), "map")) + }; + + let mut val_sorts = Vec::new(); + for i in 0..arg_cnt { + match a[i].clone() { + Sort::Array(k, v, _) => { + if *k != key_sort { + return Err(TypeErrorReason::NotEqual( + *k.clone(), + key_sort.clone(), + "map", + )); + } + val_sorts.push((*v).clone()); + }, + s => + return Err(TypeErrorReason::ExpectedArray(s.clone(), "map")) + }; + } + + let mut new_a = Vec::new(); + for i in 0..arg_cnt{ + new_a.push(&val_sorts[i]); + } + + rec_check_raw_helper(&(*op.clone()), &new_a[..]) + } + (_, _) => Err(TypeErrorReason::Custom("other".to_string())), + } +} /// Type-check this term, recursively as needed. /// All results are stored in the global type table. pub fn rec_check_raw(t: &Term) -> Result { @@ -174,140 +402,8 @@ pub fn rec_check_raw(t: &Term) -> Result { .iter() .map(|c| term_tys.get(&c.to_weak()).unwrap()) .collect::>(); - let ty = (match (&back.0.op, &tys[..]) { - (Op::Eq, &[a, b]) => eq_or(a, b, "=").map(|_| Sort::Bool), - (Op::Ite, &[&Sort::Bool, b, c]) => eq_or(b, c, "ITE").map(|_| b.clone()), - (Op::Var(_, s), &[]) => Ok(s.clone()), - (Op::Const(c), &[]) => Ok(c.sort()), - (Op::BvBinOp(_), &[a, b]) => { - let ctx = "bv binary op"; - bv_or(a, ctx) - .and_then(|_| eq_or(a, b, ctx)) - .map(|_| a.clone()) - } - (Op::BvBinPred(_), &[a, b]) => { - let ctx = "bv binary predicate"; - bv_or(a, ctx) - .and_then(|_| eq_or(a, b, ctx)) - .map(|_| Sort::Bool) - } - (Op::BvNaryOp(_), a) => { - let ctx = "bv nary op"; - all_eq_or(a.iter().cloned(), ctx) - .and_then(|t| bv_or(t, ctx)) - .map(|a| a.clone()) - } - (Op::BvUnOp(_), &[a]) => bv_or(a, "bv unary op").map(|a| a.clone()), - (Op::BoolToBv, &[Sort::Bool]) => Ok(Sort::BitVector(1)), - (Op::BvExtract(high, low), &[Sort::BitVector(w)]) => { - if low <= high && high < w { - Ok(Sort::BitVector(high - low + 1)) - } else { - Err(TypeErrorReason::OutOfBounds(format!( - "Cannot slice from {} to {} in a bit-vector of width {}", - high, low, w - ))) - } - } - (Op::BvConcat, a) => a - .iter() - .try_fold(0, |w, x| match x { - Sort::BitVector(ww) => Ok(w + ww), - s => Err(TypeErrorReason::ExpectedBv((*s).clone(), "concat")), - }) - .map(Sort::BitVector), - (Op::BvSext(a), &[Sort::BitVector(b)]) => Ok(Sort::BitVector(a + b)), - (Op::PfToBv(a), &[Sort::Field(_)]) => Ok(Sort::BitVector(*a)), - (Op::BvUext(a), &[Sort::BitVector(b)]) => Ok(Sort::BitVector(a + b)), - (Op::Implies, &[a, b]) => { - let ctx = "bool binary op"; - bool_or(a, ctx) - .and_then(|_| eq_or(a, b, ctx)) - .map(|_| a.clone()) - } - (Op::BoolNaryOp(_), a) => { - let ctx = "bool nary op"; - all_eq_or(a.iter().cloned(), ctx) - .and_then(|t| bool_or(t, ctx)) - .map(|a| a.clone()) - } - (Op::Not, &[a]) => bool_or(a, "bool unary op").map(|a| a.clone()), - (Op::BvBit(i), &[Sort::BitVector(w)]) => { - if i < w { - Ok(Sort::Bool) - } else { - Err(TypeErrorReason::OutOfBounds(format!( - "Cannot get bit {} of a {}-bit bit-vector", - i, w - ))) - } - } - (Op::BoolMaj, &[a, b, c]) => { - let ctx = "bool majority"; - bool_or(a, ctx) - .and_then(|_| bool_or(b, ctx).and_then(|_| bool_or(c, ctx))) - .map(|c| c.clone()) - } - (Op::FpBinOp(_), &[a, b]) => { - let ctx = "fp binary op"; - fp_or(a, ctx) - .and_then(|_| eq_or(a, b, ctx)) - .map(|_| a.clone()) - } - (Op::FpBinPred(_), &[a, b]) => { - let ctx = "fp binary predicate"; - fp_or(a, ctx) - .and_then(|_| eq_or(a, b, ctx)) - .map(|_| Sort::Bool) - } - (Op::FpUnOp(_), &[a]) => fp_or(a, "fp unary op").map(|a| a.clone()), - (Op::FpUnPred(_), &[a]) => fp_or(a, "fp unary predicate").map(|_| Sort::Bool), - (Op::BvToFp, &[Sort::BitVector(64)]) => Ok(Sort::F64), - (Op::BvToFp, &[Sort::BitVector(32)]) => Ok(Sort::F64), - (Op::UbvToFp(64), &[a]) => bv_or(a, "ubv-to-fp").map(|_| Sort::F64), - (Op::UbvToFp(32), &[a]) => bv_or(a, "ubv-to-fp").map(|_| Sort::F32), - (Op::SbvToFp(64), &[a]) => bv_or(a, "sbv-to-fp").map(|_| Sort::F64), - (Op::SbvToFp(32), &[a]) => bv_or(a, "sbv-to-fp").map(|_| Sort::F32), - (Op::FpToFp(64), &[a]) => fp_or(a, "fp-to-fp").map(|_| Sort::F64), - (Op::FpToFp(32), &[a]) => fp_or(a, "fp-to-fp").map(|_| Sort::F32), - (Op::PfNaryOp(_), a) => { - let ctx = "pf nary op"; - all_eq_or(a.iter().cloned(), ctx) - .and_then(|t| pf_or(t, ctx)) - .map(|a| a.clone()) - } - (Op::UbvToPf(m), &[a]) => bv_or(a, "sbv-to-fp").map(|_| Sort::Field(m.clone())), - (Op::PfUnOp(_), &[a]) => pf_or(a, "pf unary op").map(|a| a.clone()), - (Op::Select, &[Sort::Array(k, v, _), a]) => { - eq_or(k, a, "select").map(|_| (**v).clone()) - } - (Op::Store, &[Sort::Array(k, v, n), a, b]) => eq_or(k, a, "store") - .and_then(|_| eq_or(v, b, "store")) - .map(|_| Sort::Array(k.clone(), v.clone(), *n)), - (Op::Tuple, a) => Ok(Sort::Tuple(a.iter().map(|a| (*a).clone()).collect())), - (Op::Field(i), &[a]) => tuple_or(a, "tuple field access").and_then(|t| { - if i < &t.len() { - Ok(t[*i].clone()) - } else { - Err(TypeErrorReason::OutOfBounds(format!( - "index {} in tuple of sort {}", - i, a - ))) - } - }), - (Op::Update(i), &[a, b]) => tuple_or(a, "tuple field update").and_then(|t| { - if i < &t.len() { - eq_or(&t[*i], b, "tuple update")?; - Ok(a.clone()) - } else { - Err(TypeErrorReason::OutOfBounds(format!( - "index {} in tuple of sort {}", - i, a - ))) - } - }), - (_, _) => Err(TypeErrorReason::Custom("other".to_string())), - }) + + let ty = rec_check_raw_helper(&back.0.op, &tys[..]) .map_err(|reason| TypeError { op: back.0.op.clone(), args: tys.into_iter().cloned().collect(), @@ -374,6 +470,14 @@ fn array_or<'a>(a: &'a Sort, ctx: &'static str) -> Result<(&'a Sort, &'a Sort), } } +fn arrmap_or<'a>(a: &'a Sort, ctx: &'static str) -> Result<(&'a Sort, &'a Sort, &'a usize), TypeErrorReason> { + if let Sort::Array(k, v, s) = a { + Ok((&*k, &*v, &*s)) + } else { + Err(TypeErrorReason::ExpectedArray(a.clone(), ctx)) + } +} + fn bool_or<'a>(a: &'a Sort, ctx: &'static str) -> Result<&'a Sort, TypeErrorReason> { if let Sort::Bool = a { Ok(a) @@ -429,3 +533,4 @@ fn all_eq_or<'a, I: Iterator>( } Ok(first) } + From eb796061dcc67ef1b3f6eb6e17828441ed1a842c Mon Sep 17 00:00:00 2001 From: William Seo Date: Fri, 25 Mar 2022 01:55:14 +0000 Subject: [PATCH 08/21] Removed extraneous code --- src/target/fhe/mod.rs | 51 ------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/src/target/fhe/mod.rs b/src/target/fhe/mod.rs index 8c761c1fb..d7c038e5f 100644 --- a/src/target/fhe/mod.rs +++ b/src/target/fhe/mod.rs @@ -1,54 +1,3 @@ //! FHE pub mod trans; pub mod utils; - -#[derive(Clone, Debug)] -/// FHE program -/// The FHE program consists of two functions: main, and server_call -/// -/// int main(): Acts as the client. -/// - Sets up the seal parameters -/// - Encrypts the private inputs -/// - Calls the server({params}) with the ctext and ptext parameters -/// - Decrypts the output from the server call -/// - Runs post computations -/// -/// Ciphertext server(): Acts as the server -/// - Runs computations on homomorphically encrypted inputs -/// -/// The FHE program consists of 5 Vec: -/// header_inputs, server, setup, call_inputs, and post_computation -/// -/// *header_inputs* holds the code of the input list for the header of server() -/// *server* holds the lowered code from the IR to FHE, which is the body of server() -/// *setup* holds the code for setting up SEAL params and encrypted data in main() -/// *call_inputs* holds the code of the input list for the call to server() in main() -/// *post_computation* holds the code that runs after the server() output has been decrypted -pub struct FHE { - header_inputs: Vec, - server: Vec, - setup: Vec, - call_inputs: Vec, - post_computation: Vec, - main_inputs: Vec, -} - -impl Default for FHE { - fn default() -> Self { - Self::new() - } -} - -impl FHE { - /// Initialize FHE circuit - pub fn new() -> Self { - FHE { - header_inputs: Vec::new(), - server: Vec::new(), - setup: Vec::new(), - call_inputs: Vec::new(), - post_computation: Vec::new(), - main_inputs: Vec::new(), - } - } -} From 3c3f2037d8e3244998156ba3a2b5159d69dbf1ae Mon Sep 17 00:00:00 2001 From: William Seo Date: Fri, 25 Mar 2022 02:02:42 +0000 Subject: [PATCH 09/21] Fixed linting issue --- src/target/fhe/trans.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/fhe/trans.rs b/src/target/fhe/trans.rs index 42f2e9141..04cc3e4b6 100644 --- a/src/target/fhe/trans.rs +++ b/src/target/fhe/trans.rs @@ -233,7 +233,7 @@ pub fn to_fhe(ir: Computation, path: &Path, lang: &str) { outputs: terms, metadata: md, .. - } = ir.clone(); + } = ir; let mut converter = ToFHE::new(md, path, lang); From 2159c20ff3b3199845fbc4297121b364af41944f Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 05:13:24 +0000 Subject: [PATCH 10/21] Added building/testing for FHE backend --- .vscode/settings.json | 3 - driver.py | 18 +- .../boolean_tests/2pc_boolean_and.c | 5 + .../unit_tests/boolean_tests/2pc_boolean_or.c | 5 + .../{fhe_and.zok => 2pc_boolean_and.zok} | 0 .../boolean_tests/2pc_boolean_or.zok | 2 + scripts/build_fhe_c_test.zsh | 28 + scripts/build_fhe_zokrates.zsh | 25 - scripts/build_fhe_zokrates_test.zsh | 28 + scripts/build_seal.zsh | 9 + scripts/clean_seal.zsh | 3 + scripts/seal_tests/c_test_seal.py | 28 + scripts/seal_tests/test_inputs/add.txt | 3 + scripts/seal_tests/test_inputs/add_2.txt | 3 + scripts/seal_tests/test_inputs/and_1.txt | 3 + scripts/seal_tests/test_inputs/and_2.txt | 3 + scripts/seal_tests/test_inputs/and_3.txt | 3 + scripts/seal_tests/test_inputs/and_4.txt | 3 + scripts/seal_tests/test_inputs/array.txt | 3 + scripts/seal_tests/test_inputs/array_1.txt | 3 + scripts/seal_tests/test_inputs/array_2.txt | 3 + scripts/seal_tests/test_inputs/array_3.txt | 3 + scripts/seal_tests/test_inputs/array_4.txt | 3 + scripts/seal_tests/test_inputs/biomatch_1.txt | 3 + scripts/seal_tests/test_inputs/biomatch_2.txt | 3 + scripts/seal_tests/test_inputs/const_add.txt | 3 + scripts/seal_tests/test_inputs/const_eq_1.txt | 3 + scripts/seal_tests/test_inputs/const_eq_2.txt | 3 + scripts/seal_tests/test_inputs/conv.txt | 3 + scripts/seal_tests/test_inputs/div_1.txt | 3 + scripts/seal_tests/test_inputs/div_2.txt | 3 + scripts/seal_tests/test_inputs/div_3.txt | 3 + scripts/seal_tests/test_inputs/div_4.txt | 3 + scripts/seal_tests/test_inputs/eq_1.txt | 3 + scripts/seal_tests/test_inputs/eq_2.txt | 3 + scripts/seal_tests/test_inputs/ge_1.txt | 3 + scripts/seal_tests/test_inputs/ge_2.txt | 3 + scripts/seal_tests/test_inputs/ge_3.txt | 3 + scripts/seal_tests/test_inputs/gt_1.txt | 3 + scripts/seal_tests/test_inputs/gt_2.txt | 3 + scripts/seal_tests/test_inputs/gt_3.txt | 3 + scripts/seal_tests/test_inputs/index.txt | 3 + scripts/seal_tests/test_inputs/ite_1.txt | 4 + scripts/seal_tests/test_inputs/ite_2.txt | 4 + scripts/seal_tests/test_inputs/kmeans.txt | 3 + scripts/seal_tests/test_inputs/le_1.txt | 3 + scripts/seal_tests/test_inputs/le_2.txt | 3 + scripts/seal_tests/test_inputs/le_3.txt | 3 + scripts/seal_tests/test_inputs/loop_1.txt | 3 + scripts/seal_tests/test_inputs/loop_2.txt | 3 + scripts/seal_tests/test_inputs/lsh_1.txt | 3 + scripts/seal_tests/test_inputs/lsh_2.txt | 3 + scripts/seal_tests/test_inputs/lsh_3.txt | 3 + scripts/seal_tests/test_inputs/lt_1.txt | 3 + scripts/seal_tests/test_inputs/lt_2.txt | 3 + scripts/seal_tests/test_inputs/lt_3.txt | 3 + scripts/seal_tests/test_inputs/mod_1.txt | 3 + scripts/seal_tests/test_inputs/mod_2.txt | 3 + scripts/seal_tests/test_inputs/mod_3.txt | 3 + scripts/seal_tests/test_inputs/mult_1.txt | 3 + scripts/seal_tests/test_inputs/mult_2.txt | 3 + scripts/seal_tests/test_inputs/mult_3.txt | 3 + .../seal_tests/test_inputs/mult_add_pub_1.txt | 4 + .../seal_tests/test_inputs/mult_add_pub_2.txt | 4 + scripts/seal_tests/test_inputs/nary_add.txt | 4 + scripts/seal_tests/test_inputs/nary_and.txt | 4 + scripts/seal_tests/test_inputs/or_1.txt | 3 + scripts/seal_tests/test_inputs/or_2.txt | 3 + scripts/seal_tests/test_inputs/or_3.txt | 3 + scripts/seal_tests/test_inputs/or_4.txt | 3 + scripts/seal_tests/test_inputs/rsh_1.txt | 3 + scripts/seal_tests/test_inputs/rsh_2.txt | 3 + scripts/seal_tests/test_inputs/sub_1.txt | 3 + scripts/seal_tests/test_inputs/sub_2.txt | 3 + scripts/seal_tests/test_inputs/xor_1.txt | 3 + scripts/seal_tests/test_inputs/xor_2.txt | 3 + scripts/seal_tests/test_inputs/xor_3.txt | 3 + scripts/seal_tests/test_inputs/xor_4.txt | 3 + scripts/seal_tests/test_suite.py | 552 ++++++++++++++++++ .../tests/2pc_boolean_and_c_bytecode.txt} | 0 .../tests/2pc_boolean_and_zok_bytecode.txt | 4 + .../tests/2pc_boolean_or_c_bytecode.txt | 4 + .../tests/2pc_boolean_or_zok_bytecode.txt | 4 + scripts/seal_tests/util.py | 77 +++ scripts/seal_tests/zokrates_test_seal.py | 24 + src/front/c/mod.rs | 3 +- src/target/fhe/utils.rs | 16 +- third_party/SEAL_templates/cpp_template.txt | 25 - util.py | 9 +- 89 files changed, 1004 insertions(+), 72 deletions(-) delete mode 100644 .vscode/settings.json create mode 100644 examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c create mode 100644 examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c rename examples/ZoKrates/fhe/unit_tests/boolean_tests/{fhe_and.zok => 2pc_boolean_and.zok} (100%) create mode 100644 examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok create mode 100755 scripts/build_fhe_c_test.zsh delete mode 100755 scripts/build_fhe_zokrates.zsh create mode 100755 scripts/build_fhe_zokrates_test.zsh create mode 100755 scripts/build_seal.zsh create mode 100644 scripts/clean_seal.zsh create mode 100644 scripts/seal_tests/c_test_seal.py create mode 100644 scripts/seal_tests/test_inputs/add.txt create mode 100644 scripts/seal_tests/test_inputs/add_2.txt create mode 100644 scripts/seal_tests/test_inputs/and_1.txt create mode 100644 scripts/seal_tests/test_inputs/and_2.txt create mode 100644 scripts/seal_tests/test_inputs/and_3.txt create mode 100644 scripts/seal_tests/test_inputs/and_4.txt create mode 100644 scripts/seal_tests/test_inputs/array.txt create mode 100644 scripts/seal_tests/test_inputs/array_1.txt create mode 100644 scripts/seal_tests/test_inputs/array_2.txt create mode 100644 scripts/seal_tests/test_inputs/array_3.txt create mode 100644 scripts/seal_tests/test_inputs/array_4.txt create mode 100644 scripts/seal_tests/test_inputs/biomatch_1.txt create mode 100644 scripts/seal_tests/test_inputs/biomatch_2.txt create mode 100644 scripts/seal_tests/test_inputs/const_add.txt create mode 100644 scripts/seal_tests/test_inputs/const_eq_1.txt create mode 100644 scripts/seal_tests/test_inputs/const_eq_2.txt create mode 100644 scripts/seal_tests/test_inputs/conv.txt create mode 100644 scripts/seal_tests/test_inputs/div_1.txt create mode 100644 scripts/seal_tests/test_inputs/div_2.txt create mode 100644 scripts/seal_tests/test_inputs/div_3.txt create mode 100644 scripts/seal_tests/test_inputs/div_4.txt create mode 100644 scripts/seal_tests/test_inputs/eq_1.txt create mode 100644 scripts/seal_tests/test_inputs/eq_2.txt create mode 100644 scripts/seal_tests/test_inputs/ge_1.txt create mode 100644 scripts/seal_tests/test_inputs/ge_2.txt create mode 100644 scripts/seal_tests/test_inputs/ge_3.txt create mode 100644 scripts/seal_tests/test_inputs/gt_1.txt create mode 100644 scripts/seal_tests/test_inputs/gt_2.txt create mode 100644 scripts/seal_tests/test_inputs/gt_3.txt create mode 100644 scripts/seal_tests/test_inputs/index.txt create mode 100644 scripts/seal_tests/test_inputs/ite_1.txt create mode 100644 scripts/seal_tests/test_inputs/ite_2.txt create mode 100644 scripts/seal_tests/test_inputs/kmeans.txt create mode 100644 scripts/seal_tests/test_inputs/le_1.txt create mode 100644 scripts/seal_tests/test_inputs/le_2.txt create mode 100644 scripts/seal_tests/test_inputs/le_3.txt create mode 100644 scripts/seal_tests/test_inputs/loop_1.txt create mode 100644 scripts/seal_tests/test_inputs/loop_2.txt create mode 100644 scripts/seal_tests/test_inputs/lsh_1.txt create mode 100644 scripts/seal_tests/test_inputs/lsh_2.txt create mode 100644 scripts/seal_tests/test_inputs/lsh_3.txt create mode 100644 scripts/seal_tests/test_inputs/lt_1.txt create mode 100644 scripts/seal_tests/test_inputs/lt_2.txt create mode 100644 scripts/seal_tests/test_inputs/lt_3.txt create mode 100644 scripts/seal_tests/test_inputs/mod_1.txt create mode 100644 scripts/seal_tests/test_inputs/mod_2.txt create mode 100644 scripts/seal_tests/test_inputs/mod_3.txt create mode 100644 scripts/seal_tests/test_inputs/mult_1.txt create mode 100644 scripts/seal_tests/test_inputs/mult_2.txt create mode 100644 scripts/seal_tests/test_inputs/mult_3.txt create mode 100644 scripts/seal_tests/test_inputs/mult_add_pub_1.txt create mode 100644 scripts/seal_tests/test_inputs/mult_add_pub_2.txt create mode 100644 scripts/seal_tests/test_inputs/nary_add.txt create mode 100644 scripts/seal_tests/test_inputs/nary_and.txt create mode 100644 scripts/seal_tests/test_inputs/or_1.txt create mode 100644 scripts/seal_tests/test_inputs/or_2.txt create mode 100644 scripts/seal_tests/test_inputs/or_3.txt create mode 100644 scripts/seal_tests/test_inputs/or_4.txt create mode 100644 scripts/seal_tests/test_inputs/rsh_1.txt create mode 100644 scripts/seal_tests/test_inputs/rsh_2.txt create mode 100644 scripts/seal_tests/test_inputs/sub_1.txt create mode 100644 scripts/seal_tests/test_inputs/sub_2.txt create mode 100644 scripts/seal_tests/test_inputs/xor_1.txt create mode 100644 scripts/seal_tests/test_inputs/xor_2.txt create mode 100644 scripts/seal_tests/test_inputs/xor_3.txt create mode 100644 scripts/seal_tests/test_inputs/xor_4.txt create mode 100644 scripts/seal_tests/test_suite.py rename scripts/{fhe_tests/tests/fhe_and_zok_bytecode.txt => seal_tests/tests/2pc_boolean_and_c_bytecode.txt} (100%) create mode 100644 scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt create mode 100644 scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt create mode 100644 scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt create mode 100644 scripts/seal_tests/util.py create mode 100644 scripts/seal_tests/zokrates_test_seal.py delete mode 100644 third_party/SEAL_templates/cpp_template.txt diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index cad7657df..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "cmake.configureOnOpen": false -} \ No newline at end of file diff --git a/driver.py b/driver.py index b5d099b0f..50d459f1f 100755 --- a/driver.py +++ b/driver.py @@ -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 == "fhe": + if verify_path_empty(SEAL_SOURCE): + subprocess.run(["git", "clone", "https://github.com/Northrim/SEAL.git", SEAL_SOURCE]) + subprocess.run(["./scripts/build_aby.zsh"]) # install python requirements subprocess.run(["pip3", "install", "-r", "requirements.txt"]) @@ -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): """ @@ -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: @@ -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 format(): print("formatting!") @@ -133,6 +147,8 @@ def clean(features): print("cleaning!") if "aby" in features: subprocess.run(["./scripts/clean_aby.zsh"]) + if "fhe" 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"]) @@ -178,7 +194,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 , reset features with -F none") + parser.add_argument("-F", "--features", nargs="+", help="set features on , reset features with -F none") parser.add_argument("extra", metavar="PASS_THROUGH_ARGS", nargs=argparse.REMAINDER, help="Extra arguments for --flamegraph. Prefix with --") args = parser.parse_args() diff --git a/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c b/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c new file mode 100644 index 000000000..6e4e8258b --- /dev/null +++ b/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c @@ -0,0 +1,5 @@ +#include + +bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b) { + return a && b; +} \ No newline at end of file diff --git a/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c b/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c new file mode 100644 index 000000000..b66126c02 --- /dev/null +++ b/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c @@ -0,0 +1,5 @@ +#include + +bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b) { + return a || b; +} \ No newline at end of file diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_and.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok rename to examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_and.zok diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok new file mode 100644 index 000000000..025fa0597 --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok @@ -0,0 +1,2 @@ +def main(private bool a, private bool b) -> bool: + return a || b \ No newline at end of file diff --git a/scripts/build_fhe_c_test.zsh b/scripts/build_fhe_c_test.zsh new file mode 100755 index 000000000..808cf1e12 --- /dev/null +++ b/scripts/build_fhe_c_test.zsh @@ -0,0 +1,28 @@ +#!/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/2pc_boolean_and.c +fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c \ No newline at end of file diff --git a/scripts/build_fhe_zokrates.zsh b/scripts/build_fhe_zokrates.zsh deleted file mode 100755 index b834d5681..000000000 --- a/scripts/build_fhe_zokrates.zsh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env zsh - -set -ex - -disable -r time - -BIN=./target/release/examples/circ - -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 { - zpath=$1 - ipath=$2 - RUST_BACKTRACE=1 measure_time $BIN $zpath --inputs $ipath fhe -} - -# build fhe boolean tests -fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/fhe_and.zok ./examples/ZoKrates/fhe/inputs/fhe_and.txt \ No newline at end of file diff --git a/scripts/build_fhe_zokrates_test.zsh b/scripts/build_fhe_zokrates_test.zsh new file mode 100755 index 000000000..3ee2052d1 --- /dev/null +++ b/scripts/build_fhe_zokrates_test.zsh @@ -0,0 +1,28 @@ +#!/usr/bin/env zsh + +set -ex + +disable -r time + +# cargo build --release --features smt,zok --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 { + zpath=$1 + RUST_BACKTRACE=1 measure_time $BIN $zpath fhe +} + +# build boolean tests +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_and.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok diff --git a/scripts/build_seal.zsh b/scripts/build_seal.zsh new file mode 100755 index 000000000..0511b70b9 --- /dev/null +++ b/scripts/build_seal.zsh @@ -0,0 +1,9 @@ +#!/usr/bin/env zsh + +if [[ ! -z ${SEAL_SOURCE} ]]; then + mkdir -p -- ${SEAL_SOURCE}/build + cd ${SEAL_SOURCE} + cmake --build build +else + echo "Missing SEAL_SOURCE environment variable." +fi \ No newline at end of file diff --git a/scripts/clean_seal.zsh b/scripts/clean_seal.zsh new file mode 100644 index 000000000..3ccc93308 --- /dev/null +++ b/scripts/clean_seal.zsh @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +rm -rf ./scripts/seal_tests/tests diff --git a/scripts/seal_tests/c_test_seal.py b/scripts/seal_tests/c_test_seal.py new file mode 100644 index 000000000..b9968e781 --- /dev/null +++ b/scripts/seal_tests/c_test_seal.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +from util import run_tests +from test_suite import * + +if __name__ == "__main__": + tests = boolean_tests #+ \ + # arithmetic_tests + \ + # mod_tests + \ + # arithmetic_boolean_tests + \ + # nary_arithmetic_tests + \ + # bitwise_tests + \ + # nary_boolean_tests + \ + # const_arith_tests + \ + # const_bool_tests + \ + # ite_tests + \ + # div_tests + \ + # array_tests + \ + # c_array_tests + \ + # misc_tests + \ + # biomatch_tests + \ + # kmeans_tests + # shift_tests + + # TODO: add support for return value - int promotion + # unsigned_arithmetic_tests + \ + + run_tests('c', tests) diff --git a/scripts/seal_tests/test_inputs/add.txt b/scripts/seal_tests/test_inputs/add.txt new file mode 100644 index 000000000..9d0338538 --- /dev/null +++ b/scripts/seal_tests/test_inputs/add.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 3 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/add_2.txt b/scripts/seal_tests/test_inputs/add_2.txt new file mode 100644 index 000000000..a885f6020 --- /dev/null +++ b/scripts/seal_tests/test_inputs/add_2.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 6 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/and_1.txt b/scripts/seal_tests/test_inputs/and_1.txt new file mode 100644 index 000000000..bffd79e1a --- /dev/null +++ b/scripts/seal_tests/test_inputs/and_1.txt @@ -0,0 +1,3 @@ +a 0 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/and_2.txt b/scripts/seal_tests/test_inputs/and_2.txt new file mode 100644 index 000000000..a9e356a5b --- /dev/null +++ b/scripts/seal_tests/test_inputs/and_2.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/and_3.txt b/scripts/seal_tests/test_inputs/and_3.txt new file mode 100644 index 000000000..d516da12a --- /dev/null +++ b/scripts/seal_tests/test_inputs/and_3.txt @@ -0,0 +1,3 @@ +a 0 +b 1 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/and_4.txt b/scripts/seal_tests/test_inputs/and_4.txt new file mode 100644 index 000000000..e7129253a --- /dev/null +++ b/scripts/seal_tests/test_inputs/and_4.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/array.txt b/scripts/seal_tests/test_inputs/array.txt new file mode 100644 index 000000000..05cb13a42 --- /dev/null +++ b/scripts/seal_tests/test_inputs/array.txt @@ -0,0 +1,3 @@ +a 2 +b 2 +res 2 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/array_1.txt b/scripts/seal_tests/test_inputs/array_1.txt new file mode 100644 index 000000000..d84cdf330 --- /dev/null +++ b/scripts/seal_tests/test_inputs/array_1.txt @@ -0,0 +1,3 @@ +a 10 +b 3 +res 17 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/array_2.txt b/scripts/seal_tests/test_inputs/array_2.txt new file mode 100644 index 000000000..d84cdf330 --- /dev/null +++ b/scripts/seal_tests/test_inputs/array_2.txt @@ -0,0 +1,3 @@ +a 10 +b 3 +res 17 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/array_3.txt b/scripts/seal_tests/test_inputs/array_3.txt new file mode 100644 index 000000000..b64095e60 --- /dev/null +++ b/scripts/seal_tests/test_inputs/array_3.txt @@ -0,0 +1,3 @@ +a 2 +b 3 +res 18 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/array_4.txt b/scripts/seal_tests/test_inputs/array_4.txt new file mode 100644 index 000000000..52f6699ac --- /dev/null +++ b/scripts/seal_tests/test_inputs/array_4.txt @@ -0,0 +1,3 @@ +a 1 2 3 4 5 +b 1 2 3 4 5 +res 30 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/biomatch_1.txt b/scripts/seal_tests/test_inputs/biomatch_1.txt new file mode 100644 index 000000000..74069d81e --- /dev/null +++ b/scripts/seal_tests/test_inputs/biomatch_1.txt @@ -0,0 +1,3 @@ +db 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8 6 7 8 9 7 8 9 10 8 9 10 11 9 10 11 12 10 11 12 13 11 12 13 14 12 13 14 15 13 14 15 16 14 15 16 17 15 16 17 18 16 17 18 19 17 18 19 20 18 19 20 21 19 20 21 22 20 21 22 23 21 22 23 24 22 23 24 25 23 24 25 26 24 25 26 27 25 26 27 28 26 27 28 29 27 28 29 30 28 29 30 31 29 30 31 32 30 31 32 33 31 32 33 34 32 33 34 35 33 34 35 36 34 35 36 37 35 36 37 38 36 37 38 39 37 38 39 40 38 39 40 41 39 40 41 42 40 41 42 43 41 42 43 44 42 43 44 45 43 44 45 46 44 45 46 47 45 46 47 48 46 47 48 49 47 48 49 50 48 49 50 51 49 50 51 52 50 51 52 53 51 52 53 54 52 53 54 55 53 54 55 56 54 55 56 57 55 56 57 58 56 57 58 59 57 58 59 60 58 59 60 61 59 60 61 62 60 61 62 63 61 62 63 64 62 63 64 65 63 64 65 66 64 65 66 67 65 66 67 68 66 67 68 69 67 68 69 70 68 69 70 71 69 70 71 72 70 71 72 73 71 72 73 74 72 73 74 75 73 74 75 76 74 75 76 77 75 76 77 78 76 77 78 79 77 78 79 80 78 79 80 81 79 80 81 82 80 81 82 83 81 82 83 84 82 83 84 85 83 84 85 86 84 85 86 87 85 86 87 88 86 87 88 89 87 88 89 90 88 89 90 91 89 90 91 92 90 91 92 93 91 92 93 94 92 93 94 95 93 94 95 96 94 95 96 97 95 96 97 98 96 97 98 99 97 98 99 100 98 99 100 101 99 100 101 102 100 101 102 103 101 102 103 104 102 103 104 105 103 104 105 106 104 105 106 107 105 106 107 108 106 107 108 109 107 108 109 110 108 109 110 111 109 110 111 112 110 111 112 113 111 112 113 114 112 113 114 115 113 114 115 116 114 115 116 117 115 116 117 118 116 117 118 119 117 118 119 120 118 119 120 121 119 120 121 122 120 121 122 123 121 122 123 124 122 123 124 125 123 124 125 126 124 125 126 127 125 126 127 128 126 127 128 129 127 128 129 130 128 129 130 131 129 130 131 132 130 131 132 133 131 132 133 134 132 133 134 135 133 134 135 136 134 135 136 137 135 136 137 138 136 137 138 139 137 138 139 140 138 139 140 141 139 140 141 142 140 141 142 143 141 142 143 144 142 143 144 145 143 144 145 146 144 145 146 147 145 146 147 148 146 147 148 149 147 148 149 150 148 149 150 151 149 150 151 152 150 151 152 153 151 152 153 154 152 153 154 155 153 154 155 156 154 155 156 157 155 156 157 158 156 157 158 159 157 158 159 160 158 159 160 161 159 160 161 162 160 161 162 163 161 162 163 164 162 163 164 165 163 164 165 166 164 165 166 167 165 166 167 168 166 167 168 169 167 168 169 170 168 169 170 171 169 170 171 172 170 171 172 173 171 172 173 174 172 173 174 175 173 174 175 176 174 175 176 177 175 176 177 178 176 177 178 179 177 178 179 180 178 179 180 181 179 180 181 182 180 181 182 183 181 182 183 184 182 183 184 185 183 184 185 186 184 185 186 187 185 186 187 188 186 187 188 189 187 188 189 190 188 189 190 191 189 190 191 192 190 191 192 193 191 192 193 194 192 193 194 195 193 194 195 196 194 195 196 197 195 196 197 198 196 197 198 199 197 198 199 200 198 199 200 201 199 200 201 202 200 201 202 203 201 202 203 204 202 203 204 205 203 204 205 206 204 205 206 207 205 206 207 208 206 207 208 209 207 208 209 210 208 209 210 211 209 210 211 212 210 211 212 213 211 212 213 214 212 213 214 215 213 214 215 216 214 215 216 217 215 216 217 218 216 217 218 219 217 218 219 220 218 219 220 221 219 220 221 222 220 221 222 223 221 222 223 224 222 223 224 225 223 224 225 226 224 225 226 227 225 226 227 228 226 227 228 229 227 228 229 230 228 229 230 231 229 230 231 232 230 231 232 233 231 232 233 234 232 233 234 235 233 234 235 236 234 235 236 237 235 236 237 238 236 237 238 239 237 238 239 240 238 239 240 241 239 240 241 242 240 241 242 243 241 242 243 244 242 243 244 245 243 244 245 246 244 245 246 247 245 246 247 248 246 247 248 249 247 248 249 250 248 249 250 251 249 250 251 252 250 251 252 253 251 252 253 254 252 253 254 255 253 254 255 256 254 255 256 257 255 256 257 258 +sample 0 0 0 0 +res 14 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/biomatch_2.txt b/scripts/seal_tests/test_inputs/biomatch_2.txt new file mode 100644 index 000000000..b69f333b9 --- /dev/null +++ b/scripts/seal_tests/test_inputs/biomatch_2.txt @@ -0,0 +1,3 @@ +db 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8 6 7 8 9 7 8 9 10 8 9 10 11 9 10 11 12 10 11 12 13 11 12 13 14 12 13 14 15 13 14 15 16 14 15 16 17 15 16 17 18 16 17 18 19 17 18 19 20 18 19 20 21 19 20 21 22 20 21 22 23 21 22 23 24 22 23 24 25 23 24 25 26 24 25 26 27 25 26 27 28 26 27 28 29 27 28 29 30 28 29 30 31 29 30 31 32 30 31 32 33 31 32 33 34 32 33 34 35 33 34 35 36 34 35 36 37 35 36 37 38 36 37 38 39 37 38 39 40 38 39 40 41 39 40 41 42 40 41 42 43 41 42 43 44 42 43 44 45 43 44 45 46 44 45 46 47 45 46 47 48 46 47 48 49 47 48 49 50 48 49 50 51 49 50 51 52 50 51 52 53 51 52 53 54 52 53 54 55 53 54 55 56 54 55 56 57 55 56 57 58 56 57 58 59 57 58 59 60 58 59 60 61 59 60 61 62 60 61 62 63 61 62 63 64 62 63 64 65 63 64 65 66 64 65 66 67 65 66 67 68 66 67 68 69 67 68 69 70 68 69 70 71 69 70 71 72 70 71 72 73 71 72 73 74 72 73 74 75 73 74 75 76 74 75 76 77 75 76 77 78 76 77 78 79 77 78 79 80 78 79 80 81 79 80 81 82 80 81 82 83 81 82 83 84 82 83 84 85 83 84 85 86 84 85 86 87 85 86 87 88 86 87 88 89 87 88 89 90 88 89 90 91 89 90 91 92 90 91 92 93 91 92 93 94 92 93 94 95 93 94 95 96 94 95 96 97 95 96 97 98 96 97 98 99 97 98 99 100 98 99 100 101 99 100 101 102 100 101 102 103 101 102 103 104 102 103 104 105 103 104 105 106 104 105 106 107 105 106 107 108 106 107 108 109 107 108 109 110 108 109 110 111 109 110 111 112 110 111 112 113 111 112 113 114 112 113 114 115 113 114 115 116 114 115 116 117 115 116 117 118 116 117 118 119 117 118 119 120 118 119 120 121 119 120 121 122 120 121 122 123 121 122 123 124 122 123 124 125 123 124 125 126 124 125 126 127 125 126 127 128 126 127 128 129 127 128 129 130 128 129 130 131 129 130 131 132 130 131 132 133 131 132 133 134 132 133 134 135 133 134 135 136 134 135 136 137 135 136 137 138 136 137 138 139 137 138 139 140 138 139 140 141 139 140 141 142 140 141 142 143 141 142 143 144 142 143 144 145 143 144 145 146 144 145 146 147 145 146 147 148 146 147 148 149 147 148 149 150 148 149 150 151 149 150 151 152 150 151 152 153 151 152 153 154 152 153 154 155 153 154 155 156 154 155 156 157 155 156 157 158 156 157 158 159 157 158 159 160 158 159 160 161 159 160 161 162 160 161 162 163 161 162 163 164 162 163 164 165 163 164 165 166 164 165 166 167 165 166 167 168 166 167 168 169 167 168 169 170 168 169 170 171 169 170 171 172 170 171 172 173 171 172 173 174 172 173 174 175 173 174 175 176 174 175 176 177 175 176 177 178 176 177 178 179 177 178 179 180 178 179 180 181 179 180 181 182 180 181 182 183 181 182 183 184 182 183 184 185 183 184 185 186 184 185 186 187 185 186 187 188 186 187 188 189 187 188 189 190 188 189 190 191 189 190 191 192 190 191 192 193 191 192 193 194 192 193 194 195 193 194 195 196 194 195 196 197 195 196 197 198 196 197 198 199 197 198 199 200 198 199 200 201 199 200 201 202 200 201 202 203 201 202 203 204 202 203 204 205 203 204 205 206 204 205 206 207 205 206 207 208 206 207 208 209 207 208 209 210 208 209 210 211 209 210 211 212 210 211 212 213 211 212 213 214 212 213 214 215 213 214 215 216 214 215 216 217 215 216 217 218 216 217 218 219 217 218 219 220 218 219 220 221 219 220 221 222 220 221 222 223 221 222 223 224 222 223 224 225 223 224 225 226 224 225 226 227 225 226 227 228 226 227 228 229 227 228 229 230 228 229 230 231 229 230 231 232 230 231 232 233 231 232 233 234 232 233 234 235 233 234 235 236 234 235 236 237 235 236 237 238 236 237 238 239 237 238 239 240 238 239 240 241 239 240 241 242 240 241 242 243 241 242 243 244 242 243 244 245 243 244 245 246 244 245 246 247 245 246 247 248 246 247 248 249 247 248 249 250 248 249 250 251 249 250 251 252 250 251 252 253 251 252 253 254 252 253 254 255 253 254 255 256 254 255 256 257 255 256 257 258 +sample 1 2 3 4 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/const_add.txt b/scripts/seal_tests/test_inputs/const_add.txt new file mode 100644 index 000000000..903c001a2 --- /dev/null +++ b/scripts/seal_tests/test_inputs/const_add.txt @@ -0,0 +1,3 @@ +a 2 +b 3 +res 6 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/const_eq_1.txt b/scripts/seal_tests/test_inputs/const_eq_1.txt new file mode 100644 index 000000000..b7504f131 --- /dev/null +++ b/scripts/seal_tests/test_inputs/const_eq_1.txt @@ -0,0 +1,3 @@ +a 0 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/const_eq_2.txt b/scripts/seal_tests/test_inputs/const_eq_2.txt new file mode 100644 index 000000000..b35d53a3c --- /dev/null +++ b/scripts/seal_tests/test_inputs/const_eq_2.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/conv.txt b/scripts/seal_tests/test_inputs/conv.txt new file mode 100644 index 000000000..a716070f5 --- /dev/null +++ b/scripts/seal_tests/test_inputs/conv.txt @@ -0,0 +1,3 @@ +a 0 +b 7 +res 7 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/div_1.txt b/scripts/seal_tests/test_inputs/div_1.txt new file mode 100644 index 000000000..aae5f347a --- /dev/null +++ b/scripts/seal_tests/test_inputs/div_1.txt @@ -0,0 +1,3 @@ +a 10 +b 1 +res 10 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/div_2.txt b/scripts/seal_tests/test_inputs/div_2.txt new file mode 100644 index 000000000..765229865 --- /dev/null +++ b/scripts/seal_tests/test_inputs/div_2.txt @@ -0,0 +1,3 @@ +a 10 +b 2 +res 5 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/div_3.txt b/scripts/seal_tests/test_inputs/div_3.txt new file mode 100644 index 000000000..eae9243f7 --- /dev/null +++ b/scripts/seal_tests/test_inputs/div_3.txt @@ -0,0 +1,3 @@ +a 11 +b 2 +res 5 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/div_4.txt b/scripts/seal_tests/test_inputs/div_4.txt new file mode 100644 index 000000000..dfd199351 --- /dev/null +++ b/scripts/seal_tests/test_inputs/div_4.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/eq_1.txt b/scripts/seal_tests/test_inputs/eq_1.txt new file mode 100644 index 000000000..a9e356a5b --- /dev/null +++ b/scripts/seal_tests/test_inputs/eq_1.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/eq_2.txt b/scripts/seal_tests/test_inputs/eq_2.txt new file mode 100644 index 000000000..e7129253a --- /dev/null +++ b/scripts/seal_tests/test_inputs/eq_2.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/ge_1.txt b/scripts/seal_tests/test_inputs/ge_1.txt new file mode 100644 index 000000000..dfd199351 --- /dev/null +++ b/scripts/seal_tests/test_inputs/ge_1.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/ge_2.txt b/scripts/seal_tests/test_inputs/ge_2.txt new file mode 100644 index 000000000..e7129253a --- /dev/null +++ b/scripts/seal_tests/test_inputs/ge_2.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/ge_3.txt b/scripts/seal_tests/test_inputs/ge_3.txt new file mode 100644 index 000000000..b35d53a3c --- /dev/null +++ b/scripts/seal_tests/test_inputs/ge_3.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/gt_1.txt b/scripts/seal_tests/test_inputs/gt_1.txt new file mode 100644 index 000000000..dfd199351 --- /dev/null +++ b/scripts/seal_tests/test_inputs/gt_1.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/gt_2.txt b/scripts/seal_tests/test_inputs/gt_2.txt new file mode 100644 index 000000000..af7201b0c --- /dev/null +++ b/scripts/seal_tests/test_inputs/gt_2.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/gt_3.txt b/scripts/seal_tests/test_inputs/gt_3.txt new file mode 100644 index 000000000..f08a0a3f0 --- /dev/null +++ b/scripts/seal_tests/test_inputs/gt_3.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/index.txt b/scripts/seal_tests/test_inputs/index.txt new file mode 100644 index 000000000..9c3ab6935 --- /dev/null +++ b/scripts/seal_tests/test_inputs/index.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/ite_1.txt b/scripts/seal_tests/test_inputs/ite_1.txt new file mode 100644 index 000000000..999905001 --- /dev/null +++ b/scripts/seal_tests/test_inputs/ite_1.txt @@ -0,0 +1,4 @@ +a 0 +b 1 +sel 1 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/ite_2.txt b/scripts/seal_tests/test_inputs/ite_2.txt new file mode 100644 index 000000000..b76bbac12 --- /dev/null +++ b/scripts/seal_tests/test_inputs/ite_2.txt @@ -0,0 +1,4 @@ +a 0 +b 1 +sel 0 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/kmeans.txt b/scripts/seal_tests/test_inputs/kmeans.txt new file mode 100644 index 000000000..5e99f9175 --- /dev/null +++ b/scripts/seal_tests/test_inputs/kmeans.txt @@ -0,0 +1,3 @@ +a 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +b 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 +res 103 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/le_1.txt b/scripts/seal_tests/test_inputs/le_1.txt new file mode 100644 index 000000000..9c3ab6935 --- /dev/null +++ b/scripts/seal_tests/test_inputs/le_1.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/le_2.txt b/scripts/seal_tests/test_inputs/le_2.txt new file mode 100644 index 000000000..e7129253a --- /dev/null +++ b/scripts/seal_tests/test_inputs/le_2.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/le_3.txt b/scripts/seal_tests/test_inputs/le_3.txt new file mode 100644 index 000000000..9696b0dee --- /dev/null +++ b/scripts/seal_tests/test_inputs/le_3.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/loop_1.txt b/scripts/seal_tests/test_inputs/loop_1.txt new file mode 100644 index 000000000..dbfc1f40b --- /dev/null +++ b/scripts/seal_tests/test_inputs/loop_1.txt @@ -0,0 +1,3 @@ +a 2 +b 1 +res 10 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/loop_2.txt b/scripts/seal_tests/test_inputs/loop_2.txt new file mode 100644 index 000000000..cc2da46e3 --- /dev/null +++ b/scripts/seal_tests/test_inputs/loop_2.txt @@ -0,0 +1,3 @@ +a 10 +b 3 +res 10 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/lsh_1.txt b/scripts/seal_tests/test_inputs/lsh_1.txt new file mode 100644 index 000000000..adeb10c20 --- /dev/null +++ b/scripts/seal_tests/test_inputs/lsh_1.txt @@ -0,0 +1,3 @@ +a 10 +b 2 +res 20 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/lsh_2.txt b/scripts/seal_tests/test_inputs/lsh_2.txt new file mode 100644 index 000000000..aafb50571 --- /dev/null +++ b/scripts/seal_tests/test_inputs/lsh_2.txt @@ -0,0 +1,3 @@ +a 0 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/lsh_3.txt b/scripts/seal_tests/test_inputs/lsh_3.txt new file mode 100644 index 000000000..857e0b0e5 --- /dev/null +++ b/scripts/seal_tests/test_inputs/lsh_3.txt @@ -0,0 +1,3 @@ +a 2147483648 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/lt_1.txt b/scripts/seal_tests/test_inputs/lt_1.txt new file mode 100644 index 000000000..0d16f5a89 --- /dev/null +++ b/scripts/seal_tests/test_inputs/lt_1.txt @@ -0,0 +1,3 @@ +a 2 +b 1 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/lt_2.txt b/scripts/seal_tests/test_inputs/lt_2.txt new file mode 100644 index 000000000..af7201b0c --- /dev/null +++ b/scripts/seal_tests/test_inputs/lt_2.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/lt_3.txt b/scripts/seal_tests/test_inputs/lt_3.txt new file mode 100644 index 000000000..074c00099 --- /dev/null +++ b/scripts/seal_tests/test_inputs/lt_3.txt @@ -0,0 +1,3 @@ +a 0 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mod_1.txt b/scripts/seal_tests/test_inputs/mod_1.txt new file mode 100644 index 000000000..54c560466 --- /dev/null +++ b/scripts/seal_tests/test_inputs/mod_1.txt @@ -0,0 +1,3 @@ +a 0 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mod_2.txt b/scripts/seal_tests/test_inputs/mod_2.txt new file mode 100644 index 000000000..9c3ab6935 --- /dev/null +++ b/scripts/seal_tests/test_inputs/mod_2.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mod_3.txt b/scripts/seal_tests/test_inputs/mod_3.txt new file mode 100644 index 000000000..a213350db --- /dev/null +++ b/scripts/seal_tests/test_inputs/mod_3.txt @@ -0,0 +1,3 @@ +a 2 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_1.txt b/scripts/seal_tests/test_inputs/mult_1.txt new file mode 100644 index 000000000..596a6ab24 --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_1.txt @@ -0,0 +1,3 @@ +a 0 +b 5 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_2.txt b/scripts/seal_tests/test_inputs/mult_2.txt new file mode 100644 index 000000000..f3a9b265c --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_2.txt @@ -0,0 +1,3 @@ +a 1 +b 5 +res 5 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_3.txt b/scripts/seal_tests/test_inputs/mult_3.txt new file mode 100644 index 000000000..0c84b4868 --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_3.txt @@ -0,0 +1,3 @@ +a 2 +b 5 +res 10 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_add_pub_1.txt b/scripts/seal_tests/test_inputs/mult_add_pub_1.txt new file mode 100644 index 000000000..3c5e755dd --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_add_pub_1.txt @@ -0,0 +1,4 @@ +a 5 +v 7 +b 7 +res 42 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_add_pub_2.txt b/scripts/seal_tests/test_inputs/mult_add_pub_2.txt new file mode 100644 index 000000000..3c5e755dd --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_add_pub_2.txt @@ -0,0 +1,4 @@ +a 5 +v 7 +b 7 +res 42 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/nary_add.txt b/scripts/seal_tests/test_inputs/nary_add.txt new file mode 100644 index 000000000..780d3579c --- /dev/null +++ b/scripts/seal_tests/test_inputs/nary_add.txt @@ -0,0 +1,4 @@ +a 1 +b 2 +c 3 +res 6 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/nary_and.txt b/scripts/seal_tests/test_inputs/nary_and.txt new file mode 100644 index 000000000..1fffca872 --- /dev/null +++ b/scripts/seal_tests/test_inputs/nary_and.txt @@ -0,0 +1,4 @@ +a 1 +b 1 +c 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/or_1.txt b/scripts/seal_tests/test_inputs/or_1.txt new file mode 100644 index 000000000..b7504f131 --- /dev/null +++ b/scripts/seal_tests/test_inputs/or_1.txt @@ -0,0 +1,3 @@ +a 0 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/or_2.txt b/scripts/seal_tests/test_inputs/or_2.txt new file mode 100644 index 000000000..b35d53a3c --- /dev/null +++ b/scripts/seal_tests/test_inputs/or_2.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/or_3.txt b/scripts/seal_tests/test_inputs/or_3.txt new file mode 100644 index 000000000..e97a331be --- /dev/null +++ b/scripts/seal_tests/test_inputs/or_3.txt @@ -0,0 +1,3 @@ +a 0 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/or_4.txt b/scripts/seal_tests/test_inputs/or_4.txt new file mode 100644 index 000000000..e7129253a --- /dev/null +++ b/scripts/seal_tests/test_inputs/or_4.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/rsh_1.txt b/scripts/seal_tests/test_inputs/rsh_1.txt new file mode 100644 index 000000000..8dbc6905f --- /dev/null +++ b/scripts/seal_tests/test_inputs/rsh_1.txt @@ -0,0 +1,3 @@ +a 20 +b 2 +res 10 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/rsh_2.txt b/scripts/seal_tests/test_inputs/rsh_2.txt new file mode 100644 index 000000000..aafb50571 --- /dev/null +++ b/scripts/seal_tests/test_inputs/rsh_2.txt @@ -0,0 +1,3 @@ +a 0 +b 2 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/sub_1.txt b/scripts/seal_tests/test_inputs/sub_1.txt new file mode 100644 index 000000000..1eeed2583 --- /dev/null +++ b/scripts/seal_tests/test_inputs/sub_1.txt @@ -0,0 +1,3 @@ +a 3 +b 2 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/sub_2.txt b/scripts/seal_tests/test_inputs/sub_2.txt new file mode 100644 index 000000000..ba4d35810 --- /dev/null +++ b/scripts/seal_tests/test_inputs/sub_2.txt @@ -0,0 +1,3 @@ +a 2 +b 3 +res 4294967295 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/xor_1.txt b/scripts/seal_tests/test_inputs/xor_1.txt new file mode 100644 index 000000000..bffd79e1a --- /dev/null +++ b/scripts/seal_tests/test_inputs/xor_1.txt @@ -0,0 +1,3 @@ +a 0 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/xor_2.txt b/scripts/seal_tests/test_inputs/xor_2.txt new file mode 100644 index 000000000..a6e61de8e --- /dev/null +++ b/scripts/seal_tests/test_inputs/xor_2.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/xor_3.txt b/scripts/seal_tests/test_inputs/xor_3.txt new file mode 100644 index 000000000..e97a331be --- /dev/null +++ b/scripts/seal_tests/test_inputs/xor_3.txt @@ -0,0 +1,3 @@ +a 0 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/xor_4.txt b/scripts/seal_tests/test_inputs/xor_4.txt new file mode 100644 index 000000000..af7201b0c --- /dev/null +++ b/scripts/seal_tests/test_inputs/xor_4.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_suite.py b/scripts/seal_tests/test_suite.py new file mode 100644 index 000000000..45e114603 --- /dev/null +++ b/scripts/seal_tests/test_suite.py @@ -0,0 +1,552 @@ +arithmetic_tests = [ + [ + "Add two numbers", + "2pc_add", + "./scripts/seal_tests/test_inputs/add.txt", + ], + [ + "Subtract two numbers", + "2pc_sub", + "./scripts/seal_tests/test_inputs/sub_1.txt", + ], + [ + "Subtract two numbers, negative -1 == 4294967295 because u32", + "2pc_sub", + "./scripts/seal_tests/test_inputs/sub_2.txt", + ], + [ + "Multiply two numbers - 1", + "2pc_mult", + "./scripts/seal_tests/test_inputs/mult_1.txt", + ], + [ + "Multiply two numbers - 2", + "2pc_mult", + "./scripts/seal_tests/test_inputs/mult_2.txt", + ], + [ + "Multiply two numbers - 3", + "2pc_mult", + "./scripts/seal_tests/test_inputs/mult_3.txt", + ], + [ + # only server side public value works + "Multiply two numbers together and add with public value", + "2pc_mult_add_pub", + "./scripts/seal_tests/test_inputs/mult_add_pub_1.txt", + ], + [ + # only server side public value works + "Multiply two numbers together and add with public value, check only server side public value is added", + "2pc_mult_add_pub", + "./scripts/seal_tests/test_inputs/mult_add_pub_2.txt", + ], +] + +mod_tests = [ + [ + "Mod two numbers - 1", + "2pc_mod", + "./scripts/seal_tests/test_inputs/mod_1.txt", + ], + [ + "Mod two numbers - 2", + "2pc_mod", + "./scripts/seal_tests/test_inputs/mod_2.txt", + ], + [ + "Mod two numbers - 3", + "2pc_mod", + "./scripts/seal_tests/test_inputs/mod_3.txt", + ], +] + +unsigned_arithmetic_tests = [ + [ + "Add two unsigned numbers", + "2pc_add_unsigned", + "./scripts/seal_tests/test_inputs/add.txt", + ], +] + +arithmetic_boolean_tests = [ + [ + "Test two numbers are equal - 1", + "2pc_int_equals", + "./scripts/seal_tests/test_inputs/eq_1.txt", + ], + [ + "Test two numbers are equal - 2", + "2pc_int_equals", + "./scripts/seal_tests/test_inputs/eq_2.txt", + ], + [ + "Test int > int - 1", + "2pc_int_greater_than", + "./scripts/seal_tests/test_inputs/gt_1.txt", + ], + [ + "Test int > int - 2", + "2pc_int_greater_than", + "./scripts/seal_tests/test_inputs/gt_2.txt", + ], + [ + "Test int > int - 3", + "2pc_int_greater_than", + "./scripts/seal_tests/test_inputs/gt_3.txt", + ], + [ + "Test int >= int - 1", + "2pc_int_greater_equals", + "./scripts/seal_tests/test_inputs/ge_1.txt", + ], + [ + "Test int >= int - 2", + "2pc_int_greater_equals", + "./scripts/seal_tests/test_inputs/ge_2.txt", + ], + [ + "Test int >= int - 3", + "2pc_int_greater_equals", + "./scripts/seal_tests/test_inputs/ge_3.txt", + ], + [ + "Test int < int - 1", + "2pc_int_less_than", + "./scripts/seal_tests/test_inputs/lt_1.txt", + ], + [ + "Test int < int - 2", + "2pc_int_less_than", + "./scripts/seal_tests/test_inputs/lt_2.txt", + ], + [ + "Test int < int - 3", + "2pc_int_less_than", + "./scripts/seal_tests/test_inputs/lt_3.txt", + ], + [ + "Test int <= int - 1", + "2pc_int_less_equals", + "./scripts/seal_tests/test_inputs/le_1.txt", + ], + [ + "Test int <= int - 2", + "2pc_int_less_equals", + "./scripts/seal_tests/test_inputs/le_2.txt", + ], + [ + "Test int <= int - 3", + "2pc_int_less_equals", + "./scripts/seal_tests/test_inputs/le_3.txt", + ], +] + +nary_arithmetic_tests = [ + [ + "Test a + b + c", + "2pc_nary_arithmetic_add", + "./scripts/seal_tests/test_inputs/nary_add.txt", + ], +] + +bitwise_tests = [ + [ + "Bitwise & - 1", + "2pc_bitwise_and", + "./scripts/seal_tests/test_inputs/and_1.txt", + ], + [ + "Bitwise & - 2", + "2pc_bitwise_and", + "./scripts/seal_tests/test_inputs/and_2.txt", + ], + [ + "Bitwise & - 3", + "2pc_bitwise_and", + "./scripts/seal_tests/test_inputs/and_3.txt", + ], + [ + "Bitwise & - 4", + "2pc_bitwise_and", + "./scripts/seal_tests/test_inputs/and_4.txt", + ], + [ + "Bitwise | - 1", + "2pc_bitwise_or", + "./scripts/seal_tests/test_inputs/or_1.txt", + ], + [ + "Bitwise | - 2", + "2pc_bitwise_or", + "./scripts/seal_tests/test_inputs/or_2.txt", + ], + [ + "Bitwise | - 3", + "2pc_bitwise_or", + "./scripts/seal_tests/test_inputs/or_3.txt", + ], + [ + "Bitwise | - 4", + "2pc_bitwise_or", + "./scripts/seal_tests/test_inputs/or_4.txt", + ], + [ + "Bitwise ^ - 1", + "2pc_bitwise_xor", + "./scripts/seal_tests/test_inputs/xor_1.txt", + + ], + [ + "Bitwise ^ - 2", + "2pc_bitwise_xor", + "./scripts/seal_tests/test_inputs/xor_2.txt", + ], + [ + "Bitwise ^ - 3", + "2pc_bitwise_xor", + "./scripts/seal_tests/test_inputs/xor_3.txt", + ], + [ + "Bitwise ^ - 4", + "2pc_bitwise_xor", + "./scripts/seal_tests/test_inputs/xor_4.txt", + ], +] + +boolean_tests = [ + [ + "Boolean && - 1", + "2pc_boolean_and", + "./scripts/seal_tests/test_inputs/and_1.txt", + ], + [ + "Boolean && - 2", + "2pc_boolean_and", + "./scripts/seal_tests/test_inputs/and_2.txt", + ], + [ + "Boolean && - 3", + "2pc_boolean_and", + "./scripts/seal_tests/test_inputs/and_3.txt", + ], + [ + "Boolean && - 4", + "2pc_boolean_and", + "./scripts/seal_tests/test_inputs/and_4.txt", + ], + [ + "Boolean || - 1", + "2pc_boolean_or", + "./scripts/seal_tests/test_inputs/or_1.txt", + ], + [ + "Boolean || - 2", + "2pc_boolean_or", + "./scripts/seal_tests/test_inputs/or_2.txt", + + ], + [ + "Boolean || - 3", + "2pc_boolean_or", + "./scripts/seal_tests/test_inputs/or_3.txt", + + ], + [ + "Boolean || - 4", + "2pc_boolean_or", + "./scripts/seal_tests/test_inputs/or_4.txt", + ], + # [ + # "Boolean == - 1", + # "2pc_boolean_equals", + # "./scripts/seal_tests/test_inputs/eq_1.txt", + # ], + # [ + # "Boolean == - 2", + # "2pc_boolean_equals", + # "./scripts/seal_tests/test_inputs/eq_2.txt", + # ], +] + +nary_boolean_tests = [ + [ + "Test a & b & c", + "2pc_nary_boolean_and", + "./scripts/seal_tests/test_inputs/nary_and.txt", + ], +] + + +const_arith_tests = [ + [ + "Test add client int + server int to const value", + "2pc_const_arith", + "./scripts/seal_tests/test_inputs/const_add.txt", + ], +] + +const_bool_tests = [ + [ + "Test server value == const value - 1", + "2pc_const_bool", + "./scripts/seal_tests/test_inputs/const_eq_1.txt", + ], + [ + "Test server value == const value - 2", + "2pc_const_bool", + "./scripts/seal_tests/test_inputs/const_eq_2.txt", + ], +] + +ite_tests = [ + [ + "Test ite ret bool - 1", + "2pc_ite_ret_bool", + "./scripts/seal_tests/test_inputs/ite_1.txt", + ], + [ + "Test ite ret bool - 2", + "2pc_ite_ret_bool", + "./scripts/seal_tests/test_inputs/ite_2.txt", + ], + [ + "Test ite ret int - 1", + "2pc_ite_ret_int", + "./scripts/seal_tests/test_inputs/ite_1.txt", + ], + [ + "Test ite ret int - 2", + "2pc_ite_ret_int", + "./scripts/seal_tests/test_inputs/ite_2.txt", + ], + [ + "Test ite only if - 1", + "2pc_ite_only_if", + "./scripts/seal_tests/test_inputs/ite_1.txt", + ], + [ + "Test ite only if - 2", + "2pc_ite_only_if", + "./scripts/seal_tests/test_inputs/ite_2.txt", + ], +] + +array_tests = [ + [ + "Array sum test", + "2pc_array_sum", + "./scripts/seal_tests/test_inputs/add.txt", + ], + [ + "Array index test", + "2pc_array_index", + "./scripts/seal_tests/test_inputs/add.txt", + ], +] + +c_array_tests = [ + [ + "C array test", + "2pc_array", + "./scripts/seal_tests/test_inputs/array.txt", + ], + [ + "C array test 1", + "2pc_array_1", + "./scripts/seal_tests/test_inputs/array_1.txt", + ], + [ + "C array test 2", + "2pc_array_2", + "./scripts/seal_tests/test_inputs/array_2.txt", + ], + [ + "C array test 3", + "2pc_array_3", + "./scripts/seal_tests/test_inputs/array_3.txt", + ], + [ + "C array test 4", + "2pc_array_sum_c", + "./scripts/seal_tests/test_inputs/array_4.txt", + ], +] + +loop_tests = [ + [ + "Loop sum const - 1", + "2pc_loop_sum", + "./scripts/seal_tests/test_inputs/loop_1.txt", + ], + [ + "Loop sum const - 2", + "2pc_loop_sum", + "./scripts/seal_tests/test_inputs/loop_2.txt", + ], +] + +function_tests = [ + [ + "Sum() two numbers - 1", + "2pc_function_add", + "./scripts/seal_tests/test_inputs/add_2.txt", + ], +] + +shift_tests = [ + [ + "Left Shift a by 1 - 1", + "2pc_lhs", + "./scripts/seal_tests/test_inputs/lsh_1.txt", + ], + [ + "Left Shift a by 1 - 2", + "2pc_lhs", + "./scripts/seal_tests/test_inputs/lsh_2.txt", + ], + [ + "Left Shift a by 1 - 3", + "2pc_lhs", + "./scripts/seal_tests/test_inputs/lsh_3.txt", + ], + [ + "Right Shift a by 1 - 1", + "2pc_rhs", + "./scripts/seal_tests/test_inputs/rsh_1.txt", + ], + [ + "Right Shift a by 1 - 2", + "2pc_rhs", + "./scripts/seal_tests/test_inputs/rsh_2.txt", + ], +] + + +div_tests = [ + [ + "Divide a by 1", + "2pc_div", + "./scripts/seal_tests/test_inputs/div_1.txt", + ], + [ + "Divide a by b - 1", + "2pc_div", + "./scripts/seal_tests/test_inputs/div_2.txt", + ], + [ + "Divide a by b - 2", + "2pc_div", + "./scripts/seal_tests/test_inputs/div_3.txt", + ], + [ + "Divide a by b - 3", + "2pc_div", + "./scripts/seal_tests/test_inputs/div_4.txt", + ], +] + +misc_tests = [ + [ + "Millionaire's problem: server has more money than client", + "2pc_millionaires", + "./scripts/seal_tests/test_inputs/lt_1.txt", + ], + [ + "Millionaire's problem: server has equal money to client", + "2pc_millionaires", + "./scripts/seal_tests/test_inputs/lt_2.txt", + ], + [ + "Millionaire's problem: server has less money than client", + "2pc_millionaires", + "./scripts/seal_tests/test_inputs/lt_3.txt", + ], +] + +kmeans_tests = [ + [ + "kmeans", + "2pc_kmeans", + "./scripts/seal_tests/test_inputs/kmeans.txt", + ], +] + +biomatch_tests = [ + [ + "biomatch - 1", + "2pc_biomatch", + "./scripts/seal_tests/test_inputs/biomatch_1.txt", + ], + [ + "biomatch - 2", + "2pc_biomatch", + "./scripts/seal_tests/test_inputs/biomatch_2.txt", + ], +] + +# ilp_benchmark_tests = [ +# [ +# "ilp bench - array sum 1", +# 1000, +# "2pc_ilp_bench_1", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 2", +# 2000, +# "2pc_ilp_bench_2", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 3", +# 3000, +# "2pc_ilp_bench_3", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 4", +# 4000, +# "2pc_ilp_bench_4", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 5", +# 5000, +# "2pc_ilp_bench_5", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 6", +# 6000, +# "2pc_ilp_bench_6", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 7", +# 7000, +# "2pc_ilp_bench_7", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 8", +# 8000, +# "2pc_ilp_bench_8", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# [ +# "ilp bench - array sum 9", +# 9000, +# "2pc_ilp_bench_9", +# {"a": 2, "b": 0}, +# {"a": 0, "b": 1}, +# ], +# ] diff --git a/scripts/fhe_tests/tests/fhe_and_zok_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_and_c_bytecode.txt similarity index 100% rename from scripts/fhe_tests/tests/fhe_and_zok_bytecode.txt rename to scripts/seal_tests/tests/2pc_boolean_and_c_bytecode.txt diff --git a/scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt new file mode 100644 index 000000000..17d8d086f --- /dev/null +++ b/scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt @@ -0,0 +1,4 @@ +2 1 a 1 1 IN +2 1 b 1 0 IN +2 1 1 0 2 B_AND +1 0 2 OUT diff --git a/scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt new file mode 100644 index 000000000..514d02aee --- /dev/null +++ b/scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt @@ -0,0 +1,4 @@ +2 1 a 1 1 IN +2 1 b 1 0 IN +2 1 1 0 2 B_OR +1 0 2 OUT diff --git a/scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt new file mode 100644 index 000000000..514d02aee --- /dev/null +++ b/scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt @@ -0,0 +1,4 @@ +2 1 a 1 1 IN +2 1 b 1 0 IN +2 1 1 0 2 B_OR +1 0 2 OUT diff --git a/scripts/seal_tests/util.py b/scripts/seal_tests/util.py new file mode 100644 index 000000000..5583c936e --- /dev/null +++ b/scripts/seal_tests/util.py @@ -0,0 +1,77 @@ +import os +from subprocess import Popen, PIPE +import sys +from typing import List +from tqdm import tqdm + +def rename_test(name: str, lang: str) -> str: + """Append path with language type""" + return f"{name}_{lang}" + +def build_cmd(name:str, test_file: str) -> List[str]: + bytecode = f"./scripts/seal_tests/tests/{name}_bytecode.txt" + return [os.getenv("SEAL_SOURCE") + "/build/bin/sealinterpreter", "-M", "fhe", "-b", bytecode, "-t", test_file] + +def get_result(file_path): + if os.path.exists(file_path): + with open(file_path) as f: + lines = f.read().splitlines() + for line in lines: + l = line.split() + if l and l[0] == "res": + return l[1] + raise RuntimeError("Unable to find result: "+file_path) + else: + raise RuntimeError("Unable to open file: "+file_path) + + +def run_test(expected: str, cmd: List[str]) -> bool: + try: + proc = Popen(" ".join(cmd), shell=True, stdout=PIPE, stderr=PIPE) + + out, err = proc.communicate(timeout=30) + + if err: + raise RuntimeError("Error: "+err.decode("utf-8").strip()) + + out = out.decode("utf-8").strip() + + assert out == expected, "out: "+out+"\nexpected: "+expected + return True, "" + except Exception as e: + # print("Exception: ", e) + return False, e + +def run_tests(lang: str, tests: List[dict]): + """ + tests will be a list of all tests to run. each element in the list will be + 1. description of test case: str + 2. test name: str + 4. test file path: str + """ + print(f"Running FHE tests for {lang} frontend") + failed_test_descs = [] + num_retries = 2 + + for test in tqdm(tests, leave=False, dynamic_ncols=True): + assert len(test) == 3, "test configurations are wrong for test: "+test[0] + desc = test[0] + name = test[1] + rename = rename_test(name, lang) + + cmd = build_cmd(rename, test[2]) + + expected = get_result(test[2]) + + test_results = [] + for _ in range(num_retries): + test_results.append(run_test(expected, cmd)) + + if all([not r[0] for r in test_results]): + failed_test_descs += [(desc, e[1], " ".join(cmd)) for e in test_results] + + if len(failed_test_descs) == 0: + print("All tests passed ✅") + + failed_test_descs = [f"{r}:\n{e}\n{cmd}" for r, e, cmd in failed_test_descs] + assert len(failed_test_descs) == 0, "there were failed test cases:\n======\n" + "\n\n".join(failed_test_descs) \ No newline at end of file diff --git a/scripts/seal_tests/zokrates_test_seal.py b/scripts/seal_tests/zokrates_test_seal.py new file mode 100644 index 000000000..de1693694 --- /dev/null +++ b/scripts/seal_tests/zokrates_test_seal.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from util import run_tests +from test_suite import * + +if __name__ == "__main__": + tests = boolean_tests# + \ + # arithmetic_tests + \ + # arithmetic_boolean_tests + \ + # nary_arithmetic_tests + \ + # bitwise_tests + \ + # nary_boolean_tests + \ + # const_arith_tests + \ + # const_bool_tests + \ + # loop_tests + \ + # ite_tests + \ + # function_tests + \ + # misc_tests + # shift_tests + \ + # arr_tests + \ + + run_tests('zok', tests) + + diff --git a/src/front/c/mod.rs b/src/front/c/mod.rs index 1ed49837f..7cb7bcad6 100644 --- a/src/front/c/mod.rs +++ b/src/front/c/mod.rs @@ -241,6 +241,7 @@ impl CGen { )) } } + Mode::Fhe => Some(0), Mode::Proof => PROVER_VIS, _ => unimplemented!("Mode {} is not supported.", self.mode), }, @@ -640,7 +641,7 @@ impl CGen { self.gen_stmt(f.body.clone()); if let Some(r) = self.circ.exit_fn() { match self.mode { - Mode::Mpc(_) => { + Mode::Mpc(_) | Mode::Fhe => { let ret_term = r.unwrap_term(); let ret_terms = ret_term.term.terms(); self.circ diff --git a/src/target/fhe/utils.rs b/src/target/fhe/utils.rs index ac37bdbd9..a1da276ab 100644 --- a/src/target/fhe/utils.rs +++ b/src/target/fhe/utils.rs @@ -1,19 +1,9 @@ //! Utility functions to write compiler output to FHE -use std::env; use std::fs; use std::io::prelude::*; use std::path::Path; -/// Get FHE source directory -pub fn get_fhe_source() -> String { - let key = "SEAL_SOURCE"; - match env::var(key) { - Ok(val) => val, - Err(e) => panic!("Missing env variable: SEAL_SOURCE, {}", e), - } -} - /// Given Path `path` and String denominator `lang`, return the filename of the path pub fn get_path(path: &Path, lang: &str, t: &str) -> String { let filename = Path::new(&path.iter().last().unwrap()) @@ -23,13 +13,13 @@ pub fn get_path(path: &Path, lang: &str, t: &str) -> String { .into_string() .unwrap(); - match fs::create_dir_all("scripts/fhe_tests/tests") { - Err(why) => panic!("couldn't create {}: {}", "scripts/fhe_tests/tests", why), + match fs::create_dir_all("scripts/seal_tests/tests") { + Err(why) => panic!("couldn't create {}: {}", "scripts/seal_tests/tests", why), Ok(file) => file, }; let name = format!("{}_{}", filename, lang); - let path = format!("scripts/fhe_tests/tests/{}_{}.txt", name, t); + let path = format!("scripts/seal_tests/tests/{}_{}.txt", name, t); match fs::File::create(&path) { Err(why) => panic!("couldn't create {}: {}", path, why), Ok(file) => file, diff --git a/third_party/SEAL_templates/cpp_template.txt b/third_party/SEAL_templates/cpp_template.txt deleted file mode 100644 index 57b05c30b..000000000 --- a/third_party/SEAL_templates/cpp_template.txt +++ /dev/null @@ -1,25 +0,0 @@ -#include "examples.h" - -using namespace std; -using namespace seal; - -Ciphertext server(SEALContext context, PublicKey public_key{header_inputs}){ - Evaluator evaluator(context); - Encryptor encrypto(context, public_key); - Plaintext plain_one("1"); - {server} -} - -int main({main_inputs}) { - {setup} - - Ciphertext output_encrypted = server(context, public_key{call_inputs}); - - Plaintext output_plain; - decryptor.decrypt(output_encrypted, output_plain); - - {post_computation} - - - return 0; -} \ No newline at end of file diff --git a/util.py b/util.py index 215990306..2198d6b19 100644 --- a/util.py +++ b/util.py @@ -4,20 +4,21 @@ # Gloable variables feature_path = ".features.txt" mode_path = ".mode.txt" -valid_features = {"aby", "c", "lp", "r1cs", "smt", "zok"} +valid_features = {"aby", "c", "lp", "r1cs", "seal", "smt", "zok"} cargo_features = {"c", "lp", "r1cs", "smt", "zok"} # Environment variables ABY_SOURCE="./../ABY" -EZPC_SOURCE="./../EZPC" +SEAL_SOURCE="./../SEAL" def set_env(features): for f in features: if f == 'aby': if not os.getenv("ABY_SOURCE"): os.environ["ABY_SOURCE"] = ABY_SOURCE - if not os.getenv("EZPC_SOURCE"): - os.environ["EZPC_SOURCE"] = EZPC_SOURCE + if f == 'seal': + if not os.getenv("SEAL_SOURCE"): + os.environ["SEAL_SOURCE"] = SEAL_SOURCE def save_mode(mode): """ Save mode to file """ From cb53d1a7e627b25cf2ae2ab627d69e2dcee92331 Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 06:05:34 +0000 Subject: [PATCH 11/21] Deleted extraneous content. Fixed a bug --- driver.py | 4 +- .../boolean_tests/2pc_boolean_equals.c | 5 + .../boolean_tests/2pc_boolean_equals.zok | 2 + scripts/aby_tests/test_inputs/add.txt | 3 - scripts/aby_tests/test_inputs/add_2.txt | 3 - scripts/aby_tests/test_inputs/array.txt | 3 - scripts/aby_tests/test_inputs/array_1.txt | 3 - scripts/aby_tests/test_inputs/array_2.txt | 3 - scripts/aby_tests/test_inputs/array_3.txt | 3 - scripts/aby_tests/test_inputs/array_4.txt | 3 - scripts/aby_tests/test_inputs/biomatch_1.txt | 3 - scripts/aby_tests/test_inputs/biomatch_2.txt | 3 - scripts/aby_tests/test_inputs/const_add.txt | 3 - scripts/aby_tests/test_inputs/const_eq_1.txt | 3 - scripts/aby_tests/test_inputs/const_eq_2.txt | 3 - scripts/aby_tests/test_inputs/conv.txt | 3 - scripts/aby_tests/test_inputs/div_1.txt | 3 - scripts/aby_tests/test_inputs/div_2.txt | 3 - scripts/aby_tests/test_inputs/div_3.txt | 3 - scripts/aby_tests/test_inputs/div_4.txt | 3 - scripts/aby_tests/test_inputs/eq_1.txt | 3 - scripts/aby_tests/test_inputs/eq_2.txt | 3 - scripts/aby_tests/test_inputs/ge_1.txt | 3 - scripts/aby_tests/test_inputs/ge_2.txt | 3 - scripts/aby_tests/test_inputs/ge_3.txt | 3 - scripts/aby_tests/test_inputs/gt_1.txt | 3 - scripts/aby_tests/test_inputs/gt_2.txt | 3 - scripts/aby_tests/test_inputs/gt_3.txt | 3 - scripts/aby_tests/test_inputs/index.txt | 3 - scripts/aby_tests/test_inputs/ite_1.txt | 4 - scripts/aby_tests/test_inputs/ite_2.txt | 4 - scripts/aby_tests/test_inputs/kmeans.txt | 3 - scripts/aby_tests/test_inputs/le_1.txt | 3 - scripts/aby_tests/test_inputs/le_2.txt | 3 - scripts/aby_tests/test_inputs/le_3.txt | 3 - scripts/aby_tests/test_inputs/loop_1.txt | 3 - scripts/aby_tests/test_inputs/loop_2.txt | 3 - scripts/aby_tests/test_inputs/lsh_1.txt | 3 - scripts/aby_tests/test_inputs/lsh_2.txt | 3 - scripts/aby_tests/test_inputs/lsh_3.txt | 3 - scripts/aby_tests/test_inputs/lt_1.txt | 3 - scripts/aby_tests/test_inputs/lt_2.txt | 3 - scripts/aby_tests/test_inputs/lt_3.txt | 3 - scripts/aby_tests/test_inputs/mod_1.txt | 3 - scripts/aby_tests/test_inputs/mod_2.txt | 3 - scripts/aby_tests/test_inputs/mod_3.txt | 3 - scripts/aby_tests/test_inputs/mult_1.txt | 3 - scripts/aby_tests/test_inputs/mult_2.txt | 3 - scripts/aby_tests/test_inputs/mult_3.txt | 3 - .../aby_tests/test_inputs/mult_add_pub_1.txt | 4 - .../aby_tests/test_inputs/mult_add_pub_2.txt | 4 - scripts/aby_tests/test_inputs/nary_add.txt | 4 - scripts/aby_tests/test_inputs/nary_and.txt | 4 - scripts/aby_tests/test_inputs/rsh_1.txt | 3 - scripts/aby_tests/test_inputs/rsh_2.txt | 3 - scripts/aby_tests/test_inputs/sub_1.txt | 3 - scripts/aby_tests/test_inputs/sub_2.txt | 3 - scripts/aby_tests/test_inputs/xor_1.txt | 3 - scripts/aby_tests/test_inputs/xor_2.txt | 3 - scripts/aby_tests/test_inputs/xor_3.txt | 3 - scripts/aby_tests/test_inputs/xor_4.txt | 3 - scripts/clean_seal.zsh | 0 scripts/seal_tests/c_test_seal.py | 21 +- scripts/seal_tests/test_suite.py | 497 ------------------ .../tests/2pc_boolean_and_c_bytecode.txt | 4 - .../tests/2pc_boolean_and_zok_bytecode.txt | 4 - .../tests/2pc_boolean_or_c_bytecode.txt | 4 - .../tests/2pc_boolean_or_zok_bytecode.txt | 4 - scripts/seal_tests/zokrates_test_seal.py | 15 +- src/front/c/mod.rs | 3 +- 70 files changed, 12 insertions(+), 731 deletions(-) create mode 100644 examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c create mode 100644 examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok delete mode 100644 scripts/aby_tests/test_inputs/add.txt delete mode 100644 scripts/aby_tests/test_inputs/add_2.txt delete mode 100644 scripts/aby_tests/test_inputs/array.txt delete mode 100644 scripts/aby_tests/test_inputs/array_1.txt delete mode 100644 scripts/aby_tests/test_inputs/array_2.txt delete mode 100644 scripts/aby_tests/test_inputs/array_3.txt delete mode 100644 scripts/aby_tests/test_inputs/array_4.txt delete mode 100644 scripts/aby_tests/test_inputs/biomatch_1.txt delete mode 100644 scripts/aby_tests/test_inputs/biomatch_2.txt delete mode 100644 scripts/aby_tests/test_inputs/const_add.txt delete mode 100644 scripts/aby_tests/test_inputs/const_eq_1.txt delete mode 100644 scripts/aby_tests/test_inputs/const_eq_2.txt delete mode 100644 scripts/aby_tests/test_inputs/conv.txt delete mode 100644 scripts/aby_tests/test_inputs/div_1.txt delete mode 100644 scripts/aby_tests/test_inputs/div_2.txt delete mode 100644 scripts/aby_tests/test_inputs/div_3.txt delete mode 100644 scripts/aby_tests/test_inputs/div_4.txt delete mode 100644 scripts/aby_tests/test_inputs/eq_1.txt delete mode 100644 scripts/aby_tests/test_inputs/eq_2.txt delete mode 100644 scripts/aby_tests/test_inputs/ge_1.txt delete mode 100644 scripts/aby_tests/test_inputs/ge_2.txt delete mode 100644 scripts/aby_tests/test_inputs/ge_3.txt delete mode 100644 scripts/aby_tests/test_inputs/gt_1.txt delete mode 100644 scripts/aby_tests/test_inputs/gt_2.txt delete mode 100644 scripts/aby_tests/test_inputs/gt_3.txt delete mode 100644 scripts/aby_tests/test_inputs/index.txt delete mode 100644 scripts/aby_tests/test_inputs/ite_1.txt delete mode 100644 scripts/aby_tests/test_inputs/ite_2.txt delete mode 100644 scripts/aby_tests/test_inputs/kmeans.txt delete mode 100644 scripts/aby_tests/test_inputs/le_1.txt delete mode 100644 scripts/aby_tests/test_inputs/le_2.txt delete mode 100644 scripts/aby_tests/test_inputs/le_3.txt delete mode 100644 scripts/aby_tests/test_inputs/loop_1.txt delete mode 100644 scripts/aby_tests/test_inputs/loop_2.txt delete mode 100644 scripts/aby_tests/test_inputs/lsh_1.txt delete mode 100644 scripts/aby_tests/test_inputs/lsh_2.txt delete mode 100644 scripts/aby_tests/test_inputs/lsh_3.txt delete mode 100644 scripts/aby_tests/test_inputs/lt_1.txt delete mode 100644 scripts/aby_tests/test_inputs/lt_2.txt delete mode 100644 scripts/aby_tests/test_inputs/lt_3.txt delete mode 100644 scripts/aby_tests/test_inputs/mod_1.txt delete mode 100644 scripts/aby_tests/test_inputs/mod_2.txt delete mode 100644 scripts/aby_tests/test_inputs/mod_3.txt delete mode 100644 scripts/aby_tests/test_inputs/mult_1.txt delete mode 100644 scripts/aby_tests/test_inputs/mult_2.txt delete mode 100644 scripts/aby_tests/test_inputs/mult_3.txt delete mode 100644 scripts/aby_tests/test_inputs/mult_add_pub_1.txt delete mode 100644 scripts/aby_tests/test_inputs/mult_add_pub_2.txt delete mode 100644 scripts/aby_tests/test_inputs/nary_add.txt delete mode 100644 scripts/aby_tests/test_inputs/nary_and.txt delete mode 100644 scripts/aby_tests/test_inputs/rsh_1.txt delete mode 100644 scripts/aby_tests/test_inputs/rsh_2.txt delete mode 100644 scripts/aby_tests/test_inputs/sub_1.txt delete mode 100644 scripts/aby_tests/test_inputs/sub_2.txt delete mode 100644 scripts/aby_tests/test_inputs/xor_1.txt delete mode 100644 scripts/aby_tests/test_inputs/xor_2.txt delete mode 100644 scripts/aby_tests/test_inputs/xor_3.txt delete mode 100644 scripts/aby_tests/test_inputs/xor_4.txt mode change 100644 => 100755 scripts/clean_seal.zsh delete mode 100644 scripts/seal_tests/tests/2pc_boolean_and_c_bytecode.txt delete mode 100644 scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt delete mode 100644 scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt delete mode 100644 scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt diff --git a/driver.py b/driver.py index 50d459f1f..5a737d982 100755 --- a/driver.py +++ b/driver.py @@ -26,7 +26,7 @@ def verify_path_empty(path) -> bool: if f == "fhe": if verify_path_empty(SEAL_SOURCE): subprocess.run(["git", "clone", "https://github.com/Northrim/SEAL.git", SEAL_SOURCE]) - subprocess.run(["./scripts/build_aby.zsh"]) + subprocess.run(["./scripts/build_seal.zsh"]) # install python requirements subprocess.run(["pip3", "install", "-r", "requirements.txt"]) @@ -147,7 +147,7 @@ def clean(features): print("cleaning!") if "aby" in features: subprocess.run(["./scripts/clean_aby.zsh"]) - if "fhe" in features: + 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"]) diff --git a/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c b/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c new file mode 100644 index 000000000..d0b00b09b --- /dev/null +++ b/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c @@ -0,0 +1,5 @@ +#include + +bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b) { + return a == b; +} \ No newline at end of file diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok new file mode 100644 index 000000000..ef5de39b0 --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok @@ -0,0 +1,2 @@ +def main(private<1> bool a, private<2> bool b) -> bool: + return a == b \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/add.txt b/scripts/aby_tests/test_inputs/add.txt deleted file mode 100644 index 9d0338538..000000000 --- a/scripts/aby_tests/test_inputs/add.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 3 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/add_2.txt b/scripts/aby_tests/test_inputs/add_2.txt deleted file mode 100644 index a885f6020..000000000 --- a/scripts/aby_tests/test_inputs/add_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 6 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/array.txt b/scripts/aby_tests/test_inputs/array.txt deleted file mode 100644 index 05cb13a42..000000000 --- a/scripts/aby_tests/test_inputs/array.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 2 -res 2 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/array_1.txt b/scripts/aby_tests/test_inputs/array_1.txt deleted file mode 100644 index d84cdf330..000000000 --- a/scripts/aby_tests/test_inputs/array_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 10 -b 3 -res 17 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/array_2.txt b/scripts/aby_tests/test_inputs/array_2.txt deleted file mode 100644 index d84cdf330..000000000 --- a/scripts/aby_tests/test_inputs/array_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 10 -b 3 -res 17 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/array_3.txt b/scripts/aby_tests/test_inputs/array_3.txt deleted file mode 100644 index b64095e60..000000000 --- a/scripts/aby_tests/test_inputs/array_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 3 -res 18 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/array_4.txt b/scripts/aby_tests/test_inputs/array_4.txt deleted file mode 100644 index 52f6699ac..000000000 --- a/scripts/aby_tests/test_inputs/array_4.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 2 3 4 5 -b 1 2 3 4 5 -res 30 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/biomatch_1.txt b/scripts/aby_tests/test_inputs/biomatch_1.txt deleted file mode 100644 index 74069d81e..000000000 --- a/scripts/aby_tests/test_inputs/biomatch_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -db 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8 6 7 8 9 7 8 9 10 8 9 10 11 9 10 11 12 10 11 12 13 11 12 13 14 12 13 14 15 13 14 15 16 14 15 16 17 15 16 17 18 16 17 18 19 17 18 19 20 18 19 20 21 19 20 21 22 20 21 22 23 21 22 23 24 22 23 24 25 23 24 25 26 24 25 26 27 25 26 27 28 26 27 28 29 27 28 29 30 28 29 30 31 29 30 31 32 30 31 32 33 31 32 33 34 32 33 34 35 33 34 35 36 34 35 36 37 35 36 37 38 36 37 38 39 37 38 39 40 38 39 40 41 39 40 41 42 40 41 42 43 41 42 43 44 42 43 44 45 43 44 45 46 44 45 46 47 45 46 47 48 46 47 48 49 47 48 49 50 48 49 50 51 49 50 51 52 50 51 52 53 51 52 53 54 52 53 54 55 53 54 55 56 54 55 56 57 55 56 57 58 56 57 58 59 57 58 59 60 58 59 60 61 59 60 61 62 60 61 62 63 61 62 63 64 62 63 64 65 63 64 65 66 64 65 66 67 65 66 67 68 66 67 68 69 67 68 69 70 68 69 70 71 69 70 71 72 70 71 72 73 71 72 73 74 72 73 74 75 73 74 75 76 74 75 76 77 75 76 77 78 76 77 78 79 77 78 79 80 78 79 80 81 79 80 81 82 80 81 82 83 81 82 83 84 82 83 84 85 83 84 85 86 84 85 86 87 85 86 87 88 86 87 88 89 87 88 89 90 88 89 90 91 89 90 91 92 90 91 92 93 91 92 93 94 92 93 94 95 93 94 95 96 94 95 96 97 95 96 97 98 96 97 98 99 97 98 99 100 98 99 100 101 99 100 101 102 100 101 102 103 101 102 103 104 102 103 104 105 103 104 105 106 104 105 106 107 105 106 107 108 106 107 108 109 107 108 109 110 108 109 110 111 109 110 111 112 110 111 112 113 111 112 113 114 112 113 114 115 113 114 115 116 114 115 116 117 115 116 117 118 116 117 118 119 117 118 119 120 118 119 120 121 119 120 121 122 120 121 122 123 121 122 123 124 122 123 124 125 123 124 125 126 124 125 126 127 125 126 127 128 126 127 128 129 127 128 129 130 128 129 130 131 129 130 131 132 130 131 132 133 131 132 133 134 132 133 134 135 133 134 135 136 134 135 136 137 135 136 137 138 136 137 138 139 137 138 139 140 138 139 140 141 139 140 141 142 140 141 142 143 141 142 143 144 142 143 144 145 143 144 145 146 144 145 146 147 145 146 147 148 146 147 148 149 147 148 149 150 148 149 150 151 149 150 151 152 150 151 152 153 151 152 153 154 152 153 154 155 153 154 155 156 154 155 156 157 155 156 157 158 156 157 158 159 157 158 159 160 158 159 160 161 159 160 161 162 160 161 162 163 161 162 163 164 162 163 164 165 163 164 165 166 164 165 166 167 165 166 167 168 166 167 168 169 167 168 169 170 168 169 170 171 169 170 171 172 170 171 172 173 171 172 173 174 172 173 174 175 173 174 175 176 174 175 176 177 175 176 177 178 176 177 178 179 177 178 179 180 178 179 180 181 179 180 181 182 180 181 182 183 181 182 183 184 182 183 184 185 183 184 185 186 184 185 186 187 185 186 187 188 186 187 188 189 187 188 189 190 188 189 190 191 189 190 191 192 190 191 192 193 191 192 193 194 192 193 194 195 193 194 195 196 194 195 196 197 195 196 197 198 196 197 198 199 197 198 199 200 198 199 200 201 199 200 201 202 200 201 202 203 201 202 203 204 202 203 204 205 203 204 205 206 204 205 206 207 205 206 207 208 206 207 208 209 207 208 209 210 208 209 210 211 209 210 211 212 210 211 212 213 211 212 213 214 212 213 214 215 213 214 215 216 214 215 216 217 215 216 217 218 216 217 218 219 217 218 219 220 218 219 220 221 219 220 221 222 220 221 222 223 221 222 223 224 222 223 224 225 223 224 225 226 224 225 226 227 225 226 227 228 226 227 228 229 227 228 229 230 228 229 230 231 229 230 231 232 230 231 232 233 231 232 233 234 232 233 234 235 233 234 235 236 234 235 236 237 235 236 237 238 236 237 238 239 237 238 239 240 238 239 240 241 239 240 241 242 240 241 242 243 241 242 243 244 242 243 244 245 243 244 245 246 244 245 246 247 245 246 247 248 246 247 248 249 247 248 249 250 248 249 250 251 249 250 251 252 250 251 252 253 251 252 253 254 252 253 254 255 253 254 255 256 254 255 256 257 255 256 257 258 -sample 0 0 0 0 -res 14 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/biomatch_2.txt b/scripts/aby_tests/test_inputs/biomatch_2.txt deleted file mode 100644 index b69f333b9..000000000 --- a/scripts/aby_tests/test_inputs/biomatch_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -db 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 5 6 7 8 6 7 8 9 7 8 9 10 8 9 10 11 9 10 11 12 10 11 12 13 11 12 13 14 12 13 14 15 13 14 15 16 14 15 16 17 15 16 17 18 16 17 18 19 17 18 19 20 18 19 20 21 19 20 21 22 20 21 22 23 21 22 23 24 22 23 24 25 23 24 25 26 24 25 26 27 25 26 27 28 26 27 28 29 27 28 29 30 28 29 30 31 29 30 31 32 30 31 32 33 31 32 33 34 32 33 34 35 33 34 35 36 34 35 36 37 35 36 37 38 36 37 38 39 37 38 39 40 38 39 40 41 39 40 41 42 40 41 42 43 41 42 43 44 42 43 44 45 43 44 45 46 44 45 46 47 45 46 47 48 46 47 48 49 47 48 49 50 48 49 50 51 49 50 51 52 50 51 52 53 51 52 53 54 52 53 54 55 53 54 55 56 54 55 56 57 55 56 57 58 56 57 58 59 57 58 59 60 58 59 60 61 59 60 61 62 60 61 62 63 61 62 63 64 62 63 64 65 63 64 65 66 64 65 66 67 65 66 67 68 66 67 68 69 67 68 69 70 68 69 70 71 69 70 71 72 70 71 72 73 71 72 73 74 72 73 74 75 73 74 75 76 74 75 76 77 75 76 77 78 76 77 78 79 77 78 79 80 78 79 80 81 79 80 81 82 80 81 82 83 81 82 83 84 82 83 84 85 83 84 85 86 84 85 86 87 85 86 87 88 86 87 88 89 87 88 89 90 88 89 90 91 89 90 91 92 90 91 92 93 91 92 93 94 92 93 94 95 93 94 95 96 94 95 96 97 95 96 97 98 96 97 98 99 97 98 99 100 98 99 100 101 99 100 101 102 100 101 102 103 101 102 103 104 102 103 104 105 103 104 105 106 104 105 106 107 105 106 107 108 106 107 108 109 107 108 109 110 108 109 110 111 109 110 111 112 110 111 112 113 111 112 113 114 112 113 114 115 113 114 115 116 114 115 116 117 115 116 117 118 116 117 118 119 117 118 119 120 118 119 120 121 119 120 121 122 120 121 122 123 121 122 123 124 122 123 124 125 123 124 125 126 124 125 126 127 125 126 127 128 126 127 128 129 127 128 129 130 128 129 130 131 129 130 131 132 130 131 132 133 131 132 133 134 132 133 134 135 133 134 135 136 134 135 136 137 135 136 137 138 136 137 138 139 137 138 139 140 138 139 140 141 139 140 141 142 140 141 142 143 141 142 143 144 142 143 144 145 143 144 145 146 144 145 146 147 145 146 147 148 146 147 148 149 147 148 149 150 148 149 150 151 149 150 151 152 150 151 152 153 151 152 153 154 152 153 154 155 153 154 155 156 154 155 156 157 155 156 157 158 156 157 158 159 157 158 159 160 158 159 160 161 159 160 161 162 160 161 162 163 161 162 163 164 162 163 164 165 163 164 165 166 164 165 166 167 165 166 167 168 166 167 168 169 167 168 169 170 168 169 170 171 169 170 171 172 170 171 172 173 171 172 173 174 172 173 174 175 173 174 175 176 174 175 176 177 175 176 177 178 176 177 178 179 177 178 179 180 178 179 180 181 179 180 181 182 180 181 182 183 181 182 183 184 182 183 184 185 183 184 185 186 184 185 186 187 185 186 187 188 186 187 188 189 187 188 189 190 188 189 190 191 189 190 191 192 190 191 192 193 191 192 193 194 192 193 194 195 193 194 195 196 194 195 196 197 195 196 197 198 196 197 198 199 197 198 199 200 198 199 200 201 199 200 201 202 200 201 202 203 201 202 203 204 202 203 204 205 203 204 205 206 204 205 206 207 205 206 207 208 206 207 208 209 207 208 209 210 208 209 210 211 209 210 211 212 210 211 212 213 211 212 213 214 212 213 214 215 213 214 215 216 214 215 216 217 215 216 217 218 216 217 218 219 217 218 219 220 218 219 220 221 219 220 221 222 220 221 222 223 221 222 223 224 222 223 224 225 223 224 225 226 224 225 226 227 225 226 227 228 226 227 228 229 227 228 229 230 228 229 230 231 229 230 231 232 230 231 232 233 231 232 233 234 232 233 234 235 233 234 235 236 234 235 236 237 235 236 237 238 236 237 238 239 237 238 239 240 238 239 240 241 239 240 241 242 240 241 242 243 241 242 243 244 242 243 244 245 243 244 245 246 244 245 246 247 245 246 247 248 246 247 248 249 247 248 249 250 248 249 250 251 249 250 251 252 250 251 252 253 251 252 253 254 252 253 254 255 253 254 255 256 254 255 256 257 255 256 257 258 -sample 1 2 3 4 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/const_add.txt b/scripts/aby_tests/test_inputs/const_add.txt deleted file mode 100644 index 903c001a2..000000000 --- a/scripts/aby_tests/test_inputs/const_add.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 3 -res 6 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/const_eq_1.txt b/scripts/aby_tests/test_inputs/const_eq_1.txt deleted file mode 100644 index b7504f131..000000000 --- a/scripts/aby_tests/test_inputs/const_eq_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 0 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/const_eq_2.txt b/scripts/aby_tests/test_inputs/const_eq_2.txt deleted file mode 100644 index b35d53a3c..000000000 --- a/scripts/aby_tests/test_inputs/const_eq_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 0 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/conv.txt b/scripts/aby_tests/test_inputs/conv.txt deleted file mode 100644 index a716070f5..000000000 --- a/scripts/aby_tests/test_inputs/conv.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 7 -res 7 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/div_1.txt b/scripts/aby_tests/test_inputs/div_1.txt deleted file mode 100644 index aae5f347a..000000000 --- a/scripts/aby_tests/test_inputs/div_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 10 -b 1 -res 10 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/div_2.txt b/scripts/aby_tests/test_inputs/div_2.txt deleted file mode 100644 index 765229865..000000000 --- a/scripts/aby_tests/test_inputs/div_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 10 -b 2 -res 5 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/div_3.txt b/scripts/aby_tests/test_inputs/div_3.txt deleted file mode 100644 index eae9243f7..000000000 --- a/scripts/aby_tests/test_inputs/div_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 11 -b 2 -res 5 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/div_4.txt b/scripts/aby_tests/test_inputs/div_4.txt deleted file mode 100644 index dfd199351..000000000 --- a/scripts/aby_tests/test_inputs/div_4.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/eq_1.txt b/scripts/aby_tests/test_inputs/eq_1.txt deleted file mode 100644 index a9e356a5b..000000000 --- a/scripts/aby_tests/test_inputs/eq_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 0 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/eq_2.txt b/scripts/aby_tests/test_inputs/eq_2.txt deleted file mode 100644 index e7129253a..000000000 --- a/scripts/aby_tests/test_inputs/eq_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 1 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/ge_1.txt b/scripts/aby_tests/test_inputs/ge_1.txt deleted file mode 100644 index dfd199351..000000000 --- a/scripts/aby_tests/test_inputs/ge_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/ge_2.txt b/scripts/aby_tests/test_inputs/ge_2.txt deleted file mode 100644 index e7129253a..000000000 --- a/scripts/aby_tests/test_inputs/ge_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 1 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/ge_3.txt b/scripts/aby_tests/test_inputs/ge_3.txt deleted file mode 100644 index b35d53a3c..000000000 --- a/scripts/aby_tests/test_inputs/ge_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 0 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/gt_1.txt b/scripts/aby_tests/test_inputs/gt_1.txt deleted file mode 100644 index dfd199351..000000000 --- a/scripts/aby_tests/test_inputs/gt_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/gt_2.txt b/scripts/aby_tests/test_inputs/gt_2.txt deleted file mode 100644 index af7201b0c..000000000 --- a/scripts/aby_tests/test_inputs/gt_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 1 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/gt_3.txt b/scripts/aby_tests/test_inputs/gt_3.txt deleted file mode 100644 index f08a0a3f0..000000000 --- a/scripts/aby_tests/test_inputs/gt_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 0 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/index.txt b/scripts/aby_tests/test_inputs/index.txt deleted file mode 100644 index 9c3ab6935..000000000 --- a/scripts/aby_tests/test_inputs/index.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/ite_1.txt b/scripts/aby_tests/test_inputs/ite_1.txt deleted file mode 100644 index 999905001..000000000 --- a/scripts/aby_tests/test_inputs/ite_1.txt +++ /dev/null @@ -1,4 +0,0 @@ -a 0 -b 1 -sel 1 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/ite_2.txt b/scripts/aby_tests/test_inputs/ite_2.txt deleted file mode 100644 index b76bbac12..000000000 --- a/scripts/aby_tests/test_inputs/ite_2.txt +++ /dev/null @@ -1,4 +0,0 @@ -a 0 -b 1 -sel 0 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/kmeans.txt b/scripts/aby_tests/test_inputs/kmeans.txt deleted file mode 100644 index 5e99f9175..000000000 --- a/scripts/aby_tests/test_inputs/kmeans.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 -b 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 -res 103 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/le_1.txt b/scripts/aby_tests/test_inputs/le_1.txt deleted file mode 100644 index 9c3ab6935..000000000 --- a/scripts/aby_tests/test_inputs/le_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/le_2.txt b/scripts/aby_tests/test_inputs/le_2.txt deleted file mode 100644 index e7129253a..000000000 --- a/scripts/aby_tests/test_inputs/le_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 1 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/le_3.txt b/scripts/aby_tests/test_inputs/le_3.txt deleted file mode 100644 index 9696b0dee..000000000 --- a/scripts/aby_tests/test_inputs/le_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 0 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/loop_1.txt b/scripts/aby_tests/test_inputs/loop_1.txt deleted file mode 100644 index dbfc1f40b..000000000 --- a/scripts/aby_tests/test_inputs/loop_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 1 -res 10 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/loop_2.txt b/scripts/aby_tests/test_inputs/loop_2.txt deleted file mode 100644 index cc2da46e3..000000000 --- a/scripts/aby_tests/test_inputs/loop_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 10 -b 3 -res 10 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/lsh_1.txt b/scripts/aby_tests/test_inputs/lsh_1.txt deleted file mode 100644 index adeb10c20..000000000 --- a/scripts/aby_tests/test_inputs/lsh_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 10 -b 2 -res 20 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/lsh_2.txt b/scripts/aby_tests/test_inputs/lsh_2.txt deleted file mode 100644 index aafb50571..000000000 --- a/scripts/aby_tests/test_inputs/lsh_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/lsh_3.txt b/scripts/aby_tests/test_inputs/lsh_3.txt deleted file mode 100644 index 857e0b0e5..000000000 --- a/scripts/aby_tests/test_inputs/lsh_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2147483648 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/lt_1.txt b/scripts/aby_tests/test_inputs/lt_1.txt deleted file mode 100644 index 0d16f5a89..000000000 --- a/scripts/aby_tests/test_inputs/lt_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 1 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/lt_2.txt b/scripts/aby_tests/test_inputs/lt_2.txt deleted file mode 100644 index af7201b0c..000000000 --- a/scripts/aby_tests/test_inputs/lt_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 1 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/lt_3.txt b/scripts/aby_tests/test_inputs/lt_3.txt deleted file mode 100644 index 074c00099..000000000 --- a/scripts/aby_tests/test_inputs/lt_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 1 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mod_1.txt b/scripts/aby_tests/test_inputs/mod_1.txt deleted file mode 100644 index 54c560466..000000000 --- a/scripts/aby_tests/test_inputs/mod_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mod_2.txt b/scripts/aby_tests/test_inputs/mod_2.txt deleted file mode 100644 index 9c3ab6935..000000000 --- a/scripts/aby_tests/test_inputs/mod_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 2 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mod_3.txt b/scripts/aby_tests/test_inputs/mod_3.txt deleted file mode 100644 index a213350db..000000000 --- a/scripts/aby_tests/test_inputs/mod_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mult_1.txt b/scripts/aby_tests/test_inputs/mult_1.txt deleted file mode 100644 index 596a6ab24..000000000 --- a/scripts/aby_tests/test_inputs/mult_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 5 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mult_2.txt b/scripts/aby_tests/test_inputs/mult_2.txt deleted file mode 100644 index f3a9b265c..000000000 --- a/scripts/aby_tests/test_inputs/mult_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 5 -res 5 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mult_3.txt b/scripts/aby_tests/test_inputs/mult_3.txt deleted file mode 100644 index 0c84b4868..000000000 --- a/scripts/aby_tests/test_inputs/mult_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 5 -res 10 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mult_add_pub_1.txt b/scripts/aby_tests/test_inputs/mult_add_pub_1.txt deleted file mode 100644 index 3c5e755dd..000000000 --- a/scripts/aby_tests/test_inputs/mult_add_pub_1.txt +++ /dev/null @@ -1,4 +0,0 @@ -a 5 -v 7 -b 7 -res 42 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/mult_add_pub_2.txt b/scripts/aby_tests/test_inputs/mult_add_pub_2.txt deleted file mode 100644 index 3c5e755dd..000000000 --- a/scripts/aby_tests/test_inputs/mult_add_pub_2.txt +++ /dev/null @@ -1,4 +0,0 @@ -a 5 -v 7 -b 7 -res 42 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/nary_add.txt b/scripts/aby_tests/test_inputs/nary_add.txt deleted file mode 100644 index 780d3579c..000000000 --- a/scripts/aby_tests/test_inputs/nary_add.txt +++ /dev/null @@ -1,4 +0,0 @@ -a 1 -b 2 -c 3 -res 6 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/nary_and.txt b/scripts/aby_tests/test_inputs/nary_and.txt deleted file mode 100644 index 1fffca872..000000000 --- a/scripts/aby_tests/test_inputs/nary_and.txt +++ /dev/null @@ -1,4 +0,0 @@ -a 1 -b 1 -c 1 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/rsh_1.txt b/scripts/aby_tests/test_inputs/rsh_1.txt deleted file mode 100644 index 8dbc6905f..000000000 --- a/scripts/aby_tests/test_inputs/rsh_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 20 -b 2 -res 10 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/rsh_2.txt b/scripts/aby_tests/test_inputs/rsh_2.txt deleted file mode 100644 index aafb50571..000000000 --- a/scripts/aby_tests/test_inputs/rsh_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 2 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/sub_1.txt b/scripts/aby_tests/test_inputs/sub_1.txt deleted file mode 100644 index 1eeed2583..000000000 --- a/scripts/aby_tests/test_inputs/sub_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 3 -b 2 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/sub_2.txt b/scripts/aby_tests/test_inputs/sub_2.txt deleted file mode 100644 index ba4d35810..000000000 --- a/scripts/aby_tests/test_inputs/sub_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 2 -b 3 -res 4294967295 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/xor_1.txt b/scripts/aby_tests/test_inputs/xor_1.txt deleted file mode 100644 index bffd79e1a..000000000 --- a/scripts/aby_tests/test_inputs/xor_1.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 0 -res 0 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/xor_2.txt b/scripts/aby_tests/test_inputs/xor_2.txt deleted file mode 100644 index a6e61de8e..000000000 --- a/scripts/aby_tests/test_inputs/xor_2.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 0 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/xor_3.txt b/scripts/aby_tests/test_inputs/xor_3.txt deleted file mode 100644 index e97a331be..000000000 --- a/scripts/aby_tests/test_inputs/xor_3.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 0 -b 1 -res 1 \ No newline at end of file diff --git a/scripts/aby_tests/test_inputs/xor_4.txt b/scripts/aby_tests/test_inputs/xor_4.txt deleted file mode 100644 index af7201b0c..000000000 --- a/scripts/aby_tests/test_inputs/xor_4.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 1 -res 0 \ No newline at end of file diff --git a/scripts/clean_seal.zsh b/scripts/clean_seal.zsh old mode 100644 new mode 100755 diff --git a/scripts/seal_tests/c_test_seal.py b/scripts/seal_tests/c_test_seal.py index b9968e781..ae36d5407 100644 --- a/scripts/seal_tests/c_test_seal.py +++ b/scripts/seal_tests/c_test_seal.py @@ -4,25 +4,6 @@ from test_suite import * if __name__ == "__main__": - tests = boolean_tests #+ \ - # arithmetic_tests + \ - # mod_tests + \ - # arithmetic_boolean_tests + \ - # nary_arithmetic_tests + \ - # bitwise_tests + \ - # nary_boolean_tests + \ - # const_arith_tests + \ - # const_bool_tests + \ - # ite_tests + \ - # div_tests + \ - # array_tests + \ - # c_array_tests + \ - # misc_tests + \ - # biomatch_tests + \ - # kmeans_tests - # shift_tests - - # TODO: add support for return value - int promotion - # unsigned_arithmetic_tests + \ + tests = boolean_tests run_tests('c', tests) diff --git a/scripts/seal_tests/test_suite.py b/scripts/seal_tests/test_suite.py index 45e114603..dc4c67b94 100644 --- a/scripts/seal_tests/test_suite.py +++ b/scripts/seal_tests/test_suite.py @@ -1,219 +1,3 @@ -arithmetic_tests = [ - [ - "Add two numbers", - "2pc_add", - "./scripts/seal_tests/test_inputs/add.txt", - ], - [ - "Subtract two numbers", - "2pc_sub", - "./scripts/seal_tests/test_inputs/sub_1.txt", - ], - [ - "Subtract two numbers, negative -1 == 4294967295 because u32", - "2pc_sub", - "./scripts/seal_tests/test_inputs/sub_2.txt", - ], - [ - "Multiply two numbers - 1", - "2pc_mult", - "./scripts/seal_tests/test_inputs/mult_1.txt", - ], - [ - "Multiply two numbers - 2", - "2pc_mult", - "./scripts/seal_tests/test_inputs/mult_2.txt", - ], - [ - "Multiply two numbers - 3", - "2pc_mult", - "./scripts/seal_tests/test_inputs/mult_3.txt", - ], - [ - # only server side public value works - "Multiply two numbers together and add with public value", - "2pc_mult_add_pub", - "./scripts/seal_tests/test_inputs/mult_add_pub_1.txt", - ], - [ - # only server side public value works - "Multiply two numbers together and add with public value, check only server side public value is added", - "2pc_mult_add_pub", - "./scripts/seal_tests/test_inputs/mult_add_pub_2.txt", - ], -] - -mod_tests = [ - [ - "Mod two numbers - 1", - "2pc_mod", - "./scripts/seal_tests/test_inputs/mod_1.txt", - ], - [ - "Mod two numbers - 2", - "2pc_mod", - "./scripts/seal_tests/test_inputs/mod_2.txt", - ], - [ - "Mod two numbers - 3", - "2pc_mod", - "./scripts/seal_tests/test_inputs/mod_3.txt", - ], -] - -unsigned_arithmetic_tests = [ - [ - "Add two unsigned numbers", - "2pc_add_unsigned", - "./scripts/seal_tests/test_inputs/add.txt", - ], -] - -arithmetic_boolean_tests = [ - [ - "Test two numbers are equal - 1", - "2pc_int_equals", - "./scripts/seal_tests/test_inputs/eq_1.txt", - ], - [ - "Test two numbers are equal - 2", - "2pc_int_equals", - "./scripts/seal_tests/test_inputs/eq_2.txt", - ], - [ - "Test int > int - 1", - "2pc_int_greater_than", - "./scripts/seal_tests/test_inputs/gt_1.txt", - ], - [ - "Test int > int - 2", - "2pc_int_greater_than", - "./scripts/seal_tests/test_inputs/gt_2.txt", - ], - [ - "Test int > int - 3", - "2pc_int_greater_than", - "./scripts/seal_tests/test_inputs/gt_3.txt", - ], - [ - "Test int >= int - 1", - "2pc_int_greater_equals", - "./scripts/seal_tests/test_inputs/ge_1.txt", - ], - [ - "Test int >= int - 2", - "2pc_int_greater_equals", - "./scripts/seal_tests/test_inputs/ge_2.txt", - ], - [ - "Test int >= int - 3", - "2pc_int_greater_equals", - "./scripts/seal_tests/test_inputs/ge_3.txt", - ], - [ - "Test int < int - 1", - "2pc_int_less_than", - "./scripts/seal_tests/test_inputs/lt_1.txt", - ], - [ - "Test int < int - 2", - "2pc_int_less_than", - "./scripts/seal_tests/test_inputs/lt_2.txt", - ], - [ - "Test int < int - 3", - "2pc_int_less_than", - "./scripts/seal_tests/test_inputs/lt_3.txt", - ], - [ - "Test int <= int - 1", - "2pc_int_less_equals", - "./scripts/seal_tests/test_inputs/le_1.txt", - ], - [ - "Test int <= int - 2", - "2pc_int_less_equals", - "./scripts/seal_tests/test_inputs/le_2.txt", - ], - [ - "Test int <= int - 3", - "2pc_int_less_equals", - "./scripts/seal_tests/test_inputs/le_3.txt", - ], -] - -nary_arithmetic_tests = [ - [ - "Test a + b + c", - "2pc_nary_arithmetic_add", - "./scripts/seal_tests/test_inputs/nary_add.txt", - ], -] - -bitwise_tests = [ - [ - "Bitwise & - 1", - "2pc_bitwise_and", - "./scripts/seal_tests/test_inputs/and_1.txt", - ], - [ - "Bitwise & - 2", - "2pc_bitwise_and", - "./scripts/seal_tests/test_inputs/and_2.txt", - ], - [ - "Bitwise & - 3", - "2pc_bitwise_and", - "./scripts/seal_tests/test_inputs/and_3.txt", - ], - [ - "Bitwise & - 4", - "2pc_bitwise_and", - "./scripts/seal_tests/test_inputs/and_4.txt", - ], - [ - "Bitwise | - 1", - "2pc_bitwise_or", - "./scripts/seal_tests/test_inputs/or_1.txt", - ], - [ - "Bitwise | - 2", - "2pc_bitwise_or", - "./scripts/seal_tests/test_inputs/or_2.txt", - ], - [ - "Bitwise | - 3", - "2pc_bitwise_or", - "./scripts/seal_tests/test_inputs/or_3.txt", - ], - [ - "Bitwise | - 4", - "2pc_bitwise_or", - "./scripts/seal_tests/test_inputs/or_4.txt", - ], - [ - "Bitwise ^ - 1", - "2pc_bitwise_xor", - "./scripts/seal_tests/test_inputs/xor_1.txt", - - ], - [ - "Bitwise ^ - 2", - "2pc_bitwise_xor", - "./scripts/seal_tests/test_inputs/xor_2.txt", - ], - [ - "Bitwise ^ - 3", - "2pc_bitwise_xor", - "./scripts/seal_tests/test_inputs/xor_3.txt", - ], - [ - "Bitwise ^ - 4", - "2pc_bitwise_xor", - "./scripts/seal_tests/test_inputs/xor_4.txt", - ], -] - boolean_tests = [ [ "Boolean && - 1", @@ -269,284 +53,3 @@ # ], ] -nary_boolean_tests = [ - [ - "Test a & b & c", - "2pc_nary_boolean_and", - "./scripts/seal_tests/test_inputs/nary_and.txt", - ], -] - - -const_arith_tests = [ - [ - "Test add client int + server int to const value", - "2pc_const_arith", - "./scripts/seal_tests/test_inputs/const_add.txt", - ], -] - -const_bool_tests = [ - [ - "Test server value == const value - 1", - "2pc_const_bool", - "./scripts/seal_tests/test_inputs/const_eq_1.txt", - ], - [ - "Test server value == const value - 2", - "2pc_const_bool", - "./scripts/seal_tests/test_inputs/const_eq_2.txt", - ], -] - -ite_tests = [ - [ - "Test ite ret bool - 1", - "2pc_ite_ret_bool", - "./scripts/seal_tests/test_inputs/ite_1.txt", - ], - [ - "Test ite ret bool - 2", - "2pc_ite_ret_bool", - "./scripts/seal_tests/test_inputs/ite_2.txt", - ], - [ - "Test ite ret int - 1", - "2pc_ite_ret_int", - "./scripts/seal_tests/test_inputs/ite_1.txt", - ], - [ - "Test ite ret int - 2", - "2pc_ite_ret_int", - "./scripts/seal_tests/test_inputs/ite_2.txt", - ], - [ - "Test ite only if - 1", - "2pc_ite_only_if", - "./scripts/seal_tests/test_inputs/ite_1.txt", - ], - [ - "Test ite only if - 2", - "2pc_ite_only_if", - "./scripts/seal_tests/test_inputs/ite_2.txt", - ], -] - -array_tests = [ - [ - "Array sum test", - "2pc_array_sum", - "./scripts/seal_tests/test_inputs/add.txt", - ], - [ - "Array index test", - "2pc_array_index", - "./scripts/seal_tests/test_inputs/add.txt", - ], -] - -c_array_tests = [ - [ - "C array test", - "2pc_array", - "./scripts/seal_tests/test_inputs/array.txt", - ], - [ - "C array test 1", - "2pc_array_1", - "./scripts/seal_tests/test_inputs/array_1.txt", - ], - [ - "C array test 2", - "2pc_array_2", - "./scripts/seal_tests/test_inputs/array_2.txt", - ], - [ - "C array test 3", - "2pc_array_3", - "./scripts/seal_tests/test_inputs/array_3.txt", - ], - [ - "C array test 4", - "2pc_array_sum_c", - "./scripts/seal_tests/test_inputs/array_4.txt", - ], -] - -loop_tests = [ - [ - "Loop sum const - 1", - "2pc_loop_sum", - "./scripts/seal_tests/test_inputs/loop_1.txt", - ], - [ - "Loop sum const - 2", - "2pc_loop_sum", - "./scripts/seal_tests/test_inputs/loop_2.txt", - ], -] - -function_tests = [ - [ - "Sum() two numbers - 1", - "2pc_function_add", - "./scripts/seal_tests/test_inputs/add_2.txt", - ], -] - -shift_tests = [ - [ - "Left Shift a by 1 - 1", - "2pc_lhs", - "./scripts/seal_tests/test_inputs/lsh_1.txt", - ], - [ - "Left Shift a by 1 - 2", - "2pc_lhs", - "./scripts/seal_tests/test_inputs/lsh_2.txt", - ], - [ - "Left Shift a by 1 - 3", - "2pc_lhs", - "./scripts/seal_tests/test_inputs/lsh_3.txt", - ], - [ - "Right Shift a by 1 - 1", - "2pc_rhs", - "./scripts/seal_tests/test_inputs/rsh_1.txt", - ], - [ - "Right Shift a by 1 - 2", - "2pc_rhs", - "./scripts/seal_tests/test_inputs/rsh_2.txt", - ], -] - - -div_tests = [ - [ - "Divide a by 1", - "2pc_div", - "./scripts/seal_tests/test_inputs/div_1.txt", - ], - [ - "Divide a by b - 1", - "2pc_div", - "./scripts/seal_tests/test_inputs/div_2.txt", - ], - [ - "Divide a by b - 2", - "2pc_div", - "./scripts/seal_tests/test_inputs/div_3.txt", - ], - [ - "Divide a by b - 3", - "2pc_div", - "./scripts/seal_tests/test_inputs/div_4.txt", - ], -] - -misc_tests = [ - [ - "Millionaire's problem: server has more money than client", - "2pc_millionaires", - "./scripts/seal_tests/test_inputs/lt_1.txt", - ], - [ - "Millionaire's problem: server has equal money to client", - "2pc_millionaires", - "./scripts/seal_tests/test_inputs/lt_2.txt", - ], - [ - "Millionaire's problem: server has less money than client", - "2pc_millionaires", - "./scripts/seal_tests/test_inputs/lt_3.txt", - ], -] - -kmeans_tests = [ - [ - "kmeans", - "2pc_kmeans", - "./scripts/seal_tests/test_inputs/kmeans.txt", - ], -] - -biomatch_tests = [ - [ - "biomatch - 1", - "2pc_biomatch", - "./scripts/seal_tests/test_inputs/biomatch_1.txt", - ], - [ - "biomatch - 2", - "2pc_biomatch", - "./scripts/seal_tests/test_inputs/biomatch_2.txt", - ], -] - -# ilp_benchmark_tests = [ -# [ -# "ilp bench - array sum 1", -# 1000, -# "2pc_ilp_bench_1", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 2", -# 2000, -# "2pc_ilp_bench_2", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 3", -# 3000, -# "2pc_ilp_bench_3", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 4", -# 4000, -# "2pc_ilp_bench_4", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 5", -# 5000, -# "2pc_ilp_bench_5", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 6", -# 6000, -# "2pc_ilp_bench_6", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 7", -# 7000, -# "2pc_ilp_bench_7", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 8", -# 8000, -# "2pc_ilp_bench_8", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# [ -# "ilp bench - array sum 9", -# 9000, -# "2pc_ilp_bench_9", -# {"a": 2, "b": 0}, -# {"a": 0, "b": 1}, -# ], -# ] diff --git a/scripts/seal_tests/tests/2pc_boolean_and_c_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_and_c_bytecode.txt deleted file mode 100644 index 17d8d086f..000000000 --- a/scripts/seal_tests/tests/2pc_boolean_and_c_bytecode.txt +++ /dev/null @@ -1,4 +0,0 @@ -2 1 a 1 1 IN -2 1 b 1 0 IN -2 1 1 0 2 B_AND -1 0 2 OUT diff --git a/scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt deleted file mode 100644 index 17d8d086f..000000000 --- a/scripts/seal_tests/tests/2pc_boolean_and_zok_bytecode.txt +++ /dev/null @@ -1,4 +0,0 @@ -2 1 a 1 1 IN -2 1 b 1 0 IN -2 1 1 0 2 B_AND -1 0 2 OUT diff --git a/scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt deleted file mode 100644 index 514d02aee..000000000 --- a/scripts/seal_tests/tests/2pc_boolean_or_c_bytecode.txt +++ /dev/null @@ -1,4 +0,0 @@ -2 1 a 1 1 IN -2 1 b 1 0 IN -2 1 1 0 2 B_OR -1 0 2 OUT diff --git a/scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt b/scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt deleted file mode 100644 index 514d02aee..000000000 --- a/scripts/seal_tests/tests/2pc_boolean_or_zok_bytecode.txt +++ /dev/null @@ -1,4 +0,0 @@ -2 1 a 1 1 IN -2 1 b 1 0 IN -2 1 1 0 2 B_OR -1 0 2 OUT diff --git a/scripts/seal_tests/zokrates_test_seal.py b/scripts/seal_tests/zokrates_test_seal.py index de1693694..b55486fe1 100644 --- a/scripts/seal_tests/zokrates_test_seal.py +++ b/scripts/seal_tests/zokrates_test_seal.py @@ -4,20 +4,7 @@ from test_suite import * if __name__ == "__main__": - tests = boolean_tests# + \ - # arithmetic_tests + \ - # arithmetic_boolean_tests + \ - # nary_arithmetic_tests + \ - # bitwise_tests + \ - # nary_boolean_tests + \ - # const_arith_tests + \ - # const_bool_tests + \ - # loop_tests + \ - # ite_tests + \ - # function_tests + \ - # misc_tests - # shift_tests + \ - # arr_tests + \ + tests = boolean_tests run_tests('zok', tests) diff --git a/src/front/c/mod.rs b/src/front/c/mod.rs index 7cb7bcad6..e4de3ddaf 100644 --- a/src/front/c/mod.rs +++ b/src/front/c/mod.rs @@ -241,8 +241,7 @@ impl CGen { )) } } - Mode::Fhe => Some(0), - Mode::Proof => PROVER_VIS, + Mode::Fhe | Mode::Proof => PROVER_VIS, _ => unimplemented!("Mode {} is not supported.", self.mode), }, _ => panic!("Unknown visibility: {:#?}", name), From d30b3d4bf7b4a17545e1a52e93300dd472defe3b Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 21:08:11 +0000 Subject: [PATCH 12/21] Changed build script and ci.yml --- .github/workflows/ci.yml | 6 +++++- scripts/build_seal.zsh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6670d82bf..b7d63e73f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,7 @@ on: env: CARGO_TERM_COLOR: always ABY_SOURCE: "./../ABY" + SEAL_SOURCE: "./../SEAL" jobs: build: @@ -32,7 +33,10 @@ jobs: uses: actions/cache@v2 with: path: ${ABY_SOURCE}/build - key: ${{ runner.os }} + key: ${{ runner.os }}-aby + with: + path: ${SEAL_SOURCE}/build + key: ${{ runner.os }}-seal - name: Check run: python3 driver.py --check - name: Format diff --git a/scripts/build_seal.zsh b/scripts/build_seal.zsh index 0511b70b9..33ba7728b 100755 --- a/scripts/build_seal.zsh +++ b/scripts/build_seal.zsh @@ -1,8 +1,8 @@ #!/usr/bin/env zsh if [[ ! -z ${SEAL_SOURCE} ]]; then - mkdir -p -- ${SEAL_SOURCE}/build cd ${SEAL_SOURCE} + cmake -S . -B build -DSEAL_BUILD_EXAMPLES=ON cmake --build build else echo "Missing SEAL_SOURCE environment variable." From f127d5d48ea4db646058621d80b1a8b664e152ec Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 21:15:40 +0000 Subject: [PATCH 13/21] changed ci.yml --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7d63e73f..fa2b038af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,7 @@ jobs: with: path: ${ABY_SOURCE}/build key: ${{ runner.os }}-aby + uses: actions/cache@v2 with: path: ${SEAL_SOURCE}/build key: ${{ runner.os }}-seal From 308bcbc86d4311cd9c4315d9004425a78e700aa0 Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 21:16:48 +0000 Subject: [PATCH 14/21] changed ci.yml again --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa2b038af..6b520d694 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,11 +29,12 @@ jobs: run: python3 driver.py --all_features - name: Install third_party libraries run: python3 driver.py --install - - name: Cache third_party build + - name: Cache aby build uses: actions/cache@v2 with: path: ${ABY_SOURCE}/build key: ${{ runner.os }}-aby + - name: Cache seal build uses: actions/cache@v2 with: path: ${SEAL_SOURCE}/build From 5b1ac714f9771f45d764dc3d1fabda0f7a7ca72d Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 21:18:30 +0000 Subject: [PATCH 15/21] changed ci.yml again again --- .github/workflows/ci.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b520d694..69ad92fa1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,16 +29,13 @@ jobs: run: python3 driver.py --all_features - name: Install third_party libraries run: python3 driver.py --install - - name: Cache aby build + - name: Cache third_party build uses: actions/cache@v2 with: - path: ${ABY_SOURCE}/build - key: ${{ runner.os }}-aby - - name: Cache seal build - uses: actions/cache@v2 - with: - path: ${SEAL_SOURCE}/build - key: ${{ runner.os }}-seal + path: | + ${ABY_SOURCE}/build + ${SEAL_SOURCE}/build + key: ${{ runner.os }} - name: Check run: python3 driver.py --check - name: Format From d55e5a53c8f118a3aacd29bff1eaef3b9a321047 Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 21:31:54 +0000 Subject: [PATCH 16/21] fixed bug in driver --- driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver.py b/driver.py index 5a737d982..e5feb2678 100755 --- a/driver.py +++ b/driver.py @@ -23,7 +23,7 @@ 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 == "fhe": + 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"]) From fdb91e7b4e1d4c0b7bb18669de07fd55b2532e85 Mon Sep 17 00:00:00 2001 From: William Seo Date: Thu, 31 Mar 2022 21:44:37 +0000 Subject: [PATCH 17/21] fixed test inputs --- scripts/{seal_tests => aby_tests}/test_inputs/add.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/add_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/array.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/array_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/array_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/array_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/array_4.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/biomatch_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/biomatch_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/const_add.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/const_eq_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/const_eq_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/conv.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/div_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/div_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/div_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/div_4.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/eq_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/eq_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/ge_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/ge_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/ge_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/gt_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/gt_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/gt_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/index.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/ite_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/ite_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/kmeans.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/le_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/le_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/le_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/loop_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/loop_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/lsh_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/lsh_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/lsh_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/lt_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/lt_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/lt_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mod_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mod_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mod_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mult_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mult_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mult_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mult_add_pub_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/mult_add_pub_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/nary_add.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/nary_and.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/rsh_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/rsh_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/sub_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/sub_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/xor_1.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/xor_2.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/xor_3.txt | 0 scripts/{seal_tests => aby_tests}/test_inputs/xor_4.txt | 0 58 files changed, 0 insertions(+), 0 deletions(-) rename scripts/{seal_tests => aby_tests}/test_inputs/add.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/add_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/array.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/array_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/array_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/array_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/array_4.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/biomatch_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/biomatch_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/const_add.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/const_eq_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/const_eq_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/conv.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/div_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/div_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/div_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/div_4.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/eq_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/eq_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/ge_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/ge_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/ge_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/gt_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/gt_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/gt_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/index.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/ite_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/ite_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/kmeans.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/le_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/le_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/le_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/loop_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/loop_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/lsh_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/lsh_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/lsh_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/lt_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/lt_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/lt_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mod_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mod_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mod_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mult_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mult_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mult_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mult_add_pub_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/mult_add_pub_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/nary_add.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/nary_and.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/rsh_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/rsh_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/sub_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/sub_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/xor_1.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/xor_2.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/xor_3.txt (100%) rename scripts/{seal_tests => aby_tests}/test_inputs/xor_4.txt (100%) diff --git a/scripts/seal_tests/test_inputs/add.txt b/scripts/aby_tests/test_inputs/add.txt similarity index 100% rename from scripts/seal_tests/test_inputs/add.txt rename to scripts/aby_tests/test_inputs/add.txt diff --git a/scripts/seal_tests/test_inputs/add_2.txt b/scripts/aby_tests/test_inputs/add_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/add_2.txt rename to scripts/aby_tests/test_inputs/add_2.txt diff --git a/scripts/seal_tests/test_inputs/array.txt b/scripts/aby_tests/test_inputs/array.txt similarity index 100% rename from scripts/seal_tests/test_inputs/array.txt rename to scripts/aby_tests/test_inputs/array.txt diff --git a/scripts/seal_tests/test_inputs/array_1.txt b/scripts/aby_tests/test_inputs/array_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/array_1.txt rename to scripts/aby_tests/test_inputs/array_1.txt diff --git a/scripts/seal_tests/test_inputs/array_2.txt b/scripts/aby_tests/test_inputs/array_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/array_2.txt rename to scripts/aby_tests/test_inputs/array_2.txt diff --git a/scripts/seal_tests/test_inputs/array_3.txt b/scripts/aby_tests/test_inputs/array_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/array_3.txt rename to scripts/aby_tests/test_inputs/array_3.txt diff --git a/scripts/seal_tests/test_inputs/array_4.txt b/scripts/aby_tests/test_inputs/array_4.txt similarity index 100% rename from scripts/seal_tests/test_inputs/array_4.txt rename to scripts/aby_tests/test_inputs/array_4.txt diff --git a/scripts/seal_tests/test_inputs/biomatch_1.txt b/scripts/aby_tests/test_inputs/biomatch_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/biomatch_1.txt rename to scripts/aby_tests/test_inputs/biomatch_1.txt diff --git a/scripts/seal_tests/test_inputs/biomatch_2.txt b/scripts/aby_tests/test_inputs/biomatch_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/biomatch_2.txt rename to scripts/aby_tests/test_inputs/biomatch_2.txt diff --git a/scripts/seal_tests/test_inputs/const_add.txt b/scripts/aby_tests/test_inputs/const_add.txt similarity index 100% rename from scripts/seal_tests/test_inputs/const_add.txt rename to scripts/aby_tests/test_inputs/const_add.txt diff --git a/scripts/seal_tests/test_inputs/const_eq_1.txt b/scripts/aby_tests/test_inputs/const_eq_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/const_eq_1.txt rename to scripts/aby_tests/test_inputs/const_eq_1.txt diff --git a/scripts/seal_tests/test_inputs/const_eq_2.txt b/scripts/aby_tests/test_inputs/const_eq_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/const_eq_2.txt rename to scripts/aby_tests/test_inputs/const_eq_2.txt diff --git a/scripts/seal_tests/test_inputs/conv.txt b/scripts/aby_tests/test_inputs/conv.txt similarity index 100% rename from scripts/seal_tests/test_inputs/conv.txt rename to scripts/aby_tests/test_inputs/conv.txt diff --git a/scripts/seal_tests/test_inputs/div_1.txt b/scripts/aby_tests/test_inputs/div_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/div_1.txt rename to scripts/aby_tests/test_inputs/div_1.txt diff --git a/scripts/seal_tests/test_inputs/div_2.txt b/scripts/aby_tests/test_inputs/div_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/div_2.txt rename to scripts/aby_tests/test_inputs/div_2.txt diff --git a/scripts/seal_tests/test_inputs/div_3.txt b/scripts/aby_tests/test_inputs/div_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/div_3.txt rename to scripts/aby_tests/test_inputs/div_3.txt diff --git a/scripts/seal_tests/test_inputs/div_4.txt b/scripts/aby_tests/test_inputs/div_4.txt similarity index 100% rename from scripts/seal_tests/test_inputs/div_4.txt rename to scripts/aby_tests/test_inputs/div_4.txt diff --git a/scripts/seal_tests/test_inputs/eq_1.txt b/scripts/aby_tests/test_inputs/eq_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/eq_1.txt rename to scripts/aby_tests/test_inputs/eq_1.txt diff --git a/scripts/seal_tests/test_inputs/eq_2.txt b/scripts/aby_tests/test_inputs/eq_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/eq_2.txt rename to scripts/aby_tests/test_inputs/eq_2.txt diff --git a/scripts/seal_tests/test_inputs/ge_1.txt b/scripts/aby_tests/test_inputs/ge_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/ge_1.txt rename to scripts/aby_tests/test_inputs/ge_1.txt diff --git a/scripts/seal_tests/test_inputs/ge_2.txt b/scripts/aby_tests/test_inputs/ge_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/ge_2.txt rename to scripts/aby_tests/test_inputs/ge_2.txt diff --git a/scripts/seal_tests/test_inputs/ge_3.txt b/scripts/aby_tests/test_inputs/ge_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/ge_3.txt rename to scripts/aby_tests/test_inputs/ge_3.txt diff --git a/scripts/seal_tests/test_inputs/gt_1.txt b/scripts/aby_tests/test_inputs/gt_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/gt_1.txt rename to scripts/aby_tests/test_inputs/gt_1.txt diff --git a/scripts/seal_tests/test_inputs/gt_2.txt b/scripts/aby_tests/test_inputs/gt_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/gt_2.txt rename to scripts/aby_tests/test_inputs/gt_2.txt diff --git a/scripts/seal_tests/test_inputs/gt_3.txt b/scripts/aby_tests/test_inputs/gt_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/gt_3.txt rename to scripts/aby_tests/test_inputs/gt_3.txt diff --git a/scripts/seal_tests/test_inputs/index.txt b/scripts/aby_tests/test_inputs/index.txt similarity index 100% rename from scripts/seal_tests/test_inputs/index.txt rename to scripts/aby_tests/test_inputs/index.txt diff --git a/scripts/seal_tests/test_inputs/ite_1.txt b/scripts/aby_tests/test_inputs/ite_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/ite_1.txt rename to scripts/aby_tests/test_inputs/ite_1.txt diff --git a/scripts/seal_tests/test_inputs/ite_2.txt b/scripts/aby_tests/test_inputs/ite_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/ite_2.txt rename to scripts/aby_tests/test_inputs/ite_2.txt diff --git a/scripts/seal_tests/test_inputs/kmeans.txt b/scripts/aby_tests/test_inputs/kmeans.txt similarity index 100% rename from scripts/seal_tests/test_inputs/kmeans.txt rename to scripts/aby_tests/test_inputs/kmeans.txt diff --git a/scripts/seal_tests/test_inputs/le_1.txt b/scripts/aby_tests/test_inputs/le_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/le_1.txt rename to scripts/aby_tests/test_inputs/le_1.txt diff --git a/scripts/seal_tests/test_inputs/le_2.txt b/scripts/aby_tests/test_inputs/le_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/le_2.txt rename to scripts/aby_tests/test_inputs/le_2.txt diff --git a/scripts/seal_tests/test_inputs/le_3.txt b/scripts/aby_tests/test_inputs/le_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/le_3.txt rename to scripts/aby_tests/test_inputs/le_3.txt diff --git a/scripts/seal_tests/test_inputs/loop_1.txt b/scripts/aby_tests/test_inputs/loop_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/loop_1.txt rename to scripts/aby_tests/test_inputs/loop_1.txt diff --git a/scripts/seal_tests/test_inputs/loop_2.txt b/scripts/aby_tests/test_inputs/loop_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/loop_2.txt rename to scripts/aby_tests/test_inputs/loop_2.txt diff --git a/scripts/seal_tests/test_inputs/lsh_1.txt b/scripts/aby_tests/test_inputs/lsh_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/lsh_1.txt rename to scripts/aby_tests/test_inputs/lsh_1.txt diff --git a/scripts/seal_tests/test_inputs/lsh_2.txt b/scripts/aby_tests/test_inputs/lsh_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/lsh_2.txt rename to scripts/aby_tests/test_inputs/lsh_2.txt diff --git a/scripts/seal_tests/test_inputs/lsh_3.txt b/scripts/aby_tests/test_inputs/lsh_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/lsh_3.txt rename to scripts/aby_tests/test_inputs/lsh_3.txt diff --git a/scripts/seal_tests/test_inputs/lt_1.txt b/scripts/aby_tests/test_inputs/lt_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/lt_1.txt rename to scripts/aby_tests/test_inputs/lt_1.txt diff --git a/scripts/seal_tests/test_inputs/lt_2.txt b/scripts/aby_tests/test_inputs/lt_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/lt_2.txt rename to scripts/aby_tests/test_inputs/lt_2.txt diff --git a/scripts/seal_tests/test_inputs/lt_3.txt b/scripts/aby_tests/test_inputs/lt_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/lt_3.txt rename to scripts/aby_tests/test_inputs/lt_3.txt diff --git a/scripts/seal_tests/test_inputs/mod_1.txt b/scripts/aby_tests/test_inputs/mod_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mod_1.txt rename to scripts/aby_tests/test_inputs/mod_1.txt diff --git a/scripts/seal_tests/test_inputs/mod_2.txt b/scripts/aby_tests/test_inputs/mod_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mod_2.txt rename to scripts/aby_tests/test_inputs/mod_2.txt diff --git a/scripts/seal_tests/test_inputs/mod_3.txt b/scripts/aby_tests/test_inputs/mod_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mod_3.txt rename to scripts/aby_tests/test_inputs/mod_3.txt diff --git a/scripts/seal_tests/test_inputs/mult_1.txt b/scripts/aby_tests/test_inputs/mult_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mult_1.txt rename to scripts/aby_tests/test_inputs/mult_1.txt diff --git a/scripts/seal_tests/test_inputs/mult_2.txt b/scripts/aby_tests/test_inputs/mult_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mult_2.txt rename to scripts/aby_tests/test_inputs/mult_2.txt diff --git a/scripts/seal_tests/test_inputs/mult_3.txt b/scripts/aby_tests/test_inputs/mult_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mult_3.txt rename to scripts/aby_tests/test_inputs/mult_3.txt diff --git a/scripts/seal_tests/test_inputs/mult_add_pub_1.txt b/scripts/aby_tests/test_inputs/mult_add_pub_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mult_add_pub_1.txt rename to scripts/aby_tests/test_inputs/mult_add_pub_1.txt diff --git a/scripts/seal_tests/test_inputs/mult_add_pub_2.txt b/scripts/aby_tests/test_inputs/mult_add_pub_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/mult_add_pub_2.txt rename to scripts/aby_tests/test_inputs/mult_add_pub_2.txt diff --git a/scripts/seal_tests/test_inputs/nary_add.txt b/scripts/aby_tests/test_inputs/nary_add.txt similarity index 100% rename from scripts/seal_tests/test_inputs/nary_add.txt rename to scripts/aby_tests/test_inputs/nary_add.txt diff --git a/scripts/seal_tests/test_inputs/nary_and.txt b/scripts/aby_tests/test_inputs/nary_and.txt similarity index 100% rename from scripts/seal_tests/test_inputs/nary_and.txt rename to scripts/aby_tests/test_inputs/nary_and.txt diff --git a/scripts/seal_tests/test_inputs/rsh_1.txt b/scripts/aby_tests/test_inputs/rsh_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/rsh_1.txt rename to scripts/aby_tests/test_inputs/rsh_1.txt diff --git a/scripts/seal_tests/test_inputs/rsh_2.txt b/scripts/aby_tests/test_inputs/rsh_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/rsh_2.txt rename to scripts/aby_tests/test_inputs/rsh_2.txt diff --git a/scripts/seal_tests/test_inputs/sub_1.txt b/scripts/aby_tests/test_inputs/sub_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/sub_1.txt rename to scripts/aby_tests/test_inputs/sub_1.txt diff --git a/scripts/seal_tests/test_inputs/sub_2.txt b/scripts/aby_tests/test_inputs/sub_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/sub_2.txt rename to scripts/aby_tests/test_inputs/sub_2.txt diff --git a/scripts/seal_tests/test_inputs/xor_1.txt b/scripts/aby_tests/test_inputs/xor_1.txt similarity index 100% rename from scripts/seal_tests/test_inputs/xor_1.txt rename to scripts/aby_tests/test_inputs/xor_1.txt diff --git a/scripts/seal_tests/test_inputs/xor_2.txt b/scripts/aby_tests/test_inputs/xor_2.txt similarity index 100% rename from scripts/seal_tests/test_inputs/xor_2.txt rename to scripts/aby_tests/test_inputs/xor_2.txt diff --git a/scripts/seal_tests/test_inputs/xor_3.txt b/scripts/aby_tests/test_inputs/xor_3.txt similarity index 100% rename from scripts/seal_tests/test_inputs/xor_3.txt rename to scripts/aby_tests/test_inputs/xor_3.txt diff --git a/scripts/seal_tests/test_inputs/xor_4.txt b/scripts/aby_tests/test_inputs/xor_4.txt similarity index 100% rename from scripts/seal_tests/test_inputs/xor_4.txt rename to scripts/aby_tests/test_inputs/xor_4.txt From afd8bf200f1946f30f04d08422726b9c193375a6 Mon Sep 17 00:00:00 2001 From: William Seo Date: Tue, 26 Apr 2022 00:22:34 +0000 Subject: [PATCH 18/21] Added support for addition, multiplication, and simple vectorized operations --- .vscode/settings.json | 3 + .../fhe/unit_tests/arithmetic_tests/2pc_add.c | 3 + .../unit_tests/arithmetic_tests/2pc_mult.c | 3 + .../arithmetic_tests/2pc_mult_add_pub.c | 3 + .../2pc_nary_arithmetic_add.c | 3 + .../nary_boolean_tests/2pc_nary_boolean_and.c | 5 + .../unit_tests/arithmetic_tests/2pc_add.zok | 2 + .../unit_tests/arithmetic_tests/2pc_mult.zok | 2 + .../arithmetic_tests/2pc_mult_add_pub.zok | 3 + .../boolean_tests/2pc_boolean_equals.zok | 2 +- .../2pc_nary_arithmetic_add.zok | 2 + .../2pc_nary_boolean_and.zok | 2 + scripts/build_fhe_c_test.zsh | 14 +- scripts/build_fhe_zokrates_test.zsh | 13 ++ scripts/seal_tests/c_test_seal.py | 2 +- scripts/seal_tests/custom_tests/batch_add.txt | 3 + .../custom_tests/batch_add_bytecode.txt | 4 + .../seal_tests/custom_tests/batch_cons.txt | 2 + .../custom_tests/batch_cons_bytecode.txt | 6 + .../seal_tests/custom_tests/batch_mult.txt | 3 + .../custom_tests/batch_mult_bytecode.txt | 4 + scripts/seal_tests/test_inputs/add.txt | 3 + scripts/seal_tests/test_inputs/eq_1.txt | 3 + scripts/seal_tests/test_inputs/eq_2.txt | 3 + scripts/seal_tests/test_inputs/mult_1.txt | 3 + scripts/seal_tests/test_inputs/mult_2.txt | 3 + scripts/seal_tests/test_inputs/mult_3.txt | 3 + .../seal_tests/test_inputs/mult_add_pub_1.txt | 4 + .../seal_tests/test_inputs/mult_add_pub_2.txt | 4 + scripts/seal_tests/test_inputs/nary_add.txt | 4 + scripts/seal_tests/test_inputs/nary_and.txt | 4 + scripts/seal_tests/test_suite.py | 67 ++++++-- scripts/seal_tests/util.py | 17 +- scripts/seal_tests/zokrates_test_seal.py | 2 +- src/target/fhe/trans.rs | 152 ++++++++++++++++-- 35 files changed, 320 insertions(+), 36 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/C/fhe/unit_tests/arithmetic_tests/2pc_add.c create mode 100644 examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c create mode 100644 examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c create mode 100644 examples/C/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c create mode 100644 examples/C/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c create mode 100644 examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok create mode 100644 examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok create mode 100644 examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok create mode 100644 examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok create mode 100644 examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok create mode 100644 scripts/seal_tests/custom_tests/batch_add.txt create mode 100644 scripts/seal_tests/custom_tests/batch_add_bytecode.txt create mode 100644 scripts/seal_tests/custom_tests/batch_cons.txt create mode 100644 scripts/seal_tests/custom_tests/batch_cons_bytecode.txt create mode 100644 scripts/seal_tests/custom_tests/batch_mult.txt create mode 100644 scripts/seal_tests/custom_tests/batch_mult_bytecode.txt create mode 100644 scripts/seal_tests/test_inputs/add.txt create mode 100644 scripts/seal_tests/test_inputs/eq_1.txt create mode 100644 scripts/seal_tests/test_inputs/eq_2.txt create mode 100644 scripts/seal_tests/test_inputs/mult_1.txt create mode 100644 scripts/seal_tests/test_inputs/mult_2.txt create mode 100644 scripts/seal_tests/test_inputs/mult_3.txt create mode 100644 scripts/seal_tests/test_inputs/mult_add_pub_1.txt create mode 100644 scripts/seal_tests/test_inputs/mult_add_pub_2.txt create mode 100644 scripts/seal_tests/test_inputs/nary_add.txt create mode 100644 scripts/seal_tests/test_inputs/nary_and.txt diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..cad7657df --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cmake.configureOnOpen": false +} \ No newline at end of file diff --git a/examples/C/fhe/unit_tests/arithmetic_tests/2pc_add.c b/examples/C/fhe/unit_tests/arithmetic_tests/2pc_add.c new file mode 100644 index 000000000..fab58cef4 --- /dev/null +++ b/examples/C/fhe/unit_tests/arithmetic_tests/2pc_add.c @@ -0,0 +1,3 @@ +int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b) { + return a + b; +} \ No newline at end of file diff --git a/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c b/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c new file mode 100644 index 000000000..9404cd925 --- /dev/null +++ b/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c @@ -0,0 +1,3 @@ +int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b) { + return a * b; +} \ No newline at end of file diff --git a/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c b/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c new file mode 100644 index 000000000..917ec25c6 --- /dev/null +++ b/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c @@ -0,0 +1,3 @@ +int main(__attribute__((private(0))) int a, __attribute__((private(1))) int b, __attribute__((public)) int v) { + return a * b + v; +} \ No newline at end of file diff --git a/examples/C/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c b/examples/C/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c new file mode 100644 index 000000000..c8af060fa --- /dev/null +++ b/examples/C/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c @@ -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; +} \ No newline at end of file diff --git a/examples/C/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c b/examples/C/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c new file mode 100644 index 000000000..c80224b47 --- /dev/null +++ b/examples/C/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c @@ -0,0 +1,5 @@ +#include + +bool main(__attribute__((private(0))) bool a, __attribute__((private(1))) bool b, __attribute__((private(1))) bool c) { + return a && b && c; +} \ No newline at end of file diff --git a/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok new file mode 100644 index 000000000..f90f2f531 --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok @@ -0,0 +1,2 @@ +def main(private u32 a, private u32 b) -> u32: + return a + b \ No newline at end of file diff --git a/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok new file mode 100644 index 000000000..2b3e028b7 --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok @@ -0,0 +1,2 @@ +def main(private u32 a, private u32 b) -> u32: + return a * b diff --git a/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok new file mode 100644 index 000000000..804a9c902 --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok @@ -0,0 +1,3 @@ + +def main(private u32 a, private u32 b, public u32 v) -> u32: + return a * b + v diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok index ef5de39b0..977a07225 100644 --- a/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok +++ b/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok @@ -1,2 +1,2 @@ -def main(private<1> bool a, private<2> bool b) -> bool: +def main(private bool a, private bool b) -> bool: return a == b \ No newline at end of file diff --git a/examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok b/examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok new file mode 100644 index 000000000..f78e1af69 --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok @@ -0,0 +1,2 @@ +def main(private u32 a, private u32 b, private u32 c) -> u32: + return a + b + c diff --git a/examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok b/examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok new file mode 100644 index 000000000..a113942fd --- /dev/null +++ b/examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok @@ -0,0 +1,2 @@ +def main(private bool a, private bool b, private bool c) -> bool: + return a && b && c diff --git a/scripts/build_fhe_c_test.zsh b/scripts/build_fhe_c_test.zsh index 808cf1e12..0b22e13ee 100755 --- a/scripts/build_fhe_c_test.zsh +++ b/scripts/build_fhe_c_test.zsh @@ -25,4 +25,16 @@ function fhe_test { # build boolean tests fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c -fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c \ No newline at end of file +fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c +fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c + +# build nary boolean tests +fhe_test ./examples/C/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c + +# build arithmetic tests +fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/2pc_add.c +fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c +fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c + +# build nary arithmetic tests +fhe_test ./examples/C/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c \ No newline at end of file diff --git a/scripts/build_fhe_zokrates_test.zsh b/scripts/build_fhe_zokrates_test.zsh index 3ee2052d1..0bfdf9ae5 100755 --- a/scripts/build_fhe_zokrates_test.zsh +++ b/scripts/build_fhe_zokrates_test.zsh @@ -26,3 +26,16 @@ function fhe_test { # build boolean tests fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_and.zok fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok + +# build nary boolean tests +fhe_test ./examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok + +# build arithmetic tests +fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok + +# build nary arithmetic tests +fhe_test ./examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok + diff --git a/scripts/seal_tests/c_test_seal.py b/scripts/seal_tests/c_test_seal.py index ae36d5407..f6ffa5660 100644 --- a/scripts/seal_tests/c_test_seal.py +++ b/scripts/seal_tests/c_test_seal.py @@ -4,6 +4,6 @@ from test_suite import * if __name__ == "__main__": - tests = boolean_tests + tests = boolean_tests + arithmetic_tests + nary_arithmetic_tests + nary_boolean_tests run_tests('c', tests) diff --git a/scripts/seal_tests/custom_tests/batch_add.txt b/scripts/seal_tests/custom_tests/batch_add.txt new file mode 100644 index 000000000..802aafb28 --- /dev/null +++ b/scripts/seal_tests/custom_tests/batch_add.txt @@ -0,0 +1,3 @@ +arr a 1 2 3 4 5 +arr b 6 7 8 9 10 +res 7 9 11 13 15 \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_add_bytecode.txt b/scripts/seal_tests/custom_tests/batch_add_bytecode.txt new file mode 100644 index 000000000..6a867fd7d --- /dev/null +++ b/scripts/seal_tests/custom_tests/batch_add_bytecode.txt @@ -0,0 +1,4 @@ +3 1 a 1 5 1 ARR_IN +3 1 b 1 5 0 ARR_IN +2 1 1 0 2 ADD +2 0 2 5 ARR_OUT \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_cons.txt b/scripts/seal_tests/custom_tests/batch_cons.txt new file mode 100644 index 000000000..6733c4d2a --- /dev/null +++ b/scripts/seal_tests/custom_tests/batch_cons.txt @@ -0,0 +1,2 @@ +arr a 1 2 3 4 5 +res 7 \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_cons_bytecode.txt b/scripts/seal_tests/custom_tests/batch_cons_bytecode.txt new file mode 100644 index 000000000..c91a05a85 --- /dev/null +++ b/scripts/seal_tests/custom_tests/batch_cons_bytecode.txt @@ -0,0 +1,6 @@ +3 1 a 1 5 0 ARR_IN +5 1 10 100 1000 10000 100000 1 ARR_CONS +5 1 9 8 7 6 5 2 ARR_CONS +2 1 1 0 3 MUL +2 1 2 3 4 ADD +2 0 4 5 ARR_OUT \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_mult.txt b/scripts/seal_tests/custom_tests/batch_mult.txt new file mode 100644 index 000000000..ada7be813 --- /dev/null +++ b/scripts/seal_tests/custom_tests/batch_mult.txt @@ -0,0 +1,3 @@ +arr a 1 2 3 4 5 +arr b 6 7 8 9 10 +res 6 14 24 36 50 \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_mult_bytecode.txt b/scripts/seal_tests/custom_tests/batch_mult_bytecode.txt new file mode 100644 index 000000000..ab6e15b4b --- /dev/null +++ b/scripts/seal_tests/custom_tests/batch_mult_bytecode.txt @@ -0,0 +1,4 @@ +3 1 a 1 5 1 ARR_IN +3 1 b 1 5 0 ARR_IN +2 1 1 0 2 MUL +2 0 2 5 ARR_OUT \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/add.txt b/scripts/seal_tests/test_inputs/add.txt new file mode 100644 index 000000000..9d0338538 --- /dev/null +++ b/scripts/seal_tests/test_inputs/add.txt @@ -0,0 +1,3 @@ +a 1 +b 2 +res 3 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/eq_1.txt b/scripts/seal_tests/test_inputs/eq_1.txt new file mode 100644 index 000000000..a9e356a5b --- /dev/null +++ b/scripts/seal_tests/test_inputs/eq_1.txt @@ -0,0 +1,3 @@ +a 1 +b 0 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/eq_2.txt b/scripts/seal_tests/test_inputs/eq_2.txt new file mode 100644 index 000000000..e7129253a --- /dev/null +++ b/scripts/seal_tests/test_inputs/eq_2.txt @@ -0,0 +1,3 @@ +a 1 +b 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_1.txt b/scripts/seal_tests/test_inputs/mult_1.txt new file mode 100644 index 000000000..596a6ab24 --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_1.txt @@ -0,0 +1,3 @@ +a 0 +b 5 +res 0 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_2.txt b/scripts/seal_tests/test_inputs/mult_2.txt new file mode 100644 index 000000000..f3a9b265c --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_2.txt @@ -0,0 +1,3 @@ +a 1 +b 5 +res 5 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_3.txt b/scripts/seal_tests/test_inputs/mult_3.txt new file mode 100644 index 000000000..0c84b4868 --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_3.txt @@ -0,0 +1,3 @@ +a 2 +b 5 +res 10 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_add_pub_1.txt b/scripts/seal_tests/test_inputs/mult_add_pub_1.txt new file mode 100644 index 000000000..3c5e755dd --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_add_pub_1.txt @@ -0,0 +1,4 @@ +a 5 +v 7 +b 7 +res 42 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/mult_add_pub_2.txt b/scripts/seal_tests/test_inputs/mult_add_pub_2.txt new file mode 100644 index 000000000..3c5e755dd --- /dev/null +++ b/scripts/seal_tests/test_inputs/mult_add_pub_2.txt @@ -0,0 +1,4 @@ +a 5 +v 7 +b 7 +res 42 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/nary_add.txt b/scripts/seal_tests/test_inputs/nary_add.txt new file mode 100644 index 000000000..780d3579c --- /dev/null +++ b/scripts/seal_tests/test_inputs/nary_add.txt @@ -0,0 +1,4 @@ +a 1 +b 2 +c 3 +res 6 \ No newline at end of file diff --git a/scripts/seal_tests/test_inputs/nary_and.txt b/scripts/seal_tests/test_inputs/nary_and.txt new file mode 100644 index 000000000..1fffca872 --- /dev/null +++ b/scripts/seal_tests/test_inputs/nary_and.txt @@ -0,0 +1,4 @@ +a 1 +b 1 +c 1 +res 1 \ No newline at end of file diff --git a/scripts/seal_tests/test_suite.py b/scripts/seal_tests/test_suite.py index dc4c67b94..ef9f7febf 100644 --- a/scripts/seal_tests/test_suite.py +++ b/scripts/seal_tests/test_suite.py @@ -41,15 +41,62 @@ "2pc_boolean_or", "./scripts/seal_tests/test_inputs/or_4.txt", ], - # [ - # "Boolean == - 1", - # "2pc_boolean_equals", - # "./scripts/seal_tests/test_inputs/eq_1.txt", - # ], - # [ - # "Boolean == - 2", - # "2pc_boolean_equals", - # "./scripts/seal_tests/test_inputs/eq_2.txt", - # ], + [ + "Boolean == - 1", + "2pc_boolean_equals", + "./scripts/seal_tests/test_inputs/eq_1.txt", + ], + [ + "Boolean == - 2", + "2pc_boolean_equals", + "./scripts/seal_tests/test_inputs/eq_2.txt", + ], ] +arithmetic_tests = [ + [ + "Add two numbers", + "2pc_add", + "./scripts/seal_tests/test_inputs/add.txt", + ], + [ + "Multiply two numbers - 1", + "2pc_mult", + "./scripts/seal_tests/test_inputs/mult_1.txt", + ], + [ + "Multiply two numbers - 2", + "2pc_mult", + "./scripts/seal_tests/test_inputs/mult_2.txt", + ], + [ + "Multiply two numbers - 3", + "2pc_mult", + "./scripts/seal_tests/test_inputs/mult_3.txt", + ], + [ + "Multiply two numbers together and add with public value", + "2pc_mult_add_pub", + "./scripts/seal_tests/test_inputs/mult_add_pub_1.txt", + ], + [ + "Multiply two numbers together and add with public value, check only server side public value is added", + "2pc_mult_add_pub", + "./scripts/seal_tests/test_inputs/mult_add_pub_2.txt", + ], +] +nary_arithmetic_tests = [ + [ + "Test a + b + c", + "2pc_nary_arithmetic_add", + "./scripts/seal_tests/test_inputs/nary_add.txt", + ], +] + +nary_boolean_tests = [ + [ + "Test a & b & c", + "2pc_nary_boolean_and", + "./scripts/seal_tests/test_inputs/nary_and.txt", + ], +] \ No newline at end of file diff --git a/scripts/seal_tests/util.py b/scripts/seal_tests/util.py index 5583c936e..3fdb5042e 100644 --- a/scripts/seal_tests/util.py +++ b/scripts/seal_tests/util.py @@ -19,13 +19,13 @@ def get_result(file_path): for line in lines: l = line.split() if l and l[0] == "res": - return l[1] + return l[1:] raise RuntimeError("Unable to find result: "+file_path) else: raise RuntimeError("Unable to open file: "+file_path) -def run_test(expected: str, cmd: List[str]) -> bool: +def run_test(expected: List[str], cmd: List[str]) -> bool: try: proc = Popen(" ".join(cmd), shell=True, stdout=PIPE, stderr=PIPE) @@ -34,12 +34,15 @@ def run_test(expected: str, cmd: List[str]) -> bool: if err: raise RuntimeError("Error: "+err.decode("utf-8").strip()) - out = out.decode("utf-8").strip() + #out = out.decode("utf-8").strip() + output = [] + for o in out.split(): + output.append(o.decode("utf-8")) - assert out == expected, "out: "+out+"\nexpected: "+expected + assert (output == expected), "out: "+" ".join(output)+"\nexpected: "+" ".join(expected) return True, "" except Exception as e: - # print("Exception: ", e) + print("Exception: ", e) return False, e def run_tests(lang: str, tests: List[dict]): @@ -52,6 +55,10 @@ def run_tests(lang: str, tests: List[dict]): print(f"Running FHE tests for {lang} frontend") failed_test_descs = [] num_retries = 2 + + run_test(['7','9','11','13','15'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/custom_tests/batch_add_bytecode.txt -t ./scripts/seal_tests/custom_tests/batch_add.txt"]) + run_test(['6','14','24','36','50'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/custom_tests/batch_mult_bytecode.txt -t ./scripts/seal_tests/custom_tests/batch_mult.txt"]) + run_test(['19','208','3007','40006','500005'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/custom_tests/batch_cons_bytecode.txt -t ./scripts/seal_tests/custom_tests/batch_cons.txt"]) for test in tqdm(tests, leave=False, dynamic_ncols=True): assert len(test) == 3, "test configurations are wrong for test: "+test[0] diff --git a/scripts/seal_tests/zokrates_test_seal.py b/scripts/seal_tests/zokrates_test_seal.py index b55486fe1..89867678d 100644 --- a/scripts/seal_tests/zokrates_test_seal.py +++ b/scripts/seal_tests/zokrates_test_seal.py @@ -4,7 +4,7 @@ from test_suite import * if __name__ == "__main__": - tests = boolean_tests + tests = boolean_tests + arithmetic_tests + nary_arithmetic_tests + nary_boolean_tests run_tests('zok', tests) diff --git a/src/target/fhe/trans.rs b/src/target/fhe/trans.rs index 04cc3e4b6..864ed68a3 100644 --- a/src/target/fhe/trans.rs +++ b/src/target/fhe/trans.rs @@ -9,6 +9,7 @@ use std::path::Path; enum EmbeddedTerm { Bool, Bv, + Arr, } struct ToFHE { @@ -58,6 +59,7 @@ impl ToFHE { } } } + _ => panic!("Term {} is not of type Var", t), } } @@ -73,29 +75,36 @@ impl ToFHE { let s = self.term_to_stext_cnt.get(&t).unwrap(); let a = self.term_to_stext_cnt.get(&t.cs[0]).unwrap(); let b = self.term_to_stext_cnt.get(&t.cs[1]).unwrap(); - let op = "EQ"; - let line = format!("2 1 {} {} {} {}\n", a, b, s, op); - self.bytecode_output.push(line); + let op; match check(&a_term) { Sort::Bool => { self.check_bool(&a_term); self.check_bool(&b_term); self.cache.insert(t, EmbeddedTerm::Bool); + op = "B_EQ"; } Sort::BitVector(_) => { self.check_bv(&a_term); self.check_bv(&b_term); self.cache.insert(t, EmbeddedTerm::Bool); + op = "V_EQ"; } e => panic!("Unimplemented sort for Eq: {:?}", e), } + let line = format!("2 1 {} {} {} {}\n", a, b, s, op); + self.bytecode_output.push(line); } /// Given term `t`, type-check `t` is of type Bool fn check_bool(&self, t: &Term) { - self.cache + match self + .cache .get(t) - .unwrap_or_else(|| panic!("Missing expression for {:?}", t)); + .unwrap_or_else(|| panic!("Missing expression for {:?}", t)) + { + EmbeddedTerm::Bool => (), + _ => panic!("Check_bool failed"), + }; } fn embed_bool(&mut self, t: Term) { @@ -106,18 +115,18 @@ impl ToFHE { if !self.inputs.contains(&t) && self.md.input_vis.contains_key(name) { let term_name = ToFHE::get_var_name(&t); let enc = self.unwrap_vis(name); - let share_cnt = self.term_to_stext_cnt.get(&t).unwrap(); let op = "IN"; - let line = format!("2 1 {} {} {} {}\n", term_name, enc, share_cnt, op); + let line = format!("2 1 {} {} {} {}\n", term_name, enc, s, op); self.bytecode_output.insert(0, line); + self.inputs.insert(t.clone()); } if !self.cache.contains_key(&t) { self.cache.insert(t.clone(), EmbeddedTerm::Bool); } } Op::Const(Value::Bool(b)) => { - let op = "CONS_bool"; + let op = "CONS"; let line = format!("1 1 {} {} {}\n", *b as i32, s, op); self.bytecode_output.push(line); self.cache.insert(t.clone(), EmbeddedTerm::Bool); @@ -164,9 +173,14 @@ impl ToFHE { /// Given term `t`, type-check `t` is of type Bv fn check_bv(&self, t: &Term) { - self.cache + match self + .cache .get(t) - .unwrap_or_else(|| panic!("Missing expression for {:?}", t)); + .unwrap_or_else(|| panic!("Missing expression for {:?}", t)) + { + EmbeddedTerm::Bv => (), + _ => panic!("Check_bv failed"), + }; } fn embed_bv(&mut self, t: Term) { @@ -177,28 +191,119 @@ impl ToFHE { if !self.inputs.contains(&t) && self.md.input_vis.contains_key(name) { let term_name = ToFHE::get_var_name(&t); let enc = self.unwrap_vis(name); - let stext_cnt = self.term_to_stext_cnt.get(&t).unwrap(); let op = "IN"; - let line = format!("2 1 {} {} {} {}\n", term_name, enc, stext_cnt, op); + let line = format!("2 1 {} {} {} {}\n", term_name, enc, s, op); self.bytecode_output.insert(0, line); + self.inputs.insert(t.clone()); } if !self.cache.contains_key(&t) { self.cache.insert(t.clone(), EmbeddedTerm::Bv); } } Op::Const(Value::BitVector(b)) => { - let op = "CONS_bv"; + let op = "CONS"; let line = format!("1 1 {} {} {}\n", b.as_sint(), s, op); self.bytecode_output.push(line); self.cache.insert(t.clone(), EmbeddedTerm::Bv); } + Op::BvNaryOp(o) => { + self.bytecode_output.push(format!("{} 1", t.cs.len())); + + for cterm in &t.cs { + self.check_bv(cterm); + self.bytecode_output + .push(format!(" {}", self.term_to_stext_cnt.get(cterm).unwrap())); + } + + let op = match o { + BvNaryOp::Xor => "V_XOR", + BvNaryOp::Or => "V_OR", + BvNaryOp::And => "V_AND", + BvNaryOp::Add => "ADD", + BvNaryOp::Mul => "MUL", + }; + + self.bytecode_output.push(format!(" {} {}\n", s, op)); + + self.cache.insert(t.clone(), EmbeddedTerm::Bv); + } _ => { panic!("Non-field in embed_bv: {:?}", t); } } } + // Given term `t`, type-check `t` is of type arr + fn check_arr(&self, t: &Term) { + match self + .cache + .get(t) + .unwrap_or_else(|| panic!("Missing expression for {:?}", t)) + { + EmbeddedTerm::Arr => (), + _ => panic!("Check_arr failed"), + }; + } + + fn embed_arr(&mut self, t: Term) { + let s = self.term_to_stext_cnt.get(&t).unwrap(); + match &t.op { + Op::Var(name, Sort::Array(_, _, len)) => { + // write to bytecode file + if !self.inputs.contains(&t) && self.md.input_vis.contains_key(name) { + let term_name = ToFHE::get_var_name(&t); + let enc = self.unwrap_vis(name); + let op = "ARR_IN"; + + let line = format!("3 1 {} {} {} {} {}\n", term_name, enc, len, s, op); + self.bytecode_output.insert(0, line); + } + if !self.cache.contains_key(&t) { + self.cache.insert(t.clone(), EmbeddedTerm::Arr); + } + } + Op::Const(Value::Array(arr)) => { + self.bytecode_output.push(format!("{} 1", arr.size)); + + for ival in arr.key_sort.elems_iter_values().take(arr.size) { + let val = arr.select(&ival); + match val.clone() { + Value::Array(_) => panic!("Const arr does not support multi-dim arrays"), + _ => (), + }; + self.bytecode_output.push(format!(" {}", val)); + } + + let op = "ARR_CONS"; + let line = format!("{} {}\n", s, op); + self.bytecode_output.push(line); + self.cache.insert(t.clone(), EmbeddedTerm::Arr); + } + Op::Map(op) => { + self.bytecode_output.push(format!("{} 1", t.cs.len())); + for cterm in &t.cs { + self.check_arr(cterm); + self.bytecode_output + .push(format!(" {}", self.term_to_stext_cnt.get(cterm).unwrap())); + } + let opstr = match **op { + Op::BoolNaryOp(BoolNaryOp::Or) => "B_OR", + Op::BoolNaryOp(BoolNaryOp::And) => "B_AND", + Op::BoolNaryOp(BoolNaryOp::Xor) => "B_XOR", + Op::BvNaryOp(BvNaryOp::Add) => "ADD", + Op::BvNaryOp(BvNaryOp::Mul) => "MUL", + _ => panic!("Map does not support operation {}", op), + }; + self.bytecode_output.push(format!(" {} {}\n", s, opstr)); + self.cache.insert(t.clone(), EmbeddedTerm::Arr); + } + _ => { + panic!("Non-field in embed_arr: {:?}", t); + } + } + } + fn embed(&mut self, t: Term) { for c in PostOrderIter::new(t) { match check(&c) { @@ -208,6 +313,9 @@ impl ToFHE { Sort::BitVector(_) => { self.embed_bv(c); } + Sort::Array(..) => { + self.embed_arr(c); + } e => panic!("Unsupported sort in embed: {:?}", e), } } @@ -217,10 +325,20 @@ impl ToFHE { fn lower(&mut self, t: Term) { self.embed(t.clone()); - let op = "OUT"; - let s = self.term_to_stext_cnt.get(&t).unwrap(); - let line = format!("1 0 {} {}\n", s, op); - self.bytecode_output.push(line); + match check(&t) { + Sort::Array(_, _, len) => { + let op = "ARR_OUT"; + let s = self.term_to_stext_cnt.get(&t).unwrap(); + let line = format!("2 0 {} {} {}\n", s, len, op); + self.bytecode_output.push(line); + } + _ => { + let op = "OUT"; + let s = self.term_to_stext_cnt.get(&t).unwrap(); + let line = format!("1 0 {} {}\n", s, op); + self.bytecode_output.push(line); + } + } // write lines to file write_lines_to_file(&self.bytecode_path, &self.bytecode_output); From 6c590db47e1bb4d280a2c2670b02f139e832f925 Mon Sep 17 00:00:00 2001 From: William Seo Date: Tue, 26 Apr 2022 01:00:00 +0000 Subject: [PATCH 19/21] Fixed linting issue --- Cargo.lock | 63 ++++++++++++++++++++++++++++++++++++----- src/target/fhe/trans.rs | 7 ++--- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30ac3424f..91b0e227f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,7 +138,7 @@ dependencies = [ "log", "num_cpus", "pairing", - "rand_core", + "rand_core 0.6.3", "rayon", "subtle", ] @@ -149,6 +149,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitmaps" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" +dependencies = [ + "typenum", +] + [[package]] name = "bitvec" version = "0.22.3" @@ -202,7 +211,7 @@ dependencies = [ "ff", "group", "pairing", - "rand_core", + "rand_core 0.6.3", "subtle", ] @@ -246,6 +255,7 @@ dependencies = [ "good_lp", "hashconsing", "ieee754", + "im", "itertools 0.10.3", "lang-c", "lazy_static", @@ -441,7 +451,7 @@ dependencies = [ "bitvec", "byteorder", "ff_derive 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core", + "rand_core 0.6.3", "subtle", ] @@ -578,7 +588,7 @@ checksum = "bc5ac374b108929de78460075f3dc439fa66df9d8fc77e8f12caa5165fcf0c89" dependencies = [ "byteorder", "ff", - "rand_core", + "rand_core 0.6.3", "subtle", ] @@ -630,6 +640,20 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9007da9cacbd3e6343da136e98b0d2df013f553d35bdec8b518f07bea768e19c" +[[package]] +name = "im" +version = "15.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111c1983f3c5bb72732df25cddacee9b546d08325fb584b5ebd38148be7b0246" +dependencies = [ + "bitmaps", + "rand_core 0.5.1", + "rand_xoshiro", + "sized-chunks", + "typenum", + "version_check", +] + [[package]] name = "indexmap" version = "1.7.0" @@ -1009,7 +1033,7 @@ checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", - "rand_core", + "rand_core 0.6.3", "rand_hc", ] @@ -1020,9 +1044,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.3", ] +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + [[package]] name = "rand_core" version = "0.6.3" @@ -1038,7 +1068,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" dependencies = [ - "rand_core", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_xoshiro" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -1191,6 +1230,16 @@ dependencies = [ "failure", ] +[[package]] +name = "sized-chunks" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" +dependencies = [ + "bitmaps", + "typenum", +] + [[package]] name = "strsim" version = "0.8.0" diff --git a/src/target/fhe/trans.rs b/src/target/fhe/trans.rs index 864ed68a3..421f44239 100644 --- a/src/target/fhe/trans.rs +++ b/src/target/fhe/trans.rs @@ -268,10 +268,9 @@ impl ToFHE { for ival in arr.key_sort.elems_iter_values().take(arr.size) { let val = arr.select(&ival); - match val.clone() { - Value::Array(_) => panic!("Const arr does not support multi-dim arrays"), - _ => (), - }; + if let Value::Array(_) = val.clone() { + panic!("Const arr does not support multi-dim arrays") + } self.bytecode_output.push(format!(" {}", val)); } From 94b65fdd91e558b072753a8f6b9219a0efb9d642 Mon Sep 17 00:00:00 2001 From: William Seo Date: Wed, 27 Apr 2022 06:29:08 +0000 Subject: [PATCH 20/21] Cleaned up directory, changed test names --- .../arithmetic_tests/{2pc_add.c => add.c} | 0 .../arithmetic_tests/{2pc_mult.c => mult.c} | 0 .../{2pc_mult_add_pub.c => mult_add_pub.c} | 0 .../{2pc_boolean_and.c => boolean_and.c} | 0 ...{2pc_boolean_equals.c => boolean_equals.c} | 0 .../{2pc_boolean_or.c => boolean_or.c} | 0 ...arithmetic_add.c => nary_arithmetic_add.c} | 0 ..._nary_boolean_and.c => nary_boolean_and.c} | 0 examples/ZoKrates/fhe/inputs/fhe_and.txt | 3 -- .../arithmetic_tests/{2pc_add.zok => add.zok} | 0 .../{2pc_mult.zok => mult.zok} | 0 ...{2pc_mult_add_pub.zok => mult_add_pub.zok} | 0 .../{2pc_boolean_and.zok => boolean_and.zok} | 0 ..._boolean_equals.zok => boolean_equals.zok} | 0 .../{2pc_boolean_or.zok => boolean_or.zok} | 0 ...hmetic_add.zok => nary_arithmetic_add.zok} | 0 ...y_boolean_and.zok => nary_boolean_and.zok} | 0 scripts/build_fhe_c_test.zsh | 16 ++++----- scripts/build_fhe_zokrates_test.zsh | 16 ++++----- scripts/clean_seal.zsh | 1 + scripts/seal_tests/custom_tests/batch_add.txt | 3 -- .../custom_tests/batch_add_bytecode.txt | 4 --- .../seal_tests/custom_tests/batch_cons.txt | 2 -- .../custom_tests/batch_cons_bytecode.txt | 6 ---- .../seal_tests/custom_tests/batch_mult.txt | 3 -- .../custom_tests/batch_mult_bytecode.txt | 4 --- scripts/seal_tests/test_suite.py | 36 +++++++++---------- scripts/seal_tests/util.py | 5 --- src/target/fhe/trans.rs | 4 +-- src/target/fhe/utils.rs | 2 ++ 30 files changed, 39 insertions(+), 66 deletions(-) rename examples/C/fhe/unit_tests/arithmetic_tests/{2pc_add.c => add.c} (100%) rename examples/C/fhe/unit_tests/arithmetic_tests/{2pc_mult.c => mult.c} (100%) rename examples/C/fhe/unit_tests/arithmetic_tests/{2pc_mult_add_pub.c => mult_add_pub.c} (100%) rename examples/C/fhe/unit_tests/boolean_tests/{2pc_boolean_and.c => boolean_and.c} (100%) rename examples/C/fhe/unit_tests/boolean_tests/{2pc_boolean_equals.c => boolean_equals.c} (100%) rename examples/C/fhe/unit_tests/boolean_tests/{2pc_boolean_or.c => boolean_or.c} (100%) rename examples/C/fhe/unit_tests/nary_arithmetic_tests/{2pc_nary_arithmetic_add.c => nary_arithmetic_add.c} (100%) rename examples/C/fhe/unit_tests/nary_boolean_tests/{2pc_nary_boolean_and.c => nary_boolean_and.c} (100%) delete mode 100644 examples/ZoKrates/fhe/inputs/fhe_and.txt rename examples/ZoKrates/fhe/unit_tests/arithmetic_tests/{2pc_add.zok => add.zok} (100%) rename examples/ZoKrates/fhe/unit_tests/arithmetic_tests/{2pc_mult.zok => mult.zok} (100%) rename examples/ZoKrates/fhe/unit_tests/arithmetic_tests/{2pc_mult_add_pub.zok => mult_add_pub.zok} (100%) rename examples/ZoKrates/fhe/unit_tests/boolean_tests/{2pc_boolean_and.zok => boolean_and.zok} (100%) rename examples/ZoKrates/fhe/unit_tests/boolean_tests/{2pc_boolean_equals.zok => boolean_equals.zok} (100%) rename examples/ZoKrates/fhe/unit_tests/boolean_tests/{2pc_boolean_or.zok => boolean_or.zok} (100%) rename examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/{2pc_nary_arithmetic_add.zok => nary_arithmetic_add.zok} (100%) rename examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/{2pc_nary_boolean_and.zok => nary_boolean_and.zok} (100%) delete mode 100644 scripts/seal_tests/custom_tests/batch_add.txt delete mode 100644 scripts/seal_tests/custom_tests/batch_add_bytecode.txt delete mode 100644 scripts/seal_tests/custom_tests/batch_cons.txt delete mode 100644 scripts/seal_tests/custom_tests/batch_cons_bytecode.txt delete mode 100644 scripts/seal_tests/custom_tests/batch_mult.txt delete mode 100644 scripts/seal_tests/custom_tests/batch_mult_bytecode.txt diff --git a/examples/C/fhe/unit_tests/arithmetic_tests/2pc_add.c b/examples/C/fhe/unit_tests/arithmetic_tests/add.c similarity index 100% rename from examples/C/fhe/unit_tests/arithmetic_tests/2pc_add.c rename to examples/C/fhe/unit_tests/arithmetic_tests/add.c diff --git a/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c b/examples/C/fhe/unit_tests/arithmetic_tests/mult.c similarity index 100% rename from examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c rename to examples/C/fhe/unit_tests/arithmetic_tests/mult.c diff --git a/examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c b/examples/C/fhe/unit_tests/arithmetic_tests/mult_add_pub.c similarity index 100% rename from examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c rename to examples/C/fhe/unit_tests/arithmetic_tests/mult_add_pub.c diff --git a/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c b/examples/C/fhe/unit_tests/boolean_tests/boolean_and.c similarity index 100% rename from examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c rename to examples/C/fhe/unit_tests/boolean_tests/boolean_and.c diff --git a/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c b/examples/C/fhe/unit_tests/boolean_tests/boolean_equals.c similarity index 100% rename from examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c rename to examples/C/fhe/unit_tests/boolean_tests/boolean_equals.c diff --git a/examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c b/examples/C/fhe/unit_tests/boolean_tests/boolean_or.c similarity index 100% rename from examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c rename to examples/C/fhe/unit_tests/boolean_tests/boolean_or.c diff --git a/examples/C/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c b/examples/C/fhe/unit_tests/nary_arithmetic_tests/nary_arithmetic_add.c similarity index 100% rename from examples/C/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.c rename to examples/C/fhe/unit_tests/nary_arithmetic_tests/nary_arithmetic_add.c diff --git a/examples/C/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c b/examples/C/fhe/unit_tests/nary_boolean_tests/nary_boolean_and.c similarity index 100% rename from examples/C/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.c rename to examples/C/fhe/unit_tests/nary_boolean_tests/nary_boolean_and.c diff --git a/examples/ZoKrates/fhe/inputs/fhe_and.txt b/examples/ZoKrates/fhe/inputs/fhe_and.txt deleted file mode 100644 index e7129253a..000000000 --- a/examples/ZoKrates/fhe/inputs/fhe_and.txt +++ /dev/null @@ -1,3 +0,0 @@ -a 1 -b 1 -res 1 \ No newline at end of file diff --git a/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/add.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok rename to examples/ZoKrates/fhe/unit_tests/arithmetic_tests/add.zok diff --git a/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/mult.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok rename to examples/ZoKrates/fhe/unit_tests/arithmetic_tests/mult.zok diff --git a/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok b/examples/ZoKrates/fhe/unit_tests/arithmetic_tests/mult_add_pub.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok rename to examples/ZoKrates/fhe/unit_tests/arithmetic_tests/mult_add_pub.zok diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_and.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_and.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_and.zok rename to examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_and.zok diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_equals.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok rename to examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_equals.zok diff --git a/examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok b/examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_or.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok rename to examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_or.zok diff --git a/examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok b/examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/nary_arithmetic_add.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok rename to examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/nary_arithmetic_add.zok diff --git a/examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok b/examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/nary_boolean_and.zok similarity index 100% rename from examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok rename to examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/nary_boolean_and.zok diff --git a/scripts/build_fhe_c_test.zsh b/scripts/build_fhe_c_test.zsh index 0b22e13ee..d33a475ad 100755 --- a/scripts/build_fhe_c_test.zsh +++ b/scripts/build_fhe_c_test.zsh @@ -24,17 +24,17 @@ function fhe_test { } # build boolean tests -fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_and.c -fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_or.c -fhe_test ./examples/C/fhe/unit_tests/boolean_tests/2pc_boolean_equals.c +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/2pc_nary_boolean_and.c +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/2pc_add.c -fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult.c -fhe_test ./examples/C/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.c +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/2pc_nary_arithmetic_add.c \ No newline at end of file +fhe_test ./examples/C/fhe/unit_tests/nary_arithmetic_tests/nary_arithmetic_add.c \ No newline at end of file diff --git a/scripts/build_fhe_zokrates_test.zsh b/scripts/build_fhe_zokrates_test.zsh index 0bfdf9ae5..1d589ed44 100755 --- a/scripts/build_fhe_zokrates_test.zsh +++ b/scripts/build_fhe_zokrates_test.zsh @@ -24,18 +24,18 @@ function fhe_test { } # build boolean tests -fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_and.zok -fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_or.zok -fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/2pc_boolean_equals.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_and.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_or.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/boolean_tests/boolean_equals.zok # build nary boolean tests -fhe_test ./examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/2pc_nary_boolean_and.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/nary_boolean_tests/nary_boolean_and.zok # build arithmetic tests -fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_add.zok -fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult.zok -fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/2pc_mult_add_pub.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/add.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/mult.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/arithmetic_tests/mult_add_pub.zok # build nary arithmetic tests -fhe_test ./examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/2pc_nary_arithmetic_add.zok +fhe_test ./examples/ZoKrates/fhe/unit_tests/nary_arithmetic_tests/nary_arithmetic_add.zok diff --git a/scripts/clean_seal.zsh b/scripts/clean_seal.zsh index 3ccc93308..18a3cb411 100755 --- a/scripts/clean_seal.zsh +++ b/scripts/clean_seal.zsh @@ -1,3 +1,4 @@ #!/usr/bin/env zsh rm -rf ./scripts/seal_tests/tests +rm -rf ./scripts/seal_tests/__pycache__ diff --git a/scripts/seal_tests/custom_tests/batch_add.txt b/scripts/seal_tests/custom_tests/batch_add.txt deleted file mode 100644 index 802aafb28..000000000 --- a/scripts/seal_tests/custom_tests/batch_add.txt +++ /dev/null @@ -1,3 +0,0 @@ -arr a 1 2 3 4 5 -arr b 6 7 8 9 10 -res 7 9 11 13 15 \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_add_bytecode.txt b/scripts/seal_tests/custom_tests/batch_add_bytecode.txt deleted file mode 100644 index 6a867fd7d..000000000 --- a/scripts/seal_tests/custom_tests/batch_add_bytecode.txt +++ /dev/null @@ -1,4 +0,0 @@ -3 1 a 1 5 1 ARR_IN -3 1 b 1 5 0 ARR_IN -2 1 1 0 2 ADD -2 0 2 5 ARR_OUT \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_cons.txt b/scripts/seal_tests/custom_tests/batch_cons.txt deleted file mode 100644 index 6733c4d2a..000000000 --- a/scripts/seal_tests/custom_tests/batch_cons.txt +++ /dev/null @@ -1,2 +0,0 @@ -arr a 1 2 3 4 5 -res 7 \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_cons_bytecode.txt b/scripts/seal_tests/custom_tests/batch_cons_bytecode.txt deleted file mode 100644 index c91a05a85..000000000 --- a/scripts/seal_tests/custom_tests/batch_cons_bytecode.txt +++ /dev/null @@ -1,6 +0,0 @@ -3 1 a 1 5 0 ARR_IN -5 1 10 100 1000 10000 100000 1 ARR_CONS -5 1 9 8 7 6 5 2 ARR_CONS -2 1 1 0 3 MUL -2 1 2 3 4 ADD -2 0 4 5 ARR_OUT \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_mult.txt b/scripts/seal_tests/custom_tests/batch_mult.txt deleted file mode 100644 index ada7be813..000000000 --- a/scripts/seal_tests/custom_tests/batch_mult.txt +++ /dev/null @@ -1,3 +0,0 @@ -arr a 1 2 3 4 5 -arr b 6 7 8 9 10 -res 6 14 24 36 50 \ No newline at end of file diff --git a/scripts/seal_tests/custom_tests/batch_mult_bytecode.txt b/scripts/seal_tests/custom_tests/batch_mult_bytecode.txt deleted file mode 100644 index ab6e15b4b..000000000 --- a/scripts/seal_tests/custom_tests/batch_mult_bytecode.txt +++ /dev/null @@ -1,4 +0,0 @@ -3 1 a 1 5 1 ARR_IN -3 1 b 1 5 0 ARR_IN -2 1 1 0 2 MUL -2 0 2 5 ARR_OUT \ No newline at end of file diff --git a/scripts/seal_tests/test_suite.py b/scripts/seal_tests/test_suite.py index ef9f7febf..d81215828 100644 --- a/scripts/seal_tests/test_suite.py +++ b/scripts/seal_tests/test_suite.py @@ -1,54 +1,54 @@ boolean_tests = [ [ "Boolean && - 1", - "2pc_boolean_and", + "boolean_and", "./scripts/seal_tests/test_inputs/and_1.txt", ], [ "Boolean && - 2", - "2pc_boolean_and", + "boolean_and", "./scripts/seal_tests/test_inputs/and_2.txt", ], [ "Boolean && - 3", - "2pc_boolean_and", + "boolean_and", "./scripts/seal_tests/test_inputs/and_3.txt", ], [ "Boolean && - 4", - "2pc_boolean_and", + "boolean_and", "./scripts/seal_tests/test_inputs/and_4.txt", ], [ "Boolean || - 1", - "2pc_boolean_or", + "boolean_or", "./scripts/seal_tests/test_inputs/or_1.txt", ], [ "Boolean || - 2", - "2pc_boolean_or", + "boolean_or", "./scripts/seal_tests/test_inputs/or_2.txt", ], [ "Boolean || - 3", - "2pc_boolean_or", + "boolean_or", "./scripts/seal_tests/test_inputs/or_3.txt", ], [ "Boolean || - 4", - "2pc_boolean_or", + "boolean_or", "./scripts/seal_tests/test_inputs/or_4.txt", ], [ "Boolean == - 1", - "2pc_boolean_equals", + "boolean_equals", "./scripts/seal_tests/test_inputs/eq_1.txt", ], [ "Boolean == - 2", - "2pc_boolean_equals", + "boolean_equals", "./scripts/seal_tests/test_inputs/eq_2.txt", ], ] @@ -56,39 +56,39 @@ arithmetic_tests = [ [ "Add two numbers", - "2pc_add", + "add", "./scripts/seal_tests/test_inputs/add.txt", ], [ "Multiply two numbers - 1", - "2pc_mult", + "mult", "./scripts/seal_tests/test_inputs/mult_1.txt", ], [ "Multiply two numbers - 2", - "2pc_mult", + "mult", "./scripts/seal_tests/test_inputs/mult_2.txt", ], [ "Multiply two numbers - 3", - "2pc_mult", + "mult", "./scripts/seal_tests/test_inputs/mult_3.txt", ], [ "Multiply two numbers together and add with public value", - "2pc_mult_add_pub", + "mult_add_pub", "./scripts/seal_tests/test_inputs/mult_add_pub_1.txt", ], [ "Multiply two numbers together and add with public value, check only server side public value is added", - "2pc_mult_add_pub", + "mult_add_pub", "./scripts/seal_tests/test_inputs/mult_add_pub_2.txt", ], ] nary_arithmetic_tests = [ [ "Test a + b + c", - "2pc_nary_arithmetic_add", + "nary_arithmetic_add", "./scripts/seal_tests/test_inputs/nary_add.txt", ], ] @@ -96,7 +96,7 @@ nary_boolean_tests = [ [ "Test a & b & c", - "2pc_nary_boolean_and", + "nary_boolean_and", "./scripts/seal_tests/test_inputs/nary_and.txt", ], ] \ No newline at end of file diff --git a/scripts/seal_tests/util.py b/scripts/seal_tests/util.py index 3fdb5042e..3449c7900 100644 --- a/scripts/seal_tests/util.py +++ b/scripts/seal_tests/util.py @@ -34,7 +34,6 @@ def run_test(expected: List[str], cmd: List[str]) -> bool: if err: raise RuntimeError("Error: "+err.decode("utf-8").strip()) - #out = out.decode("utf-8").strip() output = [] for o in out.split(): output.append(o.decode("utf-8")) @@ -55,10 +54,6 @@ def run_tests(lang: str, tests: List[dict]): print(f"Running FHE tests for {lang} frontend") failed_test_descs = [] num_retries = 2 - - run_test(['7','9','11','13','15'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/custom_tests/batch_add_bytecode.txt -t ./scripts/seal_tests/custom_tests/batch_add.txt"]) - run_test(['6','14','24','36','50'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/custom_tests/batch_mult_bytecode.txt -t ./scripts/seal_tests/custom_tests/batch_mult.txt"]) - run_test(['19','208','3007','40006','500005'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/custom_tests/batch_cons_bytecode.txt -t ./scripts/seal_tests/custom_tests/batch_cons.txt"]) for test in tqdm(tests, leave=False, dynamic_ncols=True): assert len(test) == 3, "test configurations are wrong for test: "+test[0] diff --git a/src/target/fhe/trans.rs b/src/target/fhe/trans.rs index 421f44239..c203fcc79 100644 --- a/src/target/fhe/trans.rs +++ b/src/target/fhe/trans.rs @@ -135,7 +135,7 @@ impl ToFHE { self.embed_eq(t.clone(), t.cs[0].clone(), t.cs[1].clone()); } Op::Ite => { - panic!("Bool Ite unimplemented"); + unimplemented!("Bool Ite unimplemented"); } Op::Not => { let op = "NOT"; @@ -298,7 +298,7 @@ impl ToFHE { self.cache.insert(t.clone(), EmbeddedTerm::Arr); } _ => { - panic!("Non-field in embed_arr: {:?}", t); + unimplemented!("Array operation not implemented"); } } } diff --git a/src/target/fhe/utils.rs b/src/target/fhe/utils.rs index a1da276ab..94e55054f 100644 --- a/src/target/fhe/utils.rs +++ b/src/target/fhe/utils.rs @@ -1,5 +1,7 @@ //! Utility functions to write compiler output to FHE +//TODO: parameterize these functions so they can be shared between ABY and SEAL backends + use std::fs; use std::io::prelude::*; use std::path::Path; From 18b4112f05ffa02afdfe745a3f20b5770f530a63 Mon Sep 17 00:00:00 2001 From: William Seo Date: Fri, 30 Sep 2022 01:02:18 +0000 Subject: [PATCH 21/21] Added test case generation for testing batched vs naive --- scripts/seal_tests/make_tests.py | 104 +++++++++++++++++++++++++++++++ scripts/seal_tests/util.py | 32 +++++++++- 2 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 scripts/seal_tests/make_tests.py diff --git a/scripts/seal_tests/make_tests.py b/scripts/seal_tests/make_tests.py new file mode 100644 index 000000000..a59976d8a --- /dev/null +++ b/scripts/seal_tests/make_tests.py @@ -0,0 +1,104 @@ +def batch_add_inputs(s): + filename = "scripts/seal_tests/tests/batch_add_" + str(s) + ".txt" + with open(filename, 'w') as f: + line1 = ["arr", "a"] + line2 = ["arr", "b"] + line3 = ["res"] + [str(s)] * s + for i in range(s): + line1.append(str(i)) + line2.append(str(s-i)) + f.write(" ".join(line1) + "\n") + f.write(" ".join(line2) + "\n") + f.write(" ".join(line3)) + +def batch_mul_inputs(s): + filename = "scripts/seal_tests/tests/batch_mul_" + str(s) + ".txt" + with open(filename, 'w') as f: + line1 = ["arr", "a"] + line2 = ["arr", "b"] + line3 = ["res"] + for i in range(s): + line1.append(str(i)) + line2.append(str(s-i)) + line3.append(str(i * (s-i))) + f.write(" ".join(line1) + "\n") + f.write(" ".join(line2) + "\n") + f.write(" ".join(line3)) + +def batch_add_bytecode(s): + filename = "scripts/seal_tests/tests/batch_add_bytecode_" + str(s) + ".txt" + with open(filename, 'w') as f: + f.write("3 1 a 1 " + str(s) + " 1 ARR_IN\n") + f.write("3 1 b 1 " + str(s) + " 0 ARR_IN\n") + f.write("2 1 1 0 2 ADD\n") + f.write("2 0 2 " + str(s) + " ARR_OUT") + +def batch_mul_bytecode(s): + filename = "scripts/seal_tests/tests/batch_mul_bytecode_" + str(s) + ".txt" + with open(filename, 'w') as f: + f.write("3 1 a 1 " + str(s) + " 1 ARR_IN\n") + f.write("3 1 b 1 " + str(s) + " 0 ARR_IN\n") + f.write("2 1 1 0 2 MUL\n") + f.write("2 0 2 " + str(s) + " ARR_OUT") + +def naive_add_inputs(s): + filename = "scripts/seal_tests/tests/naive_add_" + str(s) + ".txt" + with open(filename, 'w') as f: + lines = [] + for i in range(s): + lines.append(f"a_{i} {i}") + lines.append(f"b_{i} {s-i}") + lines.append(f"res {s}") + f.write("\n".join(lines)) + +def naive_mul_inputs(s): + filename = "scripts/seal_tests/tests/naive_mul_" + str(s) + ".txt" + with open(filename, 'w') as f: + lines = [] + for i in range(s): + lines.append(f"a_{i} {i}") + lines.append(f"b_{i} {s-i}") + lines.append("res 0") + f.write("\n".join(lines)) + +def naive_add_bytecode(s): + filename = "scripts/seal_tests/tests/naive_add_bytecode_" + str(s) + ".txt" + with open(filename, 'w') as f: + for i in range(s): + f.write(f"2 1 a_{i} 1 {2*i} IN\n") + f.write(f"2 1 b_{i} 1 {2*i + 1} IN\n") + for i in range(s): + f.write(f"2 1 {2*i} {2*i + 1} {2*s + i} ADD\n") + f.write(f"1 0 {2*s} OUT") + +def naive_mul_bytecode(s): + filename = "scripts/seal_tests/tests/naive_mul_bytecode_" + str(s) + ".txt" + with open(filename, 'w') as f: + for i in range(s): + f.write(f"2 1 a_{i} 1 {2*i} IN\n") + f.write(f"2 1 b_{i} 1 {2*i + 1} IN\n") + for i in range(s): + f.write(f"2 1 {2*i} {2*i + 1} {2*s + i} MUL\n") + f.write(f"1 0 {2*s} OUT") + + +sizes = [4, 16, 64, 256, 1024] + +for s in sizes: + batch_add_inputs(s) + batch_mul_inputs(s) + batch_add_bytecode(s) + batch_mul_bytecode(s) + + naive_add_inputs(s) + naive_mul_inputs(s) + naive_add_bytecode(s) + naive_mul_bytecode(s) + +with open("scripts/seal_tests/tests/code_to_add.txt", "w") as f: + for s in sizes: + f.write(f" run_test(['99'], [\"./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_add_bytecode_{s}.txt -t ./scripts/seal_tests/tests/batch_add_{s}.txt\"], True)\n") + f.write(f" run_test(['99'], [\"./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_add_bytecode_{s}.txt -t ./scripts/seal_tests/tests/naive_add_{s}.txt\"], True)\n") + for s in sizes: + f.write(f" run_test(['99'], [\"./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_mul_bytecode_{s}.txt -t ./scripts/seal_tests/tests/batch_mul_{s}.txt\"], True)\n") + f.write(f" run_test(['99'], [\"./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_mul_bytecode_{s}.txt -t ./scripts/seal_tests/tests/naive_mul_{s}.txt\"], True)\n") \ No newline at end of file diff --git a/scripts/seal_tests/util.py b/scripts/seal_tests/util.py index 3449c7900..b87366be7 100644 --- a/scripts/seal_tests/util.py +++ b/scripts/seal_tests/util.py @@ -3,6 +3,7 @@ import sys from typing import List from tqdm import tqdm +import time def rename_test(name: str, lang: str) -> str: """Append path with language type""" @@ -25,11 +26,16 @@ def get_result(file_path): raise RuntimeError("Unable to open file: "+file_path) -def run_test(expected: List[str], cmd: List[str]) -> bool: +def run_test(expected: List[str], cmd: List[str], verbose = False) -> bool: try: + start = time.time() proc = Popen(" ".join(cmd), shell=True, stdout=PIPE, stderr=PIPE) out, err = proc.communicate(timeout=30) + end = time.time() + if verbose: + print("Command:", " ".join(cmd)) + print(" Time: ", end - start) if err: raise RuntimeError("Error: "+err.decode("utf-8").strip()) @@ -41,7 +47,7 @@ def run_test(expected: List[str], cmd: List[str]) -> bool: assert (output == expected), "out: "+" ".join(output)+"\nexpected: "+" ".join(expected) return True, "" except Exception as e: - print("Exception: ", e) + #print("Exception: ", e) return False, e def run_tests(lang: str, tests: List[dict]): @@ -51,6 +57,28 @@ def run_tests(lang: str, tests: List[dict]): 2. test name: str 4. test file path: str """ + print(f"Running Custom tests for {lang} frontend") + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_add_bytecode_4.txt -t ./scripts/seal_tests/tests/batch_add_4.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_add_bytecode_4.txt -t ./scripts/seal_tests/tests/naive_add_4.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_add_bytecode_16.txt -t ./scripts/seal_tests/tests/batch_add_16.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_add_bytecode_16.txt -t ./scripts/seal_tests/tests/naive_add_16.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_add_bytecode_64.txt -t ./scripts/seal_tests/tests/batch_add_64.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_add_bytecode_64.txt -t ./scripts/seal_tests/tests/naive_add_64.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_add_bytecode_256.txt -t ./scripts/seal_tests/tests/batch_add_256.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_add_bytecode_256.txt -t ./scripts/seal_tests/tests/naive_add_256.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_add_bytecode_1024.txt -t ./scripts/seal_tests/tests/batch_add_1024.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_add_bytecode_1024.txt -t ./scripts/seal_tests/tests/naive_add_1024.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_mul_bytecode_4.txt -t ./scripts/seal_tests/tests/batch_mul_4.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_mul_bytecode_4.txt -t ./scripts/seal_tests/tests/naive_mul_4.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_mul_bytecode_16.txt -t ./scripts/seal_tests/tests/batch_mul_16.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_mul_bytecode_16.txt -t ./scripts/seal_tests/tests/naive_mul_16.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_mul_bytecode_64.txt -t ./scripts/seal_tests/tests/batch_mul_64.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_mul_bytecode_64.txt -t ./scripts/seal_tests/tests/naive_mul_64.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_mul_bytecode_256.txt -t ./scripts/seal_tests/tests/batch_mul_256.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_mul_bytecode_256.txt -t ./scripts/seal_tests/tests/naive_mul_256.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/batch_mul_bytecode_1024.txt -t ./scripts/seal_tests/tests/batch_mul_1024.txt"], True) + run_test(['99'], ["./../SEAL/build/bin/sealinterpreter -M fhe -b ./scripts/seal_tests/tests/naive_mul_bytecode_1024.txt -t ./scripts/seal_tests/tests/naive_mul_1024.txt"], True) + print(f"Running FHE tests for {lang} frontend") failed_test_descs = [] num_retries = 2