-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tuple and list membership modules (#1660)
This PR adds tuple and list membership modules to the `gpcircuits` package. This includes additions to the proto POD GPC and modifications to the tests. All tests pass. Some relevant notes for context: * Tuples are represented as Poseidon hashes of arrays of entry value hashes of some fixed length (assumed to be between 2 and 4), and the module outputs multiple tuples as dictated by one of its parameters. Value hashes are chosen by index, and tuples may be fed into other tuples by appropriate indexing. An index of -1 implies a reference to 0, the value of choice for padding. One tuple module is instantiated in the proto POD GPC. * List membership is checked in the usual linear way. Lists are assumed to be padded with the first element of the list. One list membership module is instantiated in the proto POD GPC and the value whose membership is to be checked is referenced by index, where an index may refer to either an entry value hash or a computed tuple hash. Again, an index equal to -1 implies a reference to 0, though this device isn't strictly necessary in this case. * Some helper functions were added. A variant of `InputSelector` is included to allow for -1 index trick mentioned above while keeping an out-of-bounds check in place otherwise. * Some changes were made to the circuit family parameters. Marking this as a draft for now as the tests need to be fleshed out a bit to cover some edge cases (e.g. the case of an empty membership list), and I'd like to give the code (and comments) a once-over. The design is unlikely to change much, so feel free to peruse. --------- Co-authored-by: Andrew Twyman <[email protected]>
- Loading branch information
Showing
31 changed files
with
45,750 additions
and
90 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
extends: ["@pcd/eslint-config-custom"], | ||
root: true, | ||
root: true | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
pragma circom 2.1.8; | ||
|
||
include "circomlib/circuits/comparators.circom"; | ||
|
||
/** | ||
* Module for checking whether a value is a member of a given list. | ||
* A value may be either a POD entry value hash or a combination | ||
* of such values (e.g. a tuple encoded as a hash). | ||
*/ | ||
template ListMembershipModule( | ||
// Maximum number of valid values | ||
MAX_LIST_ELEMENTS | ||
) { | ||
// Value to be checked. | ||
signal input comparisonValue; | ||
|
||
// List of admissible value hashes. Assumed to have repetitions if the actual list length is smaller. | ||
signal input validValues[MAX_LIST_ELEMENTS]; | ||
|
||
// Boolean indicating whether `comparisonValue` lies in `validValues`. | ||
signal output isMember; | ||
|
||
signal partialProduct[MAX_LIST_ELEMENTS]; | ||
|
||
for (var i = 0; i < MAX_LIST_ELEMENTS; i++) { | ||
if (i == 0) { | ||
partialProduct[i] <== comparisonValue - validValues[i]; | ||
} else { | ||
partialProduct[i] <== partialProduct[i-1] * (comparisonValue - validValues[i]); | ||
} | ||
} | ||
|
||
if (MAX_LIST_ELEMENTS == 0) { | ||
isMember <== 0; | ||
} else { | ||
isMember <== IsZero()(partialProduct[MAX_LIST_ELEMENTS - 1]); | ||
} | ||
} |
Oops, something went wrong.