From eb66674c5557e27885f5f82df93264661de57a03 Mon Sep 17 00:00:00 2001 From: shreyas-londhe Date: Fri, 13 Sep 2024 13:43:36 +0530 Subject: [PATCH] chore: minor change --- packages/circuits/tests/base64.test.ts | 105 +++++----- .../tests/count-substring-occurrences.test.ts | 106 ++++++++++ .../tests/email-verifier-no-body.test.ts | 2 +- .../email-verifier-with-body-mask.test.ts | 2 +- .../email-verifier-with-header-mask.test.ts | 2 +- ...ail-verifier-with-soft-line-breaks.test.ts | 2 +- .../circuits/tests/email-verifier.test.ts | 2 +- packages/circuits/tests/rsa.test.ts | 191 ++++++++++++------ .../tests/select-regex-reveal.test.ts | 64 ++++-- packages/circuits/tests/sha.test.ts | 66 +++--- 10 files changed, 368 insertions(+), 174 deletions(-) create mode 100644 packages/circuits/tests/count-substring-occurrences.test.ts diff --git a/packages/circuits/tests/base64.test.ts b/packages/circuits/tests/base64.test.ts index b4711c46c..4088741e1 100644 --- a/packages/circuits/tests/base64.test.ts +++ b/packages/circuits/tests/base64.test.ts @@ -1,58 +1,57 @@ import { wasm } from "circom_tester"; import path from "path"; - describe("Base64 Lookup", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes - - let circuit: any; - - beforeAll(async () => { - circuit = await wasm( - path.join(__dirname, "./test-circuits/base64-test.circom"), - { - recompile: true, - include: path.join(__dirname, "../../../node_modules"), - // output: path.join(__dirname, "./compiled-test-circuits"), - } - ); - }); - - it("should decode valid base64 chars", async function () { - const inputs = [ - [65, 0], // A - [90, 25], // Z - [97, 26], // a - [122, 51], // z - [48, 52], // 0 - [57, 61], // 9 - [43, 62], // + - [47, 63], // / - [61, 0], // = - ] - - for (const [input, output] of inputs) { - const witness = await circuit.calculateWitness({ - in: input - }); - await circuit.checkConstraints(witness); - await circuit.assertOut(witness, { out: output }) - } - }); - - it("should fail with invalid chars", async function () { - const inputs = [34, 64, 91, 44]; - - expect.assertions(inputs.length); - for (const input of inputs) { - try { - const witness = await circuit.calculateWitness({ - in: input - }); - await circuit.checkConstraints(witness); - } catch (error) { - expect((error as Error).message).toMatch("Assert Failed"); - } - } - }); + jest.setTimeout(30 * 60 * 1000); // 30 minutes + + let circuit: any; + + beforeAll(async () => { + circuit = await wasm( + path.join(__dirname, "./test-circuits/base64-test.circom"), + { + recompile: true, + include: path.join(__dirname, "../../../node_modules"), + // output: path.join(__dirname, "./compiled-test-circuits"), + } + ); + }); + + it("should decode valid base64 chars", async function () { + const inputs = [ + [65, 0], // A + [90, 25], // Z + [97, 26], // a + [122, 51], // z + [48, 52], // 0 + [57, 61], // 9 + [43, 62], // + + [47, 63], // / + [61, 0], // = + ]; + + for (const [input, output] of inputs) { + const witness = await circuit.calculateWitness({ + in: input, + }); + await circuit.checkConstraints(witness); + await circuit.assertOut(witness, { out: output }); + } + }); + + it("should fail with invalid chars", async function () { + const inputs = [34, 64, 91, 44]; + + expect.assertions(inputs.length); + for (const input of inputs) { + try { + const witness = await circuit.calculateWitness({ + in: input, + }); + await circuit.checkConstraints(witness); + } catch (error) { + expect((error as Error).message).toMatch("Assert Failed"); + } + } + }); }); diff --git a/packages/circuits/tests/count-substring-occurrences.test.ts b/packages/circuits/tests/count-substring-occurrences.test.ts new file mode 100644 index 000000000..c84fbf7f5 --- /dev/null +++ b/packages/circuits/tests/count-substring-occurrences.test.ts @@ -0,0 +1,106 @@ +import { wasm as wasm_tester } from "circom_tester"; +import path from "path"; + +describe("CountSubstringOccurrences Circuit", () => { + jest.setTimeout(30 * 60 * 1000); // 30 minutes + + let circuit: any; + + beforeAll(async () => { + circuit = await wasm_tester( + path.join( + __dirname, + "./test-circuits/count-substring-occurrences-test.circom" + ), + { + recompile: true, + include: path.join(__dirname, "../../../node_modules"), + output: path.join(__dirname, "./compiled-test-circuits"), + } + ); + }); + + it("should count single occurrence at the beginning", async () => { + const input = { + in: [1, 2, 3, 4, 5, ...Array(1019).fill(0)], + substring: [1, 2, 3, ...Array(125).fill(0)], + }; + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + expect(witness[1]).toBe(1n); + }); + + it("should count multiple occurrences", async () => { + const input = { + in: [1, 2, 3, 4, 1, 2, 3, 5, 1, 2, 3, ...Array(1013).fill(0)], + substring: [1, 2, 3, ...Array(125).fill(0)], + }; + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + expect(witness[1]).toBe(3n); + }); + + it("should return 0 for no occurrences", async () => { + const input = { + in: [1, 2, 4, 5, 6, ...Array(1019).fill(0)], + substring: [1, 2, 3, ...Array(125).fill(0)], + }; + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + expect(witness[1]).toBe(0n); + }); + + it("should count occurrences with overlap", async () => { + const input = { + in: [1, 1, 1, 2, 1, 1, ...Array(1018).fill(0)], + substring: [1, 1, ...Array(126).fill(0)], + }; + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + expect(witness[1]).toBe(3n); + }); + + it("should handle full match of input", async () => { + const repeatedPattern = [1, 2, 3, 4]; + const input = { + in: Array(256) + .fill(repeatedPattern) + .flat() + .concat(Array(1024 - 256 * 4).fill(0)), + substring: [1, 2, 3, 4, ...Array(124).fill(0)], + }; + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + expect(witness[1]).toBe(256n); + }); + + it("should handle single character substring", async () => { + const input = { + in: [1, 2, 1, 3, 1, 4, 1, ...Array(1017).fill(0)], + substring: [1, ...Array(127).fill(0)], + }; + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + expect(witness[1]).toBe(4n); + }); + + it("should handle substring at the end of input", async () => { + const input = { + in: [...Array(1021).fill(0), 1, 2, 3], + substring: [1, 2, 3, ...Array(125).fill(0)], + }; + const witness = await circuit.calculateWitness(input); + await circuit.checkConstraints(witness); + expect(witness[1]).toBe(1n); + }); + + it("should return 0 for empty substring", async () => { + const input = { + in: [1, 2, 3, 4, 5, ...Array(1019).fill(0)], + substring: Array(128).fill(0), + }; + await expect(async () => { + await circuit.calculateWitness(input); + }).rejects.toThrow("Assert Failed"); + }); +}); diff --git a/packages/circuits/tests/email-verifier-no-body.test.ts b/packages/circuits/tests/email-verifier-no-body.test.ts index 21780215d..102621302 100644 --- a/packages/circuits/tests/email-verifier-no-body.test.ts +++ b/packages/circuits/tests/email-verifier-no-body.test.ts @@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim"; describe("EmailVerifier : Without body check", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(30 * 60 * 1000); // 30 minutes let dkimResult: DKIMVerificationResult; let circuit: any; diff --git a/packages/circuits/tests/email-verifier-with-body-mask.test.ts b/packages/circuits/tests/email-verifier-with-body-mask.test.ts index 114271732..f6c525c8b 100644 --- a/packages/circuits/tests/email-verifier-with-body-mask.test.ts +++ b/packages/circuits/tests/email-verifier-with-body-mask.test.ts @@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim"; describe("EmailVerifier : With body masking", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(30 * 60 * 1000); // 30 minutes let dkimResult: DKIMVerificationResult; let circuit: any; diff --git a/packages/circuits/tests/email-verifier-with-header-mask.test.ts b/packages/circuits/tests/email-verifier-with-header-mask.test.ts index 1fac9cd5e..04f4d5671 100644 --- a/packages/circuits/tests/email-verifier-with-header-mask.test.ts +++ b/packages/circuits/tests/email-verifier-with-header-mask.test.ts @@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim"; describe("EmailVerifier : With header masking", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(30 * 60 * 1000); // 30 minutes let dkimResult: DKIMVerificationResult; let circuit: any; diff --git a/packages/circuits/tests/email-verifier-with-soft-line-breaks.test.ts b/packages/circuits/tests/email-verifier-with-soft-line-breaks.test.ts index 9240521ef..106eb9545 100644 --- a/packages/circuits/tests/email-verifier-with-soft-line-breaks.test.ts +++ b/packages/circuits/tests/email-verifier-with-soft-line-breaks.test.ts @@ -6,7 +6,7 @@ import { generateEmailVerifierInputsFromDKIMResult } from "@zk-email/helpers/src import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim"; describe("EmailVerifier : With soft line breaks", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(30 * 60 * 1000); // 30 minutes let dkimResult: DKIMVerificationResult; let circuit: any; diff --git a/packages/circuits/tests/email-verifier.test.ts b/packages/circuits/tests/email-verifier.test.ts index 93eee579a..3221f9b62 100644 --- a/packages/circuits/tests/email-verifier.test.ts +++ b/packages/circuits/tests/email-verifier.test.ts @@ -7,7 +7,7 @@ import { verifyDKIMSignature } from "@zk-email/helpers/src/dkim"; import { poseidonLarge } from "@zk-email/helpers/src/hash"; describe("EmailVerifier", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(30 * 60 * 1000); // 30 minutes let dkimResult: DKIMVerificationResult; let circuit: any; diff --git a/packages/circuits/tests/rsa.test.ts b/packages/circuits/tests/rsa.test.ts index 4f6481b4e..273db843e 100644 --- a/packages/circuits/tests/rsa.test.ts +++ b/packages/circuits/tests/rsa.test.ts @@ -4,83 +4,142 @@ import { wasm as wasm_tester } from "circom_tester"; import { generateEmailVerifierInputs } from "@zk-email/helpers/src/input-generators"; import { toCircomBigIntBytes } from "@zk-email/helpers/src/binary-format"; - describe("RSA", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes - - let circuit: any; - let rawEmail: Buffer; + jest.setTimeout(30 * 60 * 1000); // 30 minutes - beforeAll(async () => { - circuit = await wasm_tester( - path.join(__dirname, "./test-circuits/rsa-test.circom"), - { - recompile: true, - include: path.join(__dirname, "../../../node_modules"), - // output: path.join(__dirname, "./compiled-test-circuits"), - } - ); - rawEmail = fs.readFileSync(path.join(__dirname, "./test-emails/test.eml")); - }); + let circuit: any; + let rawEmail: Buffer; - it("should verify 2048 bit rsa signature correctly", async function () { - const emailVerifierInputs = await generateEmailVerifierInputs(rawEmail, { - maxHeadersLength: 640, - maxBodyLength: 768, + beforeAll(async () => { + circuit = await wasm_tester( + path.join(__dirname, "./test-circuits/rsa-test.circom"), + { + recompile: true, + include: path.join(__dirname, "../../../node_modules"), + // output: path.join(__dirname, "./compiled-test-circuits"), + } + ); + rawEmail = fs.readFileSync( + path.join(__dirname, "./test-emails/test.eml") + ); }); + it("should verify 2048 bit rsa signature correctly", async function () { + const emailVerifierInputs = await generateEmailVerifierInputs( + rawEmail, + { + maxHeadersLength: 640, + maxBodyLength: 768, + } + ); - const witness = await circuit.calculateWitness({ - signature: emailVerifierInputs.signature, - modulus: emailVerifierInputs.pubkey, - // TODO: generate this from the input - message: ["1156466847851242602709362303526378170", "191372789510123109308037416804949834", "7204", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"], + const witness = await circuit.calculateWitness({ + signature: emailVerifierInputs.signature, + modulus: emailVerifierInputs.pubkey, + // TODO: generate this from the input + message: [ + "1156466847851242602709362303526378170", + "191372789510123109308037416804949834", + "7204", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + ], + }); + await circuit.checkConstraints(witness); + await circuit.assertOut(witness, {}); }); - await circuit.checkConstraints(witness); - await circuit.assertOut(witness, {}) - }); - it("should verify 1024 bit rsa signature correctly", async function () { - const signature = toCircomBigIntBytes( - BigInt( - 102386562682221859025549328916727857389789009840935140645361501981959969535413501251999442013082353139290537518086128904993091119534674934202202277050635907008004079788691412782712147797487593510040249832242022835902734939817209358184800954336078838331094308355388211284440290335887813714894626653613586546719n - ) - ); + it("should verify 1024 bit rsa signature correctly", async function () { + const signature = toCircomBigIntBytes( + BigInt( + 102386562682221859025549328916727857389789009840935140645361501981959969535413501251999442013082353139290537518086128904993091119534674934202202277050635907008004079788691412782712147797487593510040249832242022835902734939817209358184800954336078838331094308355388211284440290335887813714894626653613586546719n + ) + ); - const pubkey = toCircomBigIntBytes( - BigInt( - 106773687078109007595028366084970322147907086635176067918161636756354740353674098686965493426431314019237945536387044259034050617425729739578628872957481830432099721612688699974185290306098360072264136606623400336518126533605711223527682187548332314997606381158951535480830524587400401856271050333371205030999n - ) - ); + const pubkey = toCircomBigIntBytes( + BigInt( + 106773687078109007595028366084970322147907086635176067918161636756354740353674098686965493426431314019237945536387044259034050617425729739578628872957481830432099721612688699974185290306098360072264136606623400336518126533605711223527682187548332314997606381158951535480830524587400401856271050333371205030999n + ) + ); - const witness = await circuit.calculateWitness({ - signature: signature, - modulus: pubkey, - // TODO: generate this from the input - message: ["1156466847851242602709362303526378170", "191372789510123109308037416804949834", "7204", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"], + const witness = await circuit.calculateWitness({ + signature: signature, + modulus: pubkey, + // TODO: generate this from the input + message: [ + "1156466847851242602709362303526378170", + "191372789510123109308037416804949834", + "7204", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + ], + }); + await circuit.checkConstraints(witness); + await circuit.assertOut(witness, {}); }); - await circuit.checkConstraints(witness); - await circuit.assertOut(witness, {}); - }); - it("should fail when verifying with an incorrect signature", async function () { - const emailVerifierInputs = await generateEmailVerifierInputs(rawEmail, { - maxHeadersLength: 640, - maxBodyLength: 768, - }); + it("should fail when verifying with an incorrect signature", async function () { + const emailVerifierInputs = await generateEmailVerifierInputs( + rawEmail, + { + maxHeadersLength: 640, + maxBodyLength: 768, + } + ); - - expect.assertions(1); - try { - const witness = await circuit.calculateWitness({ - signature: emailVerifierInputs.signature, - modulus: emailVerifierInputs.pubkey, - message: ["1156466847851242602709362303526378171", "191372789510123109308037416804949834", "7204", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"], - }); - await circuit.checkConstraints(witness); - await circuit.assertOut(witness, {}) - } catch (error) { - expect((error as Error).message).toMatch("Assert Failed"); - } - }); + expect.assertions(1); + try { + const witness = await circuit.calculateWitness({ + signature: emailVerifierInputs.signature, + modulus: emailVerifierInputs.pubkey, + message: [ + "1156466847851242602709362303526378171", + "191372789510123109308037416804949834", + "7204", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + "0", + ], + }); + await circuit.checkConstraints(witness); + await circuit.assertOut(witness, {}); + } catch (error) { + expect((error as Error).message).toMatch("Assert Failed"); + } + }); }); diff --git a/packages/circuits/tests/select-regex-reveal.test.ts b/packages/circuits/tests/select-regex-reveal.test.ts index fdf551157..cd3f3b810 100644 --- a/packages/circuits/tests/select-regex-reveal.test.ts +++ b/packages/circuits/tests/select-regex-reveal.test.ts @@ -1,15 +1,17 @@ import { wasm } from "circom_tester"; import path from "path"; - describe("Select Regex Reveal", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(30 * 60 * 1000); // 30 minutes let circuit: any; beforeAll(async () => { circuit = await wasm( - path.join(__dirname, "./test-circuits/select-regex-reveal-test.circom"), + path.join( + __dirname, + "./test-circuits/select-regex-reveal-test.circom" + ), { recompile: true, include: path.join(__dirname, "../../../node_modules"), @@ -18,9 +20,14 @@ describe("Select Regex Reveal", () => { }); it("should reveal the substring with maximum revealed length", async function () { - let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let input = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; const startIndex = Math.floor(Math.random() * 24); - const revealed = Array.from("zk email").map(char => char.charCodeAt(0)); + const revealed = Array.from("zk email").map((char) => + char.charCodeAt(0) + ); for (let i = 0; i < revealed.length; i++) { input[startIndex + i] = revealed[i]; } @@ -29,13 +36,16 @@ describe("Select Regex Reveal", () => { startIndex: startIndex, }); await circuit.checkConstraints(witness); - await circuit.assertOut(witness, { out: revealed }) + await circuit.assertOut(witness, { out: revealed }); }); it("should reveal the substring with non-maximum revealed length", async function () { - let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let input = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; const startIndex = 30; - const revealed = Array.from("zk").map(char => char.charCodeAt(0)); + const revealed = Array.from("zk").map((char) => char.charCodeAt(0)); for (let i = 0; i < revealed.length; i++) { input[startIndex + i] = revealed[i]; } @@ -44,11 +54,16 @@ describe("Select Regex Reveal", () => { startIndex: startIndex, }); await circuit.checkConstraints(witness); - await circuit.assertOut(witness, { out: revealed.concat([0, 0, 0, 0, 0, 0]) }) + await circuit.assertOut(witness, { + out: revealed.concat([0, 0, 0, 0, 0, 0]), + }); }); it("should fail when all zero", async function () { - let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let input = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; const startIndex = Math.floor(Math.random() * 32); try { const witness = await circuit.calculateWitness({ @@ -62,9 +77,14 @@ describe("Select Regex Reveal", () => { }); it("should fail when startIndex is 0", async function () { - let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let input = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; const startIndex = 1 + Math.floor(Math.random() * 24); - const revealed = Array.from("zk email").map(char => char.charCodeAt(0)); + const revealed = Array.from("zk email").map((char) => + char.charCodeAt(0) + ); for (let i = 0; i < revealed.length; i++) { input[startIndex + i] = revealed[i]; } @@ -80,9 +100,14 @@ describe("Select Regex Reveal", () => { }); it("should fail when startIndex is not before 0", async function () { - let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let input = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; const startIndex = Math.floor(Math.random() * 23); - const revealed = Array.from("zk email").map(char => char.charCodeAt(0)); + const revealed = Array.from("zk email").map((char) => + char.charCodeAt(0) + ); for (let i = 0; i < revealed.length; i++) { input[startIndex + i] = revealed[i]; } @@ -98,16 +123,21 @@ describe("Select Regex Reveal", () => { }); it("should fail when startIndex is larger than max length", async function () { - let input = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let input = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; const startIndex = Math.floor(Math.random() * 24); - const revealed = Array.from("zk email").map(char => char.charCodeAt(0)); + const revealed = Array.from("zk email").map((char) => + char.charCodeAt(0) + ); for (let i = 0; i < revealed.length; i++) { input[startIndex + i] = revealed[i]; } try { const witness = await circuit.calculateWitness({ in: input, - startIndex: 32 + startIndex: 32, }); await circuit.checkConstraints(witness); } catch (error) { diff --git a/packages/circuits/tests/sha.test.ts b/packages/circuits/tests/sha.test.ts index 82e8623d6..e9281924c 100644 --- a/packages/circuits/tests/sha.test.ts +++ b/packages/circuits/tests/sha.test.ts @@ -1,44 +1,44 @@ import { wasm as wasm_tester } from "circom_tester"; import path from "path"; import { sha256Pad, shaHash } from "@zk-email/helpers/src/sha-utils"; -import { Uint8ArrayToCharArray, uint8ToBits } from "@zk-email/helpers/src/binary-format"; - +import { + Uint8ArrayToCharArray, + uint8ToBits, +} from "@zk-email/helpers/src/binary-format"; describe("SHA256 for email header", () => { - jest.setTimeout(10 * 60 * 1000); // 10 minutes + jest.setTimeout(30 * 60 * 1000); // 30 minutes - let circuit: any; + let circuit: any; - beforeAll(async () => { - circuit = await wasm_tester( - path.join(__dirname, "./test-circuits/sha-test.circom"), - { - recompile: true, - include: path.join(__dirname, "../../../node_modules"), - // output: path.join(__dirname, "./compiled-test-circuits"), - } - ); - }); + beforeAll(async () => { + circuit = await wasm_tester( + path.join(__dirname, "./test-circuits/sha-test.circom"), + { + recompile: true, + include: path.join(__dirname, "../../../node_modules"), + // output: path.join(__dirname, "./compiled-test-circuits"), + } + ); + }); - it("should hash correctly", async function () { - const inputs = [ - "0", "hello world", "" - ] - for (const input of inputs) { - const [ - paddedMsg, - messageLen, - ] = sha256Pad( - Buffer.from(input, "ascii"), 640 - ) + it("should hash correctly", async function () { + const inputs = ["0", "hello world", ""]; + for (const input of inputs) { + const [paddedMsg, messageLen] = sha256Pad( + Buffer.from(input, "ascii"), + 640 + ); - const witness = await circuit.calculateWitness({ - paddedIn: Uint8ArrayToCharArray(paddedMsg), - paddedInLength: messageLen, - }); + const witness = await circuit.calculateWitness({ + paddedIn: Uint8ArrayToCharArray(paddedMsg), + paddedInLength: messageLen, + }); - await circuit.checkConstraints(witness); - await circuit.assertOut(witness, { out: [...uint8ToBits(shaHash(Buffer.from(input, "ascii")))] }) - } - }); + await circuit.checkConstraints(witness); + await circuit.assertOut(witness, { + out: [...uint8ToBits(shaHash(Buffer.from(input, "ascii")))], + }); + } + }); });