Skip to content

Commit

Permalink
integration test for hybrid mpc (ignored for now) (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktaubeneck authored Dec 5, 2024
1 parent 26ee498 commit 5015b71
Showing 1 changed file with 76 additions and 3 deletions.
79 changes: 76 additions & 3 deletions ipa-core/tests/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ mod common;

use std::process::{Command, Stdio};

use common::{tempdir::TempDir, CommandExt, UnwrapStatusExt, TEST_RC_BIN};
use common::{
spawn_shards, tempdir::TempDir, test_sharded_setup, CommandExt, TerminateOnDropExt,
UnwrapStatusExt, CRYPTO_UTIL_BIN, TEST_RC_BIN,
};
use ipa_core::{cli::playbook::HybridQueryResult, helpers::query::HybridQueryParams};
use rand::thread_rng;
use rand_core::RngCore;

Expand All @@ -13,10 +17,18 @@ pub const IN_THE_CLEAR_BIN: &str = env!("CARGO_BIN_EXE_in_the_clear");
// this currently only generates data and runs in the clear
// eventaully we'll want to add the MPC as well
#[test]
#[ignore]
fn test_hybrid() {
const INPUT_SIZE: usize = 100;
const SHARDS: usize = 5;
const MAX_CONVERSION_VALUE: usize = 5;
const MAX_BREAKDOWN_KEY: usize = 20;

let config = HybridQueryParams {
max_breakdown_key: 5,
with_dp: 0,
epsilon: 0.0,
plaintext_match_keys: false, // this shouldn't be necessary
};

let dir = TempDir::new_delete_on_drop();

Expand All @@ -30,7 +42,7 @@ fn test_hybrid() {
.arg("gen-hybrid-inputs")
.args(["--count", &INPUT_SIZE.to_string()])
.args(["--max-conversion-value", &MAX_CONVERSION_VALUE.to_string()])
.args(["--max-breakdown-key", &MAX_BREAKDOWN_KEY.to_string()])
.args(["--max-breakdown-key", &config.max_breakdown_key.to_string()])
.args(["--seed", &thread_rng().next_u64().to_string()])
.silent()
.stdin(Stdio::piped());
Expand All @@ -43,4 +55,65 @@ fn test_hybrid() {
.silent()
.stdin(Stdio::piped());
command.status().unwrap_status();

// set to true to always keep the temp dir after test finishes
let dir = TempDir::new_delete_on_drop();
let path = dir.path();

let sockets = test_sharded_setup::<SHARDS>(path);
let _helpers = spawn_shards(path, &sockets, true);

// encrypt input
let mut command = Command::new(CRYPTO_UTIL_BIN);
command
.arg("hybrid-encrypt")
.args(["--input-file".as_ref(), input_file.as_os_str()])
.args(["--output-dir".as_ref(), path.as_os_str()])
.args(["--network".into(), dir.path().join("network.toml")])
.stdin(Stdio::piped());
command.status().unwrap_status();
let enc1 = dir.path().join("helper1.enc");
let enc2 = dir.path().join("helper2.enc");
let enc3 = dir.path().join("helper3.enc");

// Run Hybrid
let mut command = Command::new(TEST_RC_BIN);
command
.args(["--network".into(), dir.path().join("network.toml")])
.args(["--output-file".as_ref(), output_file.as_os_str()])
.args(["--wait", "2"])
.arg("hybrid")
.args(["--enc-input-file1".as_ref(), enc1.as_os_str()])
.args(["--enc-input-file2".as_ref(), enc2.as_os_str()])
.args(["--enc-input-file3".as_ref(), enc3.as_os_str()])
.args(["--max-breakdown-key", &config.max_breakdown_key.to_string()]);

match config.with_dp {
0 => {
command.args(["--with-dp", &config.with_dp.to_string()]);
}
_ => {
command
.args(["--with-dp", &config.with_dp.to_string()])
.args(["--epsilon", &config.epsilon.to_string()]);
}
}
command.stdin(Stdio::piped());

let _test_mpc = command.spawn().unwrap().terminate_on_drop();

// basic output checks - output should have the exact size as number of breakdowns
let output = serde_json::from_str::<HybridQueryResult>(
&std::fs::read_to_string(&output_file).expect("IPA results file exists"),
)
.expect("IPA results file is valid JSON");

assert_eq!(
usize::try_from(config.max_breakdown_key).unwrap(),
output.breakdowns.len(),
"Number of breakdowns does not match the expected",
);
assert_eq!(INPUT_SIZE, usize::from(output.input_size));

// TODO compare in the clear results with MPC results
}

0 comments on commit 5015b71

Please sign in to comment.