Skip to content

Commit

Permalink
Fix compiler test.
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Feb 10, 2024
1 parent 702d0ea commit 2e2bbc9
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/body_hash_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,12 @@ template BodyHashRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][8] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(5, 5), (3, 5)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(3, 5), (5, 5)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][3] * states[i+2][5];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][5] * states[i+2][5];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/email_addr_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ template EmailAddrRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][3] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(1, 1), (0, 1), (3, 3), (1, 2), (2, 3)}]
signal is_substr0[msg_bytes][6];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(0, 1), (1, 1), (1, 2), (2, 3), (3, 3)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][0] * states[i+2][1];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][1] * states[i+2][1];
is_substr0[i][3] <== is_substr0[i][2] + states[i+1][1] * states[i+2][2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,12 @@ template EmailAddrWithNameRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][3] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(5, 4), (2, 2), (4, 5), (4, 4), (6, 2), (6, 4), (5, 6), (5, 5), (2, 4)}]
signal is_substr0[msg_bytes][10];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(2, 2), (2, 4), (4, 4), (4, 5), (5, 4), (5, 5), (5, 6), (6, 2), (6, 4)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][2] * states[i+2][2];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][2] * states[i+2][4];
is_substr0[i][3] <== is_substr0[i][2] + states[i+1][4] * states[i+2][4];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/email_domain_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ template EmailDomainRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][3] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(2, 3), (3, 3)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(2, 3), (3, 3)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][2] * states[i+2][3];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][3] * states[i+2][3];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/from_all_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ template FromAllRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][10] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(1, 1), (8, 1)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(1, 1), (8, 1)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][8] * states[i+2][1];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/message_id_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ template MessageIdRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][7] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(1, 1), (1, 4), (17, 18), (18, 1)}]
signal is_substr0[msg_bytes][5];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(1, 1), (1, 4), (17, 18), (18, 1)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][1] * states[i+2][4];
is_substr0[i][3] <== is_substr0[i][2] + states[i+1][17] * states[i+2][18];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/subject_all_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ template SubjectAllRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][13] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(12, 1), (1, 1)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(1, 1), (12, 1)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][12] * states[i+2][1];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/timestamp_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ template TimestampRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][5] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(26, 3), (3, 3)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(3, 3), (26, 3)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][3] * states[i+2][3];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][26] * states[i+2][3];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/circuits/common/to_all_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ template ToAllRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][8] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(6, 1), (1, 1)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(1, 1), (6, 1)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][6] * states[i+2][1];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
2 changes: 1 addition & 1 deletion packages/circom/tests/circuits/negate1_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ template Negate1Regex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][4] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(1, 1), (3, 1)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(1, 1), (3, 1)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][3] * states[i+2][1];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
4 changes: 3 additions & 1 deletion packages/circom/tests/circuits/simple_regex.circom
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ template SimpleRegex(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][9] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(2, 3)}, {(6, 7), (7, 7)}, {(8, 9)}]
signal is_substr0[msg_bytes][2];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(2, 3)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][2] * states[i+2][3];
is_reveal0[i] <== is_substr0[i][1] * is_consecutive[i][1];
reveal0[i] <== in[i+1] * is_reveal0[i];
Expand All @@ -144,6 +144,7 @@ template SimpleRegex(msg_bytes) {
signal output reveal1[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr1[i][0] <== 0;
// the 1-th substring transitions: [(6, 7), (7, 7)]
is_substr1[i][1] <== is_substr1[i][0] + states[i+1][6] * states[i+2][7];
is_substr1[i][2] <== is_substr1[i][1] + states[i+1][7] * states[i+2][7];
is_reveal1[i] <== is_substr1[i][2] * is_consecutive[i][1];
Expand All @@ -154,6 +155,7 @@ template SimpleRegex(msg_bytes) {
signal output reveal2[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr2[i][0] <== 0;
// the 2-th substring transitions: [(8, 9)]
is_substr2[i][1] <== is_substr2[i][0] + states[i+1][8] * states[i+2][9];
is_reveal2[i] <== is_substr2[i][1] * is_consecutive[i][1];
reveal2[i] <== in[i+1] * is_reveal2[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ template SimpleRegexDecomposed(msg_bytes) {
is_consecutive[msg_bytes-1-i][0] <== states[num_bytes-i][4] * (1 - is_consecutive[msg_bytes-i][1]) + is_consecutive[msg_bytes-i][1];
is_consecutive[msg_bytes-1-i][1] <== state_changed[msg_bytes-i].out * is_consecutive[msg_bytes-1-i][0];
}
// substrings calculated: [{(23, 1), (1, 1)}]
signal is_substr0[msg_bytes][3];
signal is_reveal0[msg_bytes];
signal output reveal0[msg_bytes];
for (var i = 0; i < msg_bytes; i++) {
is_substr0[i][0] <== 0;
// the 0-th substring transitions: [(1, 1), (23, 1)]
is_substr0[i][1] <== is_substr0[i][0] + states[i+1][1] * states[i+2][1];
is_substr0[i][2] <== is_substr0[i][1] + states[i+1][23] * states[i+2][1];
is_reveal0[i] <== is_substr0[i][2] * is_consecutive[i][1];
Expand Down
15 changes: 7 additions & 8 deletions packages/compiler/src/circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ use crate::js_caller::*;
use crate::RegexAndDFA;
// use crate::{AllstrRegexDef, SubstrRegexDef};






use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::{fs::File};


impl RegexAndDFA {
pub fn gen_circom(
Expand Down Expand Up @@ -48,7 +42,11 @@ impl RegexAndDFA {
circom += "\t}\n";

let substr_defs_array = &self.substrs_defs.substr_defs_array;
circom += &format!("\t// substrings calculated: {:?}\n", &self.substrs_defs.substr_defs_array);
// circom += &format!(
// "\t// substrings calculated: {:?}\n",
// &self.substrs_defs.substr_defs_array
// );

for (idx, defs) in substr_defs_array.into_iter().enumerate() {
let num_defs = defs.len();
circom += &format!("\tsignal is_substr{}[msg_bytes][{}];\n", idx, num_defs + 1);
Expand All @@ -66,6 +64,7 @@ impl RegexAndDFA {
start_cmp
}
});
circom += &format!("\t\t // the {}-th substring transitions: {:?}\n", idx, defs);
for (j, (cur, next)) in defs.iter().enumerate() {
circom += &format!(
"\t\tis_substr{}[i][{}] <== is_substr{}[i][{}] + ",
Expand Down
8 changes: 5 additions & 3 deletions packages/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,16 @@ mod tests {

#[test]
fn test_gen_from_decomposed() {
let decomposed_regex_path = Path::new("../circuits/common/subject_all.json");
let circom_file_path = Some("../circuits/common/subject_all_regex.circom");
let project_root = PathBuf::new().join(env!("CARGO_MANIFEST_DIR"));
let decomposed_regex_path = project_root.join("../circom/circuits/common/subject_all.json");
let circom_file_path =
project_root.join("../circom/circuits/common/subject_all_regex.circom");
let circom_template_name = Some("SubjectAllRegex");
let gen_substrs = Some(true);

let result = gen_from_decomposed(
decomposed_regex_path.to_str().unwrap(),
circom_file_path.map(|s| s),
Some(circom_file_path.to_str().unwrap()),
circom_template_name.map(|s| s),
gen_substrs,
);
Expand Down

0 comments on commit 2e2bbc9

Please sign in to comment.