Coder Social home page Coder Social logo

gyllone / icicle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ingonyama-zk/icicle

0.0 0.0 0.0 41.91 MB

a GPU Library for Zero-Knowledge Acceleration

License: MIT License

Shell 0.16% Python 0.72% C 49.17% Go 1.37% Rust 17.49% Cuda 30.76% Makefile 0.08% CMake 0.20% Dockerfile 0.04%

icicle's Introduction

ICICLE

Icicle is a library for ZK acceleration using CUDA-enabled GPUs.

image (4)

Build status Chat with us on Discord Follow us on Twitter

Background

Zero Knowledge Proofs (ZKPs) are considered one of the greatest achievements of modern cryptography. Accordingly, ZKPs are expected to disrupt a number of industries and will usher in an era of trustless and privacy preserving services and infrastructure.

If we want ZK hardware today we have FPGAs or GPUs which are relatively inexpensive. However, the biggest selling point of GPUs is the software; we talk in particular about CUDA, which makes it easy to write code running on Nvidia GPUs, taking advantage of their highly parallel architecture. Together with the widespread availability of these devices, if we can get GPUs to work on ZK workloads, then we have made a giant step towards accessible and efficient ZK provers.

Zero Knowledge on GPU

ICICLE is a CUDA implementation of general functions widely used in ZKP. ICICLE currently provides support for MSM, NTT, and ECNTT, with plans to support Hash functions soon.

Supported primitives

Build and usage

Prerequisites

If you don't have access to a Nvidia GPU check out google-colab. If you require more compute power and are looking to build or do research with ICICLE refer to our grant program.

Steps

  1. Define or select a curve for your application; we've provided a template for defining a curve
  2. Include the curve in curve_config.cuh
  3. Now you can build the ICICLE library using nvcc
mkdir -p build
nvcc -o build/<binary_name> ./icicle/curves/index.cu -lib -arch=native

Testing the CUDA code

We are using googletest library for testing. To build and run the test suite for finite field and elliptic curve arithmetic, run from the icicle folder:

For testing, ensure the BUILD_TESTS option is enabled in cmake. If not, toggle it on by adding -DBUILD_TESTS=ON in the cmake configuration command:

cmake -S . -B build -DBUILD_TESTS=ON

Proceed with the following commands:

mkdir -p build
cmake -S . -B build
cmake --build build
cd build && ctest

NOTE: If you are using cmake versions < 3.24 add -DCUDA_ARCH=<target_cumpute_arch> to the command cmake -S . -B build

Rust Bindings

For convenience, we also provide rust bindings to the ICICLE library for the following primitives:

  • MSM
  • NTT
    • Forward NTT
    • Inverse NTT
  • ECNTT
    • Forward ECNTT
    • Inverse NTT
  • Scalar Vector Multiplication
  • Point Vector Multiplication

A custom build script is used to compile and link the ICICLE library. The environment variable ARCH_TYPE is used to determine which GPU type the library should be compiled for and it defaults to native when it is not set allowing the compiler to detect the installed GPU type.

NOTE: A GPU must be detectable and therefore installed if the ARCH_TYPE is not set.

Once you have your parameters set, run:

cargo build --release

You'll find a release ready library at target/release/libicicle_utils.rlib.

To benchmark and test the functionality available in RUST, run:

cargo bench
cargo test -- --test-threads=1

The flag --test-threads=1 is needed because currently some tests might interfere with one another inside the GPU.

Example Usage

An example of using the Rust bindings library can be found in our fast-danksharding implementation

Supporting Additional Curves

Supporting additional curves can be done as follows:

