Skip to content

Commit

Permalink
circuit: update deps, minor fix/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
saleel committed Apr 1, 2024
1 parent 2a72497 commit 84cad37
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 131 deletions.
2 changes: 1 addition & 1 deletion packages/circuits/email-verifier.circom
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include "./lib/base64.circom";
include "./lib/rsa.circom";
include "./lib/sha.circom";
include "./utils/array.circom";
include "./utils/extract.circom";
include "./utils/regex.circom";
include "./utils/hash.circom";


Expand Down
12 changes: 6 additions & 6 deletions packages/circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
"publish": "yarn npm publish --access=public",
"test": "NODE_OPTIONS=--max_old_space_size=8192 jest tests"
},
"dependencies": {
"@zk-email/zk-regex-circom": "^1.1.1",
"circomlib": "^2.0.5"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/preset-env": "^7.22.2",
"@babel/preset-typescript": "^7.21.5",
"babel-jest": "^29.5.0",
"babel-preset-jest": "^29.5.0",
"circom_tester": "^0.0.19",
"circomlib": "^2.0.5",
"circomlibjs": "^0.1.2",
"circom_tester": "^0.0.20",
"circomlibjs": "^0.1.7",
"ffjavascript": "^0.2.59",
"jest": "^29.5.0",
"typescript": "^5.2.2"
},
"dependencies": {
"@zk-email/zk-regex-circom": "^1.1.1"
}
}
8 changes: 4 additions & 4 deletions packages/circuits/utils/array.circom
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include "circomlib/circuits/comparators.circom";
include "circomlib/circuits/bitify.circom";
include "./functions.circom";

