diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d56f8a7..d5d7a69c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add support for rendering LaTeX in the docs [#630](https://github.com/dusk-network/plonk/pull/630) +- Add `append_public_witness` to `TurboComposer`. [#654](https://github.com/dusk-network/plonk/issues/654) ## [0.9.0] - 10-11-21 diff --git a/src/constraint_system/composer.rs b/src/constraint_system/composer.rs index 1bbe6a2f..fb50768f 100644 --- a/src/constraint_system/composer.rs +++ b/src/constraint_system/composer.rs @@ -242,6 +242,21 @@ impl TurboComposer { var } + /// Allocate a witness value into the composer and return its index. + /// + /// Create a public input with the scalar + pub fn append_public_witness>( + &mut self, + scalar: T, + ) -> Witness { + let scalar = scalar.into(); + let witness = self.append_witness(scalar); + + self.assert_equal_constant(witness, 0, Some(-scalar)); + + witness + } + /// Adds a width-4 poly gate. /// /// The final constraint added will enforce the following: @@ -301,12 +316,13 @@ impl TurboComposer { /// Constrain `a` to be equal to `constant + pi`. /// /// `constant` will be defined as part of the public circuit description. - pub fn assert_equal_constant( + pub fn assert_equal_constant>( &mut self, a: Witness, - constant: BlsScalar, + constant: C, pi: Option, ) { + let constant = constant.into(); let constraint = Constraint::new().left(1).constant(-constant).a(a); // TODO maybe accept `Constraint` instead of `Option`?