bellperson Crates.io

This is a fork of the great bellman library.

bellman is a crate for building zk-SNARK circuits. It provides circuit traits and primitive structures, as well as basic gadget implementations such as booleans and number abstractions.

Backend

There are currently two backends available for the implementation of Bls12 381: - paired - pure Rust implementation - blstrs - optimized with hand tuned assembly, using blst

They can be selected at compile time with the mutually exclusive features pairing and blst. Specifying one of them is enough for a working library, no additional features need to be set. The default for now is pairing, as the secure and audited choice.

GPU

This fork contains GPU parallel acceleration to the FFT and Multiexponentation algorithms in the groth16 prover codebase under the compilation feature gpu, it can be used in combination with pairing or blst.

Requirements

( For AMD devices we recommend ROCm )

Environment variables

The gpu extension contains some env vars that may be set externally to this library.

Supported / Tested Cards

Depending on the size of the proof being passed to the gpu for work, certain cards will not be able to allocate enough memory to either the FFT or Multiexp kernel. Below are a list of devices that work for small sets. In the future we will add the cuttoff point at which a given card will not be able to allocate enough memory to utilize the GPU.

| Device Name | Cores | Comments | |------------------------|-------|----------------| | Quadro RTX 6000 | 4608 | | | TITAN RTX | 4608 | | | Tesla V100 | 5120 | | | Tesla P100 | 3584 | | | Tesla T4 | 2560 | | | Quadro M5000 | 2048 | | | GeForce RTX 3090 |10496 | | | GeForce RTX 3080 | 8704 | | | GeForce RTX 3070 | 5888 | | | GeForce RTX 2080 Ti | 4352 | | | GeForce RTX 2080 SUPER | 3072 | | | GeForce RTX 2080 | 2944 | | | GeForce RTX 2070 SUPER | 2560 | | | GeForce GTX 1080 Ti | 3584 | | | GeForce GTX 1080 | 2560 | | | GeForce GTX 2060 | 1920 | | | GeForce GTX 1660 Ti | 1536 | | | GeForce GTX 1060 | 1280 | | | GeForce GTX 1650 SUPER | 1280 | | | GeForce GTX 1650 | 896 | | | | | | | gfx1010 | 2560 | AMD RX 5700 XT | | gfx906 | 7400 | AMD RADEON VII | |------------------------|-------|----------------|

Running Tests

To run using the pairing backend, you can use:

bash RUSTFLAGS="-C target-cpu=native" cargo test --release --all --no-default-features --features pairing

To run using both the gpu and blst backend, you can use:

bash RUSTFLAGS="-C target-cpu=native" cargo test --release --all --no-default-features --features gpu,blst

To run the multiexp_consistency test you can use:

bash RUST_LOG=info cargo test --features gpu -- --exact multiexp::gpu_multiexp_consistency --nocapture

Considerations

Bellperson uses rust-gpu-tools as its OpenCL backend, therefore you may see a directory named ~/.rust-gpu-tools in your home folder, which contains the compiled binaries of OpenCL kernels used in this repository.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.