/// @title ArrayShiftLeft
/// @title VarShiftLeft
/// @notice Shift input array by `shift` indices to the left
/// @notice Output array length can be reduced by setting `maxOutArrayLen`
/// @notice Based on https://demo.hedgedoc.org/s/Le0R3xUhB
Expand All @@ -13,7 +13,7 @@ include "./functions.circom";
/// @input in The input array
/// @input shift The number of indices to shift the array to the left
/// @output out hifted subarray
template ArrayShiftLeft(maxArrayLen, maxOutArrayLen) {
template VarShiftLeft(maxArrayLen, maxOutArrayLen) {
var bitLength = log2Ceil(maxArrayLen);
assert(2 ** bitLength > maxArrayLen);
assert(maxOutArrayLen <= maxArrayLen);
Expand Down Expand Up @@ -108,7 +108,7 @@ template CalculateTotal(n) {

/// @title SubArraySelector
/// @notice Select sub array from an array given a `startIndex` and `length`
/// @notice This is same as `ArrayShiftLeft` but with elements after `length` set to zero
/// @notice This is same as `VarShiftLeft` but with elements after `length` set to zero
/// @notice This is not used in ZK-Email circuits anywhere
/// @param maxArrayLen: the maximum number of bytes in the input array
/// @param maxSubArrayLen: the maximum number of integers in the output array
Expand All @@ -127,7 +127,7 @@ template SubArraySelector(maxArrayLen, maxSubArrayLen) {

assert(length <= maxSubArrayLen);

component shifter = ArrayShiftLeft(maxArrayLen, maxSubArrayLen);
component shifter = VarShiftLeft(maxArrayLen, maxSubArrayLen);
shifter.in <== in;
shifter.shift <== startIndex;

Expand Down
13 changes: 7 additions & 6 deletions packages/circuits/utils/hash.circom
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ pragma circom 2.1.6;

/// @title PoseidonLarge
/// @notice Circuit to calculate Poseidon hash of inputs more than 16
/// @notice This circuit is not very generic. It merges two consecutive chunks to bring size < 16
/// @notice Assumes input is packed ints (a + 256 * i * b)
/// @notice Also assumes that merging two elements would fit in the field
/// @param bitesPerChunk Number of bits in each chunk
/// @notice Merges two consecutive chunks to bring size < 16 assuming ints are chunks of a large number (a + bytesPerChunk * b)
/// @notice Assumes merging of two ints fit in field
/// @notice Can be made more generic by taking hash with any size inputs with nesting
/// @param bytesPerChunk Number of bits in each chunk
/// @param chunkSize Number of chunks in input
/// @input in: Array of chunkSize elements
/// @output out: Poseidon hash of input where consecutive elements are merged
template PoseidonLarge(bitesPerChunk, chunkSize) {
template PoseidonLarge(bytesPerChunk, chunkSize) {
assert(chunkSize > 16); // Can use regular Poseidon for smaller chunks
assert(chunkSize <= 32); // We only support up to 32 chunks. i.e half should be less than 16
assert(bytesPerChunk * 2 < 251);

var halfChunkSize = chunkSize >> 1;
if (chunkSize % 2 == 1) {
Expand All @@ -28,7 +29,7 @@ template PoseidonLarge(bitesPerChunk, chunkSize) {
if (i == halfChunkSize - 1 && halfChunkSize % 2 == 1) {
poseidonInput[i] <== in[2 * i];
} else {
poseidonInput[i] <== in[2 * i] + (1 << bitesPerChunk) * in[2 * i + 1];
poseidonInput[i] <== in[2 * i] + (1 << bytesPerChunk) * in[2 * i + 1];
}
}

Expand Down
69 changes: 0 additions & 69 deletions packages/circuits/utils/hex.circom

This file was deleted.

2 changes: 1 addition & 1 deletion packages/circuits/utils/regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ template SelectRegexReveal(maxArrayLen, maxRevealLen) {
isAboveMaxRevealLen[i] * (1 - isZero[i]) === 0;
}

out <== ArrayShiftLeft(maxArrayLen, maxRevealLen)(in, startIndex);
out <== VarShiftLeft(maxArrayLen, maxRevealLen)(in, startIndex);
}


Expand Down
71 changes: 27 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2758,9 +2758,9 @@ __metadata:
"@zk-email/zk-regex-circom": ^1.1.1
babel-jest: ^29.5.0
babel-preset-jest: ^29.5.0
circom_tester: ^0.0.19
circom_tester: ^0.0.20
circomlib: ^2.0.5
circomlibjs: ^0.1.2
circomlibjs: ^0.1.7
ffjavascript: ^0.2.59
jest: ^29.5.0
typescript: ^5.2.2
Expand Down Expand Up @@ -3485,13 +3485,6 @@ __metadata:
languageName: node
linkType: hard

"child_process@npm:^1.0.2":
version: 1.0.2
resolution: "child_process@npm:1.0.2"
checksum: bd814d82bc8c6e85ed6fb157878978121cd03b5296c09f6135fa3d081fd9a6a617a6d509c50397711df713af403331241a9c0397a7fad30672051485e156c2a1
languageName: node
linkType: hard

"chokidar@npm:^3.4.2":
version: 3.5.3
resolution: "chokidar@npm:3.5.3"
Expand Down Expand Up @@ -3547,19 +3540,18 @@ __metadata:
languageName: node
linkType: hard

"circom_tester@npm:^0.0.19":
version: 0.0.19
resolution: "circom_tester@npm:0.0.19"
"circom_tester@npm:^0.0.20":
version: 0.0.20
resolution: "circom_tester@npm:0.0.20"
dependencies:
chai: ^4.3.6
child_process: ^1.0.2
ffjavascript: ^0.2.56
ffjavascript: ^0.2.60
fnv-plus: ^1.3.1
r1csfile: ^0.0.41
snarkjs: 0.5.0
r1csfile: ^0.0.47
snarkjs: ^0.7.0
tmp-promise: ^3.0.3
util: ^0.12.4
checksum: 703d7317493ddafb33462b5b0caf9b8a95bde938429e030d024fa7ac41ccb45a9ddbe8ebb93f91138dbee94bb2e0d504570c0aca070802d79ee532ba1ae5db0e
util: ^0.12.5
checksum: ee9f9a4ac69ee2acb2ce46c903a817ac687b621a90a7f5b8a8bd1d8f3e42076ed694f5e3e46e0d9775febf350c73837007284a33117ac66a7b233b76cbd21ea6
languageName: node
linkType: hard

Expand All @@ -3570,7 +3562,7 @@ __metadata:
languageName: node
linkType: hard

"circomlibjs@npm:^0.1.2, circomlibjs@npm:^0.1.7":
"circomlibjs@npm:^0.1.7":
version: 0.1.7
resolution: "circomlibjs@npm:0.1.7"
dependencies:
Expand Down Expand Up @@ -4131,7 +4123,7 @@ __metadata:
languageName: node
linkType: hard

"ffjavascript@npm:^0.2.45, ffjavascript@npm:^0.2.48, ffjavascript@npm:^0.2.56, ffjavascript@npm:^0.2.59":
"ffjavascript@npm:^0.2.45, ffjavascript@npm:^0.2.48, ffjavascript@npm:^0.2.59":
version: 0.2.59
resolution: "ffjavascript@npm:0.2.59"
dependencies:
Expand All @@ -4142,6 +4134,17 @@ __metadata:
languageName: node
linkType: hard

"ffjavascript@npm:^0.2.60":
version: 0.2.63
resolution: "ffjavascript@npm:0.2.63"
dependencies:
wasmbuilder: 0.0.16
wasmcurves: 0.2.2
web-worker: 1.2.0
checksum: d4c549228b31692bb8a44f7eb46720b0504a9ff5bc00e8a9c44ad104622cb83613542b4c321f83cb3027c9dcd1b0834da2b1ea679c3277642f754e9e5ea1c06f
languageName: node
linkType: hard

"figures@npm:^3.0.0":
version: 3.2.0
resolution: "figures@npm:3.2.0"
Expand Down Expand Up @@ -6132,7 +6135,7 @@ __metadata:
languageName: node
linkType: hard

"r1csfile@npm:0.0.41, r1csfile@npm:^0.0.41":
"r1csfile@npm:0.0.41":
version: 0.0.41
resolution: "r1csfile@npm:0.0.41"
dependencies:
Expand All @@ -6144,7 +6147,7 @@ __metadata:
languageName: node
linkType: hard

"r1csfile@npm:0.0.47":
"r1csfile@npm:0.0.47, r1csfile@npm:^0.0.47":
version: 0.0.47
resolution: "r1csfile@npm:0.0.47"
dependencies:
Expand Down Expand Up @@ -6501,26 +6504,6 @@ __metadata:
languageName: node
linkType: hard

"snarkjs@npm:0.5.0":
version: 0.5.0
resolution: "snarkjs@npm:0.5.0"
dependencies:
"@iden3/binfileutils": 0.0.11
bfj: ^7.0.2
blake2b-wasm: ^2.4.0
circom_runtime: 0.1.21
ejs: ^3.1.6
fastfile: 0.0.20
ffjavascript: 0.2.56
js-sha3: ^0.8.0
logplease: ^1.2.15
r1csfile: 0.0.41
bin:
snarkjs: build/cli.cjs
checksum: f0233103548bcd0f75b2ff8998ba02437e5131486d126c4a6a31355cd3558c7ce4311e21d5f24ea9ca198d0556e91e63e2ec6aef8da44014c16b29b6a7086ca2
languageName: node
linkType: hard

"snarkjs@npm:^0.7.0":
version: 0.7.1
resolution: "snarkjs@npm:0.7.1"
Expand Down Expand Up @@ -6987,7 +6970,7 @@ __metadata:
languageName: node
linkType: hard

"util@npm:^0.12.3, util@npm:^0.12.4":
"util@npm:^0.12.3, util@npm:^0.12.5":
version: 0.12.5
resolution: "util@npm:0.12.5"
dependencies:
Expand Down Expand Up @@ -7083,7 +7066,7 @@ __metadata:
languageName: node
linkType: hard

"web-worker@npm:^1.2.0":
"web-worker@npm:1.2.0, web-worker@npm:^1.2.0":
version: 1.2.0
resolution: "web-worker@npm:1.2.0"
checksum: 1bb28348ddcf9b2e7c62c5fd02e49a84098795856cd905456de957271bba288e9618941cf69d8960f0a7ae81f5dfb74b427c0634be47ec69e3e955c4ec5213be
Expand Down

0 comments on commit 84cad37

Please sign in to comment.