8000 [MPC] Loading keypair from MPC (Depends on #67) by dtebbs · Pull Request #68 · clearmatics/zeth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[MPC] Loading keypair from MPC (Depends on #67) #68

New is 8000 sue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ addons:

matrix:
include:
- env: CI_TASK=build_release CI_USE_DOCKER=1
- env: CI_CONFIG=Release CI_USE_DOCKER=1
os: linux
language: minimal
- env: CI_CHECK_FORMAT=1 CI_TASK=build_debug CI_USE_DOCKER=1
- env: CI_CHECK_FORMAT=1 CI_CONFIG=Debug CI_USE_DOCKER=1
os: linux
language: minimal
- env: CI_TASK=build_release
- env: CI_CONFIG=Release
os: osx
osx_image: xcode11
- env: CI_TASK=build_debug
- env: CI_CONFIG=Debug
os: osx
osx_image: xcode11

script: CI_USE_DOCKER=${CI_USE_DOCKER} travis_wait 30 scripts/ci ${CI_TASK}
script: CI_USE_DOCKER=${CI_USE_DOCKER} travis_wait 30 scripts/ci ${CI_CONFIG}
20 changes: 11 additions & 9 deletions scripts/ci
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ function format_check() {
fi
}

function command_tests() {
scripts/test_pot_process
scripts/test_mpc
}

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

# Enable warnings-as-errors

Expand Down Expand Up @@ -48,14 +52,12 @@ function build() {

make -j 2 VERBOSE=1 all build_tests
make -j 2 check
cd ..
}

function build_release() {
build build-release Release
}

function build_debug() {
build build-debug Debug
function ci() {
build $1
command_tests
}

# The CI_EXECTUTE_IN_DOCKER variable determines whether we should
Expand All @@ -70,5 +72,5 @@ if [ "1" == "${CI_USE_DOCKER}" ] ; then
docker build -f Dockerfile-zeth -t zeth-dev .
docker run -t -p 50051:50051 --name zeth zeth-dev:latest $0 $@
else
eval $@
ci $@
fi
47 changes: 47 additions & 0 deletions scripts/test_mpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

set -x
set -e

POT="build/src/pot-process"
MPC="build/src/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
keypair_file=_test_keypair-${QAP_DEGREE}.bin

# 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}

# Create a dummy phase2 file
${MPC} \
dummy-phase2 --out ${phase2_file} ${linear_combination_file}

# 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}

set +x
echo "=================================================================="
echo "== PASSED =="
echo "=================================================================="
42 changes: 23 additions & 19 deletions src/CMakeLists.txt
9E7A
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ include_directories( ${Boost_INCLUDE_DIR} )
include_directories( ${PROJECT_BINARY_DIR} )

# zeth library

file(
GLOB_RECURSE
ZETH_SOURCE
Expand All @@ -78,37 +77,33 @@ file(
snarks_alias.hpp snarks/**.tcc
include_libsnark.hpp
util.?pp util.tcc
util_api.?pp util_api.tcc
zeth.h
)

add_library(
zeth
${ZETH_SOURCE})
add_library(zeth ${ZETH_SOURCE} ${PROTO_SRCS})
target_include_directories(
zeth
PUBLIC
${DEPENDS_DIR}/libsnark
${DEPENDS_DIR}/libsnark/depends/libff
${DEPENDS_DIR}/libsnark/depends/libfqfft
)
target_link_libraries(
zeth
snark)

# Building the server
add_executable(
prover_server
target_link_libraries(zeth snark)

prover_server.cc util_api.hpp util_api.cpp util_api.tcc
${PROTO_SRCS}
${GRPC_SRCS}
# prover_server executable
file(
GLOB_RECURSE
PROVER_SERVER_SOURCE
prover_server/*.?pp prover_server/*.tcc
)
add_executable(prover_server ${PROVER_SERVER_SOURCE} ${GRPC_SRCS})
target_link_libraries(
prover_server

zeth
${Boost_SYSTEM_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
gRPC::grpc++_reflection
protobuf::libprotobuf
)
Expand All @@ -122,16 +117,25 @@ target_link_libraries(
${Boost_PROGRAM_OPTIONS_LIBRARY}
)

# mpc utility executable
file(GLOB MPC_SOURCE mpc/*.?pp mpc/*.tcc)
add_executable(mpc ${MPC_SOURCE})
# mpc library
file(GLOB MPC_LIB_SOURCE mpc/mpc_*.?pp mpc/mpc_*.tcc)
add_library(libmpc ${MPC_LIB_SOURCE})
target_include_directories(libmpc PUBLIC mpc)
target_link_libraries(
mpc
libmpc
zeth
${Boost_SYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
)

# mpc utility executable
add_executable(mpc mpc/mpc.cpp)
target_link_libraries(mpc libmpc)

# mpc test utility
add_executable(mpc-test test/mpc_test_cli.cpp)
target_link_libraries(mpc-test libmpc)

## Tests
include(CTest)

Expand Down
5 changes: 2 additions & 3 deletions src/circuit-wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ template<
class CircuitWrapper
{
public:
libsnark::protoboard<FieldT> pb;
boost::filesystem::path setupPath;
std::shared_ptr<
joinsplit_gadget<FieldT, HashT, HashTreeT, NumInputs, NumOutputs>>
Expand All @@ -32,7 +31,7 @@ class CircuitWrapper
: setupPath(setupPath){};

// Generate the trusted setup
keyPairT<ppT> generate_trusted_setup();
keyPairT<ppT> generate_trusted_setup() const;

// Generate a proof and returns an extended proof
extended_proof<ppT> prove(
Expand All @@ -43,7 +42,7 @@ class CircuitWrapper
bits64 vpub_out,
const bits256 h_sig_in,
const bits256 phi_in,
provingKeyT<ppT> proving_key);
const provingKeyT<ppT> &proving_key) const;
};

} // namespace libzeth
Expand Down
12 changes: 7 additions & 5 deletions src/circuit-wrapper.tcc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __ZETH_CIRCUIT_WRAPPER_TCC__
#define __ZETH_CIRCUIT_WRAPPER_TCC__

#include "circuit-wrapper.hpp"
#include "zeth.h"

namespace libzeth
Expand All @@ -19,7 +20,7 @@ keyPairT<ppT> CircuitWrapper<
HashTreeT,
ppT,
NumInputs,
NumOutputs>::generate_trusted_setup()
NumOutputs>::generate_trusted_setup() const
{
libsnark::protoboard<FieldT> pb;
joinsplit_gadget<FieldT, HashT, HashTreeT, NumInputs, NumOutputs> g(pb);
Expand Down Expand Up @@ -55,7 +56,7 @@ extended_proof<ppT> CircuitWrapper<
bits64 vpub_out,
const bits256 h_sig_in,
const bits256 phi_in,
provingKeyT<ppT> proving_key)
const provingKeyT<ppT> &proving_key) const
{
// left hand side and right hand side of the joinsplit
bits64 lhs_value = vpub_in;
Expand Down Expand Up @@ -89,20 +90,21 @@ extended_proof<ppT> CircuitWrapper<
std::cout << "******* [DEBUG] Satisfiability result: " << is_valid_witness
<< " *******" << std::endl;

// Write the extended proof in a file (Default path is taken if not
// specified)
proofT<ppT> proof = libzeth::gen_proof<ppT>(pb, proving_key);
libsnark::r1cs_primary_input<libff::Fr<ppT>> primary_input =
pb.primary_input();

// Instantiate an extended_proof from the proof we generated and the given
// primary_input
extended_proof<ppT> ext_proof = extended_proof<ppT>(proof, primary_input);

// Write the extended proof in a file (Default path is taken if not
// specified)
ext_proof.write_extended_proof();

return ext_proof;
}

} // namespace libzeth

#endif // __ZETH_CIRCUIT_WRAPPER_TCC__
#endif // __ZETH_CIRCUIT_WRAPPER_TCC__
18 changes: 10 additions & 8 deletions src/libsnark_helpers/extended_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __ZETH_EXTENDED_PROOF_HPP__

#include "debug_helpers.hpp"
#include "snarks_alias.hpp" // Snark dependent alias for keyPairT, provingKeyT, verificationKeyT, and proofT
#include "snarks_alias.hpp"
#include "zeth.h"

namespace libzeth
Expand All @@ -22,20 +22,22 @@ template<typename ppT> class extended_proof
extended_proof(
proofT<ppT> &in_proof,
libsnark::r1cs_primary_input<libff::Fr<ppT>> &in_primary_input);
proofT<ppT> get_proof();
libsnark::r1cs_primary_input<libff::Fr<ppT>> get_primary_input();
const proofT<ppT> &get_proof() const;
const libsnark::r1cs_primary_input<libff::Fr<ppT>> &get_primary_input()
const;

// Write on disk
void write_primary_input(boost::filesystem::path path = "");
void write_proof(boost::filesystem::path path = "");
void write_extended_proof(boost::filesystem::path path = "");
void write_primary_input(boost::filesystem::path path = "") const;
void write_proof(boost::filesystem::path path = "") const;
void write_extended_proof(boost::filesystem::path path = "") const;

// Display on stdout
void dump_proof();
void dump_primary_inputs();
void dump_proof() const;
void dump_primary_inputs() const;
};

} // namespace libzeth

#include "libsnark_helpers/extended_proof.tcc"

#endif
18 changes: 10 additions & 8 deletions src/libsnark_helpers/extended_proof.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ extended_proof<ppT>::extended_proof(
in_primary_input);
}

template<typename ppT> proofT<ppT> extended_proof<ppT>::get_proof()
template<typename ppT> const proofT<ppT> &extended_proof<ppT>::get_proof() const
{
return *this->proof;
}

template<typename ppT>
libsnark::r1cs_primary_input<libff::Fr<ppT>> extended_proof<
ppT>::get_primary_input()
const libsnark::r1cs_primary_input<libff::Fr<ppT>>
&extended_proof<ppT>::get_primary_input() const
{
return *this->primary_inputs;
}

template<typename ppT>
void extended_proof<ppT>::write_primary_input(boost::filesystem::path path)
void extended_proof<ppT>::write_primary_input(
boost::filesystem::path path) const
{
if (path.empty()) {
boost::filesystem::path tmp_path =
Expand Down Expand Up @@ -67,7 +68,7 @@ void extended_proof<ppT>::write_primary_input(boost::filesystem::path path)
fh.close();
}

template<typename ppT> void extended_proof<ppT>::dump_primary_inputs()
template<typename ppT> void extended_proof<ppT>::dump_primary_inputs() const
{
std::cout << "{\n";
std::cout << " \"inputs\" :"
Expand All @@ -86,18 +87,19 @@ template<typename ppT> void extended_proof<ppT>::dump_primary_inputs()
}

template<typename ppT>
void extended_proof<ppT>::write_proof(boost::filesystem::path path)
void extended_proof<ppT>::write_proof(boost::filesystem::path path) const
{
proofToJson<ppT>(*this->proof, path);
};

template<typename ppT>
void extended_proof<ppT>::write_extended_proof(boost::filesystem::path path)
void extended_proof<ppT>::write_extended_proof(
boost::filesystem::path path) const
{
proofAndInputToJson<ppT>(*this->proof, *this->primary_inputs, path);
};

template<typename ppT> void extended_proof<ppT>::dump_proof()
template<typename ppT> void extended_proof<ppT>::dump_proof() const
{
displayProof<ppT>(*this->proof);
};
Expand Down
Loading
0