diff --git a/keyless/circuit/templates/helpers/misc.circom b/keyless/circuit/templates/helpers/misc.circom index 109e824fa6d76..3385644889bbf 100644 --- a/keyless/circuit/templates/helpers/misc.circom +++ b/keyless/circuit/templates/helpers/misc.circom @@ -98,7 +98,9 @@ template EmailVerifiedCheck(maxEVNameLen, maxEVValueLen, maxUIDNameLen) { } } - +// Given an array of ascii characters representing a JSON object, output a binary array demarquing +// input = { asdfsdf "asdf" } +// output = 000000000001111000 template StringBodies(len) { signal input in[len]; signal output out[len]; @@ -126,21 +128,24 @@ template StringBodies(len) { for (var i = 1; i < len; i++) { var is_quote = IsEqual()([in[i], 34]); var prev_is_odd_backslash = adjacent_backslash_parity[i-1]; - quotes[i] <== is_quote * (1 - prev_is_odd_backslash); - quote_parity_1[i] <== quotes[i] * (1 - quote_parity[i-1]); - quote_parity_2[i] <== (1 - quotes[i]) * quote_parity[i-1]; - quote_parity[i] <== quote_parity_1[i] + quote_parity_2[i]; + quotes[i] <== is_quote * (1 - prev_is_odd_backslash); // 1 iff there is a non-escaped quote at this position + quote_parity_1[i] <== quotes[i] * (1 - quote_parity[i-1]); // 1 iff quotes[i] == 1 and quote_parity[i-1] == 0, else 0 + quote_parity_2[i] <== (1 - quotes[i]) * quote_parity[i-1]; // 1 iff quotes[i] == 0 and quote_party[i-1] == 1, else 0 + quote_parity[i] <== quote_parity_1[i] + quote_parity_2[i]; // Or of previous two, i.e., XOR(quotes[i], quote_parity[i-1]) } - + // input = { asdfsdf "asdf" } + // output = 000000000011111000 + // i.e., still has offset-by-one error out[0] <== 0; for (var i = 1; i < len; i++) { - out[i] <== AND()(quote_parity[i-1], quote_parity[i]); + out[i] <== AND()(quote_parity[i-1], quote_parity[i]); // remove offset error } } + // Given a base64-encoded array `in`, max length `maxN`, and actual unpadded length `n`, returns // the actual length of the decoded string template Base64DecodedLength(maxN) {