Skip to content

Commit

Permalink
Merge pull request #73 from clearmatics/mpc-phase2
Browse files Browse the repository at this point in the history
[MPC] Phase2 MPC
  • Loading branch information
AntoineRondelet committed Oct 24, 2019
2 parents e14292c + 684a86c commit 2f8673b
Show file tree
Hide file tree
Showing 74 changed files with 4,325 additions and 1,175 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "depends/googletest"]
path = depends/googletest
url = https://github.com/google/googletest.git
[submodule "depends/libsodium"]
path = depends/libsodium
url = https://github.com/jedisct1/libsodium.git
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ addons:
- boost
- openssl
- cmake
- libtool
- autoconf
- automake
# - llvm

matrix:
Expand Down
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,18 @@ option(
ON
)

option(
MONTGOMERY_OUTPUT
"Serialize Fp elements as their Montgomery representations (faster but not human-readable)"
ON
)

option(
USE_PT_COMPRESSION
"Use point compression"
OFF
)

set(USE_PT_COMPRESSION OFF)

if(APPLE)
# These must be disabled to make dependencies build on macos
set(WITH_PROCPS OFF)
Expand Down Expand Up @@ -154,6 +158,10 @@ if("${BINARY_OUTPUT}")
add_definitions(-DBINARY_OUTPUT)
endif()

if("${MONTGOMERY_OUTPUT}")
add_definitions(-DMONTGOMERY_OUTPUT)
endif()

if(NOT "${USE_PT_COMPRESSION}")
add_definitions(-DNO_PT_COMPRESSION=1)
endif()
Expand Down
19 changes: 19 additions & 0 deletions depends/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# libsnark
OPTION(IS_LIBSNARK_PARENT OFF)
add_subdirectory(libsnark)

