Browse Source

Update the Floram docker to keep track of ORAM startup costs

Ian Goldberg 1 year ago
parent
commit
35556ae579
4 changed files with 146 additions and 30 deletions
  1. 8 13
      Dockerfile
  2. 110 0
      bench_oram.patch
  3. 17 11
      bench_oram_readwrite.oc
  4. 11 6
      run-experiment

+ 8 - 13
Dockerfile

@@ -2,21 +2,16 @@ FROM ubuntu:18.04
 ARG DEBIAN_FRONTEND=noninteractive 
 #the above line is avoid interaction
 WORKDIR /root
-RUN apt update && apt install -y wget git build-essential
-RUN apt-get install -y libbsd-dev libssl-dev libboost-all-dev iproute2 iperf iputils-ping wget unzip net-tools
-RUN apt-get install wget
-RUN git clone git://git-crysp.uwaterloo.ca/duoram
-RUN apt-get -y install ocaml libgcrypt20-dev ocaml-findlib opam m4 
+RUN apt update && apt install -y git build-essential libbsd-dev libssl-dev libboost-all-dev iproute2 iperf iputils-ping wget unzip net-tools wget ocaml libgcrypt20-dev ocaml-findlib opam m4 
 RUN opam init -y && opam switch 4.06.0 && eval `opam config env` && opam install -y camlp4 ocamlfind ocamlbuild batteries
 RUN git clone https://github.com/samee/obliv-c.git 
 RUN apt-get install -y ocamlbuild
 RUN cd obliv-c && ./configure && make
 RUN wget https://gitlab.com/neucrypt/floram/-/archive/floram-release/floram-floram-release.zip && unzip floram-floram-release.zip
-RUN cd floram-floram-release &&  sed -i '4i\OBLIVC_PATH = ~/obliv-c' Makefile && sed -e '8s/$/ -D _Float128=double/' Makefile > tmp && cp tmp Makefile && rm tmp
-RUN cd floram-floram-release && sed -e '28s/$/ bench_oram_readwrite/' Makefile > tmp && cp tmp Makefile && rm tmp
-RUN cd floram-floram-release/tests && touch bench_oram_readwrite.oc && cp ~/duoram/Docker-floram/bench_oram_readwrite.oc bench_oram_readwrite.oc
-RUN cd floram-floram-release && make
-
- 
- 
- 
+COPY bench_oram_readwrite.oc bench_oram.patch /root/
+RUN cd floram-floram-release &&  sed -i '4i\OBLIVC_PATH = ~/obliv-c' Makefile && sed -i -e '8s/$/ -D _Float128=double/' Makefile
+RUN cd floram-floram-release && sed -i -e '28s/$/ bench_oram_readwrite/' Makefile
+RUN cd floram-floram-release/tests && cp /root/bench_oram_readwrite.oc bench_oram_readwrite.oc
+RUN cd floram-floram-release/tests && patch -p0 < /root/bench_oram.patch
+RUN cd floram-floram-release && make -j`nproc`
+RUN apt install -y numactl

+ 110 - 0
bench_oram.patch

