diff --git a/.gitignore b/.gitignore index 6e70deabb..bc9c5ab4a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 017773b7c..7ab54e384 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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" @@ -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( @@ -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 + "Zeth parent folder option" + ON +) + option( MULTICORE "Enable parallelized execution, using OpenMP" @@ -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() diff --git a/src/cmake/FindGRPC.cmake b/cmake/FindGRPC.cmake similarity index 100% rename from src/cmake/FindGRPC.cmake rename to cmake/FindGRPC.cmake diff --git a/src/cmake/FindProtobuf.cmake b/cmake/FindProtobuf.cmake similarity index 100% rename from src/cmake/FindProtobuf.cmake rename to cmake/FindProtobuf.cmake diff --git a/coinstore/README.md b/coinstore/README.md deleted file mode 100644 index d8327ea84..000000000 --- a/coinstore/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Coinstore repository for Zeth - -Contains the list of all Zeth notes owned by a user. - -## Note - -The encrypted broadcast used in ZETH - to send the ZETH notes to the recipient - presents some nice features when we consider hardware failures or loss of notes data. In fact, one can easily set up a backup routine that periodically backs up the content of the coinstore, and more importantly, that backs up -the keystore. -In fact, having access to their decryption keys enable users to scan the entire chain and look into the logs of the zeth mixer contract to try and decrypt -all the ciphertexts to recover the list of notes they control. -Backing up the coinstore along the keystore could avoid the overhead of scanning the blockchain after a hardware failure. Having access to one's list of notes present several other nice features, but we refer the reader to the paper for more details on the design of ZETH. diff --git a/keystore/README.md b/keystore/README.md deleted file mode 100644 index 31ff69fbb..000000000 --- a/keystore/README.md +++ /dev/null @@ -1 +0,0 @@ -# Keystore repository for Zeth diff --git a/libzeth/CMakeLists.txt b/libzeth/CMakeLists.txt new file mode 100644 index 000000000..668d19a1a --- /dev/null +++ b/libzeth/CMakeLists.txt @@ -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() diff --git a/src/circuit_types.hpp b/libzeth/circuit_types.hpp similarity index 80% rename from src/circuit_types.hpp rename to libzeth/circuit_types.hpp index c825de16c..ccce64e37 100644 --- a/src/circuit_types.hpp +++ b/libzeth/circuit_types.hpp @@ -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; @@ -25,4 +28,6 @@ using HashT = BLAKE2s_256_comp; // Hash function to be used in the Merkle Tree using HashTreeT = MiMC_mp_gadget; +} // namespace libzeth + #endif // __ZETH_CIRCUIT_TYPES_HPP__ diff --git a/src/circuit_wrapper.hpp b/libzeth/circuit_wrapper.hpp similarity index 85% rename from src/circuit_wrapper.hpp rename to libzeth/circuit_wrapper.hpp index 0216726f3..af22f2613 100644 --- a/src/circuit_wrapper.hpp +++ b/libzeth/circuit_wrapper.hpp @@ -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 { @@ -62,6 +62,6 @@ class circuit_wrapper }; } // namespace libzeth -#include "circuit_wrapper.tcc" +#include "libzeth/circuit_wrapper.tcc" #endif // __ZETH_CIRCUIT_WRAPPER_HPP__ diff --git a/src/circuit_wrapper.tcc b/libzeth/circuit_wrapper.tcc similarity index 98% rename from src/circuit_wrapper.tcc rename to libzeth/circuit_wrapper.tcc index 6a03037dc..1602d5fec 100644 --- a/src/circuit_wrapper.tcc +++ b/libzeth/circuit_wrapper.tcc @@ -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 { diff --git a/src/circuits/binary_operation.hpp b/libzeth/circuits/binary_operation.hpp similarity index 96% rename from src/circuits/binary_operation.hpp rename to libzeth/circuits/binary_operation.hpp index 72e4fb8fe..b790a5f92 100644 --- a/src/circuits/binary_operation.hpp +++ b/libzeth/circuits/binary_operation.hpp @@ -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 #include @@ -119,6 +119,6 @@ class double_bit32_sum_eq_gadget : public libsnark::gadget }; } // namespace libzeth -#include "binary_operation.tcc" +#include "libzeth/circuits/binary_operation.tcc" #endif // __ZETH_CIRCUITS_BINARY_OPERATION_HPP__ \ No newline at end of file diff --git a/src/circuits/binary_operation.tcc b/libzeth/circuits/binary_operation.tcc similarity index 99% rename from src/circuits/binary_operation.tcc rename to libzeth/circuits/binary_operation.tcc index ca6f6a6a8..920d2d605 100644 --- a/src/circuits/binary_operation.tcc +++ b/libzeth/circuits/binary_operation.tcc @@ -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 #include diff --git a/src/circuits/blake2s/blake2s_comp.hpp b/libzeth/circuits/blake2s/blake2s_comp.hpp similarity index 92% rename from src/circuits/blake2s/blake2s_comp.hpp rename to libzeth/circuits/blake2s/blake2s_comp.hpp index 67e276e2f..9f2b59ddb 100644 --- a/src/circuits/blake2s/blake2s_comp.hpp +++ b/libzeth/circuits/blake2s/blake2s_comp.hpp @@ -5,11 +5,11 @@ #ifndef __ZETH_CIRCUITS_BLAKE2S_COMP_HPP__ #define __ZETH_CIRCUITS_BLAKE2S_COMP_HPP__ -#include "circuits/binary_operation.hpp" -#include "circuits/circuits-utils.hpp" -#include "g_primitive.hpp" -#include "types/bits.hpp" -#include "util.hpp" +#include "libzeth/circuits/binary_operation.hpp" +#include "libzeth/circuits/blake2s/g_primitive.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/types/bits.hpp" +#include "libzeth/util.hpp" #include #include @@ -116,7 +116,7 @@ class BLAKE2s_256_comp : public libsnark::gadget }; } // namespace libzeth -#include "blake2s_comp.tcc" -#include "blake2s_comp_setup.tcc" +#include "libzeth/circuits/blake2s/blake2s_comp.tcc" +#include "libzeth/circuits/blake2s/blake2s_comp_setup.tcc" #endif // __ZETH_CIRCUITS_BLAKE2S_COMP_HPP__ \ No newline at end of file diff --git a/src/circuits/blake2s/blake2s_comp.tcc b/libzeth/circuits/blake2s/blake2s_comp.tcc similarity index 100% rename from src/circuits/blake2s/blake2s_comp.tcc rename to libzeth/circuits/blake2s/blake2s_comp.tcc diff --git a/src/circuits/blake2s/blake2s_comp_setup.tcc b/libzeth/circuits/blake2s/blake2s_comp_setup.tcc similarity index 100% rename from src/circuits/blake2s/blake2s_comp_setup.tcc rename to libzeth/circuits/blake2s/blake2s_comp_setup.tcc diff --git a/src/circuits/blake2s/g_primitive.hpp b/libzeth/circuits/blake2s/g_primitive.hpp similarity index 93% rename from src/circuits/blake2s/g_primitive.hpp rename to libzeth/circuits/blake2s/g_primitive.hpp index 84fd29ece..5e4d1947f 100644 --- a/src/circuits/blake2s/g_primitive.hpp +++ b/libzeth/circuits/blake2s/g_primitive.hpp @@ -5,9 +5,9 @@ #ifndef __ZETH_CIRCUITS_G_PRIMITIVE_HPP__ #define __ZETH_CIRCUITS_G_PRIMITIVE_HPP__ -#include "circuits/binary_operation.hpp" -#include "circuits/circuits-utils.hpp" -#include "types/bits.hpp" +#include "libzeth/circuits/binary_operation.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/types/bits.hpp" #include #include @@ -69,6 +69,6 @@ template class g_primitive : public libsnark::gadget }; } // namespace libzeth -#include "g_primitive.tcc" +#include "libzeth/circuits/blake2s/g_primitive.tcc" #endif // __ZETH_CIRCUITS_G_PRIMITIVE_HPP__ \ No newline at end of file diff --git a/src/circuits/blake2s/g_primitive.tcc b/libzeth/circuits/blake2s/g_primitive.tcc similarity index 100% rename from src/circuits/blake2s/g_primitive.tcc rename to libzeth/circuits/blake2s/g_primitive.tcc diff --git a/src/circuits/circuits-utils.cpp b/libzeth/circuits/circuits_utils.cpp similarity index 96% rename from src/circuits/circuits-utils.cpp rename to libzeth/circuits/circuits_utils.cpp index cf0d571f6..3c5cfa094 100644 --- a/src/circuits/circuits-utils.cpp +++ b/libzeth/circuits/circuits_utils.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuits-utils.hpp" +#include "libzeth/circuits/circuits_utils.hpp" namespace libzeth { diff --git a/src/circuits/circuits-utils.hpp b/libzeth/circuits/circuits_utils.hpp similarity index 92% rename from src/circuits/circuits-utils.hpp rename to libzeth/circuits/circuits_utils.hpp index ec77cb279..38b190b32 100644 --- a/src/circuits/circuits-utils.hpp +++ b/libzeth/circuits/circuits_utils.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_CIRCUITS_CIRCUITS_UTILS_HPP__ #define __ZETH_CIRCUITS_CIRCUITS_UTILS_HPP__ -#include "types/bits.hpp" +#include "libzeth/types/bits.hpp" #include @@ -28,6 +28,6 @@ std::vector bit_list_to_ints( std::vector bit_list, const size_t wordsize); } // namespace libzeth -#include "circuits/circuits-utils.tcc" +#include "libzeth/circuits/circuits_utils.tcc" #endif // __ZETH_CIRCUITS_CIRCUITS_UTILS_HPP__ \ No newline at end of file diff --git a/src/circuits/circuits-utils.tcc b/libzeth/circuits/circuits_utils.tcc similarity index 100% rename from src/circuits/circuits-utils.tcc rename to libzeth/circuits/circuits_utils.tcc diff --git a/src/circuits/commitments/commitment.hpp b/libzeth/circuits/commitments/commitment.hpp similarity index 98% rename from src/circuits/commitments/commitment.hpp rename to libzeth/circuits/commitments/commitment.hpp index 35f456142..74ddc708b 100644 --- a/src/circuits/commitments/commitment.hpp +++ b/libzeth/circuits/commitments/commitment.hpp @@ -86,6 +86,6 @@ class COMM_cm_gadget : public libsnark::gadget }; } // namespace libzeth -#include "circuits/commitments/commitment.tcc" +#include "libzeth/circuits/commitments/commitment.tcc" #endif // __ZETH_CIRCUITS_COMMITMENT_HPP__ \ No newline at end of file diff --git a/src/circuits/commitments/commitment.tcc b/libzeth/circuits/commitments/commitment.tcc similarity index 100% rename from src/circuits/commitments/commitment.tcc rename to libzeth/circuits/commitments/commitment.tcc diff --git a/src/circuits/joinsplit.tcc b/libzeth/circuits/joinsplit.tcc similarity index 99% rename from src/circuits/joinsplit.tcc rename to libzeth/circuits/joinsplit.tcc index 1b7113cf9..3eecfc28e 100644 --- a/src/circuits/joinsplit.tcc +++ b/libzeth/circuits/joinsplit.tcc @@ -6,17 +6,18 @@ #define __ZETH_CIRCUITS_JOINSPLIT_TCC__ // Contains the circuits for the notes -#include "circuits/notes/note.hpp" -#include "types/joinsplit.hpp" +#include "libzeth/circuits/notes/note.hpp" +#include "libzeth/types/joinsplit.hpp" // Contains the definitions of the constants we use -#include "zeth.h" +#include "libzeth/zeth.h" // Contains functions for safe arithmetic -#include "safe_arithmetic.hpp" +#include "libzeth/circuits/safe_arithmetic.hpp" +#include "libzeth/types/merkle_tree_field.hpp" #include -#include -using namespace libzeth; +namespace libzeth +{ template< typename FieldT, @@ -721,4 +722,6 @@ public: } }; +} // namespace libzeth + #endif // __ZETH_CIRCUITS_JOINSPLIT_TCC__ diff --git a/src/circuits/merkle_tree/merkle_path_authenticator.hpp b/libzeth/circuits/merkle_tree/merkle_path_authenticator.hpp similarity index 93% rename from src/circuits/merkle_tree/merkle_path_authenticator.hpp rename to libzeth/circuits/merkle_tree/merkle_path_authenticator.hpp index 4987d68d7..a2857d9eb 100644 --- a/src/circuits/merkle_tree/merkle_path_authenticator.hpp +++ b/libzeth/circuits/merkle_tree/merkle_path_authenticator.hpp @@ -6,7 +6,7 @@ #ifndef __ZETH_CIRCUITS_MERKLE_PATH_AUTHENTICATOR_HPP__ #define __ZETH_CIRCUITS_MERKLE_PATH_AUTHENTICATOR_HPP__ -#include "merkle_path_compute.hpp" +#include "libzeth/circuits/merkle_tree/merkle_path_compute.hpp" namespace libzeth { @@ -49,6 +49,6 @@ class merkle_path_authenticator : public merkle_path_compute }; } // namespace libzeth -#include "merkle_path_authenticator.tcc" +#include "libzeth/circuits/merkle_tree/merkle_path_authenticator.tcc" #endif // __ZETH_CIRCUITS_MERKLE_PATH_AUTHENTICATOR_HPP__ \ No newline at end of file diff --git a/src/circuits/merkle_tree/merkle_path_authenticator.tcc b/libzeth/circuits/merkle_tree/merkle_path_authenticator.tcc similarity index 100% rename from src/circuits/merkle_tree/merkle_path_authenticator.tcc rename to libzeth/circuits/merkle_tree/merkle_path_authenticator.tcc diff --git a/src/circuits/merkle_tree/merkle_path_compute.hpp b/libzeth/circuits/merkle_tree/merkle_path_compute.hpp similarity index 92% rename from src/circuits/merkle_tree/merkle_path_compute.hpp rename to libzeth/circuits/merkle_tree/merkle_path_compute.hpp index bb99754cc..2a1ea1a7a 100644 --- a/src/circuits/merkle_tree/merkle_path_compute.hpp +++ b/libzeth/circuits/merkle_tree/merkle_path_compute.hpp @@ -6,7 +6,7 @@ #ifndef __ZETH_CIRCUITS_MERKLE_PATH_COMPUTE_HPP__ #define __ZETH_CIRCUITS_MERKLE_PATH_COMPUTE_HPP__ -#include "merkle_path_selector.hpp" +#include "libzeth/circuits/merkle_tree/merkle_path_selector.hpp" namespace libzeth { @@ -49,6 +49,6 @@ class merkle_path_compute : public libsnark::gadget }; } // namespace libzeth -#include "merkle_path_compute.tcc" +#include "libzeth/circuits/merkle_tree/merkle_path_compute.tcc" #endif // __ZETH_CIRCUITS_MERKLE_PATH_COMPUTE_HPP__ \ No newline at end of file diff --git a/src/circuits/merkle_tree/merkle_path_compute.tcc b/libzeth/circuits/merkle_tree/merkle_path_compute.tcc similarity index 100% rename from src/circuits/merkle_tree/merkle_path_compute.tcc rename to libzeth/circuits/merkle_tree/merkle_path_compute.tcc diff --git a/src/circuits/merkle_tree/merkle_path_selector.hpp b/libzeth/circuits/merkle_tree/merkle_path_selector.hpp similarity index 95% rename from src/circuits/merkle_tree/merkle_path_selector.hpp rename to libzeth/circuits/merkle_tree/merkle_path_selector.hpp index c45a19068..8186b28d2 100644 --- a/src/circuits/merkle_tree/merkle_path_selector.hpp +++ b/libzeth/circuits/merkle_tree/merkle_path_selector.hpp @@ -6,7 +6,7 @@ #ifndef __ZETH_CIRCUITS_MERKLE_PATH_SELECTOR_HPP___ #define __ZETH_CIRCUITS_MERKLE_PATH_SELECTOR_HPP___ -#include "depends/libsnark/libsnark/gadgetlib1/gadgets/basic_gadgets.hpp" +#include // Depending on the address bit, output the correct left/right inputs // for the merkle path authentication hash @@ -69,6 +69,6 @@ class merkle_path_selector : public libsnark::gadget }; } // namespace libzeth -#include "merkle_path_selector.tcc" +#include "libzeth/circuits/merkle_tree/merkle_path_selector.tcc" #endif // __ZETH_CIRCUITS_MERKLE_PATH_SELECTOR_HPP___ \ No newline at end of file diff --git a/src/circuits/merkle_tree/merkle_path_selector.tcc b/libzeth/circuits/merkle_tree/merkle_path_selector.tcc similarity index 100% rename from src/circuits/merkle_tree/merkle_path_selector.tcc rename to libzeth/circuits/merkle_tree/merkle_path_selector.tcc diff --git a/src/circuits/mimc/mimc.hpp b/libzeth/circuits/mimc/mimc.hpp similarity index 94% rename from src/circuits/mimc/mimc.hpp rename to libzeth/circuits/mimc/mimc.hpp index b7f9984f9..cf815a9c7 100644 --- a/src/circuits/mimc/mimc.hpp +++ b/libzeth/circuits/mimc/mimc.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_CIRCUITS_MIMC_HPP__ #define __ZETH_CIRCUITS_MIMC_HPP__ -#include "mimc_round.hpp" +#include "libzeth/circuits/mimc/mimc_round.hpp" // MiMCe7_permutation_gadget enforces correct computation of a MiMC permutation // with exponent 7 and rounds 91. It makes use of MiMCe7_round_gadget to enforce @@ -53,6 +53,6 @@ class MiMCe7_permutation_gadget : public libsnark::gadget }; } // namespace libzeth -#include "mimc.tcc" +#include "libzeth/circuits/mimc/mimc.tcc" #endif // __ZETH_CIRCUITS_MIMC_HPP__ \ No newline at end of file diff --git a/src/circuits/mimc/mimc.tcc b/libzeth/circuits/mimc/mimc.tcc similarity index 100% rename from src/circuits/mimc/mimc.tcc rename to libzeth/circuits/mimc/mimc.tcc diff --git a/src/circuits/mimc/mimcRoundConstantsGeneration.py b/libzeth/circuits/mimc/mimcRoundConstantsGeneration.py similarity index 100% rename from src/circuits/mimc/mimcRoundConstantsGeneration.py rename to libzeth/circuits/mimc/mimcRoundConstantsGeneration.py diff --git a/src/circuits/mimc/mimc_mp.hpp b/libzeth/circuits/mimc/mimc_mp.hpp similarity index 94% rename from src/circuits/mimc/mimc_mp.hpp rename to libzeth/circuits/mimc/mimc_mp.hpp index 62d88e865..46c92a587 100644 --- a/src/circuits/mimc/mimc_mp.hpp +++ b/libzeth/circuits/mimc/mimc_mp.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_CIRCUITS_MIMC_MP_HPP__ #define __ZETH_CIRCUITS_MIMC_MP_HPP__ -#include "mimc.hpp" +#include "libzeth/circuits/mimc/mimc.hpp" // This gadget implements the interface of the HashTreeT template // @@ -46,6 +46,6 @@ template class MiMC_mp_gadget : public libsnark::gadget }; } // namespace libzeth -#include "mimc_mp.tcc" +#include "libzeth/circuits/mimc/mimc_mp.tcc" #endif // __ZETH_CIRCUITS_MIMC_MP_HPP__ \ No newline at end of file diff --git a/src/circuits/mimc/mimc_mp.tcc b/libzeth/circuits/mimc/mimc_mp.tcc similarity index 100% rename from src/circuits/mimc/mimc_mp.tcc rename to libzeth/circuits/mimc/mimc_mp.tcc diff --git a/src/circuits/mimc/mimc_round.hpp b/libzeth/circuits/mimc/mimc_round.hpp similarity index 95% rename from src/circuits/mimc/mimc_round.hpp rename to libzeth/circuits/mimc/mimc_round.hpp index a9f8c8876..45cefed93 100644 --- a/src/circuits/mimc/mimc_round.hpp +++ b/libzeth/circuits/mimc/mimc_round.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_CIRCUITS_MIMC_ROUND_HPP__ #define __ZETH_CIRCUITS_MIMC_ROUND_HPP__ -#include "circuits/circuits-utils.hpp" +#include "libzeth/circuits/circuits_utils.hpp" #include @@ -62,6 +62,6 @@ class MiMCe7_round_gadget : public libsnark::gadget }; } // namespace libzeth -#include "mimc_round.tcc" +#include "libzeth/circuits/mimc/mimc_round.tcc" #endif // __ZETH_CIRCUITS_MIMC_ROUND_HPP__ \ No newline at end of file diff --git a/src/circuits/mimc/mimc_round.tcc b/libzeth/circuits/mimc/mimc_round.tcc similarity index 100% rename from src/circuits/mimc/mimc_round.tcc rename to libzeth/circuits/mimc/mimc_round.tcc diff --git a/src/circuits/notes/note.hpp b/libzeth/circuits/notes/note.hpp similarity index 93% rename from src/circuits/notes/note.hpp rename to libzeth/circuits/notes/note.hpp index a1bd5465a..7f6bc54d9 100644 --- a/src/circuits/notes/note.hpp +++ b/libzeth/circuits/notes/note.hpp @@ -5,18 +5,18 @@ // Content Taken and adapted from Zcash // https://github.com/zcash/zcash/blob/master/src/zcash/circuit/note.tcc -#include +#include "libzeth/circuits/merkle_tree/merkle_path_authenticator.hpp" // Get the prfs and commitments circuits -#include "circuits/commitments/commitment.hpp" -#include "circuits/prfs/prf.hpp" +#include "libzeth/circuits/commitments/commitment.hpp" +#include "libzeth/circuits/prfs/prf.hpp" // Get the utils functions -#include "circuits/circuits-utils.hpp" +#include "libzeth/circuits/circuits_utils.hpp" // Get the bits typedefs and associated functions -#include "types/bits.hpp" +#include "libzeth/types/bits.hpp" // Get the zeth_note class -#include "types/note.hpp" +#include "libzeth/types/note.hpp" namespace libzeth { @@ -127,6 +127,6 @@ class output_note_gadget : public note_gadget }; } // namespace libzeth -#include "circuits/notes/note.tcc" +#include "libzeth/circuits/notes/note.tcc" #endif // __ZETH_CIRCUITS_NOTE_HPP__ diff --git a/src/circuits/notes/note.tcc b/libzeth/circuits/notes/note.tcc similarity index 99% rename from src/circuits/notes/note.tcc rename to libzeth/circuits/notes/note.tcc index 7771516c8..462c07562 100644 --- a/src/circuits/notes/note.tcc +++ b/libzeth/circuits/notes/note.tcc @@ -5,7 +5,7 @@ // Content Taken and adapted from Zcash // https://github.com/zcash/zcash/blob/master/src/zcash/circuit/note.tcc -#include "note.hpp" +#include "libzeth/circuits/notes/note.hpp" namespace libzeth { diff --git a/src/circuits/prfs/prf.hpp b/libzeth/circuits/prfs/prf.hpp similarity index 98% rename from src/circuits/prfs/prf.hpp rename to libzeth/circuits/prfs/prf.hpp index e48010e5c..538d3e081 100644 --- a/src/circuits/prfs/prf.hpp +++ b/libzeth/circuits/prfs/prf.hpp @@ -5,7 +5,7 @@ // Content Taken and adapted from Zcash // https://github.com/zcash/zcash/blob/master/src/zcash/circuit/prfs.tcc -#include "circuits/circuits-utils.hpp" +#include "libzeth/circuits/circuits_utils.hpp" #include @@ -129,6 +129,6 @@ class PRF_rho_gadget : public PRF_gadget }; } // namespace libzeth -#include "circuits/prfs/prf.tcc" +#include "libzeth/circuits/prfs/prf.tcc" #endif // __ZETH_CIRCUITS_PRF_HPP__ diff --git a/src/circuits/prfs/prf.tcc b/libzeth/circuits/prfs/prf.tcc similarity index 100% rename from src/circuits/prfs/prf.tcc rename to libzeth/circuits/prfs/prf.tcc diff --git a/src/circuits/safe_arithmetic.cpp b/libzeth/circuits/safe_arithmetic.cpp similarity index 84% rename from src/circuits/safe_arithmetic.cpp rename to libzeth/circuits/safe_arithmetic.cpp index b39a98c53..8346be61f 100644 --- a/src/circuits/safe_arithmetic.cpp +++ b/libzeth/circuits/safe_arithmetic.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "safe_arithmetic.hpp" +#include "libzeth/circuits/safe_arithmetic.hpp" namespace libzeth { diff --git a/src/circuits/safe_arithmetic.hpp b/libzeth/circuits/safe_arithmetic.hpp similarity index 100% rename from src/circuits/safe_arithmetic.hpp rename to libzeth/circuits/safe_arithmetic.hpp diff --git a/src/circuits/sha256/sha256_ethereum.hpp b/libzeth/circuits/sha256/sha256_ethereum.hpp similarity index 89% rename from src/circuits/sha256/sha256_ethereum.hpp rename to libzeth/circuits/sha256/sha256_ethereum.hpp index 13cfb98d4..710703ce8 100644 --- a/src/circuits/sha256/sha256_ethereum.hpp +++ b/libzeth/circuits/sha256/sha256_ethereum.hpp @@ -7,17 +7,16 @@ // This gadget implements the interface of the HashT template -#include "libff/common/default_types/ec_pp.hpp" -#include "libsnark/gadgetlib1/gadget.hpp" -#include "libsnark/gadgetlib1/protoboard.hpp" -#include "libsnark/reductions/r1cs_to_qap/r1cs_to_qap.hpp" - #include +#include #include +#include #include #include #include #include +#include +#include namespace libzeth { @@ -62,6 +61,6 @@ class sha256_ethereum : public libsnark::gadget }; } // namespace libzeth -#include "circuits/sha256/sha256_ethereum.tcc" +#include "libzeth/circuits/sha256/sha256_ethereum.tcc" #endif // __ZETH_CIRCUITS_SHA256_ETHEREUM_HPP__ diff --git a/src/circuits/sha256/sha256_ethereum.tcc b/libzeth/circuits/sha256/sha256_ethereum.tcc similarity index 99% rename from src/circuits/sha256/sha256_ethereum.tcc rename to libzeth/circuits/sha256/sha256_ethereum.tcc index ef29e6782..f7ac1df57 100644 --- a/src/circuits/sha256/sha256_ethereum.tcc +++ b/libzeth/circuits/sha256/sha256_ethereum.tcc @@ -6,7 +6,7 @@ // https://gist.github.com/kobigurk/24c25e68219df87c348f1a78db51bb52 // Get the from_bits function -#include "circuits/circuits-utils.hpp" +#include "libzeth/circuits/circuits_utils.hpp" // This gadget implements the interface of the HashT template diff --git a/src/include_libsnark.hpp b/libzeth/include_libsnark.hpp similarity index 50% rename from src/include_libsnark.hpp rename to libzeth/include_libsnark.hpp index d111587b0..211d7e126 100644 --- a/src/include_libsnark.hpp +++ b/libzeth/include_libsnark.hpp @@ -8,15 +8,14 @@ #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" #if defined(ZKSNARK_GROTH16) -#include "libff/algebra/fields/field_utils.hpp" -#include "libsnark/common/default_types/r1cs_ppzksnark_pp.hpp" -#include "libsnark/gadgetlib1/pb_variable.hpp" -#include "libsnark/zk_proof_systems/ppzksnark/r1cs_gg_ppzksnark/r1cs_gg_ppzksnark.hpp" +#include +#include +#include +#include #elif defined(ZKSNARK_PGHR13) -#include "libff/algebra/fields/field_utils.hpp" -#include "libsnark/common/default_types/r1cs_ppzksnark_pp.hpp" -#include "libsnark/gadgetlib1/pb_variable.hpp" - +#include +#include +#include #include #else #error ZKSNARK not defined diff --git a/src/libsnark_helpers/debug_helpers.cpp b/libzeth/libsnark_helpers/debug_helpers.cpp similarity index 93% rename from src/libsnark_helpers/debug_helpers.cpp rename to libzeth/libsnark_helpers/debug_helpers.cpp index 721de1477..c1b12f28b 100644 --- a/src/libsnark_helpers/debug_helpers.cpp +++ b/libzeth/libsnark_helpers/debug_helpers.cpp @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "libsnark_helpers/debug_helpers.hpp" +#include "libzeth/libsnark_helpers/debug_helpers.hpp" -#include "util.hpp" +#include "libzeth/util.hpp" namespace libzeth { diff --git a/src/libsnark_helpers/debug_helpers.hpp b/libzeth/libsnark_helpers/debug_helpers.hpp similarity index 94% rename from src/libsnark_helpers/debug_helpers.hpp rename to libzeth/libsnark_helpers/debug_helpers.hpp index b302dab4a..e4ff1c139 100644 --- a/src/libsnark_helpers/debug_helpers.hpp +++ b/libzeth/libsnark_helpers/debug_helpers.hpp @@ -34,7 +34,6 @@ boost::filesystem::path get_path_to_debug_directory(); bool replace(std::string &str, const std::string &from, const std::string &to); } // namespace libzeth - -#include "libsnark_helpers/debug_helpers.tcc" +#include "libzeth/libsnark_helpers/debug_helpers.tcc" #endif // __ZETH_DEBUG_HELPERS_HPP__ diff --git a/src/libsnark_helpers/debug_helpers.tcc b/libzeth/libsnark_helpers/debug_helpers.tcc similarity index 100% rename from src/libsnark_helpers/debug_helpers.tcc rename to libzeth/libsnark_helpers/debug_helpers.tcc diff --git a/src/libsnark_helpers/extended_proof.hpp b/libzeth/libsnark_helpers/extended_proof.hpp similarity index 87% rename from src/libsnark_helpers/extended_proof.hpp rename to libzeth/libsnark_helpers/extended_proof.hpp index f60fbd315..fd1fffc26 100644 --- a/src/libsnark_helpers/extended_proof.hpp +++ b/libzeth/libsnark_helpers/extended_proof.hpp @@ -5,9 +5,9 @@ #ifndef __ZETH_EXTENDED_PROOF_HPP__ #define __ZETH_EXTENDED_PROOF_HPP__ -#include "debug_helpers.hpp" -#include "snarks_alias.hpp" -#include "zeth.h" +#include "libzeth/libsnark_helpers/debug_helpers.hpp" +#include "libzeth/snarks_alias.hpp" +#include "libzeth/zeth.h" namespace libzeth { @@ -42,6 +42,6 @@ template class extended_proof } // namespace libzeth -#include "libsnark_helpers/extended_proof.tcc" +#include "libzeth/libsnark_helpers/extended_proof.tcc" #endif diff --git a/src/libsnark_helpers/extended_proof.tcc b/libzeth/libsnark_helpers/extended_proof.tcc similarity index 98% rename from src/libsnark_helpers/extended_proof.tcc rename to libzeth/libsnark_helpers/extended_proof.tcc index eb091fdaa..ed962707f 100644 --- a/src/libsnark_helpers/extended_proof.tcc +++ b/libzeth/libsnark_helpers/extended_proof.tcc @@ -7,7 +7,7 @@ // Snark dependent implementation for generate_trusted_setup() and prove() // functions -#include "snarks_core_imports.hpp" +#include "libzeth/snarks_core_imports.hpp" namespace libzeth { diff --git a/src/libsnark_helpers/libsnark_helpers.hpp b/libzeth/libsnark_helpers/libsnark_helpers.hpp similarity index 86% rename from src/libsnark_helpers/libsnark_helpers.hpp rename to libzeth/libsnark_helpers/libsnark_helpers.hpp index b1b2c332b..ead1759c2 100644 --- a/src/libsnark_helpers/libsnark_helpers.hpp +++ b/libzeth/libsnark_helpers/libsnark_helpers.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_LIBSNARK_HELPERS_HPP__ #define __ZETH_LIBSNARK_HELPERS_HPP__ -#include "libsnark_helpers/debug_helpers.hpp" +#include "libzeth/libsnark_helpers/debug_helpers.hpp" #include #include @@ -20,10 +20,10 @@ // Contains required interfaces and types (keypair, proof, generator, prover, // verifier) -#include "extended_proof.hpp" -#include "snarks_alias.hpp" -#include "snarks_core_imports.hpp" -#include "zeth.h" +#include "libzeth/libsnark_helpers/extended_proof.hpp" +#include "libzeth/snarks_alias.hpp" +#include "libzeth/snarks_core_imports.hpp" +#include "libzeth/zeth.h" namespace libzeth { @@ -58,6 +58,6 @@ void r1cs_to_json( libsnark::protoboard> pb, boost::filesystem::path path = ""); } // namespace libzeth -#include "libsnark_helpers/libsnark_helpers.tcc" +#include "libzeth/libsnark_helpers/libsnark_helpers.tcc" #endif // __ZETH_LIBSNARK_HELPERS_HPP__ diff --git a/src/libsnark_helpers/libsnark_helpers.tcc b/libzeth/libsnark_helpers/libsnark_helpers.tcc similarity index 100% rename from src/libsnark_helpers/libsnark_helpers.tcc rename to libzeth/libsnark_helpers/libsnark_helpers.tcc diff --git a/src/snarks/groth16/api/response.hpp b/libzeth/snarks/groth16/api/response.hpp similarity index 80% rename from src/snarks/groth16/api/response.hpp rename to libzeth/snarks/groth16/api/response.hpp index 7f6361061..2ee33b233 100644 --- a/src/snarks/groth16/api/response.hpp +++ b/libzeth/snarks/groth16/api/response.hpp @@ -6,8 +6,8 @@ #define __ZETH_RESPONSE_HPP__ #include "api/prover.grpc.pb.h" -#include "libsnark_helpers/extended_proof.hpp" -#include "util_api.hpp" +#include "libzeth/libsnark_helpers/extended_proof.hpp" +#include "libzeth/util_api.hpp" namespace libzeth { @@ -21,6 +21,6 @@ void prepare_verification_key_response( prover_proto::VerificationKey *message); } // namespace libzeth -#include "response.tcc" +#include "libzeth/snarks/groth16/api/response.tcc" #endif // __ZETH_RESPONSE_HPP__ diff --git a/src/snarks/groth16/api/response.tcc b/libzeth/snarks/groth16/api/response.tcc similarity index 100% rename from src/snarks/groth16/api/response.tcc rename to libzeth/snarks/groth16/api/response.tcc diff --git a/src/snarks/groth16/core/computation.hpp b/libzeth/snarks/groth16/core/computation.hpp similarity index 84% rename from src/snarks/groth16/core/computation.hpp rename to libzeth/snarks/groth16/core/computation.hpp index 129758b52..3d29d7bfd 100644 --- a/src/snarks/groth16/core/computation.hpp +++ b/libzeth/snarks/groth16/core/computation.hpp @@ -5,8 +5,8 @@ #ifndef __ZETH_COMPUTATION_HPP__ #define __ZETH_COMPUTATION_HPP__ -#include "libsnark_helpers/debug_helpers.hpp" -#include "libsnark_helpers/extended_proof.hpp" +#include "libzeth/libsnark_helpers/debug_helpers.hpp" +#include "libzeth/libsnark_helpers/extended_proof.hpp" #include #include @@ -30,6 +30,6 @@ bool verify( } // namespace libzeth -#include "snarks/groth16/core/computation.tcc" +#include "libzeth/snarks/groth16/core/computation.tcc" #endif // __ZETH_COMPUTATION_HPP__ diff --git a/src/snarks/groth16/core/computation.tcc b/libzeth/snarks/groth16/core/computation.tcc similarity index 97% rename from src/snarks/groth16/core/computation.tcc rename to libzeth/snarks/groth16/core/computation.tcc index 515439e28..3a2649b6a 100644 --- a/src/snarks/groth16/core/computation.tcc +++ b/libzeth/snarks/groth16/core/computation.tcc @@ -5,7 +5,7 @@ #ifndef __ZETH_COMPUTATION_TCC__ #define __ZETH_COMPUTATION_TCC__ -#include "computation.hpp" +#include "libzeth/snarks/groth16/core/computation.hpp" namespace libzeth { diff --git a/src/snarks/groth16/core/helpers.hpp b/libzeth/snarks/groth16/core/helpers.hpp similarity index 90% rename from src/snarks/groth16/core/helpers.hpp rename to libzeth/snarks/groth16/core/helpers.hpp index 5a511dcfd..096438f0a 100644 --- a/src/snarks/groth16/core/helpers.hpp +++ b/libzeth/snarks/groth16/core/helpers.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_HELPERS_HPP__ #define __ZETH_HELPERS_HPP__ -#include "libsnark_helpers/debug_helpers.hpp" +#include "libzeth/libsnark_helpers/debug_helpers.hpp" #include #include @@ -36,6 +36,6 @@ void proof_to_json( libsnark::r1cs_gg_ppzksnark_proof proof, boost::filesystem::path path); } // namespace libzeth -#include "snarks/groth16/core/helpers.tcc" +#include "libzeth/snarks/groth16/core/helpers.tcc" #endif // __ZETH_HELPERS_HPP__ diff --git a/src/snarks/groth16/core/helpers.tcc b/libzeth/snarks/groth16/core/helpers.tcc similarity index 100% rename from src/snarks/groth16/core/helpers.tcc rename to libzeth/snarks/groth16/core/helpers.tcc diff --git a/src/snarks/groth16/mpc/chacha_rng.cpp b/libzeth/snarks/groth16/mpc/chacha_rng.cpp similarity index 98% rename from src/snarks/groth16/mpc/chacha_rng.cpp rename to libzeth/snarks/groth16/mpc/chacha_rng.cpp index b55933318..fe06717ed 100644 --- a/src/snarks/groth16/mpc/chacha_rng.cpp +++ b/libzeth/snarks/groth16/mpc/chacha_rng.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "snarks/groth16/mpc/chacha_rng.hpp" +#include "libzeth/snarks/groth16/mpc/chacha_rng.hpp" #include #include diff --git a/src/snarks/groth16/mpc/chacha_rng.hpp b/libzeth/snarks/groth16/mpc/chacha_rng.hpp similarity index 100% rename from src/snarks/groth16/mpc/chacha_rng.hpp rename to libzeth/snarks/groth16/mpc/chacha_rng.hpp diff --git a/src/snarks/groth16/mpc/evaluator_from_lagrange.hpp b/libzeth/snarks/groth16/mpc/evaluator_from_lagrange.hpp similarity index 90% rename from src/snarks/groth16/mpc/evaluator_from_lagrange.hpp rename to libzeth/snarks/groth16/mpc/evaluator_from_lagrange.hpp index f60f503c4..f6a98b6dd 100644 --- a/src/snarks/groth16/mpc/evaluator_from_lagrange.hpp +++ b/libzeth/snarks/groth16/mpc/evaluator_from_lagrange.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_SNARKS_GROTH16_EVALUATOR_FROM_LAGRANGE_HPP__ #define __ZETH_SNARKS_GROTH16_EVALUATOR_FROM_LAGRANGE_HPP__ -#include "include_libsnark.hpp" +#include "libzeth/include_libsnark.hpp" #include @@ -32,6 +32,6 @@ template class evaluator_from_lagrange }; } // namespace libzeth -#include "evaluator_from_lagrange.tcc" +#include "libzeth/snarks/groth16/mpc/evaluator_from_lagrange.tcc" #endif // __ZETH_SNARKS_GROTH16_EVALUATOR_FROM_LAGRANGE_HPP__ diff --git a/src/snarks/groth16/mpc/evaluator_from_lagrange.tcc b/libzeth/snarks/groth16/mpc/evaluator_from_lagrange.tcc similarity index 93% rename from src/snarks/groth16/mpc/evaluator_from_lagrange.tcc rename to libzeth/snarks/groth16/mpc/evaluator_from_lagrange.tcc index aa491cca4..3d7c0db0c 100644 --- a/src/snarks/groth16/mpc/evaluator_from_lagrange.tcc +++ b/libzeth/snarks/groth16/mpc/evaluator_from_lagrange.tcc @@ -5,8 +5,8 @@ #ifndef __ZETH_SNARKS_GROTH16_EVALUATOR_FROM_LAGRANGE_TCC__ #define __ZETH_SNARKS_GROTH16_EVALUATOR_FROM_LAGRANGE_TCC__ -#include "evaluator_from_lagrange.hpp" -#include "multi_exp.hpp" +#include "libzeth/snarks/groth16/mpc/evaluator_from_lagrange.hpp" +#include "libzeth/snarks/groth16/mpc/multi_exp.hpp" namespace libzeth { diff --git a/src/snarks/groth16/mpc/hash_utils.cpp b/libzeth/snarks/groth16/mpc/hash_utils.cpp similarity index 97% rename from src/snarks/groth16/mpc/hash_utils.cpp rename to libzeth/snarks/groth16/mpc/hash_utils.cpp index e960f1cb1..e668f8030 100644 --- a/src/snarks/groth16/mpc/hash_utils.cpp +++ b/libzeth/snarks/groth16/mpc/hash_utils.cpp @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "snarks/groth16/mpc/hash_utils.hpp" +#include "libzeth/snarks/groth16/mpc/hash_utils.hpp" -#include "util.hpp" +#include "libzeth/util.hpp" namespace libzeth { diff --git a/src/snarks/groth16/mpc/hash_utils.hpp b/libzeth/snarks/groth16/mpc/hash_utils.hpp similarity index 100% rename from src/snarks/groth16/mpc/hash_utils.hpp rename to libzeth/snarks/groth16/mpc/hash_utils.hpp diff --git a/src/snarks/groth16/mpc/mpc_utils.hpp b/libzeth/snarks/groth16/mpc/mpc_utils.hpp similarity index 96% rename from src/snarks/groth16/mpc/mpc_utils.hpp rename to libzeth/snarks/groth16/mpc/mpc_utils.hpp index 900e3f408..4cce19076 100644 --- a/src/snarks/groth16/mpc/mpc_utils.hpp +++ b/libzeth/snarks/groth16/mpc/mpc_utils.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_SNARKS_GROTH16_MPC_UTILS_HPP__ #define __ZETH_SNARKS_GROTH16_MPC_UTILS_HPP__ -#include "include_libsnark.hpp" +#include "libzeth/include_libsnark.hpp" #include @@ -75,7 +75,6 @@ srs_mpc_layer_L1 mpc_compute_linearcombination( const libsnark::qap_instance> &qap); } // namespace libzeth - -#include "snarks/groth16/mpc/mpc_utils.tcc" +#include "libzeth/snarks/groth16/mpc/mpc_utils.tcc" #endif // __ZETH_SNARKS_GROTH16_MPC_UTILS_HPP__ diff --git a/src/snarks/groth16/mpc/mpc_utils.tcc b/libzeth/snarks/groth16/mpc/mpc_utils.tcc similarity index 96% rename from src/snarks/groth16/mpc/mpc_utils.tcc rename to libzeth/snarks/groth16/mpc/mpc_utils.tcc index a96f78a5d..6749893db 100644 --- a/src/snarks/groth16/mpc/mpc_utils.tcc +++ b/libzeth/snarks/groth16/mpc/mpc_utils.tcc @@ -5,11 +5,11 @@ #ifndef __ZETH_SNARKS_GROTH16_MPC_UTILS_TCC__ #define __ZETH_SNARKS_GROTH16_MPC_UTILS_TCC__ -#include "evaluator_from_lagrange.hpp" -#include "mpc_utils.hpp" -#include "multi_exp.hpp" -#include "phase2.hpp" -#include "util.hpp" +#include "libzeth/snarks/groth16/mpc/evaluator_from_lagrange.hpp" +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/multi_exp.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" +#include "libzeth/util.hpp" #include #include diff --git a/src/snarks/groth16/mpc/multi_exp.hpp b/libzeth/snarks/groth16/mpc/multi_exp.hpp similarity index 88% rename from src/snarks/groth16/mpc/multi_exp.hpp rename to libzeth/snarks/groth16/mpc/multi_exp.hpp index 4147bce6c..ef68acf57 100644 --- a/src/snarks/groth16/mpc/multi_exp.hpp +++ b/libzeth/snarks/groth16/mpc/multi_exp.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_SNARKS_GRPOTH16_MULTI_EXP_HPP__ #define __ZETH_SNARKS_GRPOTH16_MULTI_EXP_HPP__ -#include "include_libsnark.hpp" +#include "libzeth/include_libsnark.hpp" namespace libzeth { @@ -22,7 +22,6 @@ GroupT multi_exp( const std::vector &gs, const libff::Fr_vector &fs); } // namespace libzeth - -#include "snarks/groth16/mpc/multi_exp.tcc" +#include "libzeth/snarks/groth16/mpc/multi_exp.tcc" #endif // __ZETH_SNARKS_GRPOTH16_MULTI_EXP_HPP__ diff --git a/src/snarks/groth16/mpc/multi_exp.tcc b/libzeth/snarks/groth16/mpc/multi_exp.tcc similarity index 96% rename from src/snarks/groth16/mpc/multi_exp.tcc rename to libzeth/snarks/groth16/mpc/multi_exp.tcc index 21855e54f..8a38434ac 100644 --- a/src/snarks/groth16/mpc/multi_exp.tcc +++ b/libzeth/snarks/groth16/mpc/multi_exp.tcc @@ -5,7 +5,7 @@ #ifndef __ZETH_SNARKS_GROTH16_MULTI_EXP_TCC__ #define __ZETH_SNARKS_GROTH16_MULTI_EXP_TCC__ -#include "snarks/groth16/mpc/multi_exp.hpp" +#include "libzeth/snarks/groth16/mpc/multi_exp.hpp" namespace libzeth { diff --git a/src/snarks/groth16/mpc/phase2.cpp b/libzeth/snarks/groth16/mpc/phase2.cpp similarity index 97% rename from src/snarks/groth16/mpc/phase2.cpp rename to libzeth/snarks/groth16/mpc/phase2.cpp index eeb5af914..78fabeb45 100644 --- a/src/snarks/groth16/mpc/phase2.cpp +++ b/libzeth/snarks/groth16/mpc/phase2.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "snarks/groth16/mpc/phase2.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" namespace libzeth { diff --git a/src/snarks/groth16/mpc/phase2.hpp b/libzeth/snarks/groth16/mpc/phase2.hpp similarity index 98% rename from src/snarks/groth16/mpc/phase2.hpp rename to libzeth/snarks/groth16/mpc/phase2.hpp index 17c2f35d9..15d41a43d 100644 --- a/src/snarks/groth16/mpc/phase2.hpp +++ b/libzeth/snarks/groth16/mpc/phase2.hpp @@ -5,8 +5,8 @@ #ifndef __ZETH_SNARKS_GROTH16_MPC_PHASE2_HPP__ #define __ZETH_SNARKS_GROTH16_MPC_PHASE2_HPP__ -#include "include_libsnark.hpp" -#include "snarks/groth16/mpc/hash_utils.hpp" +#include "libzeth/include_libsnark.hpp" +#include "libzeth/snarks/groth16/mpc/hash_utils.hpp" // Structures and operations related to the "Phase 2" MPC described in // [BoweGM17]. Parts of the implementation use techniques from the @@ -314,7 +314,6 @@ template libsnark::r1cs_gg_ppzksnark_keypair mpc_read_keypair(std::istream &in); } // namespace libzeth - -#include "snarks/groth16/mpc/phase2.tcc" +#include "libzeth/snarks/groth16/mpc/phase2.tcc" #endif // __ZETH_SNARKS_GROTH16_MPC_PHASE2_HPP__ diff --git a/src/snarks/groth16/mpc/phase2.tcc b/libzeth/snarks/groth16/mpc/phase2.tcc similarity index 98% rename from src/snarks/groth16/mpc/phase2.tcc rename to libzeth/snarks/groth16/mpc/phase2.tcc index 4caa2137c..d9a5764a5 100644 --- a/src/snarks/groth16/mpc/phase2.tcc +++ b/libzeth/snarks/groth16/mpc/phase2.tcc @@ -5,13 +5,14 @@ #ifndef __ZETH_SNARKS_GROTH16_MPC_PHASE2_TCC__ #define __ZETH_SNARKS_GROTH16_MPC_PHASE2_TCC__ -#include "phase2.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" // This comment preserves include order under clang-format. -#include "chacha_rng.hpp" -#include "libff/common/rng.hpp" -#include "mpc_utils.hpp" -#include "powersoftau_utils.hpp" -#include "util.hpp" +#include "libzeth/snarks/groth16/mpc/chacha_rng.hpp" +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" +#include "libzeth/util.hpp" + +#include namespace libzeth { diff --git a/src/snarks/groth16/mpc/powersoftau_utils.cpp b/libzeth/snarks/groth16/mpc/powersoftau_utils.cpp similarity index 99% rename from src/snarks/groth16/mpc/powersoftau_utils.cpp rename to libzeth/snarks/groth16/mpc/powersoftau_utils.cpp index 7b7dc50dc..8cf51e9ea 100644 --- a/src/snarks/groth16/mpc/powersoftau_utils.cpp +++ b/libzeth/snarks/groth16/mpc/powersoftau_utils.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "powersoftau_utils.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" namespace libzeth { diff --git a/src/snarks/groth16/mpc/powersoftau_utils.hpp b/libzeth/snarks/groth16/mpc/powersoftau_utils.hpp similarity index 98% rename from src/snarks/groth16/mpc/powersoftau_utils.hpp rename to libzeth/snarks/groth16/mpc/powersoftau_utils.hpp index 42055fe59..2fec899c2 100644 --- a/src/snarks/groth16/mpc/powersoftau_utils.hpp +++ b/libzeth/snarks/groth16/mpc/powersoftau_utils.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_SNARKS_GROTH_POWERSOFTAU_UTILS_HPP__ #define __ZETH_SNARKS_GROTH_POWERSOFTAU_UTILS_HPP__ -#include "include_libsnark.hpp" +#include "libzeth/include_libsnark.hpp" #include @@ -173,7 +173,6 @@ srs_lagrange_evaluations powersoftau_compute_lagrange_evaluations( const srs_powersoftau &pot, const size_t n); } // namespace libzeth - -#include "snarks/groth16/mpc/powersoftau_utils.tcc" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.tcc" #endif // __ZETH_SNARKS_GROTH_POWERSOFTAU_UTILS_HPP__ diff --git a/src/snarks/groth16/mpc/powersoftau_utils.tcc b/libzeth/snarks/groth16/mpc/powersoftau_utils.tcc similarity index 99% rename from src/snarks/groth16/mpc/powersoftau_utils.tcc rename to libzeth/snarks/groth16/mpc/powersoftau_utils.tcc index 8745d0b44..9704d0625 100644 --- a/src/snarks/groth16/mpc/powersoftau_utils.tcc +++ b/libzeth/snarks/groth16/mpc/powersoftau_utils.tcc @@ -5,8 +5,8 @@ #ifndef __ZETH_SNARKS_GROTH16_POWERSOFTAU_UTILS_TCC__ #define __ZETH_SNARKS_GROTH16_POWERSOFTAU_UTILS_TCC__ -#include "snarks/groth16/mpc/powersoftau_utils.hpp" -#include "util.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" +#include "libzeth/util.hpp" #include diff --git a/src/snarks/pghr13/api/response.hpp b/libzeth/snarks/pghr13/api/response.hpp similarity index 80% rename from src/snarks/pghr13/api/response.hpp rename to libzeth/snarks/pghr13/api/response.hpp index 29dd520ac..490aec66a 100644 --- a/src/snarks/pghr13/api/response.hpp +++ b/libzeth/snarks/pghr13/api/response.hpp @@ -6,8 +6,8 @@ #define __ZETH_RESPONSE_HPP__ #include "api/prover.grpc.pb.h" -#include "libsnark_helpers/extended_proof.hpp" -#include "util_api.hpp" +#include "libzeth/libsnark_helpers/extended_proof.hpp" +#include "libzeth/util_api.hpp" namespace libzeth { @@ -21,6 +21,6 @@ void prepare_verification_key_response( prover_proto::VerificationKey *message); } // namespace libzeth -#include "snarks/pghr13/api/response.tcc" +#include "libzeth/snarks/pghr13/api/response.tcc" #endif // __ZETH_RESPONSE_HPP__ diff --git a/src/snarks/pghr13/api/response.tcc b/libzeth/snarks/pghr13/api/response.tcc similarity index 100% rename from src/snarks/pghr13/api/response.tcc rename to libzeth/snarks/pghr13/api/response.tcc diff --git a/src/snarks/pghr13/core/computation.hpp b/libzeth/snarks/pghr13/core/computation.hpp similarity index 88% rename from src/snarks/pghr13/core/computation.hpp rename to libzeth/snarks/pghr13/core/computation.hpp index b44124c8e..21729737e 100644 --- a/src/snarks/pghr13/core/computation.hpp +++ b/libzeth/snarks/pghr13/core/computation.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_COMPUTATION_HPP__ #define __ZETH_COMPUTATION_HPP__ -#include "libsnark_helpers/extended_proof.hpp" +#include "libzeth/libsnark_helpers/extended_proof.hpp" #include #include @@ -26,6 +26,6 @@ bool verify( const libsnark::r1cs_ppzksnark_verification_key &verification_key); } // namespace libzeth -#include "snarks/pghr13/core/computation.tcc" +#include "libzeth/snarks/pghr13/core/computation.tcc" #endif // __ZETH_COMPUTATION_HPP__ diff --git a/src/snarks/pghr13/core/computation.tcc b/libzeth/snarks/pghr13/core/computation.tcc similarity index 100% rename from src/snarks/pghr13/core/computation.tcc rename to libzeth/snarks/pghr13/core/computation.tcc diff --git a/src/snarks/pghr13/core/helpers.hpp b/libzeth/snarks/pghr13/core/helpers.hpp similarity index 90% rename from src/snarks/pghr13/core/helpers.hpp rename to libzeth/snarks/pghr13/core/helpers.hpp index 23dd37c95..0d2b245fd 100644 --- a/src/snarks/pghr13/core/helpers.hpp +++ b/libzeth/snarks/pghr13/core/helpers.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_HELPERS_HPP__ #define __ZETH_HELPERS_HPP__ -#include "libsnark_helpers/debug_helpers.hpp" +#include "libzeth/libsnark_helpers/debug_helpers.hpp" #include #include @@ -32,6 +32,6 @@ void proof_to_json( libsnark::r1cs_ppzksnark_proof proof, boost::filesystem::path path); } // namespace libzeth -#include "snarks/pghr13/core/helpers.tcc" +#include "libzeth/snarks/pghr13/core/helpers.tcc" #endif // __ZETH_HELPERS_HPP__ diff --git a/src/snarks/pghr13/core/helpers.tcc b/libzeth/snarks/pghr13/core/helpers.tcc similarity index 100% rename from src/snarks/pghr13/core/helpers.tcc rename to libzeth/snarks/pghr13/core/helpers.tcc diff --git a/src/snarks_alias.hpp b/libzeth/snarks_alias.hpp similarity index 100% rename from src/snarks_alias.hpp rename to libzeth/snarks_alias.hpp diff --git a/src/snarks_api_imports.hpp b/libzeth/snarks_api_imports.hpp similarity index 78% rename from src/snarks_api_imports.hpp rename to libzeth/snarks_api_imports.hpp index 1c6bd7fc3..b71a102f8 100644 --- a/src/snarks_api_imports.hpp +++ b/libzeth/snarks_api_imports.hpp @@ -6,9 +6,9 @@ #define __ZETH_SNARKS_API_IMPORTS_HPP__ #ifdef ZKSNARK_PGHR13 -#include "snarks/pghr13/api/response.hpp" +#include "libzeth/snarks/pghr13/api/response.hpp" #elif ZKSNARK_GROTH16 -#include "snarks/groth16/api/response.hpp" +#include "libzeth/snarks/groth16/api/response.hpp" #else #error You must define one of the SNARK_* symbols indicated into the CMakelists.txt file. #endif diff --git a/src/snarks_core_imports.hpp b/libzeth/snarks_core_imports.hpp similarity index 54% rename from src/snarks_core_imports.hpp rename to libzeth/snarks_core_imports.hpp index 69454a60f..2676f8958 100644 --- a/src/snarks_core_imports.hpp +++ b/libzeth/snarks_core_imports.hpp @@ -6,13 +6,13 @@ #define __ZETH_SNARKS_CORE_IMPORTS_HPP__ #ifdef ZKSNARK_PGHR13 -#include "snarks/pghr13/core/computation.hpp" -#include "snarks/pghr13/core/helpers.hpp" +#include "libzeth/snarks/pghr13/core/computation.hpp" +#include "libzeth/snarks/pghr13/core/helpers.hpp" #elif ZKSNARK_GROTH16 -#include "snarks/groth16/core/computation.hpp" -#include "snarks/groth16/core/helpers.hpp" -#include "snarks/groth16/mpc/mpc_utils.hpp" -#include "snarks/groth16/mpc/phase2.hpp" +#include "libzeth/snarks/groth16/core/computation.hpp" +#include "libzeth/snarks/groth16/core/helpers.hpp" +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" #else #error You must define one of the SNARK_* symbols indicated into the CMakelists.txt file. #endif diff --git a/src/test/README.md b/libzeth/test/README.md similarity index 100% rename from src/test/README.md rename to libzeth/test/README.md diff --git a/src/test/binary_operation_test.cpp b/libzeth/test/binary_operation_test.cpp similarity index 98% rename from src/test/binary_operation_test.cpp rename to libzeth/test/binary_operation_test.cpp index 2ce546927..fa02f6167 100644 --- a/src/test/binary_operation_test.cpp +++ b/libzeth/test/binary_operation_test.cpp @@ -2,15 +2,15 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuits/binary_operation.hpp" -#include "snarks_alias.hpp" +#include "libzeth/circuits/binary_operation.hpp" +#include "libzeth/snarks_alias.hpp" #include "gtest/gtest.h" #include // Access the `from_bits` function and other utils -#include "circuits/circuits-utils.hpp" -#include "util.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/util.hpp" using namespace libzeth; diff --git a/src/test/blake2s_test.cpp b/libzeth/test/blake2s_test.cpp similarity index 97% rename from src/test/blake2s_test.cpp rename to libzeth/test/blake2s_test.cpp index 11be9ed86..10b630675 100644 --- a/src/test/blake2s_test.cpp +++ b/libzeth/test/blake2s_test.cpp @@ -2,16 +2,16 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuits/blake2s/blake2s_comp.hpp" -#include "circuits/blake2s/g_primitive.hpp" -#include "snarks_alias.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/circuits/blake2s/g_primitive.hpp" +#include "libzeth/snarks_alias.hpp" #include "gtest/gtest.h" #include // Access the `from_bits` function and other utils -#include "circuits/circuits-utils.hpp" -#include "util.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/util.hpp" using namespace libsnark; using namespace libzeth; diff --git a/src/test/commitments_test.cpp b/libzeth/test/commitments_test.cpp similarity index 97% rename from src/test/commitments_test.cpp rename to libzeth/test/commitments_test.cpp index 6bf255359..02059a1a5 100644 --- a/src/test/commitments_test.cpp +++ b/libzeth/test/commitments_test.cpp @@ -11,14 +11,14 @@ #include // Header to use the blake2s gadget -#include "circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" // Access the `from_bits` function and other utils -#include "circuits/circuits-utils.hpp" -#include "util.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/util.hpp" // Get the gadget to test -#include "circuits/commitments/commitment.hpp" +#include "libzeth/circuits/commitments/commitment.hpp" using namespace libzeth; diff --git a/src/test/hex_to_field_test.cpp b/libzeth/test/hex_to_field_test.cpp similarity index 98% rename from src/test/hex_to_field_test.cpp rename to libzeth/test/hex_to_field_test.cpp index 551582dfd..16b5542a8 100644 --- a/src/test/hex_to_field_test.cpp +++ b/libzeth/test/hex_to_field_test.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "util.hpp" +#include "libzeth/util.hpp" #include "gtest/gtest.h" #include @@ -11,7 +11,7 @@ // Access zeth configuration constants #include "assert.h" -#include "zeth.h" +#include "libzeth/zeth.h" // Instantiation of the templates for the tests typedef libff::default_ec_pp ppT; diff --git a/src/test/merkle_tree_test.cpp b/libzeth/test/merkle_tree_test.cpp similarity index 97% rename from src/test/merkle_tree_test.cpp rename to libzeth/test/merkle_tree_test.cpp index 46aff2d4b..2fff1cdaf 100644 --- a/src/test/merkle_tree_test.cpp +++ b/libzeth/test/merkle_tree_test.cpp @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuits/merkle_tree/merkle_path_authenticator.hpp" -#include "circuits/merkle_tree/merkle_path_selector.hpp" -#include "circuits/mimc/mimc_mp.hpp" +#include "libzeth/circuits/merkle_tree/merkle_path_authenticator.hpp" +#include "libzeth/circuits/merkle_tree/merkle_path_selector.hpp" +#include "libzeth/circuits/mimc/mimc_mp.hpp" #include "gtest/gtest.h" #include diff --git a/src/test/mimc_mp_test.cpp b/libzeth/test/mimc_mp_test.cpp similarity index 99% rename from src/test/mimc_mp_test.cpp rename to libzeth/test/mimc_mp_test.cpp index 19f3a5846..3812f519e 100644 --- a/src/test/mimc_mp_test.cpp +++ b/libzeth/test/mimc_mp_test.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuits/mimc/mimc_mp.hpp" +#include "libzeth/circuits/mimc/mimc_mp.hpp" #include "gtest/gtest.h" #include diff --git a/src/test/mpc_test.cpp b/libzeth/test/mpc_test.cpp similarity index 98% rename from src/test/mpc_test.cpp rename to libzeth/test/mpc_test.cpp index 8afb9a8cb..36dcdc27a 100644 --- a/src/test/mpc_test.cpp +++ b/libzeth/test/mpc_test.cpp @@ -2,21 +2,22 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuit_types.hpp" -#include "circuits/sha256/sha256_ethereum.hpp" -#include "snarks/groth16/mpc/chacha_rng.hpp" -#include "snarks/groth16/mpc/evaluator_from_lagrange.hpp" -#include "snarks/groth16/mpc/mpc_utils.hpp" -#include "snarks/groth16/mpc/multi_exp.hpp" -#include "snarks/groth16/mpc/phase2.hpp" -#include "snarks/groth16/mpc/powersoftau_utils.hpp" -#include "test/simple_test.hpp" -#include "util.hpp" +#include "libzeth/circuit_types.hpp" +#include "libzeth/circuits/sha256/sha256_ethereum.hpp" +#include "libzeth/snarks/groth16/mpc/chacha_rng.hpp" +#include "libzeth/snarks/groth16/mpc/evaluator_from_lagrange.hpp" +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/multi_exp.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" +#include "libzeth/test/simple_test.hpp" +#include "libzeth/util.hpp" #include #include #include +using namespace libzeth; using namespace libsnark; using Fr = libff::Fr; diff --git a/src/test/mpc_test_hash.cpp b/libzeth/test/mpc_test_hash.cpp similarity index 97% rename from src/test/mpc_test_hash.cpp rename to libzeth/test/mpc_test_hash.cpp index b6b42c8ee..4c12591bf 100644 --- a/src/test/mpc_test_hash.cpp +++ b/libzeth/test/mpc_test_hash.cpp @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "snarks/groth16/mpc/hash_utils.hpp" -#include "util.hpp" +#include "libzeth/snarks/groth16/mpc/hash_utils.hpp" +#include "libzeth/util.hpp" #include diff --git a/src/test/note_test.cpp b/libzeth/test/note_test.cpp similarity index 96% rename from src/test/note_test.cpp rename to libzeth/test/note_test.cpp index c293b4216..a12d7ca3d 100644 --- a/src/test/note_test.cpp +++ b/libzeth/test/note_test.cpp @@ -8,24 +8,24 @@ #include // Header to use the merkle tree data structure -#include "src/types/merkle_tree_field.hpp" +#include "libzeth/types/merkle_tree_field.hpp" // Header to use the blake2s gadget -#include "circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" // Access the `from_bits` function and other utils -#include "circuits/circuits-utils.hpp" -#include "util.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/util.hpp" // Access the defined constants -#include "zeth.h" +#include "libzeth/zeth.h" // Bring the types in scope -#include "types/bits.hpp" -#include "types/note.hpp" +#include "libzeth/types/bits.hpp" +#include "libzeth/types/note.hpp" // Gadget to test -#include "circuits/notes/note.hpp" +#include "libzeth/circuits/notes/note.hpp" using namespace libzeth; diff --git a/src/test/packed_addition_test.cpp b/libzeth/test/packed_addition_test.cpp similarity index 98% rename from src/test/packed_addition_test.cpp rename to libzeth/test/packed_addition_test.cpp index a13ee38a7..0a76720e1 100644 --- a/src/test/packed_addition_test.cpp +++ b/libzeth/test/packed_addition_test.cpp @@ -10,14 +10,14 @@ #include // Access zeth configuration constants -#include "zeth.h" +#include "libzeth/zeth.h" // Include the type we need -#include "circuits/circuits-utils.hpp" -#include "circuits/notes/note.hpp" -#include "types/bits.hpp" -#include "types/joinsplit.hpp" -#include "types/note.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/circuits/notes/note.hpp" +#include "libzeth/types/bits.hpp" +#include "libzeth/types/joinsplit.hpp" +#include "libzeth/types/note.hpp" using namespace libzeth; diff --git a/src/test/powersoftau_test.cpp b/libzeth/test/powersoftau_test.cpp similarity index 99% rename from src/test/powersoftau_test.cpp rename to libzeth/test/powersoftau_test.cpp index aee890c8e..8503e7a31 100644 --- a/src/test/powersoftau_test.cpp +++ b/libzeth/test/powersoftau_test.cpp @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "snarks/groth16/mpc/evaluator_from_lagrange.hpp" -#include "snarks/groth16/mpc/powersoftau_utils.hpp" -#include "util.hpp" +#include "libzeth/snarks/groth16/mpc/evaluator_from_lagrange.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" +#include "libzeth/util.hpp" #include #include diff --git a/src/test/prfs_test.cpp b/libzeth/test/prfs_test.cpp similarity index 99% rename from src/test/prfs_test.cpp rename to libzeth/test/prfs_test.cpp index 15e7cb167..3d25ab3e1 100644 --- a/src/test/prfs_test.cpp +++ b/libzeth/test/prfs_test.cpp @@ -16,14 +16,14 @@ #include // Header to use the blake2s gadget -#include "circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" // Access the `from_bits` function and other utils -#include "circuits/circuits-utils.hpp" -#include "util.hpp" +#include "libzeth/circuits/circuits_utils.hpp" +#include "libzeth/util.hpp" // Gadget to test -#include "circuits/prfs/prf.hpp" +#include "libzeth/circuits/prfs/prf.hpp" using namespace libsnark; using namespace libzeth; diff --git a/src/test/prover_test.cpp b/libzeth/test/prover_test.cpp similarity index 99% rename from src/test/prover_test.cpp rename to libzeth/test/prover_test.cpp index b3b3ddd2a..105ac3a9a 100644 --- a/src/test/prover_test.cpp +++ b/libzeth/test/prover_test.cpp @@ -14,15 +14,15 @@ // Have access to a chrono to measure the rough time of execution of a set of // instructions -#include "snarks_alias.hpp" +#include "libzeth/snarks_alias.hpp" #include // Import only the core components of the SNARK (not the API components) -#include "circuit_wrapper.hpp" -#include "circuits/blake2s/blake2s_comp.hpp" -#include "libsnark_helpers/libsnark_helpers.hpp" -#include "snarks_core_imports.hpp" -#include "util.hpp" +#include "libzeth/circuit_wrapper.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/libsnark_helpers/libsnark_helpers.hpp" +#include "libzeth/snarks_core_imports.hpp" +#include "libzeth/util.hpp" using namespace libzeth; diff --git a/src/test/sha256_test.cpp b/libzeth/test/sha256_test.cpp similarity index 99% rename from src/test/sha256_test.cpp rename to libzeth/test/sha256_test.cpp index 8d839bd8b..7aae2d25e 100644 --- a/src/test/sha256_test.cpp +++ b/libzeth/test/sha256_test.cpp @@ -19,7 +19,7 @@ #include "circuits/sha256/sha256_ethereum.hpp" // Access the `from_bits` function and other utils -#include "circuits/circuits-utils.hpp" +#include "circuits/circuits_utils.hpp" #include "util.hpp" // Use the bits256 type util functions diff --git a/src/test/simple_test.cpp b/libzeth/test/simple_test.cpp similarity index 100% rename from src/test/simple_test.cpp rename to libzeth/test/simple_test.cpp diff --git a/src/test/simple_test.hpp b/libzeth/test/simple_test.hpp similarity index 93% rename from src/test/simple_test.hpp rename to libzeth/test/simple_test.hpp index 653abb1ff..5ed784a1f 100644 --- a/src/test/simple_test.hpp +++ b/libzeth/test/simple_test.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_TEST_SIMPLE_TEST_HPP__ #define __ZETH_TEST_SIMPLE_TEST_HPP__ -#include "include_libsnark.hpp" +#include "libzeth/include_libsnark.hpp" namespace libzeth { diff --git a/src/test/simple_test.tcc b/libzeth/test/simple_test.tcc similarity index 100% rename from src/test/simple_test.tcc rename to libzeth/test/simple_test.tcc diff --git a/src/types/bits.cpp b/libzeth/types/bits.cpp similarity index 97% rename from src/types/bits.cpp rename to libzeth/types/bits.cpp index 7454f3252..5f0f3a227 100644 --- a/src/types/bits.cpp +++ b/libzeth/types/bits.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "bits.hpp" +#include "libzeth/types/bits.hpp" namespace libzeth { diff --git a/src/types/bits.hpp b/libzeth/types/bits.hpp similarity index 96% rename from src/types/bits.hpp rename to libzeth/types/bits.hpp index e58307163..e66721480 100644 --- a/src/types/bits.hpp +++ b/libzeth/types/bits.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_TYPES_BITS_HPP__ #define __ZETH_TYPES_BITS_HPP__ -#include "zeth.h" +#include "libzeth/zeth.h" #include #include @@ -56,6 +56,6 @@ std::array binary_xor( bits64 sum_bits64(bits64 a, bits64 b); } // namespace libzeth -#include "bits.tcc" +#include "libzeth/types/bits.tcc" #endif // __ZETH_TYPES_BITS_HPP__ diff --git a/src/types/bits.tcc b/libzeth/types/bits.tcc similarity index 98% rename from src/types/bits.tcc rename to libzeth/types/bits.tcc index 7cf9c5edb..8110572a6 100644 --- a/src/types/bits.tcc +++ b/libzeth/types/bits.tcc @@ -5,7 +5,7 @@ #ifndef __ZETH_TYPES_BITS_TCC__ #define __ZETH_TYPES_BITS_TCC__ -#include "bits.hpp" +#include "libzeth/types/bits.hpp" namespace libzeth { diff --git a/src/types/joinsplit.hpp b/libzeth/types/joinsplit.hpp similarity index 95% rename from src/types/joinsplit.hpp rename to libzeth/types/joinsplit.hpp index aef50b07f..258d2eaa1 100644 --- a/src/types/joinsplit.hpp +++ b/libzeth/types/joinsplit.hpp @@ -5,8 +5,8 @@ #ifndef __ZETH_TYPES_JOINSPLIT_HPP__ #define __ZETH_TYPES_JOINSPLIT_HPP__ -#include "types/bits.hpp" -#include "types/note.hpp" +#include "libzeth/types/bits.hpp" +#include "libzeth/types/note.hpp" #include #include diff --git a/src/types/merkle_tree_field.hpp b/libzeth/types/merkle_tree_field.hpp similarity index 97% rename from src/types/merkle_tree_field.hpp rename to libzeth/types/merkle_tree_field.hpp index 56942867b..0685550ec 100644 --- a/src/types/merkle_tree_field.hpp +++ b/libzeth/types/merkle_tree_field.hpp @@ -51,6 +51,6 @@ template class merkle_tree_field }; } // namespace libzeth -#include "merkle_tree_field.tcc" +#include "libzeth/types/merkle_tree_field.tcc" #endif // __ZETH_TYPES_MERKLE_TREE_FIELD_HPP__ diff --git a/src/types/merkle_tree_field.tcc b/libzeth/types/merkle_tree_field.tcc similarity index 99% rename from src/types/merkle_tree_field.tcc rename to libzeth/types/merkle_tree_field.tcc index 9ee231b13..c6e91c3c1 100644 --- a/src/types/merkle_tree_field.tcc +++ b/libzeth/types/merkle_tree_field.tcc @@ -5,7 +5,7 @@ #ifndef __ZETH_TYPES_MERKLE_TREE_FIELD_TCC__ #define __ZETH_TYPES_MERKLE_TREE_FIELD_TCC__ -#include "circuits/mimc/mimc_mp.hpp" +#include "libzeth/circuits/mimc/mimc_mp.hpp" #include #include diff --git a/src/types/note.hpp b/libzeth/types/note.hpp similarity index 96% rename from src/types/note.hpp rename to libzeth/types/note.hpp index 8ca565023..5c6edcf2a 100644 --- a/src/types/note.hpp +++ b/libzeth/types/note.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_TYPES_NOTE_HPP__ #define __ZETH_TYPES_NOTE_HPP__ -#include "types/bits.hpp" +#include "libzeth/types/bits.hpp" #include diff --git a/src/util.cpp b/libzeth/util.cpp similarity index 99% rename from src/util.cpp rename to libzeth/util.cpp index 1fd30a1ce..789be88a0 100644 --- a/src/util.cpp +++ b/libzeth/util.cpp @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "util.hpp" +#include "libzeth/util.hpp" -#include "zeth.h" +#include "libzeth/zeth.h" #include #include diff --git a/src/util.hpp b/libzeth/util.hpp similarity index 96% rename from src/util.hpp rename to libzeth/util.hpp index 8e0e9870b..4ed40210c 100644 --- a/src/util.hpp +++ b/libzeth/util.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_UTIL_HPP__ #define __ZETH_UTIL_HPP__ -#include "types/bits.hpp" +#include "libzeth/types/bits.hpp" #include #include @@ -57,6 +57,6 @@ template bool container_is_well_formed(const StructuredTs &values); } // namespace libzeth -#include "util.tcc" +#include "libzeth/util.tcc" #endif // __ZETH_UTIL_HPP__ diff --git a/src/util.tcc b/libzeth/util.tcc similarity index 99% rename from src/util.tcc rename to libzeth/util.tcc index f8ffec29e..a9709e0cb 100644 --- a/src/util.tcc +++ b/libzeth/util.tcc @@ -5,7 +5,7 @@ #ifndef __ZETH_UTIL_TCC__ #define __ZETH_UTIL_TCC__ -#include "util.hpp" +#include "libzeth/util.hpp" namespace libzeth { diff --git a/src/util_api.cpp b/libzeth/util_api.cpp similarity index 94% rename from src/util_api.cpp rename to libzeth/util_api.cpp index 02571952a..be5e6c81e 100644 --- a/src/util_api.cpp +++ b/libzeth/util_api.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "util_api.hpp" +#include "libzeth/util_api.hpp" // Message formatting and parsing utility diff --git a/src/util_api.hpp b/libzeth/util_api.hpp similarity index 79% rename from src/util_api.hpp rename to libzeth/util_api.hpp index 1703e0f02..54cc81c62 100644 --- a/src/util_api.hpp +++ b/libzeth/util_api.hpp @@ -6,11 +6,11 @@ #define __ZETH_UTIL_API_HPP__ #include "api/util.pb.h" -#include "libsnark_helpers/debug_helpers.hpp" -#include "types/bits.hpp" -#include "types/joinsplit.hpp" -#include "types/note.hpp" -#include "util.hpp" +#include "libzeth/libsnark_helpers/debug_helpers.hpp" +#include "libzeth/types/bits.hpp" +#include "libzeth/types/joinsplit.hpp" +#include "libzeth/types/note.hpp" +#include "libzeth/util.hpp" #include @@ -34,7 +34,6 @@ prover_proto::HexPointBaseGroup2Affine format_hexPointBaseGroup2Affine( const libff::G2 &point); } // namespace libzeth - -#include "util_api.tcc" +#include "libzeth/util_api.tcc" #endif // __ZETH_UTIL_API_HPP__ diff --git a/src/util_api.tcc b/libzeth/util_api.tcc similarity index 98% rename from src/util_api.tcc rename to libzeth/util_api.tcc index edf2d57d7..84fc2faa8 100644 --- a/src/util_api.tcc +++ b/libzeth/util_api.tcc @@ -5,7 +5,7 @@ #ifndef __ZETH_UTIL_API_TCC__ #define __ZETH_UTIL_API_TCC__ -#include "util_api.hpp" +#include "libzeth/util_api.hpp" namespace libzeth { diff --git a/src/zeth.h b/libzeth/zeth.h similarity index 93% rename from src/zeth.h rename to libzeth/zeth.h index cbe628c59..b0fd0d2bf 100644 --- a/src/zeth.h +++ b/libzeth/zeth.h @@ -3,6 +3,9 @@ #include +namespace libzeth +{ + static const size_t ZETH_NUM_JS_INPUTS = 2; static const size_t ZETH_NUM_JS_OUTPUTS = 2; @@ -19,4 +22,6 @@ static const size_t ZETH_R_SIZE = 48; // 384 bits for r // Size of a HashT digest in hex characters static const size_t ZETH_DIGEST_HEX_SIZE = 64; +} // namespace libzeth + #endif // __ZETH_CONSTANTS__ diff --git a/mpc/coordinator/mpc_command.py b/mpc/coordinator/mpc_command.py index 1c77fb9d6..86161d0ef 100644 --- a/mpc/coordinator/mpc_command.py +++ b/mpc/coordinator/mpc_command.py @@ -94,4 +94,5 @@ def _exec(self, args: List[str]) -> bool: def _default_mpc_tool() -> str: return os.path.join( - os.path.dirname(__file__), "..", "..", "build", "src", "mpc", "mpc") + os.path.dirname(__file__), "..", "..", + "build", "mpc_tools", "mpc_phase2", "mpc-coord-phase2") diff --git a/mpc_tools/CMakeLists.txt b/mpc_tools/CMakeLists.txt new file mode 100644 index 000000000..e6f8b542f --- /dev/null +++ b/mpc_tools/CMakeLists.txt @@ -0,0 +1,20 @@ +# Build for mpc utilities + +find_package( Boost REQUIRED COMPONENTS system filesystem program_options ) +include_directories( ${Boost_INCLUDE_DIR} ) + +# Compile the pot-process utility (GROTH16 only) +if(${ZKSNARK} STREQUAL "GROTH16") + add_executable( + pot-process + pot_process/pot_process.cpp + ) + target_link_libraries( + pot-process + + zeth + ${Boost_SYSTEM_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ) + add_subdirectory(mpc_phase2) +endif() diff --git a/mpc_tools/README.md b/mpc_tools/README.md new file mode 100644 index 000000000..ae18a00f0 --- /dev/null +++ b/mpc_tools/README.md @@ -0,0 +1,4 @@ +# Multi-Party Computation (MPC) tools + +- `pot_process`: Processes the output of "Powers of Tau", i.e. "Phase 1" +- `mpc_phase2`: Implements the "Phase 2" of the MPC diff --git a/mpc_tools/mpc_phase2/CMakeLists.txt b/mpc_tools/mpc_phase2/CMakeLists.txt new file mode 100644 index 000000000..4b31464b5 --- /dev/null +++ b/mpc_tools/mpc_phase2/CMakeLists.txt @@ -0,0 +1,29 @@ +# Build for mpc phase2 utilities + +# library of mpc subcommands +file( + GLOB + MPC_CLI_SOURCE + cli/*.?pp +) + +add_library(mpc-cli ${MPC_CLI_SOURCE}) +target_include_directories(mpc-cli PUBLIC cli) +target_link_libraries( + mpc-cli + zeth + ${Boost_SYSTEM_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} +) + +# mpc coordinator executable +add_executable(mpc-coord-phase2 mpc_coord.cpp) +target_link_libraries(mpc-coord-phase2 mpc-cli) + +# mpc client executable +add_executable(mpc-client-phase2 mpc_client.cpp) +target_link_libraries(mpc-client-phase2 mpc-cli) + +# mpc test utility +add_executable(mpc-test-phase2 test/mpc_test_cli.cpp) +target_link_libraries(mpc-test-phase2 mpc-cli) diff --git a/src/mpc/cli/README.md b/mpc_tools/mpc_phase2/cli/README.md similarity index 100% rename from src/mpc/cli/README.md rename to mpc_tools/mpc_phase2/cli/README.md diff --git a/src/mpc/cli/mpc_common.cpp b/mpc_tools/mpc_phase2/cli/mpc_common.cpp similarity index 97% rename from src/mpc/cli/mpc_common.cpp rename to mpc_tools/mpc_phase2/cli/mpc_common.cpp index a3b395f64..7c601bbca 100644 --- a/src/mpc/cli/mpc_common.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_common.cpp @@ -69,7 +69,8 @@ const std::string &subcommand::description() const return subcommand_description; } -void subcommand::init_protoboard(libsnark::protoboard &pb) const +void subcommand::init_protoboard( + libsnark::protoboard &pb) const { protoboard_init(pb); } @@ -106,7 +107,7 @@ int mpc_main( const std::map &commands, ProtoboardInitFn pb_init) { - ppT::init_public_params(); + libzeth::ppT::init_public_params(); po::options_description global("Global options"); global.add_options()("help,h", "This help")("verbose,v", "Verbose output"); diff --git a/src/mpc/cli/mpc_common.hpp b/mpc_tools/mpc_phase2/cli/mpc_common.hpp similarity index 90% rename from src/mpc/cli/mpc_common.hpp rename to mpc_tools/mpc_phase2/cli/mpc_common.hpp index 2b8bbad0e..bcf8c3e20 100644 --- a/src/mpc/cli/mpc_common.hpp +++ b/mpc_tools/mpc_phase2/cli/mpc_common.hpp @@ -5,7 +5,7 @@ #ifndef __ZETH_MPC_CLI_COMMON_HPP__ #define __ZETH_MPC_CLI_COMMON_HPP__ -#include "circuit_types.hpp" +#include "libzeth/circuit_types.hpp" #include #include @@ -13,7 +13,8 @@ #include #include -using ProtoboardInitFn = std::function &)>; +using ProtoboardInitFn = + std::function &)>; class subcommand { @@ -34,7 +35,7 @@ class subcommand const std::string &description() const; protected: - void init_protoboard(libsnark::protoboard &pb) const; + void init_protoboard(libsnark::protoboard &pb) const; private: void usage(const boost::program_options::options_description &all_options); @@ -70,10 +71,10 @@ inline ReadableT read_from_file(const std::string &file_name) // constraints above. template inline ReadableT read_from_file_and_hash( - const std::string &file_name, srs_mpc_hash_t out_hash) + const std::string &file_name, libzeth::srs_mpc_hash_t out_hash) { std::ifstream inf(file_name, std::ios_base::binary | std::ios_base::in); - hash_istream_wrapper in(inf); + libzeth::hash_istream_wrapper in(inf); in.exceptions( std::ios_base::eofbit | std::ios_base::badbit | std::ios_base::failbit); ReadableT v = ReadableT::read(in); diff --git a/src/mpc/cli/mpc_create_keypair.cpp b/mpc_tools/mpc_phase2/cli/mpc_create_keypair.cpp similarity index 96% rename from src/mpc/cli/mpc_create_keypair.cpp rename to mpc_tools/mpc_phase2/cli/mpc_create_keypair.cpp index 5780a40ca..f7d8861f2 100644 --- a/src/mpc/cli/mpc_create_keypair.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_create_keypair.cpp @@ -2,13 +2,13 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "snarks/groth16/mpc/phase2.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" // This comment preserves include order under clang-format. -#include "circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" +#include "libzeth/util.hpp" #include "mpc_common.hpp" -#include "snarks/groth16/mpc/mpc_utils.hpp" -#include "snarks/groth16/mpc/powersoftau_utils.hpp" -#include "util.hpp" #include diff --git a/src/mpc/cli/mpc_dummy_phase2.cpp b/mpc_tools/mpc_phase2/cli/mpc_dummy_phase2.cpp similarity index 94% rename from src/mpc/cli/mpc_dummy_phase2.cpp rename to mpc_tools/mpc_phase2/cli/mpc_dummy_phase2.cpp index 9ae2efc79..d9c625d58 100644 --- a/src/mpc/cli/mpc_dummy_phase2.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_dummy_phase2.cpp @@ -2,12 +2,12 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" +#include "libzeth/util.hpp" +#include "libzeth/zeth.h" #include "mpc_common.hpp" -#include "snarks/groth16/mpc/mpc_utils.hpp" -#include "snarks/groth16/mpc/phase2.hpp" -#include "util.hpp" -#include "zeth.h" using namespace libzeth; namespace po = boost::program_options; diff --git a/src/mpc/cli/mpc_linear_combination.cpp b/mpc_tools/mpc_phase2/cli/mpc_linear_combination.cpp similarity index 96% rename from src/mpc/cli/mpc_linear_combination.cpp rename to mpc_tools/mpc_phase2/cli/mpc_linear_combination.cpp index f9b1a4d93..b1bb674f6 100644 --- a/src/mpc/cli/mpc_linear_combination.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_linear_combination.cpp @@ -2,11 +2,11 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/circuits/blake2s/blake2s_comp.hpp" +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" +#include "libzeth/util.hpp" #include "mpc_common.hpp" -#include "snarks/groth16/mpc/mpc_utils.hpp" -#include "snarks/groth16/mpc/powersoftau_utils.hpp" -#include "util.hpp" #include #include diff --git a/src/mpc/cli/mpc_phase2_begin.cpp b/mpc_tools/mpc_phase2/cli/mpc_phase2_begin.cpp similarity index 97% rename from src/mpc/cli/mpc_phase2_begin.cpp rename to mpc_tools/mpc_phase2/cli/mpc_phase2_begin.cpp index 97d664a1f..ac71ec0f9 100644 --- a/src/mpc/cli/mpc_phase2_begin.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_phase2_begin.cpp @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: LGPL-3.0+ +#include "libzeth/snarks/groth16/mpc/mpc_utils.hpp" +#include "libzeth/snarks/groth16/mpc/phase2.hpp" #include "mpc_common.hpp" -#include "snarks/groth16/mpc/mpc_utils.hpp" -#include "snarks/groth16/mpc/phase2.hpp" #include #include diff --git a/src/mpc/cli/mpc_phase2_contribute.cpp b/mpc_tools/mpc_phase2/cli/mpc_phase2_contribute.cpp similarity index 99% rename from src/mpc/cli/mpc_phase2_contribute.cpp rename to mpc_tools/mpc_phase2/cli/mpc_phase2_contribute.cpp index ef2874575..88c153242 100644 --- a/src/mpc/cli/mpc_phase2_contribute.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_phase2_contribute.cpp @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: LGPL-3.0+ +#include "libzeth/snarks/groth16/mpc/phase2.hpp" #include "mpc_common.hpp" -#include "snarks/groth16/mpc/phase2.hpp" using namespace libzeth; namespace po = boost::program_options; diff --git a/src/mpc/cli/mpc_phase2_verify_contribution.cpp b/mpc_tools/mpc_phase2/cli/mpc_phase2_verify_contribution.cpp similarity index 99% rename from src/mpc/cli/mpc_phase2_verify_contribution.cpp rename to mpc_tools/mpc_phase2/cli/mpc_phase2_verify_contribution.cpp index 77edfd7da..a010dea31 100644 --- a/src/mpc/cli/mpc_phase2_verify_contribution.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_phase2_verify_contribution.cpp @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: LGPL-3.0+ +#include "libzeth/snarks/groth16/mpc/phase2.hpp" #include "mpc_common.hpp" -#include "snarks/groth16/mpc/phase2.hpp" using namespace libzeth; namespace po = boost::program_options; diff --git a/src/mpc/cli/mpc_phase2_verify_transcript.cpp b/mpc_tools/mpc_phase2/cli/mpc_phase2_verify_transcript.cpp similarity index 99% rename from src/mpc/cli/mpc_phase2_verify_transcript.cpp rename to mpc_tools/mpc_phase2/cli/mpc_phase2_verify_transcript.cpp index 6be55c58c..287ec42ca 100644 --- a/src/mpc/cli/mpc_phase2_verify_transcript.cpp +++ b/mpc_tools/mpc_phase2/cli/mpc_phase2_verify_transcript.cpp @@ -2,8 +2,8 @@ // // SPDX-License-Identifier: LGPL-3.0+ +#include "libzeth/snarks/groth16/mpc/phase2.hpp" #include "mpc_common.hpp" -#include "snarks/groth16/mpc/phase2.hpp" #include #include diff --git a/src/mpc/mpc_client.cpp b/mpc_tools/mpc_phase2/mpc_client.cpp similarity index 68% rename from src/mpc/mpc_client.cpp rename to mpc_tools/mpc_phase2/mpc_client.cpp index 4af3b973b..37d99c164 100644 --- a/src/mpc/mpc_client.cpp +++ b/mpc_tools/mpc_phase2/mpc_client.cpp @@ -6,18 +6,18 @@ // is, participants in the MPC that only contribute and potentially validate // the final transcript. -#include "circuit_wrapper.hpp" +#include "libzeth/circuit_wrapper.hpp" #include "mpc_common.hpp" -void zeth_protoboard(libsnark::protoboard &pb) +void zeth_protoboard(libsnark::protoboard &pb) { - joinsplit_gadget< - FieldT, - HashT, - HashTreeT, - ZETH_NUM_JS_INPUTS, - ZETH_NUM_JS_OUTPUTS, - ZETH_MERKLE_TREE_DEPTH> + libzeth::joinsplit_gadget< + libzeth::FieldT, + libzeth::HashT, + libzeth::HashTreeT, + libzeth::ZETH_NUM_JS_INPUTS, + libzeth::ZETH_NUM_JS_OUTPUTS, + libzeth::ZETH_MERKLE_TREE_DEPTH> js(pb); js.generate_r1cs_constraints(); } diff --git a/src/mpc/mpc.cpp b/mpc_tools/mpc_phase2/mpc_coord.cpp similarity index 69% rename from src/mpc/mpc.cpp rename to mpc_tools/mpc_phase2/mpc_coord.cpp index 360420798..825ac9952 100644 --- a/src/mpc/mpc.cpp +++ b/mpc_tools/mpc_phase2/mpc_coord.cpp @@ -2,18 +2,18 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuit_wrapper.hpp" +#include "libzeth/circuit_wrapper.hpp" #include "mpc_common.hpp" -void zeth_protoboard(libsnark::protoboard &pb) +void zeth_protoboard(libsnark::protoboard &pb) { - joinsplit_gadget< - FieldT, - HashT, - HashTreeT, - ZETH_NUM_JS_INPUTS, - ZETH_NUM_JS_OUTPUTS, - ZETH_MERKLE_TREE_DEPTH> + libzeth::joinsplit_gadget< + libzeth::FieldT, + libzeth::HashT, + libzeth::HashTreeT, + libzeth::ZETH_NUM_JS_INPUTS, + libzeth::ZETH_NUM_JS_OUTPUTS, + libzeth::ZETH_MERKLE_TREE_DEPTH> js(pb); js.generate_r1cs_constraints(); } diff --git a/src/mpc/test/mpc_test_cli.cpp b/mpc_tools/mpc_phase2/test/mpc_test_cli.cpp similarity index 81% rename from src/mpc/test/mpc_test_cli.cpp rename to mpc_tools/mpc_phase2/test/mpc_test_cli.cpp index 964e656f1..fb0864a07 100644 --- a/src/mpc/test/mpc_test_cli.cpp +++ b/mpc_tools/mpc_phase2/test/mpc_test_cli.cpp @@ -2,12 +2,12 @@ // // SPDX-License-Identifier: LGPL-3.0+ +#include "libzeth/test/simple_test.hpp" #include "mpc_common.hpp" -#include "test/simple_test.hpp" -void simple_protoboard(libsnark::protoboard &pb) +void simple_protoboard(libsnark::protoboard &pb) { - libzeth::test::simple_circuit(pb); + libzeth::test::simple_circuit(pb); } int main(int argc, char **argv) diff --git a/src/pot_process/README.md b/mpc_tools/pot_process/README.md similarity index 78% rename from src/pot_process/README.md rename to mpc_tools/pot_process/README.md index 8aa22e9f1..2d8e4eab4 100644 --- a/src/pot_process/README.md +++ b/mpc_tools/pot_process/README.md @@ -1,8 +1,8 @@ # pot-process command Command for processing powersoftau data (output from commands in -https:://github.com/clearmatics/powersoftau), independent of any -specific circuit. Main use-case is to pre-compute the evaluations of +https://github.com/clearmatics/powersoftau), independent of any +specific circuit. Main use-case is to pre-compute the evaluations of the Lagrange polynomials for domains of specific sizes, so that this data can be used during the remaining steps of the SRS computation, across multiple circuits. diff --git a/src/pot_process/pot_process.cpp b/mpc_tools/pot_process/pot_process.cpp similarity index 98% rename from src/pot_process/pot_process.cpp rename to mpc_tools/pot_process/pot_process.cpp index ab12ed60a..f54a94c57 100644 --- a/src/pot_process/pot_process.cpp +++ b/mpc_tools/pot_process/pot_process.cpp @@ -5,8 +5,8 @@ /// Small utility to check powersoftau output and to compute the evaluation of /// Lagrange polynomials at tau. -#include "circuit_types.hpp" -#include "snarks/groth16/mpc/powersoftau_utils.hpp" +#include "libzeth/circuit_types.hpp" +#include "libzeth/snarks/groth16/mpc/powersoftau_utils.hpp" #include #include diff --git a/prover_server/CMakeLists.txt b/prover_server/CMakeLists.txt new file mode 100644 index 000000000..e67aed28c --- /dev/null +++ b/prover_server/CMakeLists.txt @@ -0,0 +1,56 @@ +find_package(Protobuf REQUIRED) +find_package(GRPC REQUIRED) + +# Note: +# The target directory `PROTO_SRC_DIR` is created in the parent CMakeLists.txt. +# This target contains the protobuf and gRPC files generated by the compilation +# of the different targets. +# We could decide to keep the build of the targets independent though. +# As such, we would rather create the target directory `PROTO_SRC_DIR` +# in the target's CMakeLists.txt, from `CMAKE_CURRENT_BINARY_DIR`. +# Doing so would add redundancy in the CMakeLists.txt files but would +# keep the build of the target independent. + +# Add the directory containing the Protobuf and gRPC 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 gRPC files, and set the result of the generation in the +# given env var (GRPC_SRCS, GRPC_HDRS) +# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_SRC_DIR} ${PROTO_FILES}) +grpc_generate_cpp(GRPC_SRCS GRPC_HDRS ${PROTO_SRC_DIR} ${PROTO_FILES}) + +set_property(SOURCE ${GRPC_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} ) + +# Add the binary tree to the search path for include files +# so that we will find zethConfig.h +include_directories( ${PROJECT_BINARY_DIR} ) + +# prover_server executable +file( + GLOB_RECURSE + PROVER_SERVER_SOURCE + prover_server.cpp +) +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 +) diff --git a/prover_server/README.md b/prover_server/README.md new file mode 100644 index 000000000..feed42b86 --- /dev/null +++ b/prover_server/README.md @@ -0,0 +1,5 @@ +# Zeth Prover Server + +This component listens for incoming "proof generation" requests, generates the proof and returns it to the caller. + +Note that this program is seen as a daemon running on the machine of the Zeth user. It can be deployed on a different machine but care will need to be taken to make sure that the witness is protected while communicating with the server. This is out of scope of this work. diff --git a/src/prover_server/prover_server.cpp b/prover_server/prover_server.cpp similarity index 72% rename from src/prover_server/prover_server.cpp rename to prover_server/prover_server.cpp index 27ecc2080..a150782ac 100644 --- a/src/prover_server/prover_server.cpp +++ b/prover_server/prover_server.cpp @@ -2,12 +2,12 @@ // // SPDX-License-Identifier: LGPL-3.0+ -#include "circuit_types.hpp" -#include "libsnark_helpers/libsnark_helpers.hpp" -#include "snarks_alias.hpp" -#include "util.hpp" -#include "util_api.hpp" -#include "zeth.h" +#include "libzeth/circuit_types.hpp" +#include "libzeth/libsnark_helpers/libsnark_helpers.hpp" +#include "libzeth/snarks_alias.hpp" +#include "libzeth/util.hpp" +#include "libzeth/util_api.hpp" +#include "libzeth/zeth.h" #include "zethConfig.h" #include @@ -32,7 +32,7 @@ #pragma GCC diagnostic pop // Include the API for the given SNARK -#include "snarks_api_imports.hpp" +#include "libzeth/snarks_api_imports.hpp" namespace proto = google::protobuf; namespace po = boost::program_options; @@ -44,29 +44,29 @@ class prover_server final : public prover_proto::Prover::Service { private: libzeth::circuit_wrapper< - FieldT, - HashT, - HashTreeT, - ppT, - ZETH_NUM_JS_INPUTS, - ZETH_NUM_JS_OUTPUTS, - ZETH_MERKLE_TREE_DEPTH> + libzeth::FieldT, + libzeth::HashT, + libzeth::HashTreeT, + libzeth::ppT, + libzeth::ZETH_NUM_JS_INPUTS, + libzeth::ZETH_NUM_JS_OUTPUTS, + libzeth::ZETH_MERKLE_TREE_DEPTH> prover; // The keypair is the result of the setup - keyPairT keypair; + libzeth::keyPairT keypair; public: explicit prover_server( libzeth::circuit_wrapper< - FieldT, - HashT, - HashTreeT, - ppT, - ZETH_NUM_JS_INPUTS, - ZETH_NUM_JS_OUTPUTS, - ZETH_MERKLE_TREE_DEPTH> &prover, - keyPairT &keypair) + libzeth::FieldT, + libzeth::HashT, + libzeth::HashTreeT, + libzeth::ppT, + libzeth::ZETH_NUM_JS_INPUTS, + libzeth::ZETH_NUM_JS_OUTPUTS, + libzeth::ZETH_MERKLE_TREE_DEPTH> &prover, + libzeth::keyPairT &keypair) : prover(prover), keypair(keypair) { } @@ -81,7 +81,8 @@ class prover_server final : public prover_proto::Prover::Service std::cout << "[DEBUG] Preparing verification key for response..." << std::endl; try { - prepare_verification_key_response(this->keypair.vk, response); + libzeth::prepare_verification_key_response( + this->keypair.vk, response); } catch (const std::exception &e) { std::cout << "[ERROR] " << e.what() << std::endl; return grpc::Status( @@ -106,8 +107,8 @@ class prover_server final : public prover_proto::Prover::Service // Parse received message to feed to the prover try { - FieldT root = - libzeth::string_to_field(proof_inputs->mk_root()); + libzeth::FieldT root = libzeth::string_to_field( + proof_inputs->mk_root()); libzeth::bits64 vpub_in = libzeth::hex_value_to_bits64(proof_inputs->pub_in_value()); libzeth::bits64 vpub_out = @@ -117,61 +118,71 @@ class prover_server final : public prover_proto::Prover::Service libzeth::bits256 phi_in = libzeth::hex_digest_to_bits256(proof_inputs->phi()); - if (ZETH_NUM_JS_INPUTS != proof_inputs->js_inputs_size()) { + if (libzeth::ZETH_NUM_JS_INPUTS != proof_inputs->js_inputs_size()) { throw std::invalid_argument("Invalid number of JS inputs"); } - if (ZETH_NUM_JS_OUTPUTS != proof_inputs->js_outputs_size()) { + if (libzeth::ZETH_NUM_JS_OUTPUTS != + proof_inputs->js_outputs_size()) { throw std::invalid_argument("Invalid number of JS outputs"); } std::cout << "[DEBUG] Process all inputs of the JoinSplit" << std::endl; std::array< - libzeth::joinsplit_input, - ZETH_NUM_JS_INPUTS> + libzeth::joinsplit_input< + libzeth::FieldT, + libzeth::ZETH_MERKLE_TREE_DEPTH>, + libzeth::ZETH_NUM_JS_INPUTS> joinsplit_inputs; - for (size_t i = 0; i < ZETH_NUM_JS_INPUTS; i++) { - printf("\r input (%zu / %zu)\n", i, ZETH_NUM_JS_INPUTS); + for (size_t i = 0; i < libzeth::ZETH_NUM_JS_INPUTS; i++) { + printf( + "\r input (%zu / %zu)\n", i, libzeth::ZETH_NUM_JS_INPUTS); prover_proto::JoinsplitInput received_input = proof_inputs->js_inputs(i); - libzeth::joinsplit_input - parsed_input = - parse_joinsplit_input( - received_input); + libzeth::joinsplit_input< + libzeth::FieldT, + libzeth::ZETH_MERKLE_TREE_DEPTH> + parsed_input = libzeth::parse_joinsplit_input< + libzeth::FieldT, + libzeth::ZETH_MERKLE_TREE_DEPTH>(received_input); joinsplit_inputs[i] = parsed_input; } std::cout << "[DEBUG] Process all outputs of the JoinSplit" << std::endl; - std::array + std::array joinsplit_outputs; - for (size_t i = 0; i < ZETH_NUM_JS_OUTPUTS; i++) { - printf("\r output (%zu / %zu)\n", i, ZETH_NUM_JS_OUTPUTS); + for (size_t i = 0; i < libzeth::ZETH_NUM_JS_OUTPUTS; i++) { + printf( + "\r output (%zu / %zu)\n", + i, + libzeth::ZETH_NUM_JS_OUTPUTS); prover_proto::ZethNote received_output = proof_inputs->js_outputs(i); libzeth::zeth_note parsed_output = - parse_zeth_note(received_output); + libzeth::parse_zeth_note(received_output); joinsplit_outputs[i] = parsed_output; } std::cout << "[DEBUG] Data parsed successfully" << std::endl; std::cout << "[DEBUG] Generating the proof..." << std::endl; - extended_proof ext_proof = this->prover.prove( - root, - joinsplit_inputs, - joinsplit_outputs, - vpub_in, - vpub_out, - h_sig_in, - phi_in, - this->keypair.pk); + libzeth::extended_proof ext_proof = + this->prover.prove( + root, + joinsplit_inputs, + joinsplit_outputs, + vpub_in, + vpub_out, + h_sig_in, + phi_in, + this->keypair.pk); std::cout << "[DEBUG] Displaying the extended proof" << std::endl; ext_proof.dump_proof(); ext_proof.dump_primary_inputs(); std::cout << "[DEBUG] Preparing response..." << std::endl; - prepare_proof_response(ext_proof, proof); + libzeth::prepare_proof_response(ext_proof, proof); } catch (const std::exception &e) { std::cout << "[ERROR] " << e.what() << std::endl; @@ -223,14 +234,14 @@ void display_server_start_message() static void RunServer( libzeth::circuit_wrapper< - FieldT, - HashT, - HashTreeT, - ppT, - ZETH_NUM_JS_INPUTS, - ZETH_NUM_JS_OUTPUTS, - ZETH_MERKLE_TREE_DEPTH> &prover, - keyPairT &keypair) + libzeth::FieldT, + libzeth::HashT, + libzeth::HashTreeT, + libzeth::ppT, + libzeth::ZETH_NUM_JS_INPUTS, + libzeth::ZETH_NUM_JS_OUTPUTS, + libzeth::ZETH_MERKLE_TREE_DEPTH> &prover, + libzeth::keyPairT &keypair) { // Listen for incoming connections on 0.0.0.0:50051 std::string server_address("0.0.0.0:50051"); @@ -257,12 +268,13 @@ static void RunServer( } #ifdef ZKSNARK_GROTH16 -static keyPairT load_keypair(const std::string &keypair_file) +static libzeth::keyPairT load_keypair( + const std::string &keypair_file) { std::ifstream in(keypair_file, std::ios_base::in | std::ios_base::binary); in.exceptions( std::ios_base::eofbit | std::ios_base::badbit | std::ios_base::failbit); - return libzeth::mpc_read_keypair(in); + return libzeth::mpc_read_keypair(in); } #endif @@ -316,18 +328,18 @@ int main(int argc, char **argv) // We inititalize the curve parameters here std::cout << "[INFO] Init params" << std::endl; - ppT::init_public_params(); + libzeth::ppT::init_public_params(); libzeth::circuit_wrapper< - FieldT, - HashT, - HashTreeT, - ppT, - ZETH_NUM_JS_INPUTS, - ZETH_NUM_JS_OUTPUTS, - ZETH_MERKLE_TREE_DEPTH> + libzeth::FieldT, + libzeth::HashT, + libzeth::HashTreeT, + libzeth::ppT, + libzeth::ZETH_NUM_JS_INPUTS, + libzeth::ZETH_NUM_JS_OUTPUTS, + libzeth::ZETH_MERKLE_TREE_DEPTH> prover; - keyPairT keypair = [&keypair_file, &prover]() { + libzeth::keyPairT keypair = [&keypair_file, &prover]() { if (!keypair_file.empty()) { #ifdef ZKSNARK_GROTH16 std::cout << "[INFO] Loading keypair: " << keypair_file diff --git a/scripts/test_mpc_common.sh b/scripts/test_mpc_common.sh index ad0ead336..8193ffc9c 100644 --- a/scripts/test_mpc_common.sh +++ b/scripts/test_mpc_common.sh @@ -13,7 +13,7 @@ set -x # Directories TEST_DATA_DIR=`pwd`/testdata -BIN_DIR=`pwd`/build/src +BIN_DIR=`pwd`/build/mpc_tools PHASE1_SERVER_DIR=`pwd`/_test_server_phase1 PHASE2_SERVER_DIR=`pwd`/_test_server_phase2 @@ -30,7 +30,7 @@ SERVER_CERT=cert.pem # Commands POT_PROCESS="${BIN_DIR}/pot-process" -MPC="${BIN_DIR}/mpc/mpc-test" +MPC="${BIN_DIR}/mpc_phase2/mpc-test-phase2" POT_DIR=`pwd`"/../powersoftau" QAP_DEGREE=8 diff --git a/scripts/test_pot_process b/scripts/test_pot_process index ef9eb5cc3..f2ae6bd26 100755 --- a/scripts/test_pot_process +++ b/scripts/test_pot_process @@ -1,7 +1,7 @@ #!/usr/bin/env bash POT_PROCESS=$1 -[ "" == "${POT_PROCESS}" ] && POT_PROCESS="build/src/pot-process" +[ "" == "${POT_PROCESS}" ] && POT_PROCESS="build/mpc_tools/pot-process" POT_DATA="testdata/powersoftau_challenge.4.bin" POT_DATA_DEGREE=16 diff --git a/setup_env.sh b/setup_env.sh index 4ef36d5f7..6447fffd8 100644 --- a/setup_env.sh +++ b/setup_env.sh @@ -1,12 +1,14 @@ #!/bin/bash export ZETH=`pwd` -export ZETH_KEYSTORE=$ZETH/keystore +export ZETH_CONTRACTS_DIR=$ZETH/zeth-contracts/contracts +export ZETH_DEBUG_DIR=$ZETH/debug + +mkdir -p $ZETH/coinstore export ZETH_COINSTORE=$ZETH/coinstore + +mkdir -p $ZETH/trusted_setup export ZETH_TRUSTED_SETUP_DIR=$ZETH/trusted_setup -export ZETH_DEBUG_DIR=$ZETH/debug -export ZETH_API_DIR=$ZETH/api -export ZETH_CONTRACTS_DIR=$ZETH/zeth-contracts/contracts # Add the zeth executables in the PATH -export PATH=$ZETH/build/src:$PATH +export PATH=$ZETH/build/prover_server:$ZETH/build/mpc_tools:$ZETH/build/mpc_tools/mpc_phase2:$PATH diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 9e759fbe8..000000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,196 +0,0 @@ -include_directories(.) - -# GRPC and Protocol Buffers libraries location -# `ldconfig -p | grep libgrpc` -# `ldconfig -p | grep libprotobuf` -# Returns the location of the GRPC and Protocol Buffers libraries -# -# 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 "${CMAKE_CURRENT_LIST_DIR}/cmake") - -find_package(Protobuf REQUIRED) -find_package(GRPC REQUIRED) - -set(PROTOS - $ENV{ZETH_API_DIR}/prover.proto -) - -set(PROTOS_UTIL - $ENV{ZETH_API_DIR}/util.proto -) - -set(PROTOS_PGHR13 - $ENV{ZETH_API_DIR}/pghr13_messages.proto -) - -set(PROTOS_GROTH16 - $ENV{ZETH_API_DIR}/groth16_messages.proto -) - -# Set the target of the generated files to ${CMAKE_CURRENT_BINARY_DIR}/proto-src -# Then create this folder and add it to the include directories -set(PROTO_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto-src) -file(MAKE_DIRECTORY ${PROTO_SRC_DIR}) -include_directories(${PROTO_SRC_DIR}) - -# 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 ..) -set(PROTOBUF_PROTO_PATH ..) -set(PROTOBUF_APPEND_DEST_PATH "/api") -set(PROTOBUF_GENERATE_CPP_APPEND_PATH FALSE) -set(GRPC_GENERATE_CPP_APPEND_PATH FALSE) - -# See cmake scripts in the cmake folder -# Generate the grpc and protobuf files and set the result of the generation -# in the given env var (PROTO_SRCS, PROTO_HDRS, GRPC_SRCS, GRPC_HDRS) -protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_SRC_DIR} ${PROTOS_PGHR13} ${PROTOS_GROTH16} ${PROTOS_UTIL} ${PROTOS}) -grpc_generate_cpp(GRPC_SRCS GRPC_HDRS ${PROTO_SRC_DIR} ${PROTOS_PGHR13} ${PROTOS_GROTH16} ${PROTOS_UTIL} ${PROTOS}) - -set_property(SOURCE ${PROTO_SRCS} PROPERTY - COMPILE_FLAGS "-Wno-unused-variable -Wno-unused-parameter" -) -set_property(SOURCE ${GRPC_SRCS} PROPERTY - COMPILE_FLAGS "-Wno-unused-variable -Wno-unused-parameter" -) - -include_directories( - $ENV{ZETH} - $ENV{ZETH}/src - libff/common/default_types -) - -# 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/**.cpp types/**.hpp types/**.tcc - circuits/**.cpp circuits/**.hpp 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) - -# 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 -) - -# pot-process utility (GROTH16 only) -if(${ZKSNARK} STREQUAL "GROTH16") - add_executable(pot-process pot_process/pot_process.cpp) - target_link_libraries( - pot-process - zeth - ${Boost_SYSTEM_LIBRARY} - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ) -endif() - -## Tests -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}) - - add_subdirectory(mpc) -endif() diff --git a/src/mpc/CMakeLists.txt b/src/mpc/CMakeLists.txt deleted file mode 100644 index 423c6490b..000000000 --- a/src/mpc/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Build for mpc utilities - -# library of mpc subcommands -file(GLOB MPC_CLI_SOURCE cli/*.?pp mpc/*.tcc) -add_library(mpc-cli ${MPC_CLI_SOURCE}) -target_include_directories(mpc-cli PUBLIC cli) -target_link_libraries( - mpc-cli - zeth - ${Boost_SYSTEM_LIBRARY} - ${Boost_PROGRAM_OPTIONS_LIBRARY} -) - -# mpc administrator executable -add_executable(mpc mpc.cpp) -target_link_libraries(mpc mpc-cli) - -# mpc client executable -add_executable(mpc-client mpc_client.cpp) -target_link_libraries(mpc-client mpc-cli) - -# mpc test utility -add_executable(mpc-test test/mpc_test_cli.cpp) -target_link_libraries(mpc-test mpc-cli) diff --git a/testdata/mpc_phase2_server_config.json b/testdata/mpc_phase2_server_config.json index 33b08085e..0900dbbf4 100644 --- a/testdata/mpc_phase2_server_config.json +++ b/testdata/mpc_phase2_server_config.json @@ -10,5 +10,5 @@ "tls_certificate": "cert.pem", "port": PORT }, - "mpc_tool": "../build/src/mpc/mpc-test" + "mpc_tool": "../build/mpc_tools/mpc_phase2/mpc-test-phase2" } diff --git a/trusted_setup/README.md b/trusted_setup/README.md deleted file mode 100644 index 8ee2479e2..000000000 --- a/trusted_setup/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Result of the "trusted setup" - -This folder is the target to store: - -- The proving key -- The verification key - -**Note:** You can change the location where the result of the setup is stored, by editing the file `../setup_env.sh` - ----------------- - -For now the trusted setup is ran by a single, trusted, entity (it is ran automatically when we start the prover server). -A more advanced piece of software would use an MPC to generate the proving and verification keys. - -**Reference link:** [Zcash's power of Tau](https://z.cash.foundation/blog/conclusion-of-powers-of-tau/)