Skip to content

Commit

Permalink
Restrict input values for exists operator to 0 and 1
Browse files Browse the repository at this point in the history
  • Loading branch information
OBrezhniev committed Mar 22, 2024
1 parent 3ea0c50 commit 8cea69d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions circuits/lib/query/processQueryWithModifiers.circom
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ template ProcessQueryWithModifiers(claimLevels, maxValueArraySize){
signal isOpNoop <== IsZero()(operator);
signal merklizedAndEnabled <== AND()(enabled, merklized);

signal isOpExists <== IsEqual()([operator, 11]);

// if operator == exists and value[0] == 0 ($exists == false), then claimPathNotExists = 1 (check non-inclusion),
// otherwise claimPathNotExists = 0 (check inclusion)
signal claimPathNotExists <== AND()(IsEqual()([operator, 11]), IsZero()(value[0]));
signal claimPathNotExists <== AND()(isOpExists, IsZero()(value[0]));

// check path/in node exists in merkle tree specified by jsonldRoot
SMTVerifier(claimLevels)(
Expand All @@ -58,12 +60,18 @@ template ProcessQueryWithModifiers(claimLevels, maxValueArraySize){
);

// For non-merklized credentials exists / non-exist operators should always fail
signal isOpExists <== IsEqual()([operator, 11]);
ForceEqualIfEnabled()(
AND()(enabled, NOT()(merklized)),
[isOpExists, 0]
);

// Restrict exists operator input values to 0 and 1
ForceEqualIfEnabled()(
AND()(enabled, isOpExists),
[value[0] * (value[0] - 1), 0]
);


/////////////////////////////////////////////////////////////////
// Query Operator Processing
/////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion circuits/lib/query/query.circom
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ include "comparators.circom";
8 - greater than or equal
9 - between (value[0] <= in <= value[1])
10 - not between
11 - exist (true / false)
11 - exists (true / false)
Modifier/computation operators:
16 - selective disclosure (16 = 10000 binary)
*/
Expand Down

0 comments on commit 8cea69d

Please sign in to comment.