mirror of
https://github.com/zkemail/zk-regex.git
synced 2026-01-09 13:48:00 -05:00
Add a constraint for the input range check result.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "zk-regex-apis"
|
||||
version = "2.3.0"
|
||||
version = "2.3.1"
|
||||
license = "MIT"
|
||||
edition = "2018"
|
||||
authors = [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zk-email/zk-regex-apis",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.1",
|
||||
"description": "apis compatible with [zk-regex](https://github.com/zkemail/zk-regex/tree/main).",
|
||||
"contributors": [
|
||||
"Javier Su <javier.su.weijie@gmail.com>",
|
||||
|
||||
@@ -9,9 +9,11 @@ template BodyHashRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template EmailAddrRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template EmailDomainRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template FromAllRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template MessageIdRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template ReversedBracketRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template SubjectAllRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template TimestampRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template ToAllRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zk-email/zk-regex-circom",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.1",
|
||||
"license": "MIT",
|
||||
"description": "regex verification circuits in circom for common regexes, generated with the compiler in [zk-regex](https://github.com/zkemail/zk-regex/tree/main).",
|
||||
"contributors": [
|
||||
|
||||
@@ -83,7 +83,7 @@ describe('Bodyhash Regex', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('invalid bodyhash', async () => {
|
||||
it('bodyhash in the invalid field', 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 = {
|
||||
@@ -96,4 +96,19 @@ describe('Bodyhash Regex', () => {
|
||||
expect(0n).toEqual(witness[2 + idx]);
|
||||
}
|
||||
});
|
||||
|
||||
it('invalid bodyhash with 255', 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=`;
|
||||
let paddedStr = apis.padString(signatureField, 1022);
|
||||
paddedStr.unshift(49);
|
||||
paddedStr.unshift(255);
|
||||
const circuitInputs = {
|
||||
msg: paddedStr
|
||||
};
|
||||
async function failFn() {
|
||||
const witness = await circuit.calculateWitness(circuitInputs);
|
||||
await circuit.checkConstraints(witness);
|
||||
}
|
||||
await expect(failFn).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,9 +9,11 @@ template Asterisk1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Asterisk2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Asterisk3Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Caret1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Caret2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Caret3Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Caret4Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Caret5Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Dollar1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Dollar2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Dot1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Dot2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template InternationalCharsDecomposed(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template InvitationCodeWithPrefixRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Negate1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Negate2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Plus1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Plus2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Plus3Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Plus4Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Question1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Question2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template Question3Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template RevealCheck1Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template RevealCheck2Regex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template SimpleRegex(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ template SimpleRegexDecomposed(msg_bytes) {
|
||||
|
||||
var num_bytes = msg_bytes+1;
|
||||
signal in[num_bytes];
|
||||
signal in_range_checks[msg_bytes];
|
||||
in[0]<==255;
|
||||
for (var i = 0; i < msg_bytes; i++) {
|
||||
_ <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] <== LessThan(8)([msg[i], 255]);
|
||||
in_range_checks[i] === 1;
|
||||
in[i+1] <== msg[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ describe("From Addr Regex", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("invalid from field", async () => {
|
||||
it("from field in the invalid field", async () => {
|
||||
const fromStr = "\r\nto:from:Sora Suegami <suegamisora@gmail.com>\r\n";
|
||||
const paddedStr = apis.padString(fromStr, 1024);
|
||||
const circuitInputs = {
|
||||
@@ -228,6 +228,21 @@ describe("From Addr Regex", () => {
|
||||
await expect(failFn).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('invalid from field with 255', async () => {
|
||||
const fromStr = `from:Sora Suegami <suegamisora@gmail.com>\r\n`;
|
||||
let paddedStr = apis.padString(fromStr, 1022);
|
||||
paddedStr.unshift(49);
|
||||
paddedStr.unshift(255);
|
||||
const circuitInputs = {
|
||||
msg: paddedStr
|
||||
};
|
||||
async function failFn() {
|
||||
const witness = await circuit.calculateWitness(circuitInputs);
|
||||
await circuit.checkConstraints(witness);
|
||||
}
|
||||
await expect(failFn).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("from field containing @ in the name part", async () => {
|
||||
const fromStr = "from:Sora Suegami <suegamisora@gmail.com@dummy.com>\r\n";
|
||||
const paddedStr = apis.padString(fromStr, 1024);
|
||||
@@ -353,5 +368,4 @@ describe("From Addr Regex", () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -87,7 +87,7 @@ describe("Subject All Regex", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("invalid subject", async () => {
|
||||
it("subject in the invalid field", async () => {
|
||||
const subjectStr = "\r\nto:subject:This is a subject in To field.\r\n";
|
||||
const paddedStr = apis.padString(subjectStr, 256);
|
||||
const circuitInputs = {
|
||||
@@ -100,4 +100,19 @@ describe("Subject All Regex", () => {
|
||||
expect(0n).toEqual(witness[2 + idx]);
|
||||
}
|
||||
});
|
||||
|
||||
it('invalid subject field with 255', async () => {
|
||||
const subjectStr = `subject:This is a subject in To field.\r\n`;
|
||||
let paddedStr = apis.padString(subjectStr, 1022);
|
||||
paddedStr.unshift(49);
|
||||
paddedStr.unshift(255);
|
||||
const circuitInputs = {
|
||||
msg: paddedStr
|
||||
};
|
||||
async function failFn() {
|
||||
const witness = await circuit.calculateWitness(circuitInputs);
|
||||
await circuit.checkConstraints(witness);
|
||||
}
|
||||
await expect(failFn).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -215,7 +215,7 @@ describe("To Addr Regex", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("invalid to field", async () => {
|
||||
it("to field in the invalid field", async () => {
|
||||
const toStr = "subject:to:adityabisht@gmail.com\r\n";
|
||||
const paddedStr = apis.padString(toStr, 1024);
|
||||
const circuitInputs = {
|
||||
@@ -227,6 +227,21 @@ describe("To Addr Regex", () => {
|
||||
await expect(failFn).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('invalid to field with 255', async () => {
|
||||
const toStr = `to:adityabisht@gmail.com\r\n`;
|
||||
let paddedStr = apis.padString(toStr, 1022);
|
||||
paddedStr.unshift(49);
|
||||
paddedStr.unshift(255);
|
||||
const circuitInputs = {
|
||||
msg: paddedStr
|
||||
};
|
||||
async function failFn() {
|
||||
const witness = await circuit.calculateWitness(circuitInputs);
|
||||
await circuit.checkConstraints(witness);
|
||||
}
|
||||
await expect(failFn).rejects.toThrow();
|
||||
});
|
||||
|
||||
it("to field containing @ in the name part", async () => {
|
||||
const toStr = "to:Aditya Bisht <adityabisht@gmail.com@dummy.com>\r\n";
|
||||
const paddedStr = apis.padString(toStr, 1024);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "zk-regex-compiler"
|
||||
version = "2.3.0"
|
||||
version = "2.3.1"
|
||||
authors = [
|
||||
"Javier Su <javier.su.weijie@gmail.com>",
|
||||
"Kata Choi <kata.choi@gmail.com>",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zk-email/zk-regex-compiler",
|
||||
"version": "2.3.0",
|
||||
"version": "2.3.1",
|
||||
"description": "A compiler to generate a regex verification circuit in circom from a user-defined regex. Please check [zk-regex](https://github.com/zkemail/zk-regex/tree/main) for the detail.",
|
||||
"contributors": [
|
||||
"Javier Su <javier.su.weijie@gmail.com>",
|
||||
|
||||
@@ -582,9 +582,11 @@ fn generate_declarations(
|
||||
"".to_string(),
|
||||
"\tvar num_bytes = msg_bytes+1;".to_string(),
|
||||
"\tsignal in[num_bytes];".to_string(),
|
||||
"\tsignal in_range_checks[msg_bytes];".to_string(),
|
||||
"\tin[0]<==255;".to_string(),
|
||||
"\tfor (var i = 0; i < msg_bytes; i++) {".to_string(),
|
||||
"\t\t_ <== LessThan(8)([msg[i], 255]);".to_string(),
|
||||
"\t\tin_range_checks[i] <== LessThan(8)([msg[i], 255]);".to_string(),
|
||||
"\t\tin_range_checks[i] === 1;".to_string(),
|
||||
"\t\tin[i+1] <== msg[i];".to_string(),
|
||||
"\t}".to_string(),
|
||||
"".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user