mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-09 13:38:03 -05:00
Merge pull request #218 from zkemail/revert/regex-update
Revert index range check on SelectRegexReveal
This commit is contained in:
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@@ -0,0 +1 @@
|
||||
packages/helpers/src/lib
|
||||
5
.prettierrc
Normal file
5
.prettierrc
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"semi": true,
|
||||
"tabWidth": 2,
|
||||
"printWidth": 120
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"lint": "yarn prettier --write packages/**/**.ts",
|
||||
"test": "jest"
|
||||
},
|
||||
"workspaces": [
|
||||
@@ -12,5 +13,8 @@
|
||||
"packageManager": "yarn@3.2.3",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^3.3.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,5 +43,7 @@ describe("ByteMask Circuit", () => {
|
||||
} catch (error) {
|
||||
expect(error).toBeTruthy();
|
||||
}
|
||||
|
||||
expect.assertions(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,8 @@ import { wasm as wasm_tester } from 'circom_tester';
|
||||
import path from 'path';
|
||||
|
||||
describe('RemoveSoftLineBreaks', () => {
|
||||
jest.setTimeout(20_1000);
|
||||
|
||||
let circuit: any;
|
||||
|
||||
beforeAll(async () => {
|
||||
|
||||
@@ -20,10 +20,7 @@ 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 = new Array(34).fill(0);
|
||||
const startIndex = Math.floor(Math.random() * 24);
|
||||
const revealed = Array.from("zk email").map((char) =>
|
||||
char.charCodeAt(0)
|
||||
@@ -40,10 +37,7 @@ describe("Select Regex Reveal", () => {
|
||||
});
|
||||
|
||||
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 = new Array(34).fill(0);
|
||||
const startIndex = 30;
|
||||
const revealed = Array.from("zk").map((char) => char.charCodeAt(0));
|
||||
for (let i = 0; i < revealed.length; i++) {
|
||||
@@ -60,11 +54,8 @@ describe("Select Regex Reveal", () => {
|
||||
});
|
||||
|
||||
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,
|
||||
];
|
||||
const startIndex = Math.floor(Math.random() * 32);
|
||||
let input = new Array(34).fill(0);
|
||||
const startIndex = Math.floor(Math.random() * 34);
|
||||
try {
|
||||
const witness = await circuit.calculateWitness({
|
||||
in: input,
|
||||
@@ -74,13 +65,12 @@ describe("Select Regex Reveal", () => {
|
||||
} catch (error) {
|
||||
expect((error as Error).message).toMatch("Assert Failed");
|
||||
}
|
||||
|
||||
expect.assertions(1);
|
||||
});
|
||||
|
||||
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 = new Array(34).fill(0);
|
||||
const startIndex = 1 + Math.floor(Math.random() * 24);
|
||||
const revealed = Array.from("zk email").map((char) =>
|
||||
char.charCodeAt(0)
|
||||
@@ -97,13 +87,12 @@ describe("Select Regex Reveal", () => {
|
||||
} catch (error) {
|
||||
expect((error as Error).message).toMatch("Assert Failed");
|
||||
}
|
||||
|
||||
expect.assertions(1);
|
||||
});
|
||||
|
||||
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 = new Array(34).fill(0);
|
||||
const startIndex = Math.floor(Math.random() * 23);
|
||||
const revealed = Array.from("zk email").map((char) =>
|
||||
char.charCodeAt(0)
|
||||
@@ -120,28 +109,7 @@ describe("Select Regex Reveal", () => {
|
||||
} catch (error) {
|
||||
expect((error as Error).message).toMatch("Assert Failed");
|
||||
}
|
||||
});
|
||||
|
||||
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,
|
||||
];
|
||||
const startIndex = Math.floor(Math.random() * 24);
|
||||
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,
|
||||
});
|
||||
await circuit.checkConstraints(witness);
|
||||
} catch (error) {
|
||||
expect((error as Error).message).toMatch("Assert Failed");
|
||||
}
|
||||
expect.assertions(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ describe("SplitBytesToWords Helper unit test", () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
circuit = await wasm_tester(
|
||||
path.join(__dirname, "./test-circuits/splitBytesToWords-test.circom"),
|
||||
path.join(__dirname, "./test-circuits/split-bytes-to-words-test.circom"),
|
||||
{
|
||||
recompile: true,
|
||||
include: path.join(__dirname, "../../../node_modules"),
|
||||
@@ -2,4 +2,4 @@ pragma circom 2.1.6;
|
||||
|
||||
include "../../utils/regex.circom";
|
||||
|
||||
component main = SelectRegexReveal(32,8);
|
||||
component main = SelectRegexReveal(34, 8);
|
||||
@@ -27,10 +27,6 @@ template SelectRegexReveal(maxArrayLen, maxRevealLen) {
|
||||
signal isPreviousZero[maxArrayLen];
|
||||
signal isAboveMaxRevealLen[maxArrayLen];
|
||||
|
||||
// Assert startIndex < maxArrayLen
|
||||
signal isValidStartIndex <== LessThan(bitLength)([startIndex, maxArrayLen]);
|
||||
isValidStartIndex === 1;
|
||||
|
||||
isPreviousZero[0] <== 1;
|
||||
for(var i = 0; i < maxArrayLen; i++) {
|
||||
isStartIndex[i] <== IsEqual()([i, startIndex]);
|
||||
|
||||
11
yarn.lock
11
yarn.lock
@@ -7168,6 +7168,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"prettier@npm:^3.3.3":
|
||||
version: 3.3.3
|
||||
resolution: "prettier@npm:3.3.3"
|
||||
bin:
|
||||
prettier: bin/prettier.cjs
|
||||
checksum: bc8604354805acfdde6106852d14b045bb20827ad76a5ffc2455b71a8257f94de93f17f14e463fe844808d2ccc87248364a5691488a3304f1031326e62d9276e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pretty-format@npm:^29.0.0, pretty-format@npm:^29.7.0":
|
||||
version: 29.7.0
|
||||
resolution: "pretty-format@npm:29.7.0"
|
||||
@@ -7455,6 +7464,8 @@ __metadata:
|
||||
"root-workspace-0b6124@workspace:.":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "root-workspace-0b6124@workspace:."
|
||||
dependencies:
|
||||
prettier: ^3.3.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
|
||||
Reference in New Issue
Block a user