Skip to content

Commit

Permalink
Fix benches and make CI fail if they don't compile (#614)
Browse files Browse the repository at this point in the history
* Add `cargo check --all-targets` to CI
* Fix bench compilation

Resolves: #610
Resolves: #609
  • Loading branch information
ureeves authored Oct 13, 2021
1 parent a779ee3 commit 5748ed8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 41 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ jobs:
- name: Add target
run: rustup target add ${{ matrix.target }}

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --all-targets

- name: Build project with alloc
uses: actions-rs/cargo@v1
with:
Expand Down Expand Up @@ -95,6 +101,12 @@ jobs:
profile: minimal
toolchain: ${{ matrix.toolchain }}

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --all-targets

- name: Test project
if: ${{ matrix.os != 'ubuntu-latest' || matrix.toolchain != 'nightly' }}
uses: actions-rs/cargo@v1
Expand Down
58 changes: 17 additions & 41 deletions benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

#![allow(clippy::many_single_char_names)]

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use dusk_bls12_381::BlsScalar;
use dusk_plonk::circuit::{self, Circuit, VerifierData};
// Using prelude until PP is available on regular import path
use dusk_plonk::constraint_system::TurboComposer;
use dusk_plonk::error::Error;
use dusk_plonk::prelude::PublicParameters;
use dusk_plonk::proof_system::{Proof, ProverKey};
use dusk_plonk::prelude::*;

#[derive(Debug, Clone, Copy)]
struct BenchCircuit {
Expand Down Expand Up @@ -48,19 +44,14 @@ impl Circuit for BenchCircuit {
let y = composer.append_witness(b);
let z = composer.append_witness(c);

composer.append_gate(
x,
y,
z,
zero,
BlsScalar::one(),
BlsScalar::one(),
BlsScalar::one(),
-BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::one(),
None,
);
let constraint = Constraint::new()
.mul(1)
.left(1)
.right(1)
.output(-BlsScalar::one())
.constant(1);

composer.append_gate(x, y, z, zero, constraint);
}

Ok(())
Expand All @@ -82,7 +73,7 @@ fn constraint_system_prove(
label: &'static [u8],
) -> Proof {
circuit
.prove(&pp, &pk, label)
.prove(pp, pk, label)
.expect("Failed to prove bench circuit!")
}

Expand All @@ -105,22 +96,14 @@ fn constraint_system_benchmark(c: &mut Criterion) {
let proof =
constraint_system_prove(&mut circuit, &pp, &pk, label);

circuit::verify_proof(
&pp,
vd.key(),
&proof,
&[],
vd.public_inputs_indexes(),
label,
)
.expect("Failed to verify bench circuit!");
BenchCircuit::verify(&pp, &vd, &proof, &[], label)
.expect("Failed to verify bench circuit");

(circuit, pk, vd, proof)
})
.collect();

data.iter().for_each(|(circuit, pk, _, _)| {
let mut circuit = circuit.clone();
data.iter().for_each(|(mut circuit, pk, _, _)| {
let size = circuit.padded_gates();
let power = (size as f64).log2() as usize;
let description = format!("Prove 2^{} = {} gates", power, size);
Expand All @@ -139,15 +122,8 @@ fn constraint_system_benchmark(c: &mut Criterion) {

c.bench_function(description.as_str(), |b| {
b.iter(|| {
circuit::verify_proof(
&pp,
vd.key(),
black_box(proof),
&[],
vd.public_inputs_indexes(),
label,
)
.expect("Failed to verify bench circuit!");
BenchCircuit::verify(&pp, vd, black_box(proof), &[], label)
.expect("Failed to verify bench circuit!");
})
});
});
Expand Down

0 comments on commit 5748ed8

Please sign in to comment.