Fix mul_by_inverse for constants

This commit is contained in:
Pratyush Mishra
2021-01-08 16:53:56 -08:00
parent f52b866e59
commit a44643ed76

View File

@@ -160,6 +160,9 @@ pub trait FieldVar<F: Field, ConstraintF: Field>:
/// It is up to the caller to ensure that denominator is non-zero,
/// since in that case the result is unconstrained.
fn mul_by_inverse(&self, denominator: &Self) -> Result<Self, SynthesisError> {
if self.is_constant() && denominator.is_constant() {
Ok(self.clone() * denominator.value()?.inverse().unwrap())
} else {
let result = Self::new_witness(self.cs(), || {
let denominator_inv_native = denominator.value()?.inverse().get()?;
let result = self.value()? * &denominator_inv_native;
@@ -169,6 +172,7 @@ pub trait FieldVar<F: Field, ConstraintF: Field>:
Ok(result)
}
}
/// Computes the frobenius map over `self`.
fn frobenius_map(&self, power: usize) -> Result<Self, SynthesisError>;