Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit b9c3551

Browse files
author
siamumar
committed
batch size in prog int test
1 parent 05b96c2 commit b9c3551

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

exec/TinyGarblePI.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ int main(int argc, char** argv) {
1515
string netlist_address;
1616
string server_ip;
1717
int program;
18+
int bs_mal = 100000;
1819

1920
Timer T;
2021
memMeter M;
@@ -26,6 +27,8 @@ int main(int argc, char** argv) {
2627
("party,k", po::value<int>(&party)->default_value(1), "party id: 1 for garbler, 2 for evaluator") //
2728
("port,p", po::value<int>(&port)->default_value(1234), "socket port") //
2829
("server_ip,s", po::value<string>(&server_ip)->default_value("127.0.0.1"), "server's IP.") //
30+
("batch_size,b", po::value<int>(&bs_mal)->default_value(100000),"pre-processing bacth size for malicious setting\n\
31+
default:choose adaptively\nused for setting maximum available memory") //
2932
("sh", "semi-honest setting (default is malicious)") ;
3033

3134
po::variables_map vm;
@@ -58,8 +61,8 @@ int main(int argc, char** argv) {
5861
unit_test(TGPI_SH);
5962
}
6063
else {
61-
cout << "testing program interface in malicious setting" << endl;
62-
TGPI = new TinyGarblePI(io, party, 100000, 100000);
64+
cout << "testing program interface in malicious setting with batch size " << bs_mal << endl;
65+
TGPI = new TinyGarblePI(io, party, bs_mal, bs_mal);
6366
io->flush();
6467
unit_test(TGPI);
6568
}

exec/exec_common.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ void mat_mult(uint64_t i, uint64_t j, uint64_t k, auto &A, auto &B, auto &C, int
2121
}
2222
}
2323

24-
uint64_t test_index = 0;
24+
uint64_t test_index = 0, test_passed = 0;
2525
void verify_n_report(string test, auto res, auto ref){
2626
cout << "[<#>] test " << test_index++ << ": " << test;
27-
if (res == ref) cout << ": success!";
27+
if (res == ref){
28+
test_passed++;
29+
cout << ": success!";
30+
}
2831
else cout << ": fail! excpected: " << ref << " computed: " << res;
29-
cout << endl;
32+
cout << "(" << test_passed << "/" << test_index << ")" << endl;
3033
}
3134

3235
#endif //EXEC_COMMON_H

exec/millionaire.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@
88
using namespace std;
99
namespace po = boost::program_options;
1010

11-
#define SEC_SH 0
12-
13-
void millionaire(NetIO* io, int party){
14-
#if SEC_SH
15-
TinyGarblePI_SH* TGPI = new TinyGarblePI_SH(io, party);
16-
#else
17-
TinyGarblePI* TGPI = new TinyGarblePI(io, party);
18-
#endif
19-
io->flush();
11+
void millionaire(auto TGPI){
2012

2113
uint64_t bit_width = 64;
2214
int64_t a = 0, b = 0;
@@ -44,7 +36,7 @@ void millionaire(NetIO* io, int party){
4436
int64_t res = TGPI->reveal(res_x, 1, false);
4537

4638
#if !SEC_SH
47-
if (party == BOB) //authenticated garbling allows only evaluator to compute the result
39+
if (TGPI->party == BOB) //authenticated garbling allows only evaluator to compute the result
4840
#endif
4941
if (res == 1) cout << "BOB is richer" << endl;
5042
else cout << "ALICE is richer" << endl;
@@ -60,14 +52,14 @@ int main(int argc, char** argv) {
6052
int party = 1, port = 1234;
6153
string netlist_address;
6254
string server_ip;
63-
int program;
6455

6556
po::options_description desc{"Yao's Millionair's Problem \nAllowed options"};
6657
desc.add_options() //
6758
("help,h", "produce help message") //
6859
("party,k", po::value<int>(&party)->default_value(1), "party id: 1 for garbler, 2 for evaluator") //
6960
("port,p", po::value<int>(&port)->default_value(1234), "socket port") //
70-
("server_ip,s", po::value<string>(&server_ip)->default_value("127.0.0.1"), "server's IP.");
61+
("server_ip,s", po::value<string>(&server_ip)->default_value("127.0.0.1"), "server's IP.")
62+
("sh", "semi-honest setting (default is malicious)");
7163

7264
po::variables_map vm;
7365
try {
@@ -86,8 +78,22 @@ int main(int argc, char** argv) {
8678

8779
NetIO* io = new NetIO(party==ALICE ? nullptr:server_ip.c_str(), port, true);
8880
io->set_nodelay();
89-
90-
millionaire(io, party);
81+
82+
TinyGarblePI_SH* TGPI_SH;
83+
TinyGarblePI* TGPI;
84+
85+
if (vm.count("sh")){
86+
cout << "testing program interface in semi-honest setting" << endl;
87+
TGPI_SH = new TinyGarblePI_SH(io, party);
88+
io->flush();
89+
millionaire(TGPI_SH);
90+
}
91+
else {
92+
cout << "Millionair's Problem in malicious setting" << endl;
93+
TGPI = new TinyGarblePI(io, party, 192, 64);
94+
io->flush();
95+
millionaire(TGPI);
96+
}
9197

9298
delete io;
9399

test/test_TinyGarble.sh.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if [ ! -f "$emploc/comp_nbit_ncc_syn.emp.bin" ]; then
2020
fi
2121

2222
if [ $1 ] && [ $1 = "--pi" ]; then
23-
${loc}/TinyGarblePI $2 < test/rand.txt > /dev/null & ${loc}/TinyGarblePI $2 -k 2 < test/rand.txt
23+
${loc}/TinyGarblePI "$@" < test/rand.txt > /dev/null & ${loc}/TinyGarblePI "$@" -k 2 < test/rand.txt
2424
else
2525
empfile=comp_nbit_ncc_syn.emp.bin
2626
ref=3

0 commit comments

Comments
 (0)