Skip to content

Commit

Permalink
Add Witness as replacement of AllocatedScalar
Browse files Browse the repository at this point in the history
`AllocatedScalar` may suggest to the users to evaluate runtime scalars
to build their gadgets. This is inconsistent because it might create
different circuit descriptions out of the same code.

`AllocatedScalar` was entirely removed in favor of `Witness`. The latter
is a simple index to the witness value in the composer.

Resolves #588
  • Loading branch information
vlopes11 committed Sep 30, 2021
1 parent 90b3478 commit 7cb8276
Show file tree
Hide file tree
Showing 24 changed files with 548 additions and 709 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ 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)

### 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))

### Fixed

- Fix the document references and typos [#533](https://github.com/dusk-network/plonk/pull/533)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ impl Circuit for TestCircuit {
&mut self,
composer: &mut TurboComposer,
) -> Result<(), Error> {
let a = composer.add_input(self.a);
let b = composer.add_input(self.b);
let a = composer.append_witness(self.a);
let b = composer.append_witness(self.b);
// Make first constraint a + b = c
composer.poly_gate(
a,
b,
composer.allocated_zero(),
composer.zero(),
BlsScalar::zero(),
BlsScalar::one(),
BlsScalar::one(),
Expand All @@ -57,7 +57,7 @@ impl Circuit for TestCircuit {
composer.poly_gate(
a,
b,
composer.allocated_zero(),
composer.zero(),
BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::zero(),
Expand All @@ -66,7 +66,7 @@ impl Circuit for TestCircuit {
Some(-self.d),
);

let e = composer.add_input(self.e);
let e = composer.append_witness(self.e);
let scalar_mul_result = composer
.fixed_base_scalar_mul(e, dusk_jubjub::GENERATOR_EXTENDED);
// Apply the constrain
Expand Down
18 changes: 9 additions & 9 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ impl VerifierData {
/// composer: &mut TurboComposer,
/// ) -> Result<(), Error> {
/// // Add fixed witness zero
/// let zero = composer.add_witness_to_circuit_description(BlsScalar::zero());
/// let a = composer.add_input(self.a);
/// let b = composer.add_input(self.b);
/// let zero = composer.zero();
/// let a = composer.append_witness(self.a);
/// let b = composer.append_witness(self.b);
/// // Make first constraint a + b = c
/// composer.poly_gate(
/// a,
Expand Down Expand Up @@ -168,7 +168,7 @@ impl VerifierData {
/// Some(-self.d),
/// );
///
/// let e = composer.add_input(self.e);
/// let e = composer.append_witness(self.e);
/// let scalar_mul_result =
/// composer.fixed_base_scalar_mul(
/// e, dusk_jubjub::GENERATOR_EXTENDED,
Expand Down Expand Up @@ -376,13 +376,13 @@ mod tests {
&mut self,
composer: &mut TurboComposer,
) -> std::result::Result<(), Error> {
let a = composer.add_input(self.a);
let b = composer.add_input(self.b);
let a = composer.append_witness(self.a);
let b = composer.append_witness(self.b);
// Make first constraint a + b = c
composer.poly_gate(
a,
b,
composer.allocated_zero(),
composer.zero(),
BlsScalar::zero(),
BlsScalar::one(),
BlsScalar::one(),
Expand All @@ -397,7 +397,7 @@ mod tests {
composer.poly_gate(
a,
b,
composer.allocated_zero(),
composer.zero(),
BlsScalar::one(),
BlsScalar::zero(),
BlsScalar::zero(),
Expand All @@ -406,7 +406,7 @@ mod tests {
Some(-self.d),
);

let e = composer.add_input(self.e);
let e = composer.append_witness(self.e);
let scalar_mul_result = composer
.fixed_base_scalar_mul(e, dusk_jubjub::GENERATOR_EXTENDED);
// Apply the constrain
Expand Down
Loading

0 comments on commit 7cb8276

Please sign in to comment.