-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert index range check on SelectRegexReveal #218
Changes from all commits
9af72fe
72057f5
66ea076
3bb68a1
9d956d3
fbdf5bc
b1a8045
93b2a34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages/helpers/src/lib |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"semi": true, | ||
"tabWidth": 2, | ||
"printWidth": 120 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"lint": "yarn prettier --write packages/**/**.ts", | ||
"test": "jest" | ||
}, | ||
"workspaces": [ | ||
|
@@ -12,5 +13,8 @@ | |
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=14.0.0" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^3.3.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait why did we remove this test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By our pattern we are constraining indices where it originates (main circuits). Adding them to each utils might be redundant as main circuits would be using multiple utils. We are not doing these checks on other circuits as well. This was added recently by another PR but we already have comments saying "assumes valid index" |
||
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SoraSuegami Just FYI, we need to add this in negative testing to let jest know we expect an assertion - this ensures the catch block was executed (as our assertion is in catch). Otherwise the test would pass even if the code didn't fail as expected.