Skip to content

Commit

Permalink
feat: switch to upstream versions of group, ff and pairing
Browse files Browse the repository at this point in the history
Breaking Change: Removes the `pairing` backend, reducing to only the `blst` backend.

Co-authored-by: dignifiedquire <[email protected]>
Co-authored-by: nemo <[email protected]>
  • Loading branch information
3 people authored Sep 18, 2021
1 parent 4e8d2eb commit d1b9939
Show file tree
Hide file tree
Showing 58 changed files with 2,233 additions and 2,174 deletions.
79 changes: 11 additions & 68 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
parameters:
nightly-version:
type: string
default: "nightly-2020-11-20"
default: "nightly-2021-04-24"

#orbs:
# codecov: codecov/[email protected]
Expand All @@ -22,7 +22,7 @@ restore-workspace: &restore-workspace
restore-cache: &restore-cache
restore_cache:
keys:
- cargo-v1-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
- cargo-v2-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
- repo-source-{{ .Branch }}-{{ .Revision }}

commands:
Expand All @@ -44,30 +44,6 @@ commands:
sudo apt-get update -y
sudo apt install -y ocl-icd-opencl-dev
test_target_pairing:
parameters:
target:
type: string
steps:
- *restore-workspace
- *restore-cache
- run:
name: Test pairing (<< parameters.target >>)
command: TARGET=<< parameters.target >> cargo test --no-default-features --features pairing
no_output_timeout: 15m

test_target_pairing_gpu:
parameters:
target:
type: string
steps:
- *restore-workspace
- *restore-cache
- run:
name: Test pairing (GPU) (<< parameters.target >>)
command: TARGET=<< parameters.target >> cargo test --release --no-default-features --features gpu,pairing
no_output_timeout: 30m

test_target_blst:
parameters:
target:
Expand All @@ -77,7 +53,7 @@ commands:
- *restore-cache
- run:
name: Test blst (<< parameters.target >>)
command: TARGET=<< parameters.target >> cargo test --no-default-features --features blst
command: TARGET=<< parameters.target >> cargo test --all
no_output_timeout: 15m

test_target_blst_gpu:
Expand All @@ -89,7 +65,7 @@ commands:
- *restore-cache
- run:
name: Test blst (GPU) (<< parameters.target >>)
command: TARGET=<< parameters.target >> cargo test --release --no-default-features --features gpu,blst
command: TARGET=<< parameters.target >> cargo test --all --release --features gpu
no_output_timeout: 30m

test_target_blst_ignored:
Expand All @@ -101,7 +77,7 @@ commands:
- *restore-cache
- run:
name: Test blst ignored (<< parameters.target >>)
command: TARGET=<< parameters.target >> cargo test --release --no-default-features --features blst -- --ignored
command: TARGET=<< parameters.target >> cargo test --release -- --ignored
no_output_timeout: 30m
- run:
name: Show results
Expand All @@ -126,7 +102,7 @@ jobs:
command: cargo generate-lockfile
- restore_cache:
keys:
- cargo-v1-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
- cargo-v2-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
- run: cargo update
- run: cargo fetch
- run: rustup install $(cat rust-toolchain)
Expand All @@ -141,28 +117,11 @@ jobs:
paths:
- gpuci
- save_cache:
key: cargo-v1-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
key: cargo-v2-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
paths:
- "~/.cargo"
- "~/.rustup"

test_pairing_x86_64-unknown-linux-gnu:
executor: default
steps:
- set-env-path
- install-gpu-deps
- test_target_pairing:
target: "x86_64-unknown-linux-gnu"

test_pairing_gpu_x86_64-unknown-linux-gnu:
executor: default
steps:
- set-env-path
- install-gpu-deps
- test_target_pairing_gpu:
target: "x86_64-unknown-linux-gnu"


test_blst_x86_64-unknown-linux-gnu:
executor: default
steps:
Expand Down Expand Up @@ -204,20 +163,11 @@ jobs:
- *restore-cache
- set-env-path
- run:
name: Run cargo clippy (default features (pairing))
command: cargo clippy --all-targets --features gpu -- -D warnings
- run:
name: Run cargo clippy (pairing)
command: cargo clippy --all-targets --no-default-features --features pairing -- -D warnings
- run:
name: Run cargo clippy (blst)
command: cargo clippy --all-targets --no-default-features --features blst -- -D warnings
name: Run cargo clippy (default features)
command: cargo clippy --all --all-targets -- -D warnings
- run:
name: Run cargo clippy (pairing,gpu)
command: cargo clippy --all-targets --no-default-features --features pairing,gpu -- -D warnings
- run:
name: Run cargo clippy (blst,gpu)
command: cargo clippy --all-targets --no-default-features --features blst,gpu -- -D warnings
name: Run cargo clippy (gpu)
command: cargo clippy --all --all-targets --features gpu -- -D warnings

coverage_run:
executor: default
Expand Down Expand Up @@ -281,13 +231,6 @@ workflows:
requires:
- cargo_fetch

- test_pairing_x86_64-unknown-linux-gnu:
requires:
- cargo_fetch
- test_pairing_gpu_x86_64-unknown-linux-gnu:
requires:
- cargo_fetch

