Skip to content

Commit

Permalink
add vole f2k test
Browse files Browse the repository at this point in the history
  • Loading branch information
carlweng committed Sep 2, 2023
1 parent 216c4f2 commit 9816549
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ add_test_case_with_run(vole vole_triple)
add_test_case_with_run(vole cope)
add_test_case_with_run(vole base_svole)
add_test_case_with_run(vole lpn)
add_test_case_with_run(vole vole_f2k_triple)

add_test_case_with_run(ram ram_test)
add_test_case_with_run(ram ram_ext_test)
Expand Down
124 changes: 124 additions & 0 deletions test/vole/vole_f2k_triple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include "emp-tool/emp-tool.h"
#include "emp-ot/emp-ot.h"
#include "emp-zk/emp-zk.h"
#if defined(__linux__)
#include <sys/time.h>
#include <sys/resource.h>
#elif defined(__APPLE__)
#include <unistd.h>
#include <sys/resource.h>
#include <mach/mach.h>
#endif

using namespace emp;
using namespace std;

int party, port;
const int threads = 4;

void check_triple(const block delta,
const block *x,
const block *y,
int size,
NetIO *io) {
if (party == BOB) {
io->send_data(&delta, sizeof(block));
io->send_data(y, size * sizeof(block));
io->flush();
} else {
block delta_;
block *k = new block[size];
io->recv_data(&delta_, sizeof(block));
io->recv_data(k, size * sizeof(block));
for (int i = 0; i < size; ++i) {
block tmp;
gfmul(delta_, x[i], &tmp);
tmp = tmp ^ k[i];
if ((memcmp(&tmp, &y[i], sizeof(block))) != 0) {
std::cout << "triple error at index: " << i << std::endl;
abort();
}
}
delete[] k;
}
}


void test_vole_triple(
NetIO **ios,
BoolIO<NetIO> **ios_bool,
int party) {
// instantiate OT
FerretCOT<BoolIO<NetIO>> ferretcot(
3 - party, threads, ios_bool, true);

// instantiate F2K VOLE
SVoleF2k<BoolIO<NetIO>> vtriple(
party, threads, ios_bool, &ferretcot);

PRG prg;
block Delta = ferretcot.Delta;
auto start = clock_start();
vtriple.setup(Delta);
std::cout << "setup " << time_from(start) / 1000 << " ms" << std::endl;
check_triple(Delta, vtriple.pre_x, vtriple.pre_yz, vtriple.param.n_pre, ios[0]);

std::size_t triple_need = vtriple.ot_limit;
std::size_t buf_sz = vtriple.param.n;
block *buf_x = new block[buf_sz];
block *buf_yz = new block[buf_sz];
for(int i = 0; i < 16; ++i) {
start = clock_start();
vtriple.extend_inplace(buf_x, buf_yz, buf_sz);
std::cout << "extend " << time_from(start) / 1000 << " ms" << std::endl;
check_triple(Delta, buf_x, buf_yz, triple_need, ios[0]);
}
delete[] buf_x;
delete[] buf_yz;

#if defined(__linux__)
struct rusage rusage;
if (!getrusage(RUSAGE_SELF, &rusage))
std::cout << "[Linux]Peak resident set size: " << (size_t)rusage.ru_maxrss
<< std::endl;
else
std::cout << "[Linux]Query RSS failed" << std::endl;
#elif defined(__APPLE__)
struct mach_task_basic_info info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info,
&count) == KERN_SUCCESS)
std::cout << "[Mac]Peak resident set size: "
<< (size_t)info.resident_size_max << std::endl;
else
std::cout << "[Mac]Query RSS failed" << std::endl;
#endif
}

int main(int argc, char **argv) {
parse_party_and_port(argv, &party, &port);

NetIO *ios[threads];
for (int i = 0; i < threads; ++i)
ios[i] = new NetIO(party == ALICE ? nullptr : "127.0.0.1", port + i);


BoolIO<NetIO> *ios_bool[threads];
for (int i = 0; i < threads; ++i)
ios_bool[i] = new BoolIO<NetIO>(
ios[i], party == ALICE);


std::cout << std::endl
<< "------------ VOLE f2k ------------" << std::endl
<< std::endl;
;

test_vole_triple(ios, ios_bool, party);

for (int i = 0; i < threads; ++i) {
delete ios[i];
delete ios_bool[i];
}
return 0;
}

0 comments on commit 9816549

Please sign in to comment.