Add `Assigned::is_zero_vartime` method

This commit is contained in:
Jack Grigg 2021-12-08 03:34:57 +00:00
parent 9d0e0b7be9
commit 927463f76a
1 changed files with 12 additions and 0 deletions

View File

@ -152,6 +152,18 @@ impl<F: Field> Assigned<F> {
}
}
/// Returns true iff this element is zero.
pub fn is_zero_vartime(&self) -> bool {
match self {
Self::Zero => true,
Self::Trivial(x) => x.is_zero_vartime(),
// Assigned maps x/0 -> 0.
Self::Rational(numerator, denominator) => {
numerator.is_zero_vartime() || denominator.is_zero_vartime()
}
}
}
/// Inverts this assigned value (taking the inverse of zero to be zero).
pub fn invert(&self) -> Self {
match self {