From 08dc0f6a24abf7233022d82347386fe9ade556d8 Mon Sep 17 00:00:00 2001 From: moana Date: Wed, 20 Dec 2023 18:12:25 +0100 Subject: [PATCH] Turn `Composer` into a struct And rename `Arithmetization` to `Gate`. Resolves #802 --- CHANGELOG.md | 7 + README.md | 4 +- benches/plonk.rs | 17 +- src/composer.rs | 352 +++++++++++++------ src/composer/builder.rs | 160 --------- src/composer/circuit.rs | 11 +- src/composer/compiler.rs | 24 +- src/composer/compiler/compress.rs | 32 +- src/composer/{arithmetization.rs => gate.rs} | 4 +- src/composer/prover.rs | 6 +- src/composer/verifier.rs | 4 +- src/constraint_system/constraint.rs | 4 +- src/prelude.rs | 2 +- src/proof_system/proof.rs | 14 +- src/runtime.rs | 9 - tests/append_gate.rs | 5 +- tests/assert_point.rs | 10 +- tests/assert_scalar.rs | 10 +- tests/boolean.rs | 5 +- tests/composer.rs | 17 +- tests/debugger.rs | 5 +- tests/decomposition.rs | 5 +- tests/ecc.rs | 12 +- tests/error_size.rs | 9 +- tests/gate_add_mul.rs | 5 +- tests/logic.rs | 10 +- tests/range.rs | 5 +- tests/select_bls.rs | 15 +- tests/select_point.rs | 10 +- 29 files changed, 334 insertions(+), 439 deletions(-) delete mode 100644 src/composer/builder.rs rename src/composer/{arithmetization.rs => gate.rs} (92%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e9b3932..a49a0eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improve InvalidCircuitSize error [#792] - Hide all modules except 'prelude' [#782] +- Turn `Composer` trait into a struct [#802] +- Rename `Arithmetization` to `Gate` [#802] + +### Removed + +- Remove `Builder` struct with introduction of `Composer` struct [#802] ## [0.18.0] - 2023-12-13 @@ -542,6 +548,7 @@ is necessary since `rkyv/validation` was required as a bound. - Proof system module. +[#802]: https://github.com/dusk-network/plonk/issues/802 [#797]: https://github.com/dusk-network/plonk/issues/797 [#796]: https://github.com/dusk-network/plonk/issues/796 [#792]: https://github.com/dusk-network/plonk/issues/792 diff --git a/README.md b/README.md index c5b3001e..2a9459f0 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,7 @@ pub struct TestCircuit { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let a = composer.append_witness(self.a); let b = composer.append_witness(self.b); diff --git a/benches/plonk.rs b/benches/plonk.rs index f5dbdabf..c2761284 100644 --- a/benches/plonk.rs +++ b/benches/plonk.rs @@ -31,10 +31,7 @@ impl Default for BenchCircuit { } impl Circuit for BenchCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); let w_b = composer.append_witness(self.b); let w_x = composer.append_witness(self.x); @@ -59,7 +56,7 @@ impl Circuit for BenchCircuit { composer.component_add_point(w_z, w_z); composer.append_logic_and::<128>(w_a, w_b); composer.append_logic_xor::<128>(w_a, w_b); - composer.component_boolean(C::ONE); + composer.component_boolean(Composer::ONE); composer.component_decomposition::<254>(w_a); composer.component_mul_generator( w_y, @@ -67,11 +64,11 @@ impl Circuit for BenchCircuit { )?; composer.component_mul_point(w_y, w_z); composer.component_range::<128>(w_a); - composer.component_select(C::ONE, w_a, w_b); - composer.component_select_identity(C::ONE, w_z); - composer.component_select_one(C::ONE, w_a); - composer.component_select_point(C::ONE, w_z, w_z); - composer.component_select_zero(C::ONE, w_a); + composer.component_select(Composer::ONE, w_a, w_b); + composer.component_select_identity(Composer::ONE, w_z); + composer.component_select_one(Composer::ONE, w_a); + composer.component_select_point(Composer::ONE, w_z, w_z); + composer.component_select_zero(Composer::ONE, w_a); diff = composer.constraints() - prev; prev = composer.constraints(); diff --git a/src/composer.rs b/src/composer.rs index 36ddf429..1c61d70e 100644 --- a/src/composer.rs +++ b/src/composer.rs @@ -7,8 +7,8 @@ //! PLONK turbo composer definitions use alloc::vec::Vec; -use core::cmp; -use core::ops::Index; +use core::{cmp, ops}; +use hashbrown::HashMap; use dusk_bls12_381::BlsScalar; use dusk_jubjub::{JubJubAffine, JubJubExtended, JubJubScalar}; @@ -19,72 +19,144 @@ use crate::constraint_system::{ Constraint, Selector, WiredWitness, Witness, WitnessPoint, }; use crate::error::Error; +use crate::permutation::Permutation; use crate::runtime::{Runtime, RuntimeEvent}; -mod arithmetization; -mod builder; mod circuit; mod compiler; +mod gate; mod prover; mod verifier; -pub use arithmetization::Arithmetization; -pub use builder::Builder; pub use circuit::Circuit; pub use compiler::Compiler; +pub use gate::Gate; pub use prover::Prover; pub use verifier::Verifier; +/// Construct and prove circuits +#[derive(Debug, Clone)] +pub struct Composer { + /// Constraint system gates + pub(crate) constraints: Vec, + + /// Sparse representation of the public inputs + pub(crate) public_inputs: HashMap, + + /// Witness values + pub(crate) witnesses: Vec, + + /// Permutation argument. + pub(crate) perm: Permutation, + + /// PLONK runtime controller + pub(crate) runtime: Runtime, +} + +impl ops::Index for Composer { + type Output = BlsScalar; + + fn index(&self, w: Witness) -> &Self::Output { + &self.witnesses[w.index()] + } +} + +// pub trait Composer: Sized + Index { /// Circuit builder tool -pub trait Composer: Sized + Index { +impl Composer { /// Zero representation inside the constraint system. /// /// A turbo composer expects the first witness to be always present and to /// be zero. - const ZERO: Witness = Witness::ZERO; + pub const ZERO: Witness = Witness::ZERO; /// `One` representation inside the constraint system. /// /// A turbo composer expects the 2nd witness to be always present and to /// be one. - const ONE: Witness = Witness::ONE; + pub const ONE: Witness = Witness::ONE; /// Identity point representation inside the constraint system - const IDENTITY: WitnessPoint = WitnessPoint::new(Self::ZERO, Self::ONE); - - /// Create an empty constraint system. - /// - /// This shouldn't be used directly; instead, use [`Self::initialized`] - #[deprecated( - since = "0.13.0", - note = "this function is meant for internal use. call `initialized` instead" - )] - fn uninitialized() -> Self; + pub const IDENTITY: WitnessPoint = WitnessPoint::new(Self::ZERO, Self::ONE); /// Constraints count - fn constraints(&self) -> usize; + pub fn constraints(&self) -> usize { + self.constraints.len() + } /// Allocate a witness value into the composer and return its index. - #[deprecated( - since = "0.13.0", - note = "this function is meant for internal use. call `append_witness` instead" - )] - fn append_witness_internal(&mut self, witness: BlsScalar) -> Witness; - - /// Append a new width-4 poly gate/constraint. - #[deprecated( - since = "0.13.0", - note = "this function is meant for internal use. call `append_custom_gate` instead" - )] - fn append_custom_gate_internal(&mut self, constraint: Constraint); + fn append_witness_internal(&mut self, witness: BlsScalar) -> Witness { + let n = self.witnesses.len(); + + // Get a new Witness from the permutation + self.perm.new_witness(); + + // Bind the allocated witness + self.witnesses.push(witness); + + Witness::new(n) + } + + /// Append a new width-4 gate/constraint. + fn append_custom_gate_internal(&mut self, constraint: Constraint) { + let n = self.constraints.len(); + + let w_a = constraint.witness(WiredWitness::A); + let w_b = constraint.witness(WiredWitness::B); + let w_o = constraint.witness(WiredWitness::O); + let w_d = constraint.witness(WiredWitness::D); + + let q_m = *constraint.coeff(Selector::Multiplication); + let q_l = *constraint.coeff(Selector::Left); + let q_r = *constraint.coeff(Selector::Right); + let q_o = *constraint.coeff(Selector::Output); + let q_4 = *constraint.coeff(Selector::Fourth); + let q_c = *constraint.coeff(Selector::Constant); + + let q_arith = *constraint.coeff(Selector::Arithmetic); + let q_range = *constraint.coeff(Selector::Range); + let q_logic = *constraint.coeff(Selector::Logic); + let q_fixed_group_add = *constraint.coeff(Selector::GroupAddFixedBase); + let q_variable_group_add = + *constraint.coeff(Selector::GroupAddVariableBase); + + let gate = Gate { + q_m, + q_l, + q_r, + q_o, + q_4, + q_c, + q_arith, + q_range, + q_logic, + q_fixed_group_add, + q_variable_group_add, + w_a, + w_b, + w_o, + w_d, + }; + + self.constraints.push(gate); + + if constraint.has_public_input() { + let pi = *constraint.coeff(Selector::PublicInput); + + self.public_inputs.insert(n, pi); + } + + self.perm.add_witnesses_to_map(w_a, w_b, w_o, w_d, n); + } /// PLONK runtime controller - fn runtime(&mut self) -> &mut Runtime; + pub(crate) fn runtime(&mut self) -> &mut Runtime { + &mut self.runtime + } /// Initialize the constraint system with the constants for 0 and 1 and /// append two dummy gates - fn initialized() -> Self { - #[allow(deprecated)] + pub fn initialized() -> Self { let mut slf = Self::uninitialized(); let zero = slf.append_witness(0); @@ -98,11 +170,64 @@ pub trait Composer: Sized + Index { slf } + /// Create an empty constraint system. + /// + /// This shouldn't be used directly; instead, use [`Self::initialized`] + fn uninitialized() -> Self { + Self { + constraints: Vec::new(), + public_inputs: HashMap::new(), + witnesses: Vec::new(), + perm: Permutation::new(), + runtime: Runtime::new(), + } + } + + /// Adds blinding factors to the witness polynomials with two dummy + /// arithmetic constraints + fn append_dummy_gates(&mut self) { + let six = self.append_witness(BlsScalar::from(6)); + let one = self.append_witness(BlsScalar::from(1)); + let seven = self.append_witness(BlsScalar::from(7)); + let min_twenty = self.append_witness(-BlsScalar::from(20)); + + // Add a dummy constraint so that we do not have zero polynomials + let constraint = Constraint::new() + .mult(1) + .left(2) + .right(3) + .fourth(1) + .constant(4) + .output(4) + .a(six) + .b(seven) + .d(one) + .o(min_twenty); + + self.append_gate(constraint); + + // Add another dummy constraint so that we do not get the identity + // permutation + let constraint = Constraint::new() + .mult(1) + .left(1) + .right(1) + .constant(127) + .output(1) + .a(min_twenty) + .b(six) + .o(seven); + + self.append_gate(constraint); + } + /// Allocate a witness value into the composer and return its index. - fn append_witness>(&mut self, witness: W) -> Witness { + pub fn append_witness>( + &mut self, + witness: W, + ) -> Witness { let witness = witness.into(); - #[allow(deprecated)] let witness = self.append_witness_internal(witness); let v = self[witness]; @@ -112,12 +237,11 @@ pub trait Composer: Sized + Index { witness } - /// Append a new width-4 poly gate/constraint. - fn append_custom_gate(&mut self, constraint: Constraint) { + /// Append a new width-4 gate/constraint. + pub fn append_custom_gate(&mut self, constraint: Constraint) { self.runtime() .event(RuntimeEvent::ConstraintAppended { c: constraint }); - #[allow(deprecated)] self.append_custom_gate_internal(constraint) } @@ -132,7 +256,7 @@ pub trait Composer: Sized + Index { /// `a` and `b`. /// - is_component_xor = 0 -> Performs AND between the first `num_bits` for /// `a` and `b`. - fn append_logic_component( + pub fn append_logic_component( &mut self, a: Witness, b: Witness, @@ -245,7 +369,7 @@ pub trait Composer: Sized + Index { /// /// Will error with a `JubJubScalarMalformed` error if `jubjub` doesn't fit /// `Fr` - fn component_mul_generator>( + pub fn component_mul_generator>( &mut self, jubjub: Witness, generator: P, @@ -399,11 +523,11 @@ pub trait Composer: Sized + Index { Ok(WitnessPoint::new(acc_x, acc_y)) } - /// Append a new width-4 poly gate/constraint. + /// Append a new width-4 gate/constraint. /// /// The constraint added will enforce the following: /// `q_m · a · b + q_l · a + q_r · b + q_o · o + q_4 · d + q_c + PI = 0`. - fn append_gate(&mut self, constraint: Constraint) { + pub fn append_gate(&mut self, constraint: Constraint) { let constraint = Constraint::arithmetic(&constraint); self.append_custom_gate(constraint) @@ -412,7 +536,10 @@ pub trait Composer: Sized + Index { /// Evaluate the polynomial and append an output that satisfies the equation /// /// Return `None` if the output selector is zero - fn append_evaluated_output(&mut self, s: Constraint) -> Option { + pub fn append_evaluated_output( + &mut self, + s: Constraint, + ) -> Option { let a = s.witness(WiredWitness::A); let b = s.witness(WiredWitness::B); let d = s.witness(WiredWitness::D); @@ -458,47 +585,12 @@ pub trait Composer: Sized + Index { o.map(|o| self.append_witness(o)) } - /// Adds blinding factors to the witness polynomials with two dummy - /// arithmetic constraints - fn append_dummy_gates(&mut self) { - let six = self.append_witness(BlsScalar::from(6)); - let one = self.append_witness(BlsScalar::from(1)); - let seven = self.append_witness(BlsScalar::from(7)); - let min_twenty = self.append_witness(-BlsScalar::from(20)); - - // Add a dummy constraint so that we do not have zero polynomials - let constraint = Constraint::new() - .mult(1) - .left(2) - .right(3) - .fourth(1) - .constant(4) - .output(4) - .a(six) - .b(seven) - .d(one) - .o(min_twenty); - - self.append_gate(constraint); - - // Add another dummy constraint so that we do not get the identity - // permutation - let constraint = Constraint::new() - .mult(1) - .left(1) - .right(1) - .constant(127) - .output(1) - .a(min_twenty) - .b(six) - .o(seven); - - self.append_gate(constraint); - } - /// Constrain a scalar into the circuit description and return an allocated /// [`Witness`] with its value - fn append_constant>(&mut self, constant: C) -> Witness { + pub fn append_constant>( + &mut self, + constant: C, + ) -> Witness { let constant = constant.into(); let witness = self.append_witness(constant); @@ -508,7 +600,7 @@ pub trait Composer: Sized + Index { } /// Appends a point in affine form as [`WitnessPoint`] - fn append_point>( + pub fn append_point>( &mut self, affine: P, ) -> WitnessPoint { @@ -522,7 +614,7 @@ pub trait Composer: Sized + Index { /// Constrain a point into the circuit description and return an allocated /// [`WitnessPoint`] with its coordinates - fn append_constant_point>( + pub fn append_constant_point>( &mut self, affine: P, ) -> WitnessPoint { @@ -537,7 +629,7 @@ pub trait Composer: Sized + Index { /// Appends a point in affine form as [`WitnessPoint`] /// /// Creates two public inputs as `(x, y)` - fn append_public_point>( + pub fn append_public_point>( &mut self, affine: P, ) -> WitnessPoint { @@ -562,7 +654,7 @@ pub trait Composer: Sized + Index { /// Allocate a witness value into the composer and return its index. /// /// Create a public input with the scalar - fn append_public>(&mut self, public: P) -> Witness { + pub fn append_public>(&mut self, public: P) -> Witness { let public = public.into(); let witness = self.append_witness(public); @@ -576,7 +668,7 @@ pub trait Composer: Sized + Index { } /// Asserts `a == b` by appending a gate - fn assert_equal(&mut self, a: Witness, b: Witness) { + pub fn assert_equal(&mut self, a: Witness, b: Witness) { let constraint = Constraint::new().left(1).right(-BlsScalar::one()).a(a).b(b); @@ -586,7 +678,7 @@ pub trait Composer: Sized + Index { /// Adds a logical AND gate that performs the bitwise AND between two values /// specified first `num_bits = BIT_PAIRS * 2` bits returning a [`Witness`] /// holding the result. - fn append_logic_and( + pub fn append_logic_and( &mut self, a: Witness, b: Witness, @@ -597,7 +689,7 @@ pub trait Composer: Sized + Index { /// Adds a logical XOR gate that performs the XOR between two values for the /// specified first `num_bits = BIT_PAIRS * 2` bits returning a [`Witness`] /// holding the result. - fn append_logic_xor( + pub fn append_logic_xor( &mut self, a: Witness, b: Witness, @@ -608,7 +700,7 @@ pub trait Composer: Sized + Index { /// Constrain `a` to be equal to `constant + pi`. /// /// `constant` will be defined as part of the public circuit description. - fn assert_equal_constant>( + pub fn assert_equal_constant>( &mut self, a: Witness, constant: C, @@ -627,7 +719,7 @@ pub trait Composer: Sized + Index { /// Asserts that the coordinates of the two points `a` and `b` are the same /// by appending two gates - fn assert_equal_point(&mut self, a: WitnessPoint, b: WitnessPoint) { + pub fn assert_equal_point(&mut self, a: WitnessPoint, b: WitnessPoint) { self.assert_equal(*a.x(), *b.x()); self.assert_equal(*a.y(), *b.y()); } @@ -635,7 +727,7 @@ pub trait Composer: Sized + Index { /// Asserts `point == public`. /// /// Will add `public` affine coordinates `(x,y)` as public inputs - fn assert_equal_public_point>( + pub fn assert_equal_public_point>( &mut self, point: WitnessPoint, public: P, @@ -656,7 +748,7 @@ pub trait Composer: Sized + Index { } /// Adds two curve points by consuming 2 gates. - fn component_add_point( + pub fn component_add_point( &mut self, a: WitnessPoint, b: WitnessPoint, @@ -705,7 +797,7 @@ pub trait Composer: Sized + Index { /// Note that using this constraint with whatever [`Witness`] that /// is not representing a value equalling 0 or 1, will always force the /// equation to fail. - fn component_boolean(&mut self, a: Witness) { + pub fn component_boolean(&mut self, a: Witness) { let zero = Self::ZERO; let constraint = Constraint::new() .mult(1) @@ -728,7 +820,7 @@ pub trait Composer: Sized + Index { /// an unsatisfied circuit. /// /// Consumes `2 · N + 1` gates - fn component_decomposition( + pub fn component_decomposition( &mut self, scalar: Witness, ) -> [Witness; N] { @@ -770,7 +862,7 @@ pub trait Composer: Sized + Index { /// /// `bit` is expected to be constrained by /// [`Composer::component_boolean`] - fn component_select_identity( + pub fn component_select_identity( &mut self, bit: Witness, a: WitnessPoint, @@ -782,7 +874,7 @@ pub trait Composer: Sized + Index { } /// Evaluate `jubjub · point` as a [`WitnessPoint`] - fn component_mul_point( + pub fn component_mul_point( &mut self, jubjub: Witness, point: WitnessPoint, @@ -809,7 +901,7 @@ pub trait Composer: Sized + Index { /// /// `bit` is expected to be constrained by /// [`Composer::component_boolean`] - fn component_select( + pub fn component_select( &mut self, bit: Witness, a: Witness, @@ -844,7 +936,7 @@ pub trait Composer: Sized + Index { /// /// `bit` is expected to be constrained by /// [`Composer::component_boolean`] - fn component_select_one( + pub fn component_select_one( &mut self, bit: Witness, value: Witness, @@ -876,7 +968,7 @@ pub trait Composer: Sized + Index { /// /// `bit` is expected to be constrained by /// [`Composer::component_boolean`] - fn component_select_point( + pub fn component_select_point( &mut self, bit: Witness, a: WitnessPoint, @@ -895,7 +987,7 @@ pub trait Composer: Sized + Index { /// /// `bit` is expected to be constrained by /// [`Composer::component_boolean`] - fn component_select_zero( + pub fn component_select_zero( &mut self, bit: Witness, value: Witness, @@ -914,7 +1006,10 @@ pub trait Composer: Sized + Index { /// (num_bits - 1)/8 + 9 gates, when num_bits > 0, /// and 7 gates, when num_bits = 0 /// to the circuit description. - fn component_range(&mut self, witness: Witness) { + pub fn component_range( + &mut self, + witness: Witness, + ) { // the bits are iterated as chunks of two; hence, we require an even // number let num_bits = cmp::min(BIT_PAIRS * 2, 256); @@ -1022,7 +1117,7 @@ pub trait Composer: Sized + Index { /// /// Set `q_o = (-1)` and override the output of the constraint with: /// `o := q_l · a + q_r · b + q_4 · d + q_c + PI` - fn gate_add(&mut self, s: Constraint) -> Witness { + pub fn gate_add(&mut self, s: Constraint) -> Witness { let s = Constraint::arithmetic(&s).output(-BlsScalar::one()); let o = self @@ -1039,7 +1134,7 @@ pub trait Composer: Sized + Index { /// /// Set `q_o = (-1)` and override the output of the constraint with: /// `o := q_m · a · b + q_4 · d + q_c + PI` - fn gate_mul(&mut self, s: Constraint) -> Witness { + pub fn gate_mul(&mut self, s: Constraint) -> Witness { let s = Constraint::arithmetic(&s).output(-BlsScalar::one()); let o = self @@ -1052,18 +1147,18 @@ pub trait Composer: Sized + Index { o } - /// Prove a circuit with a builder initialized with dummy gates - fn prove(constraints: usize, circuit: &C) -> Result + /// Prove a circuit with a composer initialized with dummy gates + pub fn prove(constraints: usize, circuit: &C) -> Result where C: Circuit, { - let mut builder = Self::initialized(); + let mut composer = Self::initialized(); - circuit.circuit(&mut builder)?; + circuit.circuit(&mut composer)?; // assert that the circuit has the same amount of constraints as the // circuit description - let description_size = builder.constraints(); + let description_size = composer.constraints(); if description_size != constraints { return Err(Error::InvalidCircuitSize( description_size, @@ -1071,8 +1166,39 @@ pub trait Composer: Sized + Index { )); } - builder.runtime().event(RuntimeEvent::ProofFinished); + composer.runtime().event(RuntimeEvent::ProofFinished); + + Ok(composer) + } + + pub(crate) fn public_input_indexes(&self) -> Vec { + let mut public_input_indexes: Vec<_> = + self.public_inputs.keys().copied().collect(); + + public_input_indexes.as_mut_slice().sort(); + + public_input_indexes + } + + pub(crate) fn public_inputs(&self) -> Vec { + self.public_input_indexes() + .iter() + .filter_map(|idx| self.public_inputs.get(idx).copied()) + .collect() + } + + pub(crate) fn dense_public_inputs( + public_input_indexes: &[usize], + public_inputs: &[BlsScalar], + size: usize, + ) -> Vec { + let mut dense_public_inputs = vec![BlsScalar::zero(); size]; + + public_input_indexes + .iter() + .zip(public_inputs.iter()) + .for_each(|(idx, pi)| dense_public_inputs[*idx] = *pi); - Ok(builder) + dense_public_inputs } } diff --git a/src/composer/builder.rs b/src/composer/builder.rs deleted file mode 100644 index 5e8da1fa..00000000 --- a/src/composer/builder.rs +++ /dev/null @@ -1,160 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -use alloc::vec::Vec; -use core::ops; - -use dusk_bls12_381::BlsScalar; -use hashbrown::HashMap; - -use crate::constraint_system::{Constraint, Selector, WiredWitness, Witness}; -use crate::permutation::Permutation; -use crate::runtime::Runtime; - -use super::{Arithmetization, Composer}; - -/// Construct and prove circuits -#[derive(Debug, Clone)] -pub struct Builder { - /// Constraint system gates - pub(crate) constraints: Vec, - - /// Sparse representation of the public inputs - pub(crate) public_inputs: HashMap, - - /// Witness values - pub(crate) witnesses: Vec, - - /// Permutation argument. - pub(crate) perm: Permutation, - - /// PLONK runtime controller - pub(crate) runtime: Runtime, -} - -impl Builder { - pub(crate) fn public_input_indexes(&self) -> Vec { - let mut public_input_indexes: Vec<_> = - self.public_inputs.keys().copied().collect(); - - public_input_indexes.as_mut_slice().sort(); - - public_input_indexes - } - - pub(crate) fn public_inputs(&self) -> Vec { - self.public_input_indexes() - .iter() - .filter_map(|idx| self.public_inputs.get(idx).copied()) - .collect() - } - - pub(crate) fn dense_public_inputs( - public_input_indexes: &[usize], - public_inputs: &[BlsScalar], - size: usize, - ) -> Vec { - let mut dense_public_inputs = vec![BlsScalar::zero(); size]; - - public_input_indexes - .iter() - .zip(public_inputs.iter()) - .for_each(|(idx, pi)| dense_public_inputs[*idx] = *pi); - - dense_public_inputs - } -} - -impl ops::Index for Builder { - type Output = BlsScalar; - - fn index(&self, w: Witness) -> &Self::Output { - &self.witnesses[w.index()] - } -} - -impl Composer for Builder { - fn uninitialized() -> Self { - Self { - constraints: Vec::new(), - public_inputs: HashMap::new(), - witnesses: Vec::new(), - perm: Permutation::new(), - runtime: Runtime::new(), - } - } - - fn constraints(&self) -> usize { - self.constraints.len() - } - - fn append_witness_internal(&mut self, witness: BlsScalar) -> Witness { - let n = self.witnesses.len(); - - // Get a new Witness from the permutation - self.perm.new_witness(); - - // Bind the allocated witness - self.witnesses.push(witness); - - Witness::new(n) - } - - fn append_custom_gate_internal(&mut self, constraint: Constraint) { - let n = self.constraints.len(); - - let w_a = constraint.witness(WiredWitness::A); - let w_b = constraint.witness(WiredWitness::B); - let w_o = constraint.witness(WiredWitness::O); - let w_d = constraint.witness(WiredWitness::D); - - let q_m = *constraint.coeff(Selector::Multiplication); - let q_l = *constraint.coeff(Selector::Left); - let q_r = *constraint.coeff(Selector::Right); - let q_o = *constraint.coeff(Selector::Output); - let q_4 = *constraint.coeff(Selector::Fourth); - let q_c = *constraint.coeff(Selector::Constant); - - let q_arith = *constraint.coeff(Selector::Arithmetic); - let q_range = *constraint.coeff(Selector::Range); - let q_logic = *constraint.coeff(Selector::Logic); - let q_fixed_group_add = *constraint.coeff(Selector::GroupAddFixedBase); - let q_variable_group_add = - *constraint.coeff(Selector::GroupAddVariableBase); - - let poly = Arithmetization { - q_m, - q_l, - q_r, - q_o, - q_4, - q_c, - q_arith, - q_range, - q_logic, - q_fixed_group_add, - q_variable_group_add, - w_a, - w_b, - w_o, - w_d, - }; - - self.constraints.push(poly); - - if constraint.has_public_input() { - let pi = *constraint.coeff(Selector::PublicInput); - - self.public_inputs.insert(n, pi); - } - - self.perm.add_witnesses_to_map(w_a, w_b, w_o, w_d, n); - } - - fn runtime(&mut self) -> &mut Runtime { - &mut self.runtime - } -} diff --git a/src/composer/circuit.rs b/src/composer/circuit.rs index deba2055..20272ff2 100644 --- a/src/composer/circuit.rs +++ b/src/composer/circuit.rs @@ -13,16 +13,11 @@ use super::Composer; /// The default implementation will be used to generate the proving arguments. pub trait Circuit: Default { /// Circuit definition - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer; + fn circuit(&self, composer: &mut Composer) -> Result<(), Error>; /// Returns the size of the circuit. - fn size(&self) -> usize - where - C: Composer, - { - let mut composer = C::initialized(); + fn size(&self) -> usize { + let mut composer = Composer::initialized(); match self.circuit(&mut composer) { Ok(_) => composer.constraints(), Err(_) => 0, diff --git a/src/composer/compiler.rs b/src/composer/compiler.rs index 7cdf385d..a87d2a66 100644 --- a/src/composer/compiler.rs +++ b/src/composer/compiler.rs @@ -16,7 +16,7 @@ use crate::fft::{EvaluationDomain, Evaluations, Polynomial}; use crate::proof_system::preprocess::Polynomials; use crate::proof_system::{widget, ProverKey}; -use super::{Arithmetization, Builder, Circuit, Composer, Prover, Verifier}; +use super::{Circuit, Composer, Gate, Prover, Verifier}; #[cfg(feature = "alloc")] mod compress; @@ -35,10 +35,10 @@ impl Compiler { where C: Circuit, { - let mut builder = Builder::initialized(); - C::default().circuit(&mut builder)?; + let mut composer = Composer::initialized(); + C::default().circuit(&mut composer)?; - Self::compile_with_builder(pp, label, &builder) + Self::compile_with_composer(pp, label, &composer) } /// Create a new arguments set from a given circuit instance @@ -52,10 +52,10 @@ impl Compiler { where C: Circuit, { - let mut builder = Builder::initialized(); - circuit.circuit(&mut builder)?; + let mut composer = Composer::initialized(); + circuit.circuit(&mut composer)?; - Self::compile_with_builder(pp, label, &builder) + Self::compile_with_composer(pp, label, &composer) } /// Return a bytes representation of a compressed circuit, capable of @@ -81,17 +81,17 @@ impl Compiler { /// Create a new arguments set from a given circuit instance /// /// Use the default implementation of the circuit - fn compile_with_builder( + fn compile_with_composer( pp: &PublicParameters, label: &[u8], - builder: &Builder, + composer: &Composer, ) -> Result<(Prover, Verifier), Error> { - let n = (builder.constraints() + 6).next_power_of_two(); + let n = (composer.constraints() + 6).next_power_of_two(); let (commit, opening) = pp.trim(n)?; let (prover, verifier) = - Self::preprocess(label, commit, opening, builder)?; + Self::preprocess(label, commit, opening, composer)?; Ok((prover, verifier)) } @@ -100,7 +100,7 @@ impl Compiler { label: &[u8], commit_key: CommitKey, opening_key: OpeningKey, - prover: &Builder, + prover: &Composer, ) -> Result<(Prover, Verifier), Error> { let mut perm = prover.perm.clone(); diff --git a/src/composer/compiler/compress.rs b/src/composer/compiler/compress.rs index af7ef4b1..ea8e4d54 100644 --- a/src/composer/compiler/compress.rs +++ b/src/composer/compiler/compress.rs @@ -11,8 +11,8 @@ use msgpacker::{MsgPacker, Packable, Unpackable}; use alloc::vec::Vec; use super::{ - Arithmetization, BlsScalar, Builder, Circuit, Compiler, Composer, - Constraint, Error, Prover, PublicParameters, Selector, Verifier, Witness, + BlsScalar, Circuit, Compiler, Composer, Constraint, Error, Gate, Prover, + PublicParameters, Selector, Verifier, Witness, }; mod hades; @@ -84,18 +84,21 @@ impl CompressedCircuit { where C: Circuit, { - let mut builder = Builder::initialized(); - C::default().circuit(&mut builder)?; - Ok(Self::from_builder(hades_optimization, builder)) + let mut composer = Composer::initialized(); + C::default().circuit(&mut composer)?; + Ok(Self::from_composer(hades_optimization, composer)) } - pub fn from_builder(hades_optimization: bool, builder: Builder) -> Vec { + pub fn from_composer( + hades_optimization: bool, + composer: Composer, + ) -> Vec { let mut public_inputs: Vec<_> = - builder.public_inputs.keys().copied().collect(); + composer.public_inputs.keys().copied().collect(); public_inputs.sort(); - let witnesses = builder.witnesses.len(); - let polynomials = builder.constraints; + let witnesses = composer.witnesses.len(); + let polynomials = composer.constraints; let constraints = polynomials.into_iter(); let mut scalars = scalar_map(hades_optimization); @@ -103,7 +106,7 @@ impl CompressedCircuit { let mut polynomials = HashMap::new(); let constraints = constraints .map( - |Arithmetization { + |Gate { q_m, q_l, q_r, @@ -241,14 +244,13 @@ impl CompressedCircuit { } let scalars = version_scalars; - #[allow(deprecated)] // we use `uninitialized` because the decompressor will also contain the // dummy constraints, if they were part of the prover when encoding. - let mut builder = Builder::uninitialized(); + let mut composer = Composer::uninitialized(); let mut pi = 0; (0..witnesses).for_each(|_| { - builder.append_witness(BlsScalar::zero()); + composer.append_witness(BlsScalar::zero()); }); for ( @@ -353,9 +355,9 @@ impl CompressedCircuit { } } - builder.append_custom_gate(constraint); + composer.append_custom_gate(constraint); } - Compiler::compile_with_builder(pp, label, &builder) + Compiler::compile_with_composer(pp, label, &composer) } } diff --git a/src/composer/arithmetization.rs b/src/composer/gate.rs similarity index 92% rename from src/composer/arithmetization.rs rename to src/composer/gate.rs index 9b769b20..41e26178 100644 --- a/src/composer/arithmetization.rs +++ b/src/composer/gate.rs @@ -8,9 +8,9 @@ use dusk_bls12_381::BlsScalar; use crate::constraint_system::Witness; -/// Represents a polynomial in coefficient form with its associated wire data +/// Represents a gate with its associated wire data #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct Arithmetization { +pub struct Gate { // Selectors /// Multiplier selector pub(crate) q_m: BlsScalar, diff --git a/src/composer/prover.rs b/src/composer/prover.rs index 7a3413fa..0b0d09ca 100644 --- a/src/composer/prover.rs +++ b/src/composer/prover.rs @@ -22,7 +22,7 @@ use crate::proof_system::{ }; use crate::transcript::TranscriptProtocol; -use super::{Builder, Circuit, Composer}; +use super::{Circuit, Composer}; /// Turbo Prover with processed keys #[derive(Clone)] @@ -231,7 +231,7 @@ impl Prover { C: Circuit, R: RngCore + CryptoRng, { - let prover = Builder::prove(self.constraints, circuit)?; + let prover = Composer::prove(self.constraints, circuit)?; let constraints = self.constraints; let size = self.size; @@ -242,7 +242,7 @@ impl Prover { let public_inputs = prover.public_inputs(); let public_input_indexes = prover.public_input_indexes(); - let dense_public_inputs = Builder::dense_public_inputs( + let dense_public_inputs = Composer::dense_public_inputs( &public_input_indexes, &public_inputs, self.size, diff --git a/src/composer/verifier.rs b/src/composer/verifier.rs index ec81a83b..bca72919 100644 --- a/src/composer/verifier.rs +++ b/src/composer/verifier.rs @@ -15,7 +15,7 @@ use crate::error::Error; use crate::proof_system::{Proof, VerifierKey}; use crate::transcript::TranscriptProtocol; -use super::Builder; +use super::Composer; /// Verify proofs of a given circuit pub struct Verifier { @@ -208,7 +208,7 @@ impl Verifier { .iter() .for_each(|pi| transcript.append_scalar(b"pi", pi)); - let dense_public_inputs = Builder::dense_public_inputs( + let dense_public_inputs = Composer::dense_public_inputs( &self.public_input_indexes, public_inputs, self.size, diff --git a/src/constraint_system/constraint.rs b/src/constraint_system/constraint.rs index bf846663..3ce87b98 100644 --- a/src/constraint_system/constraint.rs +++ b/src/constraint_system/constraint.rs @@ -4,7 +4,7 @@ // // Copyright (c) DUSK NETWORK. All rights reserved. -use crate::composer::{Builder, Composer}; +use crate::composer::Composer; use crate::constraint_system::Witness; use dusk_bls12_381::BlsScalar; @@ -103,7 +103,7 @@ impl Constraint { pub const fn new() -> Self { Self { coefficients: [BlsScalar::zero(); Self::COEFFICIENTS], - witnesses: [Builder::ZERO; Self::WITNESSES], + witnesses: [Composer::ZERO; Self::WITNESSES], has_public_input: false, } } diff --git a/src/prelude.rs b/src/prelude.rs index 7a788ff8..f9f538df 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -12,7 +12,7 @@ #[cfg(feature = "alloc")] pub use crate::{ commitment_scheme::PublicParameters, - composer::{Builder, Circuit, Compiler, Composer, Prover, Verifier}, + composer::{Circuit, Compiler, Composer, Prover, Verifier}, constraint_system::{Constraint, Witness, WitnessPoint}, }; diff --git a/src/proof_system/proof.rs b/src/proof_system/proof.rs index 3ba4df17..da7036a9 100644 --- a/src/proof_system/proof.rs +++ b/src/proof_system/proof.rs @@ -26,12 +26,14 @@ use rkyv::{ /// Quotient, Shifted and Opening polynomials as well as the /// `ProofEvaluations`. /// -/// It's main goal is to allow the `Verifier` to -/// formally verify that the secret witnesses used to generate the [`Proof`] -/// satisfy a circuit that both [`Builder`](crate::prelude::Builder) and -/// [`Verifier`](crate::prelude::Verifier) have in common succintly -/// and without any capabilities of adquiring any kind of knowledge about the -/// witness used to construct the Proof. +/// It's main goal is to allow the `Verifier` to formally verify that the secret +/// witnesses used to generate the [`Proof`] satisfy a circuit that both +/// [`Composer`] and [`Verifier`] have in common succintly and without any +/// capabilities of adquiring any kind of knowledge about the witness used to +/// construct the Proof. +/// +/// [`Composer`]: [`crate::prelude::Composer`] +/// [`Verifier`]: [`crate::prelude::Verifier`] #[derive(Debug, Eq, PartialEq, Clone, Default)] #[cfg_attr( feature = "rkyv-impl", diff --git a/src/runtime.rs b/src/runtime.rs index 2861ccab..01905a8b 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -58,15 +58,6 @@ impl Runtime { } } - /// Create a new PLONK runtime with the provided capacity - #[allow(unused_variables)] - pub fn with_capacity(capacity: usize) -> Self { - Self { - #[cfg(feature = "debug")] - debugger: Debugger::with_capacity(capacity), - } - } - #[allow(unused_variables)] pub(crate) fn event(&mut self, event: RuntimeEvent) { #[cfg(feature = "debug")] diff --git a/tests/append_gate.rs b/tests/append_gate.rs index e6867ac7..77e75ff6 100644 --- a/tests/append_gate.rs +++ b/tests/append_gate.rs @@ -36,10 +36,7 @@ fn append_gate() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); let w_b = composer.append_witness(self.b); let w_o = composer.append_witness(self.o); diff --git a/tests/assert_point.rs b/tests/assert_point.rs index 66364e53..6fab08e3 100644 --- a/tests/assert_point.rs +++ b/tests/assert_point.rs @@ -34,10 +34,7 @@ fn assert_equal_point() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_p1 = composer.append_point(self.p1); let w_p2 = composer.append_point(self.p2); composer.assert_equal_point(w_p1, w_p2); @@ -126,10 +123,7 @@ fn assert_equal_public_point() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_point = composer.append_point(self.point); composer.assert_equal_public_point(w_point, self.public); diff --git a/tests/assert_scalar.rs b/tests/assert_scalar.rs index 351e328a..f1e870ca 100644 --- a/tests/assert_scalar.rs +++ b/tests/assert_scalar.rs @@ -38,10 +38,7 @@ fn assert_equal() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_scalar_a = composer.append_witness(self.scalar_a); let w_scalar_b = composer.append_witness(self.scalar_b); @@ -127,10 +124,7 @@ fn assert_equal_constant() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_scalar = composer.append_witness(self.scalar); composer.assert_equal_constant( diff --git a/tests/boolean.rs b/tests/boolean.rs index 05f0535b..0f4e0f46 100644 --- a/tests/boolean.rs +++ b/tests/boolean.rs @@ -31,10 +31,7 @@ fn component_boolean() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_bit = composer.append_witness(self.bit); composer.component_boolean(w_bit); diff --git a/tests/composer.rs b/tests/composer.rs index 7818827a..56ee9936 100644 --- a/tests/composer.rs +++ b/tests/composer.rs @@ -37,10 +37,7 @@ fn circuit_with_all_gates() { } impl Circuit for DummyCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); let w_b = composer.append_witness(self.b); let w_x = composer.append_witness(self.x); @@ -65,7 +62,7 @@ fn circuit_with_all_gates() { composer.component_add_point(w_z, w_z); composer.append_logic_and::<128>(w_a, w_b); - composer.component_boolean(Builder::ONE); + composer.component_boolean(Composer::ONE); composer.component_decomposition::<254>(w_a); composer.component_mul_generator( w_y, @@ -73,11 +70,11 @@ fn circuit_with_all_gates() { )?; composer.component_mul_point(w_y, w_z); composer.component_range::<128>(w_a); - composer.component_select(Builder::ONE, w_a, w_b); - composer.component_select_identity(Builder::ONE, w_z); - composer.component_select_one(Builder::ONE, w_a); - composer.component_select_point(Builder::ONE, w_z, w_z); - composer.component_select_zero(Builder::ONE, w_a); + composer.component_select(Composer::ONE, w_a, w_b); + composer.component_select_identity(Composer::ONE, w_z); + composer.component_select_one(Composer::ONE, w_a); + composer.component_select_point(Composer::ONE, w_z, w_z); + composer.component_select_zero(Composer::ONE, w_a); composer.append_logic_xor::<128>(w_a, w_b); Ok(()) diff --git a/tests/debugger.rs b/tests/debugger.rs index b2d37cc5..9d91e30b 100644 --- a/tests/debugger.rs +++ b/tests/debugger.rs @@ -13,10 +13,7 @@ use dusk_plonk::prelude::*; struct EmptyCircuit; impl Circuit for EmptyCircuit { - fn circuit(&self, _composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, _composer: &mut Composer) -> Result<(), Error> { Ok(()) } } diff --git a/tests/decomposition.rs b/tests/decomposition.rs index 0a017fa9..bf5f9e06 100644 --- a/tests/decomposition.rs +++ b/tests/decomposition.rs @@ -32,10 +32,7 @@ fn component_decomposition() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); let decomp_circuit: [Witness; N] = composer.component_decomposition(w_a); diff --git a/tests/ecc.rs b/tests/ecc.rs index 450cc104..1fd44907 100644 --- a/tests/ecc.rs +++ b/tests/ecc.rs @@ -40,10 +40,7 @@ fn component_add_point() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_p1 = composer.append_point(self.p1); let w_p2 = composer.append_point(self.p2); let w_sum = composer.append_point(self.sum); @@ -144,7 +141,7 @@ fn component_mul_generator() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_scalar = composer.append_witness(self.scalar); let w_result = composer.append_point(self.result); @@ -246,10 +243,7 @@ fn component_mul_point() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_scalar = composer.append_witness(self.scalar); let w_point = composer.append_point(self.point); let w_result = composer.append_point(self.result); diff --git a/tests/error_size.rs b/tests/error_size.rs index 558e7bab..87726852 100644 --- a/tests/error_size.rs +++ b/tests/error_size.rs @@ -24,11 +24,8 @@ impl TestSize { } impl Circuit for TestSize { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { - let sum = self.witnesses.iter().fold(C::ZERO, |acc, scalar| { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { + let sum = self.witnesses.iter().fold(Composer::ZERO, |acc, scalar| { let w = composer.append_witness(*scalar); let constraint = Constraint::new().left(1).a(acc).right(1).b(w); composer.gate_add(constraint) @@ -57,7 +54,7 @@ fn size() { let sum = witnesses.iter().sum(); let circuit = TestSize::new(witnesses, sum); let result = prover.prove(rng, &circuit); - let empty_circuit_size = Builder::initialized().constraints(); + let empty_circuit_size = Composer::initialized().constraints(); assert!(result.is_err_and(|e| e == Error::InvalidCircuitSize( empty_circuit_size + 5, diff --git a/tests/gate_add_mul.rs b/tests/gate_add_mul.rs index 98a90da0..dd1e1947 100644 --- a/tests/gate_add_mul.rs +++ b/tests/gate_add_mul.rs @@ -42,10 +42,7 @@ fn gate_add_mul() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); let w_b = composer.append_witness(self.b); let w_d = composer.append_witness(self.d); diff --git a/tests/logic.rs b/tests/logic.rs index 8864583d..916f76c4 100644 --- a/tests/logic.rs +++ b/tests/logic.rs @@ -39,10 +39,7 @@ fn append_logic_and() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); let w_b = composer.append_witness(self.b); let w_result = composer.append_witness(self.result); @@ -217,10 +214,7 @@ fn append_logic_xor() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); let w_b = composer.append_witness(self.b); let w_result = composer.append_witness(self.result); diff --git a/tests/range.rs b/tests/range.rs index 56effa2d..a4764dfe 100644 --- a/tests/range.rs +++ b/tests/range.rs @@ -26,10 +26,7 @@ fn range() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_a = composer.append_witness(self.a); composer.component_range::(w_a); diff --git a/tests/select_bls.rs b/tests/select_bls.rs index de6a15f2..75f8389e 100644 --- a/tests/select_bls.rs +++ b/tests/select_bls.rs @@ -49,10 +49,7 @@ fn component_select() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_bit = composer.append_witness(self.bit); let w_value_a = composer.append_witness(self.value_a); let w_value_b = composer.append_witness(self.value_b); @@ -212,10 +209,7 @@ fn component_select_one() { } } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_bit = composer.append_witness(self.bit); let w_value = composer.append_witness(self.value); let w_result = composer.append_witness(self.result); @@ -362,10 +356,7 @@ fn component_select_zero() { } } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_bit = composer.append_witness(self.bit); let w_value = composer.append_witness(self.value); let w_result = composer.append_witness(self.result); diff --git a/tests/select_point.rs b/tests/select_point.rs index db79c6fe..330176f2 100644 --- a/tests/select_point.rs +++ b/tests/select_point.rs @@ -49,10 +49,7 @@ fn component_select_point() { } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_bit = composer.append_witness(self.bit); let w_point_a = composer.append_point(self.point_a); let w_point_b = composer.append_point(self.point_b); @@ -244,10 +241,7 @@ fn component_select_identity() { } } impl Circuit for TestCircuit { - fn circuit(&self, composer: &mut C) -> Result<(), Error> - where - C: Composer, - { + fn circuit(&self, composer: &mut Composer) -> Result<(), Error> { let w_bit = composer.append_witness(self.bit); let w_point = composer.append_point(self.point); let w_result = composer.append_point(self.result);