Skip to content

rapidsnark is a fast zkSNARK prover written in C++, that generates proofs for circuits created with circom and snarkjs.

License

Notifications You must be signed in to change notification settings

burnt-labs/rapidsnark

 
 

Repository files navigation

rapidsnark-gpu

This is a CUDA-accelerated version of rapidsnark.

We provide a prover_cuda program that uses Ingonyama's ICICLE GPU library for NTT/MSM to build proof, current only supporting standalone mode.This accelerated implementation has notably reduced the building proof's time from 41.757 seconds to 8.443 seconds.

Rapidsnark is a zkSnark proof generation written in C++ and intel/arm assembly. That generates proofs created in circom and snarkjs very fast.

Prerequistes

  • CUDA Toolkit version, CMake version and GCC version etc. (please see ICICLE)
  • Ubuntu 22.04
  • x86_64 host machine

Dependencies

sudo apt-get install build-essential libgmp-dev libsodium-dev nasm curl m4

Compile prover_cuda

git submodule init
git submodule update
./build_gmp.sh host
mkdir build_prover && cd build_prover
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j$(nproc) && make install

Building proof

git submodule init
git submodule update
./build_gmp.sh macos_arm64
make macos_arm64

Compile prover for linux arm64 host machine

git submodule init
git submodule update
./build_gmp.sh host
make host_arm64

Compile prover for linux arm64 machine

git submodule init
git submodule update
./build_gmp.sh host
make arm64

Compile prover for Android

Install Android NDK from https://developer.android.com/ndk or with help of "SDK Manager" in Android Studio.

Set the value of ANDROID_NDK environment variable to the absolute path of Android NDK root directory.

Examples:

export ANDROID_NDK=/home/test/Android/Sdk/ndk/23.1.7779620  # NDK is installed by "SDK Manager" in Android Studio.
export ANDROID_NDK=/home/test/android-ndk-r23b              # NDK is installed as a stand-alone package.

Prerequisites if build on Ubuntu:

apt-get install curl xz-utils build-essential cmake m4 nasm

Compilation:

git submodule init
git submodule update
./build_gmp.sh android
make android

Compile prover for iOS

Install Xcode

git submodule init
git submodule update
./build_gmp.sh ios
make ios

Open generated Xcode project and compile prover.

Build for iOS emulator

Install Xcode

git submodule init
git submodule update
./build_gmp.sh ios_simulator
make ios_simulator

Files that you need to copy to your XCode project to link against Rapidsnark:

  • build_prover_ios_simulator/src/Debug-iphonesimulator/librapidsnark.a
  • build_prover_ios_simulator/src/Debug-iphonesimulator/libfq.a
  • build_prover_ios_simulator/src/Debug-iphonesimulator/libfr.a
  • depends/gmp/package_iphone_simulator/lib/libgmp.a

Building proof

You have a full prover compiled in the build directory.

So you can replace snarkjs command:

snarkjs groth16 prove <circuit.zkey> <witness.wtns> <proof.json> <public.json>

by this one

=======
You can replace rapidsnark command:

```bash
>>>>>>> upstream/main
./package/bin/prover <circuit.zkey> <witness.wtns> <proof.json> <public.json>

by this one

./package/bin/prover_cuda <circuit.zkey> <witness.wtns> <proof.json> <public.json>

Results

Test machine: GPU — NVIDIA GeForce RTX 4090 24GB
CPU — 2* AMD EPYC 7763 64-Core Processor
RAM - 256GB

CPU version:

init and set str for altBbn128r: 0 ms
get zkey,zkeyHeader,wtns,wtnsHeader: 0 ms
make prover: 64 ms
get wtnsData: 0 ms
Multiexp A: 1816 ms
Multiexp B1: 2020 ms
Multiexp B2: 2520 ms
Multiexp C: 2775 ms
Initializing a b c A: 59 ms
Processing coefs: 593 ms
Calculating c: 49 ms
Initializing fft: 0 ms
iFFT A: 18158 ms
a After ifft: 0 ms
Shift A: 46 ms
a After shift: 0 ms
FFT A: 3188 ms
a After fft: 0 ms
iFFT B: 1805 ms
b After ifft: 0 ms
Shift B: 45 ms
b After shift: 0 ms
FFT B: 750 ms
b After fft: 0 ms
iFFT C: 971 ms
c After ifft: 0 ms
Shift C: 49 ms
c After shift: 0 ms
FFT C: 779 ms
c After fft: 0 ms
Start ABC: 48 ms
abc: 0 ms
Multiexp H: 4720 ms
generate proof: 40708 ms
write proof to file: 0 ms
write public to file: 0 ms
prover total: 41757 ms

GPU version:

init and set str for altBbn128r: 0 ms
get zkey,zkeyHeader,wtns,wtnsHeader: 0 ms
make prover: 65 ms
get wtnsData: 0 ms
get MSM config: 0 ms
Multiexp A: 848 ms
Multiexp B1: 679 ms
Multiexp B2: 1080 ms
Multiexp C: 683 ms
Initializing a b c A: 75 ms
Processing coefs: 618 ms
Calculating c: 38 ms
Initializing fft: 148 ms
iFFT A: 291 ms
a After ifft: 0 ms
Shift A: 164 ms
a After shift: 0 ms
FFT A: 294 ms
a After fft: 0 ms
iFFT B: 272 ms
b After ifft: 0 ms
Shift B: 33 ms
b After shift: 0 ms
FFT B: 308 ms
b After fft: 0 ms
iFFT C: 255 ms
c After ifft: 0 ms
Shift C: 28 ms
c After shift: 0 ms
FFT C: 278 ms
c After fft: 0 ms
Start ABC: 46 ms
abc: 0 ms
Multiexp H: 929 ms
generate proof: 7362 ms
write proof to file: 0 ms
write public to file: 0 ms
prover cuda total: 8443 ms

Wrappers

Rapidsnark can be used with several programming languages and environments through wrappers that provide integration with the original library. Below is a list of available wrappers:

Wrapper Repository Link
Go https://github.com/iden3/go-rapidsnark
iOS https://github.com/iden3/ios-rapidsnark
Android https://github.com/iden3/android-rapidsnark
React Native https://github.com/iden3/react-native-rapidsnark
Flutter https://github.com/iden3/flutter-rapidsnark

Benchmark

Note

This project has been tested only under the following configurations:

  • Ubuntu 22.04
  • Kernel version 6.5.0-25-generic
  • CUDA 12.3
  • GCC/G++ 12.3.0
  • GPU — NVIDIA GeForce RTX 4090 24GB
  • CPU — 2* AMD EPYC 7763 64-Core Processor

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 section. After that you can run tests with the following command from the build directory:

# 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:

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

License

rapidsnark is part of the iden3 project copyright 2021 0KIMS association and published with LGPL-3 license. Please check the COPYING file for more details.

About

rapidsnark is a fast zkSNARK prover written in C++, that generates proofs for circuits created with circom and snarkjs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 65.3%
  • Assembly 29.1%
  • Cuda 2.4%
  • CMake 1.0%
  • Shell 0.8%
  • C 0.7%
  • Other 0.7%