From fca9c923a2cb7cd33b9b4e7b3c892c20766b3395 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 11 Dec 2023 14:42:29 +0200 Subject: [PATCH 1/3] add enabled[N] to linkedMultiQuery --- circuits/lib/query/processQueryWithModifiers.circom | 8 ++++++-- circuits/linked/multiQuery.circom | 2 ++ circuits/linkedMultiQuery10.circom | 2 +- circuits/linkedMultiQuery3.circom | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/circuits/lib/query/processQueryWithModifiers.circom b/circuits/lib/query/processQueryWithModifiers.circom index 5e39c0e4..8636546a 100644 --- a/circuits/lib/query/processQueryWithModifiers.circom +++ b/circuits/lib/query/processQueryWithModifiers.circom @@ -6,6 +6,7 @@ include "modifiers.circom"; include "../utils/claimUtils.circom"; template ProcessQueryWithModifiers(claimLevels, valueArraySize){ + signal input enabled; signal input claimPathNotExists; // 0 for inclusion, 1 for non-inclusion signal input claimPathMtp[claimLevels]; signal input claimPathMtpNoAux; // 1 if aux node is empty, 0 if non-empty or for inclusion proofs @@ -24,9 +25,11 @@ template ProcessQueryWithModifiers(claimLevels, valueArraySize){ // Modifier/Computation Operator output ($sd) signal output operatorOutput; + signal smtEnabled <== AND()(enabled, merklized); + // check path/in node exists in merkletree specified by jsonldRoot SMTVerifier(claimLevels)( - enabled <== merklized, // if merklize flag 0 skip MTP verification + enabled <== smtEnabled, // if merklize flag 0 or enabled 0 skip MTP verification fnc <== claimPathNotExists, // inclusion root <== merklizedRoot, siblings <== claimPathMtp, @@ -61,8 +64,9 @@ template ProcessQueryWithModifiers(claimLevels, valueArraySize){ ); signal isQueryOp <== LessThan(5)([operator, 16]); + signal querySatisfiedEnabled <== AND()(enabled, isQueryOp); ForceEqualIfEnabled()( - isQueryOp, + querySatisfiedEnabled, [querySatisfied, 1] ); diff --git a/circuits/linked/multiQuery.circom b/circuits/linked/multiQuery.circom index e2024fcb..80ab16e9 100644 --- a/circuits/linked/multiQuery.circom +++ b/circuits/linked/multiQuery.circom @@ -15,6 +15,7 @@ template LinkedMultiQuery(N, claimLevels, valueArraySize) { signal input issuerClaim[8]; // query signals + signal input enabled[N]; // 1 if query non-empty, 0 to skip query check signal input claimSchema; signal input claimPathNotExists[N]; // 0 for inclusion, 1 for non-inclusion signal input claimPathMtp[N][claimLevels]; @@ -74,6 +75,7 @@ template LinkedMultiQuery(N, claimLevels, valueArraySize) { // output value only if modifier operation was selected operatorOutput[i] <== ProcessQueryWithModifiers(claimLevels, valueArraySize)( + enabled[i], claimPathNotExists[i], claimPathMtp[i], claimPathMtpNoAux[i], diff --git a/circuits/linkedMultiQuery10.circom b/circuits/linkedMultiQuery10.circom index 2345cf5d..dcbb5954 100644 --- a/circuits/linkedMultiQuery10.circom +++ b/circuits/linkedMultiQuery10.circom @@ -2,4 +2,4 @@ pragma circom 2.1.1; include "linked/multiQuery.circom"; -component main = LinkedMultiQuery(10, 32, 64); // 163694 constraints +component main {public [enabled]} = LinkedMultiQuery(10, 32, 64); // 164791 constraints diff --git a/circuits/linkedMultiQuery3.circom b/circuits/linkedMultiQuery3.circom index 69bc88ec..dd524cea 100644 --- a/circuits/linkedMultiQuery3.circom +++ b/circuits/linkedMultiQuery3.circom @@ -2,4 +2,4 @@ pragma circom 2.1.1; include "linked/multiQuery.circom"; -component main = LinkedMultiQuery(3, 32, 64); // 49300 constraints +component main {public [enabled]} = LinkedMultiQuery(3, 32, 64); // 50383 constraints From df8f208d1418eccde38a4dbefdd6a60f5b1d11ab Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Tue, 12 Dec 2023 12:40:34 +0200 Subject: [PATCH 2/3] zero circuitQueryHash if enabled 0 --- circuits/linked/multiQuery.circom | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/circuits/linked/multiQuery.circom b/circuits/linked/multiQuery.circom index 80ab16e9..40597cc6 100644 --- a/circuits/linked/multiQuery.circom +++ b/circuits/linked/multiQuery.circom @@ -55,11 +55,8 @@ template LinkedMultiQuery(N, claimLevels, valueArraySize) { // Verify issuerClaim schema verifyCredentialSchema()(one, issuerClaimHeader.schema, claimSchema); // 3 constraints - signal slotValue[N]; - signal fieldValue[N]; - signal querySatisfied[N]; - signal isQueryOp[N]; signal valueHash[N]; + signal queryHash[N]; signal issuerClaimHash, issuerClaimHi, issuerClaimHv; (issuerClaimHash, issuerClaimHi, issuerClaimHv) <== getClaimHash()(issuerClaim); // 834 constraints @@ -96,8 +93,7 @@ template LinkedMultiQuery(N, claimLevels, valueArraySize) { ///////////////////////////////////////////////////////////////// // 4950 constraints (SpongeHash+Poseidon) valueHash[i] <== SpongeHash(valueArraySize, 6)(value[i]); // 6 - max size of poseidon hash available on-chain - - circuitQueryHash[i] <== Poseidon(6)([ + queryHash[i] <== Poseidon(6)([ claimSchema, slotIndex[i], operator[i], @@ -105,5 +101,7 @@ template LinkedMultiQuery(N, claimLevels, valueArraySize) { claimPathNotExists[i], valueHash[i] ]); + + circuitQueryHash[i] <== Mux1()([0, queryHash[i]], enabled[i]); } } \ No newline at end of file From d89acca83ef252efac517e53a43f32664821ea94 Mon Sep 17 00:00:00 2001 From: vbasiuk Date: Mon, 18 Dec 2023 12:25:43 +0200 Subject: [PATCH 3/3] add enabled one to ProcessQueryWithModifiers in v3 --- circuits/offchain/credentialAtomicQueryV3OffChain.circom | 1 + 1 file changed, 1 insertion(+) diff --git a/circuits/offchain/credentialAtomicQueryV3OffChain.circom b/circuits/offchain/credentialAtomicQueryV3OffChain.circom index 3d602a29..755d1be0 100644 --- a/circuits/offchain/credentialAtomicQueryV3OffChain.circom +++ b/circuits/offchain/credentialAtomicQueryV3OffChain.circom @@ -232,6 +232,7 @@ template credentialAtomicQueryV3OffChain(issuerLevels, claimLevels, valueArraySi ///////////////////////////////////////////////////////////////// // output value only if modifier operation was selected operatorOutput <== ProcessQueryWithModifiers(claimLevels, valueArraySize)( + one, claimPathNotExists, claimPathMtp, claimPathMtpNoAux,