Create a JSON file with the curve parameters. The curve is defined by the following parameters:

  • curve_name - e.g. bls12_381.
  • modulus_p - scalar field modulus (in decimal).
  • bit_count_p - number of bits needed to represent modulus_p .
  • limb_p - number of (32-bit) limbs needed to represent modulus_p (rounded up).
  • ntt_size - log of the maximal size subgroup of the scalar field.
  • modulus_q - base field modulus (in decimal).
  • bit_count_q - number of bits needed to represent modulus_q .
  • limb_q - number of (32-bit) limbs needed to represent modulus_q (rounded up).
  • weierstrass_b - b of the curve in Weierstrauss form.
  • weierstrass_b_g2_re - real part of the b value in of the g2 curve in Weierstrass form.
  • weierstrass_b_g2_im - imaginary part of the b value in of the g2 curve in Weierstrass form.
  • gen_x - x coordinate of a generator element for the curve.
  • gen_y - y coordinate of a generator element for the curve.
  • gen_x_re - real part of the x coordinate of generator element for the g2 curve.
  • gen_x_im - imaginary part of the x coordinate of generator element for the g2 curve.
  • gen_y_re - real part of the y coordinate of generator element for the g2 curve.
  • gen_y_im - imaginary part of the y coordinate of generator element for the g2 curve.
  • nonresidue - nonresidue, or i^2, or u^2 - square of the element that generates quadratic extension field of the base field.

Here's an example for BLS12-381.

{
    "curve_name" : "bls12_381", 
    "modulus_p" : 52435875175126190479447740508185965837690552500527637822603658699938581184513,
    "bit_count_p" : 255,
    "limb_p" :  8,
    "ntt_size" : 32,
    "modulus_q" : 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787,
    "bit_count_q" : 381,
    "limb_q" : 12,
    "weierstrass_b" : 4,
    "weierstrass_b_g2_re" : 4,
    "weierstrass_b_g2_im" : 4,
    "gen_x" : 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507,
    "gen_y" : 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569,
    "gen_x_re" : 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160,
    "gen_x_im" : 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758,
    "gen_y_re" : 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905,
    "gen_y_im" : 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582,
    "nonresidue" : -1
}

Save the parameters JSON file under the curve_parameters directory.

Then run the Python script new_curve_script.py from the root folder:

python3 ./curve_parameters/new_curve_script.py ./curve_parameters/bls12_381.json

The script does the following:

  • Creates a folder in icicle/curves with the curve name, which contains all of the files needed for the supported operations in cuda.
  • Adds the curve's exported operations to icicle/curves/index.cu.
  • Creates a file with the curve name in src/curves with the relevant objects for the curve.
  • Creates a test file with the curve name in src.

Also files from ./icicle/curves/<curve_name>/supported_operations.cu should be added individually to add_library section of ./icicle/CMakeLists.txt

Testing the new curve could be done by running the tests in tests_curve_name (e.g. tests_bls12_381).

Docker

We offer a simple Docker container so you can simply run ICICLE without setting everything up locally.

docker build -t <name_of_your_choice> .
docker run --gpus all -it <name_of_your_choice> /bin/bash

Google Colab

Colab is a hosted Jupyter Notebook service that requires no setup to use and provides free access to computing resources including GPUS!

You can easily run ICICLE in Google Colab on a free GPU instance, this is a great option for those who want to get started with ICICLE instantly without any local setup or GPU.

Follow this guide for more details.

Contributions

Join our Discord Server and find us on the icicle channel. We will be happy to work together to support your use case and talk features, bugs and design.

Development Contributions

If you are changing code, please make sure to change your git hooks path to the repo's hooks directory by running the following command:

git config core.hooksPath ./scripts/hooks

In case clang-format is missing on your system, you can install it using the following command:

sudo apt install clang-format

This will ensure our custom hooks are run and will make it easier to follow our coding guidelines.

Hall of Fame

  • Robik, for his ongoing support and mentorship
  • liuxiao, for being a top notch bug smasher
  • gkigiermo, for making it intuitive to use ICICLE in Google Colab.

Help & Support

For help and support talk to our devs in our discord channel "ICICLE"

License

ICICLE is distributed under the terms of the MIT License.

See LICENSE-MIT for details.

icicle's People

Contributors

jeremyfelder avatar immanuelsegol avatar leonhibnik avatar omershlo avatar vhnatyk avatar dmytrotym avatar guy-ingo avatar hadaringonyama avatar weijiekoh avatar chickenlover avatar gkigiermo avatar bigsky77 avatar punk5736 avatar otsar-raikou avatar liuxiaobleach avatar omahs avatar robik75 avatar vuittont60 avatar

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.