Giter Club home page Giter Club logo

cuzk's Introduction

cuZK: An Efficient GPU Implemetation of zkSNARK

This library is an efficient GPU implemetation of zkSNARK. It contains source code of the paper cuZK: Accelerating Zero-Knowledge Proof with A Faster Parallel Multi-Scalar Multiplication Algorithm on GPUs submitted to TCHES 2023.

License

This library is licensed under the Apache License Version 2.0 and MIT licenses.

Requirement

Our experiments can be finished in the following setup.

  1. Ubuntu 20.04
  2. CUDA 11.5
  3. gcc 7.5.0
  4. Nvidia V100 (32 GB)

Build

First we need to make sure NVIDIA CUDA Toolkit is installed.

Our GPU Implemetation of MSM relies on CUB, which provides state-of-the-art, reusable software components for every layer of the CUDA programming model.

By default, CUB is included in the CUDA Toolkit. If there is no CUB after installing the CUDA Toolkit, it is no need to build CUB separately. CUB is implemented as a C++ header library. To use CUB primitives in your code, simply:

  1. Download and unzip the latest CUB distribution
  2. #include the <cub/cub.cuh> header file in your CUDA C++ sources.
  3. Compile your program with NVIDIA's nvcc CUDA compiler, specifying a -I include-path flag to reference the location of the CUB header library.

After that, we build the library. (It will take some time to compile)

cd test
make

To run a test of an MSM of 2^20 scale and EC points on the BLS12-381 curve, run:

## (It will take some time to run for the first time.)
./msmtestb 20 

To run a test of Groth protocol with 2^20 constraint scales and EC points on the BLS12-381 curve, run:

## (It will take some time to run for the first time.)
./testb 20

For EC points on the ALT_BN128 curve and MNT4, run:

## ALT_BN128
./msmtesta 20
./testb 20

## MNT4
./msmtestm 20
./testm 20

In addition, our BLS12-377 carve implementation has a Rust binding with the template from Sppark developed by Supranational LLC. To install the latest version of Rust, first install rustup. Once rustup is installed, install the Rust toolchain by invoking:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup install stable

To test BLS12-377 carve implementation.

cd test/BLS377
cargo bench

Rusults

Here are a selection of the results tested under NVIDIA V100 GPU card with BLS12-381 curve. More results can be found in the paper cuZK.

For MSM computation,

Scale Bellperson cuZK Speedup
2^19 0.23 s 0.12 2.08x
2^20 0.41 s 0.19 2.18x
2^21 0.73 s 0.33 2.20x
2^22 1.30 s 0.58 2.25x
2^23 2.64 s 1.15 2.29x

For Groth's protocol,

Scale Bellperson cuZK Speedup
2^19 2.62 s 0.98 2.67x
2^20 4.45 s 1.68 2.65x
2^21 7.96 s 2.76 2.88x
2^22 14.20 s 5.08 2.80x
2^23 29.13 s 9.91 2.94x

cuzk's People

Contributors

speakspeak avatar

Stargazers

zzzzz avatar 0xDktb avatar Zach Kelling avatar logicat avatar  avatar Paul avatar Sigrid Jin (ง'̀-'́)ง oO avatar Shahzad Ahmad Butt avatar Jung-Woo Chang avatar fuyutarow avatar  avatar Taehoon Tom Kim avatar Wan Ziyi avatar liquan.eth avatar 0xYYY avatar  avatar Security.eth avatar V.O.T avatar Sora Suegami avatar  avatar  avatar Tal Derei avatar

Watchers

 avatar

cuzk's Issues

missing requirements

There may be some undocumented dependencies, on a Linux VM (with Debian as OS) the following happens:

(.detectron2) root@2d29a0a64e2d:/home/zkp/cuZK/test# make
nvcc -arch=sm_35 -rdc=true --expt-extended-lambda ./MSMtestbn.cu libgmp.a ../depends/libff-cuda/curves/alt_bn128/alt_bn128_pp_host.cu  ../depends/libff-cuda/curves/alt_bn128/alt_bn128_init_host.cu  ../depends/libff-cuda/curves/alt_bn128/alt_bn128_g1_host.cu ../depends/libff-cuda/curves/alt_bn128/alt_bn128_g2_host.cu  ../depends/libstl-cuda/memory.cu ../depends/libff-cuda/common/utils.cu ../depends/libff-cuda/mini-mp-cuda/mini-mp-cuda.cu -o msmtesta
nvcc warning : The 'compute_35', 'compute_37', 'sm_35', and 'sm_37' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
In file included from ./MSMtestbn.cu:45:
./../depends/libff-cuda/fields/bigint_host.cuh:4:10: fatal error: gmp.h: No such file or directory
    4 | #include <gmp.h>

I think a Docker image showing the minimal setup could solve the problem and improve reproducibility.
In this specific case it is the package libgmp3-dev.

Missing compiler flags

In my case, the code won't compile with error like:

/usr/lib/gcc/x86_64-pc-linux-gnu/7.5.0/include/c++/type_traits:83:83: error: redefinition of ‘constexpr const _Tp   std::integral_constant<_Tp, __v>::value’
   template<typename _Tp, _Tp __v>

Fix it by appending flag: --std=c++14.

多GPU的实验问题

如过有多张GPU那么您的代码时自动适配多GPU的吗。还是只能运行在一张GPU上。

cub doesn't work

文件位置:
depends/libstl-cuda/algorithm.cu
报错函数:
cub::DeviceRadixSort::SortPairs()
报错日志:
./../depends/libmatrix-cuda/transpose/../depends/libstl-cuda/algorithm.cu(131): error: no instance of overloaded function "cub::DeviceRadixSort::SortPairs" matches the argument list argument types are: (void *, size_t, size_t *, libff::bls12_381_pp::G1_type **, size_t *, libff::bls12_381_pp::G1_type **, size_t, size_t, size_t)
备注:sort_pair_host中的地址指针key_out_addr和output_addr的声明方式好像也是错的,get_host模板初始化有问题

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.