Skip to content
New issue

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

Support other curves in mpc #223

Merged
merged 4 commits into from
May 29, 2020
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,6 @@ endif()
add_subdirectory(libzeth)
add_subdirectory(prover_server)
# For now the MPC for Groth16 only is tailored to the alt_bn128 pairing group
if(${ZKSNARK} STREQUAL "GROTH16" AND ${CURVE} STREQUAL "ALT_BN128")
if(${ZKSNARK} STREQUAL "GROTH16")
add_subdirectory(mpc_tools)
endif()
2 changes: 1 addition & 1 deletion depends/libsnark
Submodule libsnark updated 1 files
+1 −1 depends/libff
2 changes: 2 additions & 0 deletions libzeth/circuits/circuit_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "libzeth/circuits/mimc/mimc_mp.hpp"
#include "libzeth/core/include_libsnark.hpp"

#include <libff/common/default_types/ec_pp.hpp>

// Types that must be common across all executable, defined once here. Outside
// of tests, these should not be set anywhere else in the code. Do not include
// this file in code that is generic (parameterized on ppT or FieldT).
Expand Down
2 changes: 1 addition & 1 deletion libzeth/core/include_libff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

// Include minimal set of libff types for curve-independent operations.

#include <libff/algebra/curves/public_params.hpp>
#include <libff/algebra/fields/bigint.hpp>
#include <libff/algebra/fields/field_utils.hpp>
#include <libff/common/default_types/ec_pp.hpp>

#endif // __ZETH_CORE_INCLUDE_LIBFF__
76 changes: 0 additions & 76 deletions libzeth/mpc/groth16/phase2.cpp

This file was deleted.

59 changes: 59 additions & 0 deletions libzeth/mpc/groth16/phase2.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ void srs_mpc_phase2_accumulator<ppT>::write(std::ostream &out) const
}
}

template<typename ppT>
void srs_mpc_phase2_accumulator<ppT>::write_compressed(std::ostream &out) const
{
using G1 = libff::G1<ppT>;
check_well_formed(*this, "mpc_layer2 (write)");

// Write cs_hash and sizes first.

const size_t H_size = H_g1.size();
const size_t L_size = L_g1.size();
out.write((const char *)cs_hash, sizeof(mpc_hash_t));
out.write((const char *)&H_size, sizeof(H_size));
out.write((const char *)&L_size, sizeof(L_size));

delta_g1.write_compressed(out);
delta_g2.write_compressed(out);
for (const G1 &h : H_g1) {
h.write_compressed(out);
}
for (const G1 &l : L_g1) {
l.write_compressed(out);
}
}

template<typename ppT>
srs_mpc_phase2_accumulator<ppT> srs_mpc_phase2_accumulator<ppT>::read(
std::istream &in)
Expand Down Expand Up @@ -103,6 +127,41 @@ srs_mpc_phase2_accumulator<ppT> srs_mpc_phase2_accumulator<ppT>::read(
return accum;
}

template<typename ppT>
srs_mpc_phase2_accumulator<ppT> srs_mpc_phase2_accumulator<
ppT>::read_compressed(std::istream &in)
{
using G1 = libff::G1<ppT>;
using G2 = libff::G2<ppT>;

mpc_hash_t cs_hash;
size_t H_size;
size_t L_size;
in.read((char *)cs_hash, sizeof(mpc_hash_t));
in.read((char *)&H_size, sizeof(H_size));
in.read((char *)&L_size, sizeof(L_size));

G1 delta_g1;
G1::read_compressed(in, delta_g1);
G2 delta_g2;
G2::read_compressed(in, delta_g2);

libff::G1_vector<ppT> H_g1(H_size);
for (G1 &h : H_g1) {
G1::read_compressed(in, h);
}

libff::G1_vector<ppT> L_g1(L_size);
for (G1 &l : L_g1) {
G1::read_compressed(in, l);
}

srs_mpc_phase2_accumulator<ppT> l2(
cs_hash, delta_g1, delta_g2, std::move(H_g1), std::move(L_g1));
check_well_formed(l2, "mpc_layer2 (read)");
return l2;
}

template<typename ppT>
srs_mpc_phase2_publickey<ppT>::srs_mpc_phase2_publickey(
const mpc_hash_t transcript_digest,
Expand Down
Loading