Skip to content

Commit

Permalink
Add build option -DNO_REVEAL_OUTPUT in SCI (#143)
Browse files Browse the repository at this point in the history
* Add optional  argument `output` to `Athos/CompilerScripts/convert_np_to_fixedpt.py`.

* Add build option DNO_REVEAL_OUTPUT in SCI

* Add Docker instructions for modified SCI.

* Add setup file.
  • Loading branch information
Divyanshu Agrawal authored Jul 4, 2022
1 parent e2957fc commit dd5d299
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
27 changes: 27 additions & 0 deletions Dockerfile_AI_Validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Authors: Divyanshu Agrawal.

# Copyright:
# Copyright (c) 2021 Microsoft Research
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

FROM ubuntu:18.04
RUN apt-get update
RUN apt-get -y install sudo software-properties-common git wget vim apt-utils
RUN mkdir -p /ezpc_dir
WORKDIR /ezpc_dir
RUN git clone https://github.com/mpc-msri/EzPC
RUN cd EzPC && ./setup_env_and_build.sh quick NO_REVEAL_OUTPUT
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ Alternatively you can use the **setup_env_and_build.sh** script. It installs dep

Please do ``source mpc_venv/bin/activate`` before using the toolchain.

## Secure AI Validation

To setup the repo with modified SCI build such that only secret shares are revealed at the end of 2PC, run the setup script as ``./setup_env_and_build.sh quick NO_REVEAL_OUTPUT``.
Alternatively, just rebuild SCI. For instructions to build modified SCI, see README for SCI.

To build docker image for Secure AI Validation, use the `Dockerfile_AI_Validation` dockerfile.

```docker build -t ezpc_modified - < path/to/EzPC/Dockerfile_AI_Validation```


### Docker
You can use a pre-built docker image from docker hub using ``docker pull ezpc/ezpc:latest``. We occasionally push stable images to that channel. However, if you want a docker image with the latest code, you can build it yourself using:

Expand Down
8 changes: 8 additions & 0 deletions SCI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ cmake_minimum_required (VERSION 3.13)
project (SCI)
set(NAME "SCI")


option(NO_REVEAL_OUTPUT "Only output secret shares after 2PC" OFF)
message(STATUS "Option: NO_REVEAL_OUTPUT = ${NO_REVEAL_OUTPUT}")

option(BUILD_TESTS "Build tests" OFF)
message(STATUS "Option: BUILD_TESTS = ${BUILD_TESTS}")

Expand All @@ -13,6 +17,10 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if (NO_REVEAL_OUTPUT)
add_compile_definitions(NO_REVEAL_OUTPUT=1)
endif()

add_subdirectory(src)

if (BUILD_TESTS)
Expand Down
10 changes: 9 additions & 1 deletion SCI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ To compile the library:

```
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=./install .. [-DBUILD_TESTS=ON] [-DBUILD_NETWORKS=ON]
cmake -DCMAKE_INSTALL_PREFIX=./install .. [-DBUILD_TESTS=ON] [-DBUILD_NETWORKS=ON] [-DNO_REVEAL_OUTPUT=ON]
cmake --build . --target install --parallel
```

To compile for secure AI validation so that outputs are not revealed at the end of 2PC, compile with `-DNO_REVEAL_OUTPUT=ON` flag:

```
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=./install .. -DNO_REVEAL_OUTPUT=ON
cmake --build . --target install --parallel
```

Expand Down
14 changes: 13 additions & 1 deletion SCI/src/functionalities_uniform.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
copies of the Software, and to` permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Expand Down Expand Up @@ -104,6 +104,17 @@ void funcReconstruct2PCCons(signedIntType *y, const intType *x, int len) {
}

signedIntType funcReconstruct2PCCons(intType x, int revealParty) {
#ifdef NO_REVEAL_OUTPUT
// Modified code for secure AI validation ("mlcomp")
#warning ("At the end of 2PC, output will not be revealed and secret shares will be APPENDED to file secret_shares.txt")
std::ofstream ofile;
ofile.open("secret_shares.txt", std::ios::app);
ofile<<x<<std::endl;
ofile.close();
return x;
#else
// Original code for reveal
#warning ("At the end of 2PC, output will revealed as usual.")
assert(revealParty == 2 && "Reveal to only client is supported right now.");
intType temp = 0;
signedIntType ans = 0;
Expand All @@ -123,6 +134,7 @@ signedIntType funcReconstruct2PCCons(intType x, int revealParty) {
}
}
return ans;
#endif
}

signedIntType div_floor(signedIntType a, signedIntType b) {
Expand Down
11 changes: 10 additions & 1 deletion setup_env_and_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

mode=$1

# If 2nd argument is provided, then SCI build will be modified. See SCI readme.
NO_REVEAL_OUTPUT=$2

sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo add-apt-repository ppa:avsm/ppa -y
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
Expand Down Expand Up @@ -185,7 +188,13 @@ make -j
cd $ROOT/SCI
mkdir -p build
cd build
cmake -DCMAKE_INSTALL_PREFIX=./install ../

if [[ "$NO_REVEAL_OUTPUT" == "NO_REVEAL_OUTPUT" ]]; then
cmake -DCMAKE_INSTALL_PREFIX=./install ../ -DNO_REVEAL_OUTPUT=ON
else
cmake -DCMAKE_INSTALL_PREFIX=./install ../
fi

cmake --build . --target install --parallel

#Install pre-commit hook for formatting
Expand Down

0 comments on commit dd5d299

Please sign in to comment.