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

Organization refactor #177

Merged
merged 21 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
69cf32a
Added IS_ZETH_PARENT option to ease the use of zeth as a dependency
AntoineRondelet Mar 24, 2020
b9174ae
Switched DEPENDS_DIR to normal variable and added ZETH variables to p…
AntoineRondelet Mar 25, 2020
ad13bdf
First changes in the repo organization and fixed include directives
AntoineRondelet Mar 25, 2020
07df62a
Refactored handling of proto files
AntoineRondelet Mar 26, 2020
34193ac
Extended libzeth library
AntoineRondelet Mar 26, 2020
89fed92
Factorized proto config in parent cmake file
AntoineRondelet Mar 26, 2020
14ae691
Renamed mpc command to match changes in cpp code
AntoineRondelet Mar 26, 2020
5d0f66b
Fixed path to pot-process exec
AntoineRondelet Mar 26, 2020
6d8de52
Brought libzeth to scope
AntoineRondelet Mar 26, 2020
38c0cd7
Updated setup script to create folders and point to executables
AntoineRondelet Mar 26, 2020
cced7b8
Removed debug instructions in CMakeLists file
AntoineRondelet Mar 26, 2020
522b370
Fixed rebasing omission
AntoineRondelet Mar 26, 2020
8f6e0f7
Fixed ci error due to linter rule violations
AntoineRondelet Mar 26, 2020
de51f4d
Switched to new mpc binary path in test config
AntoineRondelet Mar 26, 2020
4fe009d
Fixed broken link
AntoineRondelet Mar 26, 2020
a0ee73c
Merge pull request #180 from clearmatics/typo-fix
AntoineRondelet Mar 26, 2020
2f7ef99
Modified include syntax
AntoineRondelet Apr 1, 2020
ce3e052
Documented the use of PARENT option
AntoineRondelet Apr 1, 2020
760f8e7
Removed unused environment variables
AntoineRondelet Apr 1, 2020
a3eb8d7
Removed keystore from gitignore
AntoineRondelet Apr 1, 2020
4ccf7e0
Fixed forgotten include directives and renamed to circuits_utils for …
AntoineRondelet Apr 1, 2020
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
12 changes: 3 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
/jsClient/node_modules/*
/jsClient/package-lock.json

# Ignore the build repo
/build/

# Ignore the coins we created
/coinstore/

# Ignore the content of the keystore
/keystore/*.pem
/keystore/*.json

# Ignore the output of the trusted setup (ie: Proving and Verifying key)
/trusted_setup/*.raw
/trusted_setup/*.json
/trusted_setup/

# Ignore the content of the debug folder
debug/*json
Expand All @@ -32,6 +24,8 @@ debug/*json
/_test_contributors_from_csv/
/_test_server_phase*/
/_test_phase2_data/
/_test_zeth_cli/
/_test_zeth_cli_token/

# Ignore python cache dirs

Expand Down
72 changes: 60 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ endif()
project(zeth)

# Versionning of the project
set (ZETH_VERSION_MAJOR 0)
set (ZETH_VERSION_MINOR 3)
set(ZETH_VERSION_MAJOR 0)
set(ZETH_VERSION_MINOR 3)

# Configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/zethConfig.h.in"
"${PROJECT_BINARY_DIR}/zethConfig.h"
configure_file(
"${PROJECT_SOURCE_DIR}/zethConfig.h.in"
"${PROJECT_BINARY_DIR}/zethConfig.h"
)

