Skip to content

Commit 0bb7976

Browse files
committed
Ignore zero entries on multi-proofs
1 parent b7ac008 commit 0bb7976

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

circuits/presentationFieldsAuth.circom

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,20 @@ template VerifyCredentialMultiField(cdl, ctl) {
9999

100100
// Verify whether the fields exists in the credential tree
101101
component fieldHasher[m];
102+
component zero[m];
102103
component credtree = MerkleMultiProof(cdl);
104+
signal s[m];
103105
for (var i = 0; i < m; i++) {
106+
zero[i] = IsZero();
107+
zero[i].in <== fields[i][0];
108+
s[i] <== 1 - zero[i].out;
109+
104110
fieldHasher[i] = CredentialLeafHasher();
105111
fieldHasher[i].key <== fields[i][0];
106112
fieldHasher[i].value <== fields[i][1];
107113
fieldHasher[i].salt <== fields[i][2];
108-
credtree.leaves[i] <== fieldHasher[i].out;
114+
115+
credtree.leaves[i] <== (fieldHasher[i].out)*s[i];
109116
credtree.pathElements[i] <== pathFieldElements[i];
110117
credtree.leafIndices[i] <== fieldIndices[i];
111118
}

circuits/score.circom

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,26 @@ include "presentationFieldsAuth.circom";
66

77
// Verifies whether all credentials exists in the certree and
88
// that each credential's field exists in the correspondent credential tree using merkle multiproof
9-
// @param `tagIdx` is the index of the tag Field in the credential
109
// @param `gradeIdx` is the index of the grade Field in the credential
11-
// @param `m` is the number of leaves/fields to be proved in each credential tree (precise-proof)
10+
// @param `tagIdx` is the index of the tag Field in the credential
1211
// @param `n` is the number of credentials to be verified
1312
// @param `cdl` is the level of the credential tree
1413
// @param `ctl` is the level of the certree
1514
// Note:
1615
// - each leave of the certree contains a commitment to a credential tree root
1716
// - currently m must be the same for all credentials in the certree
1817
// - each leave of a credential tree has 3 fields: key, value and salt
19-
template Score(tagIdx, gradeIdx, m, n, cdl, ctl) {
20-
assert(m > 1);
21-
18+
template Score(gradeIdx, tagIdx, n, cdl, ctl) {
2219
signal input certreeRoot;
2320
signal input requiredTags[n];
2421
signal input weights[n];
2522
signal input result;
2623

27-
signal input nullifierHashes[n];
24+
var m = 1 << cdl;
2825
signal input fields[n][m][3];
2926
signal input pathFieldElements[n][m];
3027
signal input fieldIndices[n][m];
28+
signal input nullifierHashes[n];
3129
signal input credentialRoots[n];
3230
signal input subjects[n];
3331
signal input secrets[n];
@@ -44,7 +42,7 @@ template Score(tagIdx, gradeIdx, m, n, cdl, ctl) {
4442
credAuth[i].certreeRoot <== certreeRoot;
4543
credAuth[i].nullifierHash <== nullifierHashes[i];
4644

47-
// ensure tags match
45+
// ensure tags match
4846
sameTags[i] = IsEqual();
4947
sameTags[i].in[0] <== requiredTags[i];
5048
sameTags[i].in[1] <== fields[i][tagIdx][1];

circuits/score12.circom

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ pragma circom 2.0.4;
22

33
include "score.circom";
44

5-
component main {public [certreeRoot, requiredTags, weights, result]} = Score(0, 1, 2, 5, 4, 12);
5+
component main {public [certreeRoot, requiredTags, weights, result]} = Score(0, 1, 5, 4, 12);

0 commit comments

Comments
 (0)