mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-13 01:11:31 +01:00
Introduce mul_by_inverse_unchecked, and use it (#75)
This commit is contained in:
@@ -421,6 +421,14 @@ impl<F: PrimeField> AllocatedFp<F> {
|
||||
other: &Self,
|
||||
should_enforce: &Boolean<F>,
|
||||
) -> Result<(), SynthesisError> {
|
||||
// The high level logic is as follows:
|
||||
// We want to check that self - other != 0. We do this by checking that
|
||||
// (self - other).inverse() exists. In more detail, we check the following:
|
||||
// If `should_enforce == true`, then we set `multiplier = (self - other).inverse()`,
|
||||
// and check that (self - other) * multiplier == 1. (i.e., that the inverse exists)
|
||||
//
|
||||
// If `should_enforce == false`, then we set `multiplier == 0`, and check that
|
||||
// (self - other) * 0 == 0, which is always satisfied.
|
||||
let multiplier = Self::new_witness(self.cs.clone(), || {
|
||||
if should_enforce.value()? {
|
||||
(self.value.get()? - other.value.get()?).inverse().get()
|
||||
|
||||
Reference in New Issue
Block a user