From 30508236a772cacda146e4f518125c438617202c Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Fri, 8 Apr 2022 15:16:34 -0500 Subject: [PATCH 1/2] Add Dockerfile --- Dockerfile | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..e01dd5c53 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,149 @@ +############################################################################### +# Build this stage for a build environment, e.g.: # +# # +# docker build --tag mpspdz:buildenv --target buildenv . # +# # +# The above is equivalent to: # +# # +# docker build --tag mpspdz:buildenv \ # +# --target buildenv \ # +# --build-arg arch=native \ # +# --build-arg cxx=clang++-11 \ # +# --build-arg use_ntl=0 \ # +# --build-arg prep_dir="Player-Data" \ # +# --build-arg ssl_dir="Player-Data" # +# --build-arg cryptoplayers=0 # +# # +# To build for an x86-64 architecture, with g++, NTL (for HE), custom # +# prep_dir & ssl_dir, and to use encrypted channels for 4 players: # +# # +# docker build --tag mpspdz:buildenv \ # +# --target buildenv \ # +# --build-arg arch=x86-64 \ # +# --build-arg cxx=g++ \ # +# --build-arg use_ntl=1 \ # +# --build-arg prep_dir="/opt/prepdata" \ # +# --build-arg ssl_dir="/opt/ssl" # +# --build-arg cryptoplayers=4 . # +# # +# To work in a container to build different machines, and compile programs: # +# # +# docker run --rm -it mpspdz:buildenv bash # +# # +# Once in the container, build a machine and compile a program: # +# # +# $ make replicated-ring-party.x # +# $ ./compile.py -R 64 tutorial # +# # +############################################################################### +FROM python:3.10.3-bullseye as buildenv + +RUN apt-get update && apt-get install -y --no-install-recommends \ + automake \ + build-essential \ + clang-11 \ + git \ + libboost-dev \ + libboost-thread-dev \ + libclang-dev \ + libntl-dev \ + libsodium-dev \ + libssl-dev \ + libtool \ + m4 \ + texinfo \ + yasm \ + vim \ + gdb \ + valgrind \ + && rm -rf /var/lib/apt/lists/* + +# mpir +COPY --from=initc3/mpir:55fe6a9 /usr/local/mpir/include/* /usr/local/include/ +COPY --from=initc3/mpir:55fe6a9 /usr/local/mpir/lib/* /usr/local/lib/ +COPY --from=initc3/mpir:55fe6a9 /usr/local/mpir/share/info/* /usr/local/share/info/ + +ENV MP_SPDZ_HOME /usr/src/MP-SPDZ +WORKDIR $MP_SPDZ_HOME + +RUN pip install --upgrade pip ipython + +COPY . . + +ARG arch=native +ARG cxx=clang++-11 +ARG use_ntl=0 +ARG prep_dir="Player-Data" +ARG ssl_dir="Player-Data" + +RUN echo "ARCH = -march=${arch}" >> CONFIG.mine \ + && echo "CXX = ${cxx}" >> CONFIG.mine \ + && echo "USE_NTL = ${use_ntl}" >> CONFIG.mine \ + && echo "MY_CFLAGS += -I/usr/local/include" >> CONFIG.mine \ + && echo "MY_LDLIBS += -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib" \ + >> CONFIG.mine \ + && mkdir -p $prep_dir $ssl_dir \ + && echo "PREP_DIR = '-DPREP_DIR=\"${prep_dir}/\"'" >> CONFIG.mine \ + && echo "SSL_DIR = '-DSSL_DIR=\"${ssl_dir}/\"'" >> CONFIG.mine + +# ssl keys +ARG cryptoplayers=0 +ENV PLAYERS ${cryptoplayers} +RUN ./Scripts/setup-ssl.sh ${cryptoplayers} ${ssl_dir} + + +############################################################################### +# Use this stage to a build a specific virtual machine. For example: # +# # +# docker build --tag mpspdz:shamir \ # +# --target machine \ # +# --build-arg machine=shamir-party.x \ # +# --build-arg gfp_mod_sz=4 . # +# # +# The above will build shamir-party.x with 256 bit length. # +# # +# If no build arguments are passed (via --build-arg), mascot-party.x is built # +# with the default 128 bit length. # +############################################################################### +FROM buildenv as machine + +ARG machine="mascot-party.x" + +ARG gfp_mod_sz=2 + +RUN echo "MOD = -DGFP_MOD_SZ=${gfp_mod_sz}" >> CONFIG.mine + +RUN make clean && make ${machine} && cp ${machine} /usr/local/bin/ + + +################################################################################ +# This is the default stage. Use it to compile a high-level program. # +# By default, tutorial.mpc is compiled with --field=64 bits. # +# # +# docker build --tag mpspdz:mascot-tutorial \ # +# --build-arg src=tutorial \ # +# --build-arg compile_options="--field=64" . # +# # +# Note that build arguments from previous stages can also be passed. For # +# instance, building replicated-ring-party.x, for 3 crypto players with custom # +# PREP_DIR and SSL_DIR, and compiling tutorial.mpc with --ring=64: # +# # +# docker build --tag mpspdz:replicated-ring \ # +# --build-arg machine=replicated-ring-party.x \ # +# --build-arg prep_dir=/opt/prep \ # +# --build-arg ssl_dir=/opt/ssl \ # +# --build-arg nparties=3 \ # +# --build-arg compile_options="--ring=64" . # +# # +# Test it: # +# # +# docker run --rm -it mpspdz:replicated-ring ./Scripts/ring.sh tutorial # +################################################################################ +FROM machine as program + +ARG src="tutorial" +ARG compile_options="--field=64" +RUN ./compile.py ${compile_options} ${src} +RUN mkdir -p Player-Data \ + && echo 1 2 3 4 > Player-Data/Input-P0-0 \ + && echo 1 2 3 4 > Player-Data/Input-P1-0 From 4d17b4f38957306e5c105dd4e097a0138a60f889 Mon Sep 17 00:00:00 2001 From: Sylvain Bellemare Date: Mon, 11 Apr 2022 15:18:07 -0500 Subject: [PATCH 2/2] Add tl;dr for docker in readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 4f9b44567..b5b4445ee 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,21 @@ echo 1 2 3 4 > Player-Data/Input-P1-0 Scripts/mascot.sh tutorial ``` +#### TL;DR (Docker) +Build a docker image for `mascot-party.x`: + +``` +docker build --tag mpspdz:mascot-party --build-arg machine=mascot-party.x . +``` + +Run the [the tutorial](Programs/Source/tutorial.mpc): + +``` +docker run --rm -it mpspdz:mascot-party ./Scripts/mascot.sh tutorial +``` + +See the [`Dockerfile`](./Dockerfile) for examples of how it can be used. + #### Preface The primary aim of this software is to run the same computation in