From bd515aaa15d78f117e115d82d9ca51edece74364 Mon Sep 17 00:00:00 2001 From: Dimitri Date: Tue, 22 Oct 2024 10:02:27 +0700 Subject: [PATCH] fix: function signatures of extractSubstrIdxes --- packages/circom/tests/asterisk.test.js | 195 +++++++------- packages/circom/tests/body_hash_regex.test.js | 176 ++++++------ packages/circom/tests/caret.test.js | 252 +++++++++--------- packages/circom/tests/dollar.test.js | 87 +++--- packages/circom/tests/dot.test.js | 68 +++-- packages/circom/tests/plus.test.js | 212 +++++++-------- packages/circom/tests/question.test.js | 171 ++++++------ packages/circom/tests/reveal_check.test.js | 122 ++++----- 8 files changed, 641 insertions(+), 642 deletions(-) diff --git a/packages/circom/tests/asterisk.test.js b/packages/circom/tests/asterisk.test.js index 9b936ff..fe7d102 100644 --- a/packages/circom/tests/asterisk.test.js +++ b/packages/circom/tests/asterisk.test.js @@ -1,15 +1,15 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Asterisk Regex", () => { +describe('Asterisk Regex', () => { let circuit1; let circuit2; let circuit3; @@ -18,47 +18,47 @@ describe("Asterisk Regex", () => { // let circuit6; beforeAll(async () => { writeFileSync( - path.join(__dirname, "./circuits/asterisk1_regex.circom"), + path.join(__dirname, './circuits/asterisk1_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/asterisk1.json"), - "utf8" + path.join(__dirname, './circuits/asterisk1.json'), + 'utf8' ), - "Asterisk1Regex" + 'Asterisk1Regex' ) ); circuit1 = await wasm_tester( - path.join(__dirname, "./circuits/test_asterisk1_regex.circom"), + path.join(__dirname, './circuits/test_asterisk1_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/asterisk2_regex.circom"), + path.join(__dirname, './circuits/asterisk2_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/asterisk2.json"), - "utf8" + path.join(__dirname, './circuits/asterisk2.json'), + 'utf8' ), - "Asterisk2Regex" + 'Asterisk2Regex' ) ); circuit2 = await wasm_tester( - path.join(__dirname, "./circuits/test_asterisk2_regex.circom"), + path.join(__dirname, './circuits/test_asterisk2_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/asterisk3_regex.circom"), + path.join(__dirname, './circuits/asterisk3_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/asterisk3.json"), - "utf8" + path.join(__dirname, './circuits/asterisk3.json'), + 'utf8' ), - "Asterisk3Regex" + 'Asterisk3Regex' ) ); circuit3 = await wasm_tester( - path.join(__dirname, "./circuits/test_asterisk3_regex.circom"), + path.join(__dirname, './circuits/test_asterisk3_regex.circom'), option ); @@ -108,11 +108,11 @@ describe("Asterisk Regex", () => { // ); }); - it("asterisk1 valid case 1", async () => { + it('asterisk1 valid case 1', async () => { const inputStr = `xb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -120,9 +120,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk1.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -133,11 +134,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk1 valid case 2", async () => { + it('asterisk1 valid case 2', async () => { const inputStr = `xab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -145,9 +146,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk1.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -158,11 +160,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk1 valid case 3", async () => { + it('asterisk1 valid case 3', async () => { const inputStr = `xaab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -170,9 +172,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk1.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -183,11 +186,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk1 valid case 4", async () => { + it('asterisk1 valid case 4', async () => { const inputStr = `710xab98`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -195,9 +198,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk1.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -208,12 +212,11 @@ describe("Asterisk Regex", () => { } }); - - it("asterisk1 invalid case 1", async () => { + it('asterisk1 invalid case 1', async () => { const inputStr = `xaaa`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -223,11 +226,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk1 invalid case 2", async () => { + it('asterisk1 invalid case 2', async () => { const inputStr = `aaabx`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -237,12 +240,11 @@ describe("Asterisk Regex", () => { } }); - - it("asterisk2 valid case 1", async () => { + it('asterisk2 valid case 1', async () => { const inputStr = `aaa`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -250,9 +252,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk2.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -263,11 +266,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk2 valid case 2", async () => { + it('asterisk2 valid case 2', async () => { const inputStr = `ab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -275,9 +278,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk2.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -288,11 +292,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk2 valid case 3", async () => { + it('asterisk2 valid case 3', async () => { const inputStr = `abbba`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -300,9 +304,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk2.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -313,12 +318,11 @@ describe("Asterisk Regex", () => { } }); - - it("asterisk2 valid case 4", async () => { + it('asterisk2 valid case 4', async () => { const inputStr = `717abb9`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -326,9 +330,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk2.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -339,11 +344,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk2 invalid case 1", async () => { + it('asterisk2 invalid case 1', async () => { const inputStr = `bbb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -353,11 +358,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk2 invalid case 2", async () => { + it('asterisk2 invalid case 2', async () => { const inputStr = `19bd7`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -367,11 +372,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk3 valid case 1", async () => { + it('asterisk3 valid case 1', async () => { const inputStr = `ab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -379,9 +384,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk3.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -392,11 +398,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk3 valid case 2", async () => { + it('asterisk3 valid case 2', async () => { const inputStr = `xaxxyxby`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -404,9 +410,10 @@ describe("Asterisk Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/asterisk3.json"), - "utf8" - ) + path.join(__dirname, './circuits/asterisk3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -417,11 +424,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk3 invalid case 1", async () => { + it('asterisk3 invalid case 1', async () => { const inputStr = `axyxyyyx`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -431,11 +438,11 @@ describe("Asterisk Regex", () => { } }); - it("asterisk3 invalid case 2", async () => { + it('asterisk3 invalid case 2', async () => { const inputStr = `xyyxxyba`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -459,7 +466,7 @@ describe("Asterisk Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/asterisk4.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -498,7 +505,7 @@ describe("Asterisk Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/asterisk5.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -523,7 +530,7 @@ describe("Asterisk Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/asterisk5.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -562,7 +569,7 @@ describe("Asterisk Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/asterisk6.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -587,7 +594,7 @@ describe("Asterisk Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/asterisk6.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -612,7 +619,7 @@ describe("Asterisk Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/asterisk6.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -622,6 +629,4 @@ describe("Asterisk Regex", () => { // } // } // }); - - }); diff --git a/packages/circom/tests/body_hash_regex.test.js b/packages/circom/tests/body_hash_regex.test.js index af6e24e..fd49da6 100644 --- a/packages/circom/tests/body_hash_regex.test.js +++ b/packages/circom/tests/body_hash_regex.test.js @@ -1,97 +1,99 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Bodyhash Regex", () => { - let circuit; - beforeAll(async () => { - const email_addr_json = readFileSync( - path.join(__dirname, "../circuits/common/body_hash.json"), - "utf8" - ); - const circom = compiler.genFromDecomposed( - email_addr_json, - "BodyHashRegex" - ); - writeFileSync( - path.join(__dirname, "../circuits/common/body_hash_regex.circom"), - circom - ); +describe('Bodyhash Regex', () => { + let circuit; + beforeAll(async () => { + const email_addr_json = readFileSync( + path.join(__dirname, '../circuits/common/body_hash.json'), + 'utf8' + ); + const circom = compiler.genFromDecomposed( + email_addr_json, + 'BodyHashRegex' + ); + writeFileSync( + path.join(__dirname, '../circuits/common/body_hash_regex.circom'), + circom + ); - circuit = await wasm_tester( - path.join(__dirname, "./circuits/test_body_hash_regex.circom"), - option - ); - }); + circuit = await wasm_tester( + path.join(__dirname, './circuits/test_body_hash_regex.circom'), + option + ); + }); - it("bodyhash in the header", async () => { - const signatureField = `dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; - const paddedStr = apis.padString(signatureField, 1024); - const circuitInputs = { - msg: paddedStr, - }; - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractSubstrIdxes( - signatureField, - readFileSync( - path.join(__dirname, "../circuits/common/body_hash.json"), - "utf8" - ) - )[0]; - for (let idx = 0; idx < 1024; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); + it('bodyhash in the header', async () => { + const signatureField = `dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; + const paddedStr = apis.padString(signatureField, 1024); + const circuitInputs = { + msg: paddedStr + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractSubstrIdxes( + signatureField, + readFileSync( + path.join(__dirname, '../circuits/common/body_hash.json'), + 'utf8' + ), + false + )[0]; + for (let idx = 0; idx < 1024; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); - it("bodyhash after new line", async () => { - const signatureField = `\r\ndkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; - const paddedStr = apis.padString(signatureField, 1024); - const circuitInputs = { - msg: paddedStr, - }; - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(1n).toEqual(witness[1]); - const prefixIdxes = apis.extractSubstrIdxes( - signatureField, - readFileSync( - path.join(__dirname, "../circuits/common/body_hash.json"), - "utf8" - ) - )[0]; - for (let idx = 0; idx < 1024; ++idx) { - if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { - expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); - } else { - expect(0n).toEqual(witness[2 + idx]); - } - } - }); + it('bodyhash after new line', async () => { + const signatureField = `\r\ndkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; + const paddedStr = apis.padString(signatureField, 1024); + const circuitInputs = { + msg: paddedStr + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(1n).toEqual(witness[1]); + const prefixIdxes = apis.extractSubstrIdxes( + signatureField, + readFileSync( + path.join(__dirname, '../circuits/common/body_hash.json'), + 'utf8' + ), + false + )[0]; + for (let idx = 0; idx < 1024; ++idx) { + if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { + expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); + } else { + expect(0n).toEqual(witness[2 + idx]); + } + } + }); - it("invalid bodyhash", async () => { - const signatureField = `\r\nto: dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; - const paddedStr = apis.padString(signatureField, 1024); - const circuitInputs = { - msg: paddedStr, - }; - const witness = await circuit.calculateWitness(circuitInputs); - await circuit.checkConstraints(witness); - expect(0n).toEqual(witness[1]); - for (let idx = 0; idx < 1024; ++idx) { - expect(0n).toEqual(witness[2 + idx]); - } - }); + it('invalid bodyhash', async () => { + const signatureField = `\r\nto: dkim-signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1694989812; x=1695594612; dara=google.com; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=BWETwQ9JDReS4GyR2v2TTR8Bpzj9ayumsWQJ3q7vehs=; b=`; + const paddedStr = apis.padString(signatureField, 1024); + const circuitInputs = { + msg: paddedStr + }; + const witness = await circuit.calculateWitness(circuitInputs); + await circuit.checkConstraints(witness); + expect(0n).toEqual(witness[1]); + for (let idx = 0; idx < 1024; ++idx) { + expect(0n).toEqual(witness[2 + idx]); + } + }); }); diff --git a/packages/circom/tests/caret.test.js b/packages/circom/tests/caret.test.js index d4ffdfd..600b9ed 100644 --- a/packages/circom/tests/caret.test.js +++ b/packages/circom/tests/caret.test.js @@ -1,15 +1,15 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Caret Regex", () => { +describe('Caret Regex', () => { let circuit1; let circuit2; let circuit3; @@ -17,86 +17,86 @@ describe("Caret Regex", () => { let circuit5; beforeAll(async () => { writeFileSync( - path.join(__dirname, "./circuits/caret1_regex.circom"), + path.join(__dirname, './circuits/caret1_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/caret1.json"), - "utf8" + path.join(__dirname, './circuits/caret1.json'), + 'utf8' ), - "Caret1Regex" + 'Caret1Regex' ) ); circuit1 = await wasm_tester( - path.join(__dirname, "./circuits/test_caret1_regex.circom"), + path.join(__dirname, './circuits/test_caret1_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/caret2_regex.circom"), + path.join(__dirname, './circuits/caret2_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/caret2.json"), - "utf8" + path.join(__dirname, './circuits/caret2.json'), + 'utf8' ), - "Caret2Regex" + 'Caret2Regex' ) ); circuit2 = await wasm_tester( - path.join(__dirname, "./circuits/test_caret2_regex.circom"), + path.join(__dirname, './circuits/test_caret2_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/caret3_regex.circom"), + path.join(__dirname, './circuits/caret3_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/caret3.json"), - "utf8" + path.join(__dirname, './circuits/caret3.json'), + 'utf8' ), - "Caret3Regex" + 'Caret3Regex' ) ); circuit3 = await wasm_tester( - path.join(__dirname, "./circuits/test_caret3_regex.circom"), + path.join(__dirname, './circuits/test_caret3_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/caret4_regex.circom"), + path.join(__dirname, './circuits/caret4_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/caret4.json"), - "utf8" + path.join(__dirname, './circuits/caret4.json'), + 'utf8' ), - "Caret4Regex" + 'Caret4Regex' ) ); circuit4 = await wasm_tester( - path.join(__dirname, "./circuits/test_caret4_regex.circom"), + path.join(__dirname, './circuits/test_caret4_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/caret5_regex.circom"), + path.join(__dirname, './circuits/caret5_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/caret5.json"), - "utf8" + path.join(__dirname, './circuits/caret5.json'), + 'utf8' ), - "Caret5Regex" + 'Caret5Regex' ) ); circuit5 = await wasm_tester( - path.join(__dirname, "./circuits/test_caret5_regex.circom"), + path.join(__dirname, './circuits/test_caret5_regex.circom'), option ); }); - it("caret1 valid case 1", async () => { + it('caret1 valid case 1', async () => { const inputStr = `a`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -104,9 +104,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret1.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -117,11 +118,11 @@ describe("Caret Regex", () => { } }); - it("caret1 valid case 2", async () => { + it('caret1 valid case 2', async () => { const inputStr = `abnjknda`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -129,9 +130,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret1.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -142,11 +144,11 @@ describe("Caret Regex", () => { } }); - it("caret1 invalid case 1", async () => { + it('caret1 invalid case 1', async () => { const inputStr = `ba`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -156,11 +158,11 @@ describe("Caret Regex", () => { } }); - it("caret1 invalid case 2", async () => { + it('caret1 invalid case 2', async () => { const inputStr = `bav`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -170,12 +172,11 @@ describe("Caret Regex", () => { } }); - - it("caret2 valid case 1", async () => { + it('caret2 valid case 1', async () => { const inputStr = `abc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -183,9 +184,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret2.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -196,11 +198,11 @@ describe("Caret Regex", () => { } }); - it("caret2 valid case 2", async () => { + it('caret2 valid case 2', async () => { const inputStr = `bca`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -208,9 +210,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret2.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -221,11 +224,11 @@ describe("Caret Regex", () => { } }); - it("caret2 valid case 3", async () => { + it('caret2 valid case 3', async () => { const inputStr = `cab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -233,9 +236,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret2.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -246,11 +250,11 @@ describe("Caret Regex", () => { } }); - it("caret2 invalid case 1", async () => { + it('caret2 invalid case 1', async () => { const inputStr = `7abc9mna`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -260,11 +264,11 @@ describe("Caret Regex", () => { } }); - it("caret3 valid case 1", async () => { + it('caret3 valid case 1', async () => { const inputStr = `bb817267`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -272,9 +276,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret3.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -285,11 +290,11 @@ describe("Caret Regex", () => { } }); - it("caret3 valid case 2", async () => { + it('caret3 valid case 2', async () => { const inputStr = `818abbb9`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -297,9 +302,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret3.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -310,11 +316,11 @@ describe("Caret Regex", () => { } }); - it("caret3 invalid case 1", async () => { + it('caret3 invalid case 1', async () => { const inputStr = `81b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -324,11 +330,11 @@ describe("Caret Regex", () => { } }); - it("caret4 valid case 1", async () => { + it('caret4 valid case 1', async () => { const inputStr = `xabaaabb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -336,9 +342,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret4.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret4.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -349,11 +356,11 @@ describe("Caret Regex", () => { } }); - it("caret4 valid case 2", async () => { + it('caret4 valid case 2', async () => { const inputStr = `xbaab82a`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -361,9 +368,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret4.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret4.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -374,11 +382,11 @@ describe("Caret Regex", () => { } }); - it("caret4 valid case 3", async () => { + it('caret4 valid case 3', async () => { const inputStr = `7w1\nxabb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -386,9 +394,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret4.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret4.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -399,11 +408,11 @@ describe("Caret Regex", () => { } }); - it("caret4 valid case 4", async () => { + it('caret4 valid case 4', async () => { const inputStr = `7w\nxbbb9`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -411,9 +420,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret4.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret4.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -424,12 +434,11 @@ describe("Caret Regex", () => { } }); - - it("caret4 invalid case 1", async () => { + it('caret4 invalid case 1', async () => { const inputStr = `7w1nxaba`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -439,11 +448,11 @@ describe("Caret Regex", () => { } }); - it("caret4 invalid case 2", async () => { + it('caret4 invalid case 2', async () => { const inputStr = `abba\nx`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -453,11 +462,11 @@ describe("Caret Regex", () => { } }); - it("caret5 valid case 1", async () => { + it('caret5 valid case 1', async () => { const inputStr = `xdefabc1`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit5.calculateWitness(circuitInputs); await circuit5.checkConstraints(witness); @@ -465,9 +474,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret5.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret5.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -478,11 +488,11 @@ describe("Caret Regex", () => { } }); - it("caret5 valid case 2", async () => { + it('caret5 valid case 2', async () => { const inputStr = `9\nx9eabc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit5.calculateWitness(circuitInputs); await circuit5.checkConstraints(witness); @@ -490,9 +500,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/caret5.json"), - "utf8" - ) + path.join(__dirname, './circuits/caret5.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -503,11 +514,11 @@ describe("Caret Regex", () => { } }); - it("caret5 invalid case 1", async () => { + it('caret5 invalid case 1', async () => { const inputStr = `xabc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit5.calculateWitness(circuitInputs); await circuit5.checkConstraints(witness); @@ -517,11 +528,11 @@ describe("Caret Regex", () => { } }); - it("caret5 invalid case 2", async () => { + it('caret5 invalid case 2', async () => { const inputStr = `1\ndef`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit5.calculateWitness(circuitInputs); await circuit5.checkConstraints(witness); @@ -531,13 +542,11 @@ describe("Caret Regex", () => { } }); - - - it("caret5 invalid case 3", async () => { + it('caret5 invalid case 3', async () => { const inputStr = `a8abc8`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit5.calculateWitness(circuitInputs); await circuit5.checkConstraints(witness); @@ -547,11 +556,11 @@ describe("Caret Regex", () => { } }); - it("caret5 invalid case 4", async () => { + it('caret5 invalid case 4', async () => { const inputStr = `71\na81ma`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit5.calculateWitness(circuitInputs); await circuit5.checkConstraints(witness); @@ -560,5 +569,4 @@ describe("Caret Regex", () => { expect(0n).toEqual(witness[2 + idx]); } }); - }); diff --git a/packages/circom/tests/dollar.test.js b/packages/circom/tests/dollar.test.js index 6a2cdbd..76d008b 100644 --- a/packages/circom/tests/dollar.test.js +++ b/packages/circom/tests/dollar.test.js @@ -1,54 +1,54 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Caret Regex", () => { +describe('Caret Regex', () => { let circuit1; let circuit2; beforeAll(async () => { writeFileSync( - path.join(__dirname, "./circuits/dollar1_regex.circom"), + path.join(__dirname, './circuits/dollar1_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/dollar1.json"), - "utf8" + path.join(__dirname, './circuits/dollar1.json'), + 'utf8' ), - "Dollar1Regex" + 'Dollar1Regex' ) ); circuit1 = await wasm_tester( - path.join(__dirname, "./circuits/test_dollar1_regex.circom"), + path.join(__dirname, './circuits/test_dollar1_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/dollar2_regex.circom"), + path.join(__dirname, './circuits/dollar2_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/dollar2.json"), - "utf8" + path.join(__dirname, './circuits/dollar2.json'), + 'utf8' ), - "Dollar2Regex" + 'Dollar2Regex' ) ); circuit2 = await wasm_tester( - path.join(__dirname, "./circuits/test_dollar2_regex.circom"), + path.join(__dirname, './circuits/test_dollar2_regex.circom'), option ); }); - it("dollar1 valid case 1", async () => { + it('dollar1 valid case 1', async () => { const inputStr = `ab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -56,9 +56,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/dollar1.json"), - "utf8" - ) + path.join(__dirname, './circuits/dollar1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -69,11 +70,11 @@ describe("Caret Regex", () => { } }); - it("dollar1 invalid case 1", async () => { + it('dollar1 invalid case 1', async () => { const inputStr = `abg`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -83,11 +84,11 @@ describe("Caret Regex", () => { } }); - it("dollar1 invalid case 2", async () => { + it('dollar1 invalid case 2', async () => { const inputStr = `18abcg`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -97,11 +98,11 @@ describe("Caret Regex", () => { } }); - it("dollar2 valid case 1", async () => { + it('dollar2 valid case 1', async () => { const inputStr = `xab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -109,9 +110,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/dollar2.json"), - "utf8" - ) + path.join(__dirname, './circuits/dollar2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -122,11 +124,11 @@ describe("Caret Regex", () => { } }); - it("dollar2 valid case 2", async () => { + it('dollar2 valid case 2', async () => { const inputStr = `ak\nxab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -134,9 +136,10 @@ describe("Caret Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/dollar2.json"), - "utf8" - ) + path.join(__dirname, './circuits/dollar2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -147,11 +150,11 @@ describe("Caret Regex", () => { } }); - it("dollar2 invalid case 1", async () => { + it('dollar2 invalid case 1', async () => { const inputStr = `abg`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -161,11 +164,11 @@ describe("Caret Regex", () => { } }); - it("dollar2 invalid case 2", async () => { + it('dollar2 invalid case 2', async () => { const inputStr = `\nabg`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -175,11 +178,11 @@ describe("Caret Regex", () => { } }); - it("dollar2 invalid case 2", async () => { + it('dollar2 invalid case 2', async () => { const inputStr = `\nabg`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); diff --git a/packages/circom/tests/dot.test.js b/packages/circom/tests/dot.test.js index 5bfcc8b..f5b7914 100644 --- a/packages/circom/tests/dot.test.js +++ b/packages/circom/tests/dot.test.js @@ -1,64 +1,62 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Dot Regex", () => { +describe('Dot Regex', () => { let circuit1; let circuit2; beforeAll(async () => { writeFileSync( - path.join(__dirname, "./circuits/dot1_regex.circom"), + path.join(__dirname, './circuits/dot1_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/dot1.json"), - "utf8" + path.join(__dirname, './circuits/dot1.json'), + 'utf8' ), - "Dot1Regex" + 'Dot1Regex' ) ); circuit1 = await wasm_tester( - path.join(__dirname, "./circuits/test_dot1_regex.circom"), + path.join(__dirname, './circuits/test_dot1_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/dot2_regex.circom"), + path.join(__dirname, './circuits/dot2_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/dot2.json"), - "utf8" + path.join(__dirname, './circuits/dot2.json'), + 'utf8' ), - "Dot2Regex" + 'Dot2Regex' ) ); circuit2 = await wasm_tester( - path.join(__dirname, "./circuits/test_dot2_regex.circom"), + path.join(__dirname, './circuits/test_dot2_regex.circom'), option ); }); - it("dot1 valid case 1", async () => { + it('dot1 valid case 1', async () => { const inputStr = `a`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/dot1.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/dot1.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -83,7 +81,7 @@ describe("Dot Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/dot1.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -94,21 +92,19 @@ describe("Dot Regex", () => { // } // }); - it("dot2 valid case 1", async () => { + it('dot2 valid case 1', async () => { const inputStr = `a6b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/dot2.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/dot2.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -133,7 +129,7 @@ describe("Dot Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/dot2.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -144,11 +140,11 @@ describe("Dot Regex", () => { // } // }); - it("dot2 invalid case 1", async () => { + it('dot2 invalid case 1', async () => { const inputStr = `819nc8b8`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -158,11 +154,11 @@ describe("Dot Regex", () => { } }); - it("dot2 invalid case 2", async () => { + it('dot2 invalid case 2', async () => { const inputStr = `78aa6cc8`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -170,5 +166,5 @@ describe("Dot Regex", () => { for (let idx = 0; idx < 8; ++idx) { expect(0n).toEqual(witness[2 + idx]); } - }); + }); }); diff --git a/packages/circom/tests/plus.test.js b/packages/circom/tests/plus.test.js index 869e11b..6a37047 100644 --- a/packages/circom/tests/plus.test.js +++ b/packages/circom/tests/plus.test.js @@ -1,15 +1,15 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Plus Regex", () => { +describe('Plus Regex', () => { let circuit1; let circuit2; let circuit3; @@ -18,62 +18,62 @@ describe("Plus Regex", () => { // let circuit6; beforeAll(async () => { writeFileSync( - path.join(__dirname, "./circuits/plus1_regex.circom"), + path.join(__dirname, './circuits/plus1_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/plus1.json"), - "utf8" + path.join(__dirname, './circuits/plus1.json'), + 'utf8' ), - "Plus1Regex" + 'Plus1Regex' ) ); circuit1 = await wasm_tester( - path.join(__dirname, "./circuits/test_plus1_regex.circom"), + path.join(__dirname, './circuits/test_plus1_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/plus2_regex.circom"), + path.join(__dirname, './circuits/plus2_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/plus2.json"), - "utf8" + path.join(__dirname, './circuits/plus2.json'), + 'utf8' ), - "Plus2Regex" + 'Plus2Regex' ) ); circuit2 = await wasm_tester( - path.join(__dirname, "./circuits/test_plus2_regex.circom"), + path.join(__dirname, './circuits/test_plus2_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/plus3_regex.circom"), + path.join(__dirname, './circuits/plus3_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/plus3.json"), - "utf8" + path.join(__dirname, './circuits/plus3.json'), + 'utf8' ), - "Plus3Regex" + 'Plus3Regex' ) ); circuit3 = await wasm_tester( - path.join(__dirname, "./circuits/test_plus3_regex.circom"), + path.join(__dirname, './circuits/test_plus3_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/plus4_regex.circom"), + path.join(__dirname, './circuits/plus4_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/plus4.json"), - "utf8" + path.join(__dirname, './circuits/plus4.json'), + 'utf8' ), - "Plus4Regex" + 'Plus4Regex' ) ); circuit4 = await wasm_tester( - path.join(__dirname, "./circuits/test_plus4_regex.circom"), + path.join(__dirname, './circuits/test_plus4_regex.circom'), option ); @@ -108,21 +108,19 @@ describe("Plus Regex", () => { // ); }); - it("plus1 valid case 1", async () => { + it('plus1 valid case 1', async () => { const inputStr = `ab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus1.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus1.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -133,22 +131,19 @@ describe("Plus Regex", () => { } }); - - it("plus1 valid case 2", async () => { + it('plus1 valid case 2', async () => { const inputStr = `aaaab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus1.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus1.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -159,21 +154,19 @@ describe("Plus Regex", () => { } }); - it("plus1 valid case 3", async () => { + it('plus1 valid case 3', async () => { const inputStr = `7aab89ac`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus1.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus1.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -184,11 +177,11 @@ describe("Plus Regex", () => { } }); - it("plus1 invalid case 1", async () => { + it('plus1 invalid case 1', async () => { const inputStr = `b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -198,11 +191,11 @@ describe("Plus Regex", () => { } }); - it("plus1 invalid case 2", async () => { + it('plus1 invalid case 2', async () => { const inputStr = `aacaadae`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -212,11 +205,11 @@ describe("Plus Regex", () => { } }); - it("plus1 invalid case 3", async () => { + it('plus1 invalid case 3', async () => { const inputStr = `aaaaaaaa`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -226,21 +219,19 @@ describe("Plus Regex", () => { } }); - it("plus2 valid case 1", async () => { + it('plus2 valid case 1', async () => { const inputStr = `ab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus2.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus2.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -251,21 +242,19 @@ describe("Plus Regex", () => { } }); - it("plus2 valid case 2", async () => { + it('plus2 valid case 2', async () => { const inputStr = `ac`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus2.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus2.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -276,21 +265,19 @@ describe("Plus Regex", () => { } }); - it("plus2 valid case 3", async () => { + it('plus2 valid case 3', async () => { const inputStr = `abccbbcc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus2.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus2.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -301,21 +288,19 @@ describe("Plus Regex", () => { } }); - it("plus2 valid case 4", async () => { + it('plus2 valid case 4', async () => { const inputStr = `7abbcaa`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus2.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus2.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -326,11 +311,11 @@ describe("Plus Regex", () => { } }); - it("plus2 invalid case 1", async () => { + it('plus2 invalid case 1', async () => { const inputStr = `adefghij`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -340,21 +325,19 @@ describe("Plus Regex", () => { } }); - it("plus3 valid case 1", async () => { + it('plus3 valid case 1', async () => { const inputStr = `abcbcbc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus3.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus3.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -365,21 +348,19 @@ describe("Plus Regex", () => { } }); - it("plus3 valid case 2", async () => { + it('plus3 valid case 2', async () => { const inputStr = `acbabcbc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus3.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus3.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -390,21 +371,19 @@ describe("Plus Regex", () => { } }); - it("plus3 valid case 3", async () => { + it('plus3 valid case 3', async () => { const inputStr = `abccbcbb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus3.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus3.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -415,11 +394,11 @@ describe("Plus Regex", () => { } }); - it("plus3 invalid case 1", async () => { + it('plus3 invalid case 1', async () => { const inputStr = `abab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -429,21 +408,19 @@ describe("Plus Regex", () => { } }); - it("plus4 valid case 1", async () => { + it('plus4 valid case 1', async () => { const inputStr = `1234512b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus4.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus4.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -454,21 +431,19 @@ describe("Plus Regex", () => { } }); - it("plus4 valid case 2", async () => { + it('plus4 valid case 2', async () => { const inputStr = `2134512b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); expect(1n).toEqual(witness[1]); const prefixIdxes = apis.extractSubstrIdxes( inputStr, - readFileSync( - path.join(__dirname, "./circuits/plus4.json"), - "utf8" - ) + readFileSync(path.join(__dirname, './circuits/plus4.json'), 'utf8'), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -479,11 +454,11 @@ describe("Plus Regex", () => { } }); - it("plus4 invalid case 1", async () => { + it('plus4 invalid case 1', async () => { const inputStr = `1234b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -493,11 +468,11 @@ describe("Plus Regex", () => { } }); - it("plus4 invalid case 2", async () => { + it('plus4 invalid case 2', async () => { const inputStr = `34512`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit4.calculateWitness(circuitInputs); await circuit4.checkConstraints(witness); @@ -521,7 +496,7 @@ describe("Plus Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/plus5.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -546,7 +521,7 @@ describe("Plus Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/plus5.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -571,7 +546,7 @@ describe("Plus Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/plus5.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -610,7 +585,6 @@ describe("Plus Regex", () => { // } // }); - // it("plus6 valid case 1", async () => { // const inputStr = `aaaabbbb`; // const paddedStr = apis.padString(inputStr, 8); @@ -625,7 +599,7 @@ describe("Plus Regex", () => { // readFileSync( // path.join(__dirname, "./circuits/plus6.json"), // "utf8" - // ) + // ),false // )[0]; // for (let idx = 0; idx < 8; ++idx) { // if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { diff --git a/packages/circom/tests/question.test.js b/packages/circom/tests/question.test.js index 573358a..0a5170e 100644 --- a/packages/circom/tests/question.test.js +++ b/packages/circom/tests/question.test.js @@ -1,70 +1,70 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Question Regex", () => { +describe('Question Regex', () => { let circuit1; let circuit2; let circuit3; beforeAll(async () => { writeFileSync( - path.join(__dirname, "./circuits/question1_regex.circom"), + path.join(__dirname, './circuits/question1_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/question1.json"), - "utf8" + path.join(__dirname, './circuits/question1.json'), + 'utf8' ), - "Question1Regex" + 'Question1Regex' ) ); circuit1 = await wasm_tester( - path.join(__dirname, "./circuits/test_question1_regex.circom"), + path.join(__dirname, './circuits/test_question1_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/question2_regex.circom"), + path.join(__dirname, './circuits/question2_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/question2.json"), - "utf8" + path.join(__dirname, './circuits/question2.json'), + 'utf8' ), - "Question2Regex" + 'Question2Regex' ) ); circuit2 = await wasm_tester( - path.join(__dirname, "./circuits/test_question2_regex.circom"), + path.join(__dirname, './circuits/test_question2_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/question3_regex.circom"), + path.join(__dirname, './circuits/question3_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/question3.json"), - "utf8" + path.join(__dirname, './circuits/question3.json'), + 'utf8' ), - "Question3Regex" + 'Question3Regex' ) ); circuit3 = await wasm_tester( - path.join(__dirname, "./circuits/test_question3_regex.circom"), + path.join(__dirname, './circuits/test_question3_regex.circom'), option ); }); - it("question1 valid case 1", async () => { + it('question1 valid case 1', async () => { const inputStr = `b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -72,9 +72,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question1.json"), - "utf8" - ) + path.join(__dirname, './circuits/question1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -85,11 +86,11 @@ describe("Question Regex", () => { } }); - it("question1 valid case 2", async () => { + it('question1 valid case 2', async () => { const inputStr = `ab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -97,9 +98,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question1.json"), - "utf8" - ) + path.join(__dirname, './circuits/question1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -110,11 +112,11 @@ describe("Question Regex", () => { } }); - it("question1 valid case 3", async () => { + it('question1 valid case 3', async () => { const inputStr = `199aabb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -122,9 +124,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question1.json"), - "utf8" - ) + path.join(__dirname, './circuits/question1.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -135,11 +138,11 @@ describe("Question Regex", () => { } }); - it("question1 invalid case 1", async () => { + it('question1 invalid case 1', async () => { const inputStr = `aaaaaaaa`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -149,11 +152,11 @@ describe("Question Regex", () => { } }); - it("question1 invalid case 2", async () => { + it('question1 invalid case 2', async () => { const inputStr = `cccccccc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -163,11 +166,11 @@ describe("Question Regex", () => { } }); - it("question2 valid case 1", async () => { + it('question2 valid case 1', async () => { const inputStr = `12b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -175,9 +178,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question2.json"), - "utf8" - ) + path.join(__dirname, './circuits/question2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -188,11 +192,11 @@ describe("Question Regex", () => { } }); - it("question2 valid case 2", async () => { + it('question2 valid case 2', async () => { const inputStr = `11x2bb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -200,9 +204,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question2.json"), - "utf8" - ) + path.join(__dirname, './circuits/question2.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -213,11 +218,11 @@ describe("Question Regex", () => { } }); - it("question2 invalid case 1", async () => { + it('question2 invalid case 1', async () => { const inputStr = `1x2`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -227,11 +232,11 @@ describe("Question Regex", () => { } }); - it("question2 invalid case 2", async () => { + it('question2 invalid case 2', async () => { const inputStr = `1xb`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -241,11 +246,11 @@ describe("Question Regex", () => { } }); - it("question3 valid case 1", async () => { + it('question3 valid case 1', async () => { const inputStr = `12c`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -253,9 +258,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question3.json"), - "utf8" - ) + path.join(__dirname, './circuits/question3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -266,11 +272,11 @@ describe("Question Regex", () => { } }); - it("question3 valid case 2", async () => { + it('question3 valid case 2', async () => { const inputStr = `12ac`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -278,9 +284,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question3.json"), - "utf8" - ) + path.join(__dirname, './circuits/question3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -291,11 +298,11 @@ describe("Question Regex", () => { } }); - it("question3 valid case 2", async () => { + it('question3 valid case 2', async () => { const inputStr = `12bc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -303,9 +310,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question3.json"), - "utf8" - ) + path.join(__dirname, './circuits/question3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -316,11 +324,11 @@ describe("Question Regex", () => { } }); - it("question3 valid case 4", async () => { + it('question3 valid case 4', async () => { const inputStr = `12a12bc1`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -328,9 +336,10 @@ describe("Question Regex", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/question3.json"), - "utf8" - ) + path.join(__dirname, './circuits/question3.json'), + 'utf8' + ), + false )[0]; for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { @@ -341,11 +350,11 @@ describe("Question Regex", () => { } }); - it("question3 invalid case 1", async () => { + it('question3 invalid case 1', async () => { const inputStr = `1ac`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -355,11 +364,11 @@ describe("Question Regex", () => { } }); - it("question3 invalid case 2", async () => { + it('question3 invalid case 2', async () => { const inputStr = `12abc`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); @@ -369,11 +378,11 @@ describe("Question Regex", () => { } }); - it("question3 invalid case 3", async () => { + it('question3 invalid case 3', async () => { const inputStr = `12a12b`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit3.calculateWitness(circuitInputs); await circuit3.checkConstraints(witness); diff --git a/packages/circom/tests/reveal_check.test.js b/packages/circom/tests/reveal_check.test.js index 695ebf8..3ae4603 100644 --- a/packages/circom/tests/reveal_check.test.js +++ b/packages/circom/tests/reveal_check.test.js @@ -1,54 +1,54 @@ -import circom_tester from "circom_tester"; -import * as path from "path"; -import { readFileSync, writeFileSync } from "fs"; -import apis from "../../apis/pkg"; -import compiler from "../../compiler/pkg"; +import circom_tester from 'circom_tester'; +import * as path from 'path'; +import { readFileSync, writeFileSync } from 'fs'; +import apis from '../../apis/pkg'; +import compiler from '../../compiler/pkg'; const option = { - include: path.join(__dirname, "../../../node_modules"), + include: path.join(__dirname, '../../../node_modules') }; const wasm_tester = circom_tester.wasm; jest.setTimeout(600000); -describe("Revealed Chars Check", () => { +describe('Revealed Chars Check', () => { let circuit1; let circuit2; beforeAll(async () => { writeFileSync( - path.join(__dirname, "./circuits/reveal_check1_regex.circom"), + path.join(__dirname, './circuits/reveal_check1_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/reveal_check1.json"), - "utf8" + path.join(__dirname, './circuits/reveal_check1.json'), + 'utf8' ), - "RevealCheck1Regex" + 'RevealCheck1Regex' ) ); circuit1 = await wasm_tester( - path.join(__dirname, "./circuits/test_reveal_check1_regex.circom"), + path.join(__dirname, './circuits/test_reveal_check1_regex.circom'), option ); writeFileSync( - path.join(__dirname, "./circuits/reveal_check2_regex.circom"), + path.join(__dirname, './circuits/reveal_check2_regex.circom'), compiler.genFromDecomposed( readFileSync( - path.join(__dirname, "./circuits/reveal_check2.json"), - "utf8" + path.join(__dirname, './circuits/reveal_check2.json'), + 'utf8' ), - "RevealCheck2Regex" + 'RevealCheck2Regex' ) ); circuit2 = await wasm_tester( - path.join(__dirname, "./circuits/test_reveal_check2_regex.circom"), + path.join(__dirname, './circuits/test_reveal_check2_regex.circom'), option ); }); - it("reveal check1 valid case 1", async () => { + it('reveal check1 valid case 1', async () => { const inputStr = `aba`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -56,11 +56,12 @@ describe("Revealed Chars Check", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/reveal_check1.json"), - "utf8" - ) + path.join(__dirname, './circuits/reveal_check1.json'), + 'utf8' + ), + false )[0]; - expect(prefixIdxes).toEqual([0,3]); + expect(prefixIdxes).toEqual([0, 3]); for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); @@ -70,12 +71,11 @@ describe("Revealed Chars Check", () => { } }); - - it("reveal check1 valid case 2", async () => { + it('reveal check1 valid case 2', async () => { const inputStr = `7abaab9`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -83,11 +83,12 @@ describe("Revealed Chars Check", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/reveal_check1.json"), - "utf8" - ) + path.join(__dirname, './circuits/reveal_check1.json'), + 'utf8' + ), + false )[0]; - expect(prefixIdxes).toEqual([1,4]); + expect(prefixIdxes).toEqual([1, 4]); for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); @@ -97,11 +98,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check1 invalid case 1", async () => { + it('reveal check1 invalid case 1', async () => { const inputStr = `aca`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -111,11 +112,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check1 invalid case 2", async () => { + it('reveal check1 invalid case 2', async () => { const inputStr = `aaa`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit1.calculateWitness(circuitInputs); await circuit1.checkConstraints(witness); @@ -125,11 +126,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check2 valid case 1", async () => { + it('reveal check2 valid case 1', async () => { const inputStr = `aa`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -137,11 +138,12 @@ describe("Revealed Chars Check", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/reveal_check2.json"), - "utf8" - ) + path.join(__dirname, './circuits/reveal_check2.json'), + 'utf8' + ), + false )[0]; - expect(prefixIdxes).toEqual([0,2]); + expect(prefixIdxes).toEqual([0, 2]); for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); @@ -151,11 +153,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check2 valid case 2", async () => { + it('reveal check2 valid case 2', async () => { const inputStr = `ab`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -163,11 +165,12 @@ describe("Revealed Chars Check", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/reveal_check2.json"), - "utf8" - ) + path.join(__dirname, './circuits/reveal_check2.json'), + 'utf8' + ), + false )[0]; - expect(prefixIdxes).toEqual([0,2]); + expect(prefixIdxes).toEqual([0, 2]); for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); @@ -177,11 +180,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check2 valid case 3", async () => { + it('reveal check2 valid case 3', async () => { const inputStr = `aba`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -189,11 +192,12 @@ describe("Revealed Chars Check", () => { const prefixIdxes = apis.extractSubstrIdxes( inputStr, readFileSync( - path.join(__dirname, "./circuits/reveal_check2.json"), - "utf8" - ) + path.join(__dirname, './circuits/reveal_check2.json'), + 'utf8' + ), + false )[0]; - expect(prefixIdxes).toEqual([0,2]); + expect(prefixIdxes).toEqual([0, 2]); for (let idx = 0; idx < 8; ++idx) { if (idx >= prefixIdxes[0] && idx < prefixIdxes[1]) { expect(BigInt(paddedStr[idx])).toEqual(witness[2 + idx]); @@ -203,11 +207,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check2 invalid case 1", async () => { + it('reveal check2 invalid case 1', async () => { const inputStr = `ac`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -217,11 +221,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check2 invalid case 2", async () => { + it('reveal check2 invalid case 2', async () => { const inputStr = `bad`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -231,11 +235,11 @@ describe("Revealed Chars Check", () => { } }); - it("reveal check2 invalid case 3", async () => { + it('reveal check2 invalid case 3', async () => { const inputStr = `bad`; const paddedStr = apis.padString(inputStr, 8); const circuitInputs = { - msg: paddedStr, + msg: paddedStr }; const witness = await circuit2.calculateWitness(circuitInputs); await circuit2.checkConstraints(witness); @@ -244,6 +248,4 @@ describe("Revealed Chars Check", () => { expect(0n).toEqual(witness[2 + idx]); } }); - - });