mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-13 01:11:31 +01:00
Make mul_by_inverse use one constraint (#42)
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
This commit is contained in:
@@ -716,21 +716,6 @@ impl<F: PrimeField> FieldVar<F, F> for FpVar<F> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns (self / denominator), but requires fewer constraints than
|
||||
/// self * denominator.inverse()
|
||||
/// It is up to the caller to ensure that denominator is non-zero,
|
||||
/// since in that case the result is unconstrained.
|
||||
#[tracing::instrument(target = "r1cs")]
|
||||
fn mul_by_inverse(&self, denominator: &Self) -> Result<Self, SynthesisError> {
|
||||
use FpVar::*;
|
||||
match (self, denominator) {
|
||||
(Constant(s), Constant(d)) => Ok(Constant(*s / *d)),
|
||||
(Var(s), Constant(d)) => Ok(Var(s.mul_constant(d.inverse().get()?))),
|
||||
(Constant(s), Var(d)) => Ok(Var(d.inverse()?.mul_constant(*s))),
|
||||
(Var(s), Var(d)) => Ok(Var(d.inverse()?.mul(s))),
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(target = "r1cs")]
|
||||
fn frobenius_map(&self, power: usize) -> Result<Self, SynthesisError> {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user