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..40597cc6 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]; @@ -54,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 @@ -74,6 +72,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], @@ -94,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], @@ -103,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 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 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,