# Flags and compilation options to chose the type of zksnark
Expand All @@ -45,8 +45,8 @@ option(

# Flags and compilation options for use with libsnark
set(
CURVE # Variable name
"ALT_BN128" # We use the ALT_BN128 curve here, this is useful to pick the settings related to alt_bn128 in https://github.com/scipr-lab/libff/blob/master/libff/common/default_types/ec_pp.hpp
CURVE
"ALT_BN128"
CACHE
STRING
"Default curve: one of ALT_BN128, BN128, EDWARDS, MNT4, MNT6"
Expand All @@ -55,9 +55,6 @@ set(
set(
DEPENDS_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/depends"
CACHE
STRING
"Optionally specify the dependency installation directory relative to the source directory (default: inside dependency folder)"
)

set(
Expand All @@ -68,6 +65,17 @@ set(
"Override C++ compiler optimization flags"
)

# This option allows to set Zeth as a top-level project
# or a dependency. This option is used to manage conflicting
# targets definitions.
# See, discussion here for more details:
# https://github.com/clearmatics/zeth/pull/177#discussion_r399424467
option(
IS_ZETH_PARENT
AntoineRondelet marked this conversation as resolved.
Show resolved Hide resolved
"Zeth parent folder option"
ON
)

option(
MULTICORE
"Enable parallelized execution, using OpenMP"
Expand Down Expand Up @@ -173,8 +181,48 @@ endif()
# Add the given directories to those the compiler uses to search for include files
include_directories(.)

add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
if ("${IS_ZETH_PARENT}")
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
endif()

# Global gRPC and Protocol Buffers configuration.
# The libraries location can be known by running:
# `ldconfig -p | grep libgrpc`
# `ldconfig -p | grep libprotobuf`
#
# CMAKE_MODULE_PATH: Path used for searching by FIND_XXX(), with appropriate suffixes added.
# See: https://cmake.org/cmake/help/v3.0/variable/CMAKE_PREFIX_PATH.html
list(APPEND CMAKE_PREFIX_PATH "/usr/local/lib" "/usr/lib")
# Cmake find modules
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# Set the target of the Protobuf and gRPC generated files.
set(
PROTO_SRC_DIR
${PROJECT_BINARY_DIR}/proto_src
)
file(MAKE_DIRECTORY ${PROTO_SRC_DIR})

# Get the proto files
file(
GLOB
PROTO_FILES
${PROJECT_SOURCE_DIR}/api/*.proto
)

# Generating sensibly into a python module requires setting --proto_path to the
# zeth root, and referencing files as 'api/prover.proto' etc. This requires us
# to tweak the references to the source files.
set(PROTOBUF_IMPORT_DIRS ${PROJECT_SOURCE_DIR})
set(PROTOBUF_PROTO_PATH ${PROJECT_SOURCE_DIR})
set(PROTOBUF_APPEND_DEST_PATH "/api")
set(PROTOBUF_GENERATE_CPP_APPEND_PATH FALSE)
set(GRPC_GENERATE_CPP_APPEND_PATH FALSE)

# Add sub-directories for the build
add_subdirectory(depends)
add_subdirectory(src)
add_subdirectory(libzeth)
add_subdirectory(prover_server)
if(${ZKSNARK} STREQUAL "GROTH16")
add_subdirectory(mpc_tools)
endif()
File renamed without changes.
File renamed without changes.
11 changes: 0 additions & 11 deletions coinstore/README.md

This file was deleted.

1 change: 0 additions & 1 deletion keystore/README.md

This file was deleted.

128 changes: 128 additions & 0 deletions libzeth/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
include_directories(.)

find_package(Protobuf REQUIRED)
find_package(GRPC REQUIRED)

# Add the directory containing the Protobuf generated files.
# `PROTO_SRC_DIR` is defined in the parent CMakeLists.txt
include_directories(${PROTO_SRC_DIR})

# Function defined in the cmake scripts in the cmake folder.
# Generate the protobuf files and set the result of the generation
# in the given env var (PROTO_SRCS, PROTO_HDRS).
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_SRC_DIR} ${PROTO_FILES})

set_property(SOURCE ${PROTO_SRCS} PROPERTY
COMPILE_FLAGS "-Wno-unused-variable -Wno-unused-parameter"
)

# Enable Boost for program_options
find_package( Boost REQUIRED COMPONENTS system filesystem program_options )
include_directories( ${Boost_INCLUDE_DIR} )

# libsodium
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
ZETH_SOURCE
types/**.?pp types/**.tcc
circuits/**.?pp circuits/**.tcc
circuit_wrapper.???
commitments/**.?pp commitments/**.tcc
libsnark_helpers/**.?pp libsnark_helpers/**.tcc
snarks/**.hpp snarks/**.tcc snarks/${ZKSNARK_NAME}/**.cpp
snarks_alias.hpp
include_libsnark.hpp
util.?pp util.tcc
util_api.?pp util_api.tcc
zeth.h
)
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
${libsodium_INCLUDE_DIR}
)
target_link_libraries(
zeth

snark
${libsodium_LIBRARY}
)
add_dependencies(zeth libsodium)

## Tests
if ("${IS_ZETH_PARENT}")
include(CTest)

# A target which builds all tests, even if they will not be run.
add_custom_target(build_tests)

function(zeth_test TEST_NAME)
cmake_parse_arguments(zeth_test "FAST" "" "SOURCE" ${ARGN} )
file(GLOB test_src ${zeth_test_SOURCE})

# Test executable
add_executable(${TEST_NAME} EXCLUDE_FROM_ALL ${test_src})
target_link_libraries(${TEST_NAME} zeth gtest_main)

# Add all tests to the 'build_tests' target
add_dependencies(build_tests ${TEST_NAME})

if((NOT FAST_TESTS_ONLY) OR zeth_test_FAST)
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
add_dependencies(check ${TEST_NAME})
else()
message("Skipping slow test ${TEST_NAME}")
endif()
endfunction(zeth_test)

zeth_test(test_addition SOURCE test/packed_addition_test.cpp FAST)
zeth_test(test_hex_to_field SOURCE test/hex_to_field_test.cpp FAST)
zeth_test(test_binary_operation SOURCE test/binary_operation_test.cpp FAST)
zeth_test(test_blake2s SOURCE test/blake2s_test.cpp FAST)
zeth_test(test_mimc_mp SOURCE test/mimc_mp_test.cpp FAST)
zeth_test(test_prfs SOURCE test/prfs_test.cpp FAST)
zeth_test(test_commitments SOURCE test/commitments_test.cpp FAST)
zeth_test(test_merkle_tree SOURCE test/merkle_tree_test.cpp FAST)
zeth_test(test_note SOURCE test/note_test.cpp FAST)
zeth_test(test_prover SOURCE test/prover_test.cpp)

# Old Tests
# zeth_test(test_sha256 test/sha256_test.cpp TRUE)

# prover test has extra dependencies
target_link_libraries(
test_prover
${Boost_SYSTEM_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
)

# Groth16-only tests and MPC
if(${ZKSNARK} STREQUAL "GROTH16")
zeth_test(test_simple SOURCE test/simple_test.cpp FAST)
zeth_test(test_powersoftau SOURCE test/powersoftau_test.cpp FAST)
zeth_test(test_mpc SOURCE test/mpc_*.cpp FAST)
target_link_libraries(
test_mpc ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})
endif()
endif()
11 changes: 8 additions & 3 deletions src/circuit_types.hpp → libzeth/circuit_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
#ifndef __ZETH_CIRCUIT_TYPES_HPP__
#define __ZETH_CIRCUIT_TYPES_HPP__

#include "circuit_wrapper.hpp"
#include "circuits/blake2s/blake2s_comp.hpp"
#include "include_libsnark.hpp"
#include "libzeth/circuit_wrapper.hpp"
#include "libzeth/circuits/blake2s/blake2s_comp.hpp"
#include "libzeth/include_libsnark.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).

namespace libzeth
{

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

Expand All @@ -25,4 +28,6 @@ using HashT = BLAKE2s_256_comp<FieldT>;
// Hash function to be used in the Merkle Tree
using HashTreeT = MiMC_mp_gadget<FieldT>;

} // namespace libzeth

#endif // __ZETH_CIRCUIT_TYPES_HPP__
12 changes: 6 additions & 6 deletions src/circuit_wrapper.hpp → libzeth/circuit_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#ifndef __ZETH_CIRCUIT_WRAPPER_HPP__
#define __ZETH_CIRCUIT_WRAPPER_HPP__

#include "circuits/joinsplit.tcc"
#include "libsnark_helpers/libsnark_helpers.hpp"
#include "types/note.hpp"
#include "libzeth/circuits/joinsplit.tcc"
#include "libzeth/libsnark_helpers/libsnark_helpers.hpp"
#include "libzeth/types/note.hpp"

// zkSNARK specific aliases and imports
#include "snarks_alias.hpp"
#include "snarks_core_imports.hpp"
#include "libzeth/snarks_alias.hpp"
#include "libzeth/snarks_core_imports.hpp"

namespace libzeth
{
Expand Down Expand Up @@ -62,6 +62,6 @@ class circuit_wrapper
};

} // namespace libzeth
#include "circuit_wrapper.tcc"
#include "libzeth/circuit_wrapper.tcc"

#endif // __ZETH_CIRCUIT_WRAPPER_HPP__
4 changes: 2 additions & 2 deletions src/circuit_wrapper.tcc → libzeth/circuit_wrapper.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef __ZETH_CIRCUIT_WRAPPER_TCC__
#define __ZETH_CIRCUIT_WRAPPER_TCC__

#include "snarks_alias.hpp"
#include "zeth.h"
#include "libzeth/snarks_alias.hpp"
#include "libzeth/zeth.h"

namespace libzeth
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#ifndef __ZETH_CIRCUITS_BINARY_OPERATION_HPP__
#define __ZETH_CIRCUITS_BINARY_OPERATION_HPP__

#include "circuits/circuits-utils.hpp"
#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/types/bits.hpp"
#include "math.h"
#include "types/bits.hpp"

#include <libsnark/gadgetlib1/gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/basic_gadgets.hpp>
Expand Down Expand Up @@ -119,6 +119,6 @@ class double_bit32_sum_eq_gadget : public libsnark::gadget<FieldT>
};

} // namespace libzeth
#include "binary_operation.tcc"
#include "libzeth/circuits/binary_operation.tcc"

#endif // __ZETH_CIRCUITS_BINARY_OPERATION_HPP__
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef __ZETH_CIRCUITS_BINARY_OPERATION_TCC__
#define __ZETH_CIRCUITS_BINARY_OPERATION_TCC__

#include "circuits/circuits-utils.hpp"
#include "types/bits.hpp"
#include "libzeth/circuits/circuits_utils.hpp"
#include "libzeth/types/bits.hpp"

#include <libsnark/gadgetlib1/gadget.hpp>
#include <libsnark/gadgetlib1/gadgets/basic_gadgets.hpp>
Expand Down
Loading