8000 Changes to support bls12-377 and bw6-761 by dtebbs · Pull Request #225 · clearmatics/zeth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Changes to support bls12-377 and bw6-761 #225

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

Merged
merged 8 commits into from
Jul 23, 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
55 changes: 28 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,42 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif ()
endif ()

# Configure a header file to pass some of the CMake settings
# to the source code
configure_file(
"${PROJECT_SOURCE_DIR}/zeth_config.h.in"
"${PROJECT_BINARY_DIR}/zeth_config.h"
# Default curve to use with zeth. Only useful for applications since all
# library functions should be parameterized by type. Note, this is
# intentionally independent of the libff variable `CURVE` to help ensure that
# library code remains fully parameterized (and to avoid unnecessary rebuilds
# of libff caused by changing compiler command line).
set(
ZETH_CURVE
"ALT_BN128"
CACHE
STRING
"Default curve: one of BLS12_377, BW6_761, ALT_BN128, BN128, EDWARDS, MNT4, MNT6"
)

# Flags and compilation options to chose the type of zksnark
# Configure a header file to pass some of the CMake settings
# Option selecting the zk-SNARK scheme.
set(
ZKSNARK
ZETH_SNARK
"GROTH16"
CACHE
STRING
"Default snark: one of PGHR13, GROTH16"
)

# Write configuration variables to the config header.
configure_file(
"${PROJECT_SOURCE_DIR}/zeth_config.h.in"
"${PROJECT_BINARY_DIR}/zeth_config.h"
)

# Run only fast test (e.g. on CI machine)
option(
FAST_TESTS_ONLY
"Include only fast-running tests"
OFF
)

# Flags and compilation options for use with libsnark
set(
CURVE
"ALT_BN128"
CACHE
STRING
"Default curve: one of ALT_BN128, BN128, EDWARDS, MNT4, MNT6"
)

set(
DEPENDS_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/depends"
Expand Down Expand Up @@ -179,15 +183,8 @@ else()
" No guarantees can be made if another compiler is used.")
endif()

add_definitions(-DCURVE_${CURVE})
add_definitions(-DZKSNARK_${ZKSNARK})

enable_testing()

if(${CURVE} STREQUAL "BN128")
add_definitions(-DBN_SUPPORT_SNARK=1)
endif()

if("${VERBOSE}")
add_definitions(-DVERBOSE=1)
endif()
Expand Down Expand Up @@ -288,8 +285,12 @@ endif()

# Add all local subdirecetories
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")
add_subdirectory(mpc_tools)

# If zeth is being used as a dependency, skip the tools build
if ("${IS_ZETH_PARENT}")
add_subdirectory(prover_server)
# For now the MPC for Groth16 only is tailored to the alt_bn128 pairing group
if(${ZETH_SNARK} STREQUAL "GROTH16")
add_subdirectory(mpc_tools)
endif()
endif()
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ Some flags to the `cmake` command can control the build configuration.
a release or debug build.

By default, zeth makes use F438 of the GROTH16 zk-snark. To chose a different
zksnark run the following: ``` cmake -DZKSNARK=$ZKSNARK .. ``` where `$ZKSNARK`
is `PGHR13` (see https://eprint.iacr.org/2013/279,
zksnark run the following: ``` cmake -DZETH_SNARK=$ZKSNARK .. ``` where
`$ZETH_SNARK` is `PGHR13` (see https://eprint.iacr.org/2013/279,
http://eprint.iacr.org/2013/879) or `GROTH16`(see
https://eprint.iacr.org/2016/260).

Expand Down
6 changes: 0 additions & 6 deletions libzeth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ ExternalProject_Get_Property(libsodium INSTALL_DIR)
set(libsodium_INCLUDE_DIR "${INSTALL_DIR}/include")
set(libsodium_LIBRARY "${INSTALL_DIR}/lib/libsodium.a")

# Add the binary tree to the search path for include files
# so that we will find zethConfig.h
include_directories(${PROJECT_BINARY_DIR})

string(TOLOWER ${ZKSNARK} ZKSNARK_NAME)

# zeth library
file(
GLOB_RECURSE
Expand Down
14 changes: 3 additions & 11 deletions libzeth/circuits/circuit_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,18 @@
#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).
// this file in code that is intended to be parameterized by hash type.

namespace libzeth
{

// Use the pairing from build configuration
using ppT = libff::default_ec_pp;

// Field type for the pairing.
using FieldT = libff::Fr<ppT>;

// Hash used for the commitments and PRFs
using HashT = BLAKE2s_256<FieldT>;
template<typename FieldT> using HashT = BLAKE2s_256<FieldT>;

// Hash function to be used in the Merkle Tree
using HashTreeT = MiMC_mp_gadget<FieldT>;
template<typename FieldT> using HashTreeT = MiMC_mp_gadget<FieldT>;

} // namespace libzeth

Expand Down
8 changes: 4 additions & 4 deletions libzeth/circuits/circuit_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ class circuit_wrapper
joinsplit_g;

public:
using FieldT = libff::Fr<ppT>;
using Field = libff::Fr<ppT>;

circuit_wrapper();

// Generate the trusted setup
typename snarkT::KeypairT generate_trusted_setup() const;

// Retrieve the constraint system (intended for debugging purposes).
libsnark::protoboard<FieldT> get_constraint_system() const;
libsnark::protoboard<Field> get_constraint_system() const;

// Generate a proof and returns an extended proof
extended_proof<ppT, snarkT> prove(
const FieldT &root,
const std::array<joinsplit_input<FieldT, TreeDepth>, NumInputs> &inputs,
const Field &root,
const std::array<joinsplit_input<Field, TreeDepth>, NumInputs> &inputs,
const std::array<zeth_note, NumOutputs> &outputs,
const bits64 &vpub_in,
const bits64 &vpub_out,
Expand Down
16 changes: 8 additions & 8 deletions libzeth/circuits/circuit_wrapper.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ typename snarkT::KeypairT circuit_wrapper<
NumOutputs,
TreeDepth>::generate_trusted_setup() const
{
libsnark::protoboard<FieldT> pb;
joinsplit_gadget<FieldT, HashT, HashTreeT, NumInputs, NumOutputs, TreeDepth>
libsnark::protoboard<Field> pb;
joinsplit_gadget<Field, HashT, HashTreeT, NumInputs, NumOutputs, TreeDepth>
g(pb);
g.generate_r1cs_constraints();

Expand All @@ -73,8 +73,8 @@ libsnark::protoboard<libff::Fr<ppT>> circuit_wrapper<
NumOutputs,
TreeDepth>::get_constraint_system() const
{
libsnark::protoboard<FieldT> pb;
joinsplit_gadget<FieldT, HashT, HashTreeT, NumInputs, NumOutputs, TreeDepth>
libsnark::protoboard<Field> pb;
joinsplit_gadget<Field, HashT, HashTreeT, NumInputs, NumOutputs, TreeDepth>
g(pb);
g.generate_r1cs_constraints();
return pb;
Expand All @@ -97,8 +97,8 @@ extended_proof<ppT, snarkT> circuit_wrapper<
NumOutputs,
TreeDepth>::
prove(
const FieldT &root,
const std::array<joinsplit_input<FieldT, TreeDepth>, NumInputs> &inputs,
const Field &root,
const std::array<joinsplit_input<Field, TreeDepth>, NumInputs> &inputs,
const std::array<zeth_note, NumOutputs> &outputs,
const bits64 &vpub_in,
const bits64 &vpub_out,
Expand Down Expand Up @@ -128,9 +128,9 @@ extended_proof<ppT, snarkT> circuit_wrapper<
throw std::invalid_argument("invalid joinsplit balance");
}

libsnark::protoboard<FieldT> pb;
libsnark::protoboard<Field> pb;

joinsplit_gadget<FieldT, HashT, HashTreeT, NumInputs, NumOutputs, TreeDepth>
joinsplit_gadget<Field, HashT, HashTreeT, NumInputs, NumOutputs, TreeDepth>
g(pb);
g.generate_r1cs_constraints();
g.generate_r1cs_witness(
Expand Down
28 changes: 0 additions & 28 deletions libzeth/snarks/default/default_api_handler.hpp

This file was deleted.

26 changes: 0 additions & 26 deletions libzeth/snarks/default/default_snark.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion libzeth/snarks/groth16/groth16_api_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "libzeth/core/extended_proof.hpp"
#include "libzeth/snarks/groth16/groth16_snark.hpp"

#include <api/snark_messages.grpc.pb.h>
#include <api/snark_messages.pb.h>

namespace libzeth
{
Expand Down
3 changes: 2 additions & 1 deletion libzeth/snarks/pghr13/pghr13_api_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#ifndef __ZETH_SNARKS_PGHR13_PGHR13_API_HANDLER_HPP__
#define __ZETH_SNARKS_PGHR13_PGHR13_API_HANDLER_HPP__

#include "api/snark_messages.grpc.pb.h"
#include "libzeth/core/extended_proof.hpp"
#include "libzeth/snarks/pghr13/pghr13_snark.hpp"

#include <api/snark_messages.pb.h>

namespace libzeth
{

Expand Down
Loading
0