- test_blst_x86_64-unknown-linux-gnu:
requires:
- cargo_fetch
Expand Down
45 changes: 22 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,50 @@ edition = "2018"
[dependencies]
bit-vec = "0.6"
blake2s_simd = "0.5"
ff = { version = "0.3.0", package = "fff" }
groupy = "0.4.1"
rand_core = "0.5"
ff = "0.11.0"
group = "0.11.0"
rand_core = "0.6"
byteorder = "1"
log = "0.4.8"
lazy_static = "1.4.0"
rand = "0.7"
rand = "0.8"
rayon = "1.5.0"
memmap = "0.7.0"
thiserror = "1.0.10"
rustc-hash = "1.1.0"
num_cpus = "1"
crossbeam-channel = "0.5.0"
digest = "0.9.0"
itertools = "0.9.0"
itertools = "0.10.0"
bincode = "1.3.1"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.9"

# blst feature
blstrs = { version = "0.3", optional = true }

# pairing feature
paired = { version = "0.22.0", optional = true }
blstrs = { git = "https://github.com/filecoin-project/blstrs", branch = "master" }
pairing = "0.21"
yastl = "0.1.2"

# gpu feature
rust-gpu-tools = { version = "0.4.0", optional = true }
ff-cl-gen = { version = "0.3.0", optional = true }
ec-gpu = { git = "https://github.com/filecoin-project/ec-gpu", branch = "master", optional = true }
ec-gpu-gen = { git = "https://github.com/filecoin-project/ec-gpu", branch = "master", optional = true }
fs2 = { version = "0.4.3", optional = true }
yastl = "0.1.2"


[dev-dependencies]
hex-literal = "0.3"
rand_xorshift = "0.2.0"
env_logger = "0.8.1"
rand_xorshift = "0.3"
env_logger = "0.9.0"
criterion = "0.3.2"
rand_chacha = "0.2.2"
rand_chacha = "0.3"
csv = "1.1.5"
tempfile = "3.1.0"
subtle = "2.2.1"

[features]
default = ["blst"]
gpu = ["rust-gpu-tools", "ff-cl-gen", "fs2"]
default = ["groth16"]
gpu = ["rust-gpu-tools", "ec-gpu", "ec-gpu-gen", "fs2", "blstrs/gpu"]
groth16 = []

blst = ["blstrs", "groth16"]
pairing = ["paired", "groth16"]


# This feature disables/modifies long running tests to make the suitable for code coverage
# reporting
_coverage = []
Expand All @@ -77,7 +72,11 @@ required-features = ["groth16"]
[badges]
maintenance = { status = "actively-developed" }


[[bench]]
name = "lc"
harness = false

[workspace]
members = [
"verifier-bench"
]
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ booleans and number abstractions.

## Backend

There are currently two backends available for the implementation of Bls12 381:
There is currently one backend available for the implementation of Bls12 381:
- [`blstrs`](https://github.com/filecoin-project/blstrs) - optimized with hand tuned assembly, using [blst](https://github.com/supranational/blst)
- [`paired`](https://github.com/filecoin-project/paired) - pure Rust implementation

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

The default for now is `blst`, as the secure and audited choice. Note that `pairing` is deprecated and may be removed in the future.

## 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 `blst` or `pairing`.
This fork contains GPU parallel acceleration to the FFT and Multiexponentation algorithms in the groth16 prover codebase under the compilation feature `gpu`.

### Requirements
- NVIDIA or AMD GPU Graphics Driver
Expand Down Expand Up @@ -108,16 +103,14 @@ Depending on the size of the proof being passed to the gpu for work, certain car

### 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
RUSTFLAGS="-C target-cpu=native" cargo test --release --all
```

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

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

To run the multiexp_consistency test you can use:
Expand Down
12 changes: 7 additions & 5 deletions benches/lc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use bellperson::{bls::Bls12, Index, LinearCombination, Variable};
use bellperson::{Index, LinearCombination, Variable};
use blstrs::Bls12;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ff::{Field, ScalarEngine};
use ff::Field;
use pairing::Engine;

fn lc_benchmark(c: &mut Criterion) {
c.bench_function("LinearCombination::add((Fr, Variable))", |b| {
b.iter(|| {
let mut lc = LinearCombination::<Bls12>::zero();
for i in 0..100 {
let coeff = <Bls12 as ScalarEngine>::Fr::one();
let coeff = <Bls12 as Engine>::Fr::one();
lc = lc + (coeff, Variable::new_unchecked(Index::Aux(i)));
}
black_box(lc);
Expand All @@ -17,10 +19,10 @@ fn lc_benchmark(c: &mut Criterion) {
let mut lc1 = LinearCombination::<Bls12>::zero();
let mut lc2 = LinearCombination::<Bls12>::zero();
for i in 0..10 {
let coeff = <Bls12 as ScalarEngine>::Fr::one();
let coeff = <Bls12 as Engine>::Fr::one();
lc1 = lc1 + (coeff, Variable::new_unchecked(Index::Aux(i)));

let coeff = <Bls12 as ScalarEngine>::Fr::one();
let coeff = <Bls12 as Engine>::Fr::one();
lc2 = lc2 + (coeff, Variable::new_unchecked(Index::Aux(i * 2)));
}

Expand Down
23 changes: 0 additions & 23 deletions examples/verifier_bench/Cargo.toml

This file was deleted.

15 changes: 0 additions & 15 deletions src/bls.rs

This file was deleted.

Loading

0 comments on commit d1b9939

Please sign in to comment.