Skip to content

Commit

Permalink
Add public unsafe evaluate_witness() to the composer (#601)
Browse files Browse the repository at this point in the history
Resolves: #612
  • Loading branch information
ZER0 authored and vlopes11 committed Oct 18, 2021
1 parent 510ce1f commit 0d7fd73
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/constraint_system/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ impl TurboComposer {
}

/// Evaluate the runtime value of a witness
#[allow(dead_code)]
pub(crate) fn evaluate_witness(&self, witness: &Witness) -> &BlsScalar {
///
/// # Safety
///
/// Witness evaluation inside a gadget isn't expected and could produce an
/// unsound circuit (different circuit representation for the same code).
///
/// Calling this function performs operations outside the circuit.
pub unsafe fn evaluate_witness(&self, witness: &Witness) -> &BlsScalar {
&self.witnesses[witness]
}

Expand Down
10 changes: 6 additions & 4 deletions src/constraint_system/ecc/curve_addition/variable_base_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ mod test {
composer.gate_add(d_x1_x2_y1_y2, zero, zero, constraint);

// Compute the inverse
let inv_x_denom =
composer.evaluate_witness(&x_denominator).invert().unwrap();
let inv_x_denom = unsafe {
composer.evaluate_witness(&x_denominator).invert().unwrap()
};
let inv_x_denom = composer.append_witness(inv_x_denom);

let constraint = Constraint::new().mul(1).constant(-BlsScalar::one());
Expand All @@ -164,8 +165,9 @@ mod test {
let y_denominator =
composer.gate_add(d_x1_x2_y1_y2, zero, zero, constraint);

let inv_y_denom =
composer.evaluate_witness(&y_denominator).invert().unwrap();
let inv_y_denom = unsafe {
composer.evaluate_witness(&y_denominator).invert().unwrap()
};
let inv_y_denom = composer.append_witness(inv_y_denom);

// Assert that we actually have the inverse
Expand Down

0 comments on commit 0d7fd73

Please sign in to comment.