Expand All @@ -8,3 +9,21 @@ set_target_properties(snark PROPERTIES COMPILE_FLAGS
set_target_properties(ff PROPERTIES COMPILE_FLAGS
"-Wno-unused-variable -Wno-unused-parameter"
)

# get NUM_CPUS
include(ProcessorCount)
ProcessorCount(NUM_CPUS)
if(NOT NUM_CPUS EQUAL 0)
set(MAKE_BUILD_FLAGS -j${NUM_CPUS})
endif()

# libsodium
set(LIBSODIUM_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libsodium)

include(ExternalProject)
ExternalProject_Add(
libsodium
SOURCE_DIR ${LIBSODIUM_SOURCE_DIR}
CONFIGURE_COMMAND cd ${LIBSODIUM_SOURCE_DIR} && ./autogen.sh && ./configure --prefix=<INSTALL_DIR> --enable-minimal --disable-shared --enable-static
BUILD_COMMAND cd ${LIBSODIUM_SOURCE_DIR} && make ${MAKE_BUILD_FLAGS}
INSTALL_COMMAND cd ${LIBSODIUM_SOURCE_DIR} && make install)
1 change: 1 addition & 0 deletions depends/libsodium
Submodule libsodium added at 940ef4
25 changes: 20 additions & 5 deletions scripts/ci
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function command_tests() {

function build() {
build_type=$1
full=$2

# Enable warnings-as-errors
cxx_flags="-Werror"
Expand All @@ -33,13 +34,17 @@ function build() {
export PATH="/usr/local/opt/llvm/bin:/usr/local/bin:${PATH}"
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
export LIBRARY_PATH="/usr/local/opt/openssl/lib"
export LDFLAGS="-L/usr/local/opt/llvm/lib -L-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include -I/usr/local/include"
export LDFLAGS="-L/usr/local/lib"
export CPPFLAGS="-I/usr/local/include"

cxx_flags="${cxx_flags} -I/usr/local/opt/openssl/include"
cxx_flags="${cxx_flags} -Wno-deprecated-declarations"
fi

cmake_flags="-DCMAKE_BUILD_TYPE=${build_type}"
if ! [ "${full}" == "1" ] ; then
cmake_flags="${cmake_flags} -DFAST_TESTS_ONLY=ON"
fi

. setup_env.sh
mkdir -p build
Expand All @@ -55,10 +60,20 @@ function build() {
}

function ci() {
build $1
build $1 $2
command_tests
}

build_type=$1
full_build=$2
if [ "${full_build}" == "" ] ; then
if [ "${TRAVIS_PULL_REQUEST}" == "false" ] || [ "${TRAVIS_PULL_REQUEST}" == "" ] ; then
full_build=0
else
full_build=1
fi
fi

if [ "${CI_CHECK_FORMAT}" == "1" ] ; then
format_check
fi
Expand All @@ -68,7 +83,7 @@ fi
if [ "${CI_USE_DOCKER}" == "1" ] ; then
docker pull clearmatics/zeth-base:latest
docker build -f Dockerfile-zeth -t zeth-dev .
docker run -t -p 50051:50051 --name zeth zeth-dev:latest $0 $@
docker run -t -p 50051:50051 --name zeth zeth-dev:latest $0 ${build_type} ${full_build}
else
ci $@
ci $build_type ${build_type} ${full_build}
fi
106 changes: 88 additions & 18 deletions scripts/test_mpc
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,112 @@ set -x
set -e

POT="build/src/pot-process"
MPC="build/src/mpc-test"
MPC="build/src/mpc/mpc-test"
QAP_DEGREE=8

pot_file=_test_pot-${QAP_DEGREE}.bin
lagrange_file=_test_lagrange-${QAP_DEGREE}.bin

linear_combination_file=_test_linear_combination-${QAP_DEGREE}.bin
phase2_file=_test_phase2-${QAP_DEGREE}.bin

transcript_file=_test_transcript.bin
challenge_0_file=_test_challenge_0.bin
response_1_file=_test_response_1.bin
response_digest_1_file=_test_response_digest_1.bin
challenge_1_file=_test_challenge_1.bin
response_2_file=_test_response_2.bin
response_digest_2_file=_test_response_digest_2.bin
challenge_2_file=_test_challenge_2.bin
response_3_file=_test_response_3.bin
response_digest_3_file=_test_response_digest_3.bin
challenge_3_file=_test_challenge_3.bin
final_phase2_file=${challenge_3_file}
invalid_response_digest_file=_test_response_digest_invalid.bin

keypair_file=_test_keypair-${QAP_DEGREE}.bin

rm -f ${transcript_file}

# Dummy pot data
${POT} --dummy ${pot_file} ${QAP_DEGREE}

# Compute lagrange points
${POT} --out ${lagrange_file} ${pot_file} ${QAP_DEGREE}

# Generate the linear combination
${MPC} \
linear-combination --out ${linear_combination_file} \
${pot_file} ${lagrange_file}
${MPC} linear-combination \
${pot_file} ${lagrange_file} ${linear_combination_file}

# Begin Phase2 MPC and run some rounds, accumulating transcript.
${MPC} phase2-begin ${linear_combination_file} ${challenge_0_file}

${MPC} phase2-contribute \
--skip-user-input \
--digest ${response_digest_1_file} \
${challenge_0_file} ${response_1_file}
${MPC} phase2-verify-contribution \
--transcript ${transcript_file} \
--new-challenge ${challenge_1_file} \
${challenge_0_file} ${response_1_file}

# Create a dummy phase2 file
${MPC} \
dummy-phase2 --out ${phase2_file} ${linear_combination_file}
${MPC} phase2-contribute \
--skip-user-input \
--digest ${response_digest_2_file} \
${challenge_1_file} ${response_2_file}
${MPC} phase2-verify-contribution \
--transcript ${transcript_file} \
--new-challenge ${challenge_2_file} \
${challenge_1_file} ${response_2_file}

${MPC} phase2-contribute \
--skip-user-input \
--digest ${response_digest_3_file} \
${challenge_2_file} ${response_3_file}
${MPC} phase2-verify-contribution \
--transcript ${transcript_file} \
--new-challenge ${challenge_3_file} \
${challenge_2_file} ${response_3_file}

# Verify the transcript
${MPC} phase2-verify-transcript \
${challenge_0_file} ${transcript_file} ${challenge_3_file}

# Verify the transcript, checking for each contribution
${MPC} phase2-verify-transcript \
--digest ${response_digest_1_file} \
${challenge_0_file} ${transcript_file} ${challenge_3_file}
${MPC} phase2-verify-transcript \
--digest ${response_digest_2_file} \
${challenge_0_file} ${transcript_file} ${challenge_3_file}
${MPC} phase2-verify-transcript \
--digest ${response_digest_3_file} \
${challenge_0_file} ${transcript_file} ${challenge_3_file}

# Invalid contribution check
echo 00000000 >> ${invalid_response_digest_file}
cat ${response_digest_3_file} >> ${invalid_response_digest_file}
if (${MPC} phase2-verify-transcript \
--digest ${invalid_response_digest_file} \
${challenge_0_file} ${transcript_file} ${challenge_3_file}) then
echo ERROR: expected failure
exit 1
fi

# Create the keypair
${MPC} \
create-keypair --out ${keypair_file} \
${pot_file} ${linear_combination_file} ${phase2_file}

rm \
${pot_file} \
${lagrange_file} \
${linear_combination_file} \
${phase2_file} \
${keypair_file}
${MPC} create-keypair \
${pot_file} ${linear_combination_file} ${final_phase2_file} \
${keypair_file}

# Clean up files
rm ${pot_file} ${lagrange_file} ${linear_combination_file}
rm ${transcript_file}
rm ${challenge_0_file}
rm ${response_1_file} ${challenge_1_file} ${response_1_digest_file}
rm ${response_2_file} ${challenge_2_file} ${response_2_digest_file}
rm ${response_3_file} ${challenge_3_file} ${response_3_digest_file}
rm -f ${final_phase2_file} # Same as challenge_3_file
rm ${invalid_response_digest_file}
rm ${keypair_file}

set +x
echo "=================================================================="
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_pot_process
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
POT=$1
[ "" == "${POT}" ] && POT="build/src/pot-process"

POT_DATA="testdata/powersoftau_response.4.bin"
POT_DATA="testdata/powersoftau_challenge.4.bin"
POT_DATA_DEGREE=16

set -e
Expand Down
Loading

0 comments on commit 2f8673b

Please sign in to comment.