forked from ProvableHQ/snarkVM
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize field (in)equality circuit.
To calculate `z = x != y`, instead of ``` (z) (1 - z) = (0) (x - y) (w) = (z) (x - y) (1 - z) = (0) ``` (where `w` is an internal variable) we just need ``` (x - y) (w) = (z) (x - y) (1 - z) = (0) ``` i.e. just the 2nd and 3rd constraints, because they imply the 1st one. So we save one constraint for every field (in)equality. This optimization has been already verified in the ACL2 theorem prover. To avoid generating the boolean constraint, we need to avoid `Boolean::new`, and instead generate the `Boolean` directly, as in boolean AND for example. However, boolean AND has access to the private `LinearCombination` component of `Boolean`, while field (in)equality does not. So I've added a `from_variable` constructor to `Boolean`, but if there is a better or more desirable approach, we can revise this part.
- Loading branch information
Showing
2 changed files
with
37 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters