Skip to content

Commit

Permalink
Refactor TurboComposer for API consistency
Browse files Browse the repository at this point in the history
The current`TurboComposer` API constaints a lot of legacy functions with
inconsistent signatures.

For the addition gate, we have `big_add`, `big_add_gate`, `add`,
`add_gate` with different signatures that internally perform the same
operation.

This commit aims to create an uniform API for the composer.

Resolves #565 , #583 , #584 , #587 , #588
  • Loading branch information
vlopes11 committed Sep 30, 2021
1 parent 7cb8276 commit cc9c448
Show file tree
Hide file tree
Showing 59 changed files with 1,019 additions and 1,166 deletions.
1 change: 0 additions & 1 deletion .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
**/*.rs.bk
Cargo.lock
notes.md
scrap.rs
kzg10.rs
design.md
refactor_notes
.DS_Store
.DS_Store
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add back benchmarks to the crate. [#555](https://github.com/dusk-network/plonk/issue/555)
- Add `Witness` by removing `AllocatedScalar`. [#588](https://github.com/dusk-network/plonk/issue/588)

### Changed

- Change `StandardComposer` to `TurboComposer`. [#288](https://github.com/dusk-network/plonk/issue/288)
- Change `Variable` usage in favor of `AllocatedScalar`. [#565]((https://github.com/dusk-network/plonk/issue/565))
- Add `Witness` by removing `AllocatedScalar`. [#588]((https://github.com/dusk-network/plonk/issue/588))
- Change `Variable` usage in favor of `AllocatedScalar`. [#565](https://github.com/dusk-network/plonk/issue/565)
- Change `TurboComposer` to consistent API. [#587](https://github.com/dusk-network/plonk/issue/587)
- Change `plonkup_gate` to use public inputs. [#584](https://github.com/dusk-network/plonk/issue/584)

### Fixed

- Fix the document references and typos [#533](https://github.com/dusk-network/plonk/pull/533)
- Fix if condition to match [#545](https://github.com/dusk-network/plonk/pull/545)

### Removed

- Remove old perm-computation fns from perm module [#515](https://github.com/dusk-network/plonk/issues/515)
- Remove unused `plonkup` module. [#583](https://github.com/dusk-network/plonk/issue/583)

## [0.8.1] - 07-06-21

Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,50 @@ impl Circuit for TestCircuit {
let a = composer.append_witness(self.a);
let b = composer.append_witness(self.b);
// Make first constraint a + b = c
composer.poly_gate(
composer.append_gate(
a,
b,
composer.zero(),
composer.constant_zero(),
composer.constant_zero(),
BlsScalar::zero(),
BlsScalar::one(),
BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::zero(),
BlsScalar::zero(),
Some(-self.c),
);
// Check that a and b are in range
composer.range_gate(a, 1 << 6);
composer.range_gate(b, 1 << 5);
composer.gate_range(a, 1 << 6);
composer.gate_range(b, 1 << 5);
// Make second constraint a * b = d
composer.poly_gate(
composer.append_gate(
a,
b,
composer.zero(),
composer.constant_zero(),
composer.constant_zero(),
BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::zero(),
BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::zero(),
Some(-self.d),
);

let e = composer.append_witness(self.e);
let scalar_mul_result = composer
.fixed_base_scalar_mul(e, dusk_jubjub::GENERATOR_EXTENDED);
.gate_mul_generator(e, dusk_jubjub::GENERATOR_EXTENDED);
// Apply the constrain
composer.assert_equal_public_point(scalar_mul_result, self.f);
Ok(())
}
fn padded_circuit_size(&self) -> usize {

fn into_public_inputs(&self) -> Vec<PublicInputValue> {
vec![self.c.into(), self.d.into(), self.f.into()]
}

fn padded_constraints(&self) -> usize {
1 << 11
}
}
Expand All @@ -97,7 +106,7 @@ let proof = {
dusk_jubjub::GENERATOR_EXTENDED * JubJubScalar::from(2u64),
),
};
circuit.gen_proof(&pp, &pk, b"Test").unwrap()
circuit.prove(&pp, &pk, b"Test").unwrap()
};
// Verifier POV
let public_inputs: Vec<PublicInputValue> = vec![
Expand Down
20 changes: 14 additions & 6 deletions benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ impl Circuit for BenchCircuit {
let mut b = BlsScalar::from(3u64);
let mut c;

while composer.circuit_size() < self.padded_circuit_size() {
let zero = composer.constant_zero();

while composer.constraints() < self.padded_constraints() {
a += BlsScalar::one();
b += BlsScalar::one();
c = a * b + a + b + BlsScalar::one();
Expand All @@ -46,14 +48,16 @@ impl Circuit for BenchCircuit {
let y = composer.add_input(b);
let z = composer.add_input(c);

composer.poly_gate(
composer.append_gate(
x,
y,
z,
zero,
BlsScalar::one(),
BlsScalar::one(),
BlsScalar::one(),
-BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::one(),
None,
);
Expand All @@ -62,7 +66,11 @@ impl Circuit for BenchCircuit {
Ok(())
}

fn padded_circuit_size(&self) -> usize {
fn into_public_inputs(&self) -> Vec<PublicInputValue> {
vec![]
}

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

Expand Down Expand Up @@ -113,7 +121,7 @@ fn constraint_system_benchmark(c: &mut Criterion) {

data.iter().for_each(|(circuit, pk, _, _)| {
let mut circuit = circuit.clone();
let size = circuit.padded_circuit_size();
let size = circuit.padded_constraints();
let power = (size as f64).log2() as usize;
let description = format!("Prove 2^{} = {} constraints", power, size);

Expand All @@ -125,7 +133,7 @@ fn constraint_system_benchmark(c: &mut Criterion) {
});

data.iter().for_each(|(circuit, _, vd, proof)| {
let size = circuit.padded_circuit_size();
let size = circuit.padded_constraints();
let power = (size as f64).log2() as usize;
let description = format!("Verify 2^{} = {} constraints", power, size);

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2021-06-06
nightly-2021-09-25
Loading

0 comments on commit cc9c448

Please sign in to comment.