@@ -0,0 +1,110 @@
+--- bench_oram_read.oc.orig	2018-02-19 19:03:45.000000000 -0500
++++ bench_oram_read.oc	2023-02-06 08:16:10.000000000 -0500
+@@ -79,8 +79,8 @@
+ 			}
+ 		} else if (arg == 'i') {
+ 			samples = atoi(optarg);
+-			if (samples <= 0) {
+-				fprintf (stderr, "Argument for -%c must be positive.\n", arg);
++			if (samples < 0) {
++				fprintf (stderr, "Argument for -%c must be nonnegative.\n", arg);
+ 				return;
+ 			}
+ 		} else if (arg == '?' || arg == ':') {
+@@ -96,10 +96,6 @@
+ 		}
+ 	}
+ 
+-	#ifndef ORAM_PROFILE_SCHEDULING
+-	fprintf(stdout, "# ORAM ACCESS (READ) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
+-	#endif
+-
+ 	OcCopy cpy = ocCopyIntN(elsz);
+ 
+ 	uint64_t tally = 0;
+@@ -107,10 +103,21 @@
+ 	uint64_t tallybytes = 0;
+ 	obliv uint32_t * output = calloc(1, elsz * sizeof(obliv uint32_t));
+ 
++	int64_t startuptime = -current_timestamp();
++	int64_t startupgates = -yaoGateCount();
++	int64_t startupbytes = -tcp2PBytesSent(ocCurrentProto());
+ 	oram * o = oram_new(ORAM_TYPE_AUTO, &cpy, elct);
++	startuptime += current_timestamp();
++	startupgates += yaoGateCount();
++	startupbytes += tcp2PBytesSent(ocCurrentProto());
+ 
+ 	#ifndef ORAM_PROFILE_SCHEDULING
++	fprintf(stdout, "# ORAM ACCESS (SETUP) (element count, element size, startup microseconds, startup gates, startup bytes)\n");
+ 	fprintf(stdout, "%lld,%lld", elct, elsz);
++	fprintf(stdout, ",%llu,%llu,%llu\n", startuptime,startupgates,startupbytes);
++	fprintf(stdout, "# ORAM ACCESS (READ) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
++	fprintf(stdout, "%lld,%lld", elct, elsz);
++	fflush(stdout);
+ 	#endif
+ 
+ 	for (int ii = 0; ii < samples; ii++) {
+@@ -137,6 +144,8 @@
+ 	#ifndef ORAM_PROFILE_SCHEDULING
+ 	fprintf(stdout, "\n");
+ 	#endif
++	if (samples > 0) {
+ 	fprintf(stderr, "ORAM Read (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
++	}
+ 
+ }
+--- bench_oram_write.oc.orig	2018-02-19 19:03:45.000000000 -0500
++++ bench_oram_write.oc	2023-02-06 08:22:19.000000000 -0500
+@@ -79,8 +79,8 @@
+ 			}
+ 		} else if (arg == 'i') {
+ 			samples = atoi(optarg);
+-			if (samples <= 0) {
+-				fprintf (stderr, "Argument for -%c must be positive.\n", arg);
++			if (samples < 0) {
++				fprintf (stderr, "Argument for -%c must be nonnegative.\n", arg);
+ 				return;
+ 			}
+ 		} else if (arg == '?' || arg == ':') {
+@@ -96,10 +96,6 @@
+ 		}
+ 	}
+ 
+-	#ifndef ORAM_PROFILE_SCHEDULING
+-	fprintf(stdout, "# ORAM ACCESS (WRITE) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
+-	#endif
+-
+ 	OcCopy cpy = ocCopyIntN(elsz);
+ 
+ 	uint64_t tally = 0;
+@@ -107,10 +103,21 @@
+ 	uint64_t tallybytes = 0;
+ 	obliv uint32_t * input = calloc(1, elsz * sizeof(obliv uint32_t));
+ 
++	int64_t startuptime = -current_timestamp();
++	int64_t startupgates = -yaoGateCount();
++	int64_t startupbytes = -tcp2PBytesSent(ocCurrentProto());
+ 	oram * o = oram_new(ORAM_TYPE_AUTO, &cpy, elct);
++	startuptime += current_timestamp();
++	startupgates += yaoGateCount();
++	startupbytes += tcp2PBytesSent(ocCurrentProto());
+ 
+ 	#ifndef ORAM_PROFILE_SCHEDULING
++	fprintf(stdout, "# ORAM ACCESS (SETUP) (element count, element size, startup microseconds, startup gates, startup bytes)\n");
+ 	fprintf(stdout, "%lld,%lld", elct, elsz);
++	fprintf(stdout, ",%llu,%llu,%llu\n", startuptime,startupgates,startupbytes);
++	fprintf(stdout, "# ORAM ACCESS (WRITE) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
++	fprintf(stdout, "%lld,%lld", elct, elsz);
++	fflush(stdout);
+ 	#endif
+ 
+ 	for (int ii = 0; ii < samples; ii++) {
+@@ -138,6 +145,8 @@
+ 	#ifndef ORAM_PROFILE_SCHEDULING
+ 	fprintf(stdout, "\n");
+ 	#endif
++	if (samples > 0) {
+ 	fprintf(stderr, "ORAM Write (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
++	}
+ 
+ }

+ 17 - 11
bench_oram_readwrite.oc

@@ -79,8 +79,8 @@ void test_main(void*varg) {
 			}
 		} else if (arg == 'i') {
 			samples = atoi(optarg);
-			if (samples <= 0) {
-				fprintf (stderr, "Argument for -%c must be positive.\n", arg);
+			if (samples < 0) {
+				fprintf (stderr, "Argument for -%c must be nonnegative.\n", arg);
 				return;
 			}
 		} else if (arg == '?' || arg == ':') {
@@ -96,10 +96,6 @@ void test_main(void*varg) {
 		}
 	}
 
-	#ifndef ORAM_PROFILE_SCHEDULING
-	fprintf(stdout, "# ORAM ACCESS (READ/WRITE) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
-	#endif
-
 	OcCopy cpy = ocCopyIntN(elsz);
 
 	uint64_t tally = 0;
@@ -107,10 +103,21 @@ void test_main(void*varg) {
 	uint64_t tallybytes = 0;
 	obliv uint32_t * input = calloc(1, elsz * sizeof(obliv uint32_t));
 
+	int64_t startuptime = -current_timestamp();
+	int64_t startupgates = -yaoGateCount();
+	int64_t startupbytes = -tcp2PBytesSent(ocCurrentProto());
 	oram * o = oram_new(ORAM_TYPE_AUTO, &cpy, elct);
+	startuptime += current_timestamp();
+	startupgates += yaoGateCount();
+	startupbytes += tcp2PBytesSent(ocCurrentProto());
 
 	#ifndef ORAM_PROFILE_SCHEDULING
+	fprintf(stdout, "# ORAM ACCESS (SETUP) (element count, element size, startup microseconds, startup gates, startup bytes)\n");
 	fprintf(stdout, "%lld,%lld", elct, elsz);
+	fprintf(stdout, ",%llu,%llu,%llu\n", startuptime,startupgates,startupbytes);
+	fprintf(stdout, "# ORAM ACCESS (READ/WRITE) (element count, element size, sample 1 microseconds, sample 1 gates, sample 1 bytes, ...)\n");
+	fprintf(stdout, "%lld,%lld", elct, elsz);
+	fflush(stdout);
 	#endif
 
 	for (int ii = 0; ii < samples; ii++) {
@@ -120,11 +127,8 @@ void test_main(void*varg) {
 		int64_t runtime = -current_timestamp();
 		int64_t rungates = -yaoGateCount();
 		int64_t runbytes = -tcp2PBytesSent(ocCurrentProto());
-		for (int j = 0; j < 16; ++j)
-		{
-			oram_write(o, input, index);
-			oram_read(o, input, index);
-		}
+		oram_write(o, input, index);
+		oram_read(o, input, index);
 		runtime += current_timestamp();
 		rungates += yaoGateCount();
 		runbytes += tcp2PBytesSent(ocCurrentProto());
@@ -142,6 +146,8 @@ void test_main(void*varg) {
 	#ifndef ORAM_PROFILE_SCHEDULING
 	fprintf(stdout, "\n");
 	#endif
+	if (samples > 0) {
 	fprintf(stderr, "ORAM Write (count:%lld, size: %lld): %llu microseconds avg, %llu gates avg, %llu bytes avg\n", elct, elsz, tally / samples, tallygates/samples, tallybytes/samples);
+	}
 
 }

+ 11 - 6
run-experiment-reads → run-experiment

@@ -4,27 +4,32 @@
 p0addr=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' floram_p0)
 p1addr=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' floram_p1)
 
-# The ORAM size
+# The Floram mode and size
+# mode is read, write, readwrite, or init
+mode=read
 size=26
 iters=128
 if [ "$1" != "" ]; then
-    size="$1"
+    mode="$1"
 fi
 if [ "$2" != "" ]; then
-    iters="$2"
+    size="$2"
+fi
+if [ "$3" != "" ]; then
+    iters="$3"
 fi
 
 items=$((1<<size))
 
-echo ===== Running floram $size $iters
+echo ===== Running floram $mode $size $iters
 date "+===== Start %s %F %T"
 
 # Run, saving the output
 savefilep0=$$.p0.out
 savefilep1=$$.p1.out
-docker exec -w /root/floram-floram-release/build/tests floram_p0 bash -c "$FLORAM_NUMA_P0 stdbuf -o 0  ./bench_oram_read -p 3000 -s 8 -o fssl_cprg -e $items -i $iters > $savefilep0 2>&1" &
+docker exec -w /root/floram-floram-release/build/tests floram_p0 bash -c "$FLORAM_NUMA_P0 stdbuf -o 0  ./bench_oram_$mode -p 3000 -s 8 -o fssl_cprg -e $items -i $iters > $savefilep0 2>&1" &
 sleep 2
-docker exec -w /root/floram-floram-release/build/tests floram_p1 bash -c "$FLORAM_NUMA_P1 stdbuf -o 0  ./bench_oram_read -c $p0addr -p 3000 -s 8 -o fssl_cprg -e $items -i $iters > $savefilep1 2>&1" &
+docker exec -w /root/floram-floram-release/build/tests floram_p1 bash -c "$FLORAM_NUMA_P1 stdbuf -o 0  ./bench_oram_$mode -c $p0addr -p 3000 -s 8 -o fssl_cprg -e $items -i $iters > $savefilep1 2>&1" &
 wait
 echo ===== P0 output
 docker exec -w /root/floram-floram-release/build/tests floram_p0 cat $savefilep0