Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add verifier #12

Merged
merged 6 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ jobs:
mkdir -p build_prover && cd build_prover
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j4 && make install
ctest --rerun-failed --output-on-failure

- name: test prover for linux
- name: test rapidsnark
run: |
set -x
set -e
npm install -g snarkjs
package/bin/prover testdata/circuit_final.zkey testdata/witness.wtns proof.json public.json
snarkjs groth16 verify testdata/verification_key.json public.json proof.json
package/bin/verifier testdata/verification_key.json public.json proof.json
# make a wrong public.json by decrementing the first element by 1
(value_0=$(jq '.[0]' public.json | tr -d '"') && value_0=$(echo "$value_0 - 1" | BC_LINE_LENGTH=100 bc) && jq --arg value_0 "$value_0" '.[0] = $value_0' public.json) > public_bad.json
set +e
package/bin/verifier testdata/verification_key.json public_bad.json proof.json
exit_code=$?
set -e
[ $exit_code -ne 0 ]

- name: upload Linux amd64 dev artifacts
if: github.event_name != 'release'
Expand Down Expand Up @@ -161,14 +168,21 @@ jobs:
mkdir -p build_prover_macos_arm64 && cd build_prover_macos_arm64
cmake .. -DTARGET_PLATFORM=macos_arm64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_arm64
make -j4 && make install
ctest --rerun-failed --output-on-failure

- name: test prover
- name: test rapidsnark
run: |
set -x
set -e
npm install -g snarkjs
package_macos_arm64/bin/prover testdata/circuit_final.zkey testdata/witness.wtns proof.json public.json
snarkjs groth16 verify testdata/verification_key.json public.json proof.json
package_macos_arm64/bin/verifier testdata/verification_key.json public.json proof.json
# make a wrong public.json by decrementing the first element by 1
(value_0=$(jq '.[0]' public.json | tr -d '"') && value_0=$(echo "$value_0 - 1" | BC_LINE_LENGTH=100 bc) && jq --arg value_0 "$value_0" '.[0] = $value_0' public.json) > public_bad.json
set +e
package_macos_arm64/bin/verifier testdata/verification_key.json public_bad.json proof.json
exit_code=$?
set -e
[ $exit_code -ne 0 ]

- name: upload macOS arm64 dev artifacts
if: github.event_name != 'release'
Expand Down Expand Up @@ -256,14 +270,21 @@ jobs:
mkdir -p build_prover_macos_x86_64 && cd build_prover_macos_x86_64
cmake .. -DTARGET_PLATFORM=macos_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_x86_64
make -j4 && make install
ctest --rerun-failed --output-on-failure

- name: test prover
- name: test rapidsnark
run: |
set -x
set -e
npm install -g snarkjs
package_macos_x86_64/bin/prover testdata/circuit_final.zkey testdata/witness.wtns proof.json public.json
snarkjs groth16 verify testdata/verification_key.json public.json proof.json
package_macos_x86_64/bin/verifier testdata/verification_key.json public.json proof.json
# make a wrong public.json by decrementing the first element by 1
(value_0=$(jq '.[0]' public.json | tr -d '"') && value_0=$(echo "$value_0 - 1" | BC_LINE_LENGTH=100 bc) && jq --arg value_0 "$value_0" '.[0] = $value_0' public.json) > public_bad.json
set +e
package_macos_x86_64/bin/verifier testdata/verification_key.json public_bad.json proof.json
exit_code=$?
set -e
[ $exit_code -ne 0 ]

- name: upload macOS x86_64 dev artifacts
if: github.event_name != 'release'
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(cmake/platform.cmake)
set(USE_ASM ON CACHE BOOL "Use asm implementation for Fr and Fq")
set(USE_OPENMP ON CACHE BOOL "Use OpenMP")

project(rapidsnark LANGUAGES CXX ASM)
project(rapidsnark LANGUAGES CXX C ASM)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -53,13 +53,15 @@ endif()
add_subdirectory(src)


install(TARGETS prover rapidsnark rapidsnarkStatic rapidsnarkStaticFrFq test_prover fr fq
install(TARGETS prover verifier rapidsnark rapidsnarkStatic rapidsnarkStaticFrFq test_prover fr fq
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
BUNDLE DESTINATION ${CMAKE_INSTALL_PREFIX}/app
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)

install(FILES "${GMP_LIB_DIR}/${GMP_LIB_FILE}"
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)

install(FILES src/prover.h
install(FILES src/prover.h src/verifier.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include)

enable_testing()
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ The prover is much faster that snarkjs and faster than bellman.

[TODO] Some comparative tests should be done.

## Run tests

You need to perform all the steps from the
[Compile prover in standalone mode](#compile-prover-in-standalone-mode) section.
After that you can run tests with the following command from the build
directory:

```sh
# Make sure you are in the build directory
# ./build_prover for linux, ./build_prover_macos_arm64 for macOS.
cmake --build . --parallel && ctest --rerun-failed --output-on-failure
```

To run just the `test_public_size` test for custom zkey to measure the
performance, you can run the following command from the build directory:

```sh
src/test_public_size ../testdata/circuit_final.zkey 86
```

## License

Expand Down
2 changes: 1 addition & 1 deletion depends/ffiasm
2 changes: 1 addition & 1 deletion depends/pistache
Submodule pistache updated 251 files
15 changes: 15 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ set(LIB_SOURCES
fileloader.hpp
prover.cpp
prover.h
verifier.cpp
verifier.h
../depends/ffiasm/c/misc.cpp
../depends/ffiasm/c/naf.cpp
../depends/ffiasm/c/splitparstr.cpp
Expand Down Expand Up @@ -115,25 +117,38 @@ set_target_properties(rapidsnarkStaticFrFq PROPERTIES OUTPUT_NAME rapidsnark-fr-
add_executable(prover main_prover.cpp)
target_link_libraries(prover rapidsnarkStatic)

add_executable(verifier main_verifier.cpp)
target_link_libraries(verifier rapidsnarkStatic)

add_library(rapidsnark SHARED ${LIB_SOURCES})

if(USE_LOGGER OR NOT USE_OPENMP)
target_link_libraries(prover pthread)
target_link_libraries(verifier pthread)
endif()

if(USE_SODIUM)
target_link_libraries(prover sodium)
endif()


enable_testing()
add_executable(test_public_size test_public_size.c)
target_link_libraries(test_public_size rapidsnarkStaticFrFq)
add_test(NAME test_public_size COMMAND test_public_size circuit_final.zkey 86
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/testdata)

if(OpenMP_CXX_FOUND)

if(TARGET_PLATFORM MATCHES "android")
target_link_libraries(prover -static-openmp -fopenmp)
target_link_libraries(verifier -static-openmp -fopenmp)
target_link_libraries(rapidsnark -static-openmp -fopenmp)

elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(prover OpenMP::OpenMP_CXX)
target_link_libraries(verifier OpenMP::OpenMP_CXX)
target_link_libraries(test_public_size OpenMP::OpenMP_CXX)
endif()

endif()
Expand Down
2 changes: 2 additions & 0 deletions src/fileloader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class FileLoader
void* dataBuffer() { return addr; }
size_t dataSize() const { return size; }

std::string dataAsString() { return std::string((char*)addr, size); }

private:
void* addr;
size_t size;
Expand Down
Loading
Loading