Skip to content

Commit bcf50a2

Browse files
authored
Merge pull request #34 from zkemail/rutefig/reg-473-fix-testdecomposedregex-in-sdk-and-relayerutils
Rutefig/reg 473 fix testdecomposedregex in sdk and relayerutils
2 parents e211f00 + d238dc4 commit bcf50a2

File tree

15 files changed

+1358
-115
lines changed

15 files changed

+1358
-115
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ pkg
66

77
tests/outputs
88
tests/fixtures/confidential*
9+
10+
11+
.claude
12+
thoughts/

Cargo.lock

Lines changed: 3 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "relayer-utils"
3-
version = "0.4.62-12"
3+
version = "0.4.62-16"
44
authors = ["Sora Suegami", "Aditya Bisht"]
55
license = "MIT"
66
edition = "2018"
@@ -13,10 +13,11 @@ crate-type = ["rlib", "cdylib"]
1313
itertools = "0.10.3"
1414
serde_json = "1.0.95"
1515
serde = { version = "1.0.159", features = ["derive"] }
16-
zk-regex-apis = { git = "https://github.com/zkemail/zk-regex.git" }
17-
zk-regex-compiler = { git = "https://github.com/zkemail/zk-regex.git", rev = "35014c2bff69115bb92be2dc2c9b006fa69a6649"}
16+
zk-regex-compiler = { git = "https://github.com/zkemail/zk-regex.git", rev = "35014c2bff69115bb92be2dc2c9b006fa69a6649" }
1817
hex = "0.4.3"
1918
anyhow = "1.0.75"
19+
thiserror = "1.0"
20+
fancy-regex = "0.13.0"
2021
halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves.git", rev = "8771fe5a5d54fc03e74dbc8915db5dad3ab46a83", default-features = false }
2122
poseidon-rs = { git = "https://github.com/zkemail/poseidon-rs.git", version = "1.0.0" }
2223
rand_core = { version = "0.6", default-features = false }

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"wasm:postbuild": "node build.js",
1111
"build": "npm run wasm:build && npm run wasm:postbuild"
1212
},
13-
"version": "0.4.66-4",
13+
"version": "0.4.66-8",
1414
"devDependencies": {
1515
"@types/bun": "latest",
1616
"prettier": "^3.3.3"

src/circuit/circom.rs

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
use crate::regex::{DecomposedRegexConfig, RegexPart};
12
use anyhow::Result;
2-
use js_sys::Number;
33
use serde::{Deserialize, Serialize};
44
use serde_json::{json, Value};
55
use std::collections::VecDeque;
6-
use zk_regex_apis::extract_substrs::{
7-
extract_substr_idxes, DecomposedRegexConfig, RegexPartConfig,
8-
};
96
use zk_regex_compiler::{gen_circuit_inputs, NFAGraph, ProverInputs, ProvingFramework};
107

118
use crate::{
@@ -58,18 +55,112 @@ struct ClaimCircuitInput {
5855
account_code: String, // The account code as a string
5956
}
6057

58+
/// Serializable wrapper for RegexPart that can be used in JSON files
6159
#[derive(Serialize, Deserialize, Debug, Clone)]
60+
#[serde(untagged)]
61+
pub enum SerializableRegexPart {
62+
Pattern(String),
63+
PublicPattern((String, usize)),
64+
}
65+
66+
impl From<SerializableRegexPart> for RegexPart {
67+
fn from(part: SerializableRegexPart) -> Self {
68+
match part {
69+
SerializableRegexPart::Pattern(p) => RegexPart::Pattern(p),
70+
SerializableRegexPart::PublicPattern((p, max)) => RegexPart::PublicPattern((p, max)),
71+
}
72+
}
73+
}
74+
75+
impl From<RegexPart> for SerializableRegexPart {
76+
fn from(part: RegexPart) -> Self {
77+
match part {
78+
RegexPart::Pattern(p) => SerializableRegexPart::Pattern(p),
79+
RegexPart::PublicPattern((p, max)) => SerializableRegexPart::PublicPattern((p, max)),
80+
}
81+
}
82+
}
83+
84+
impl From<&RegexPart> for SerializableRegexPart {
85+
fn from(part: &RegexPart) -> Self {
86+
match part {
87+
RegexPart::Pattern(p) => SerializableRegexPart::Pattern(p.clone()),
88+
RegexPart::PublicPattern((p, max)) => {
89+
SerializableRegexPart::PublicPattern((p.clone(), *max))
90+
}
91+
}
92+
}
93+
}
94+
95+
#[derive(Serialize, Deserialize)]
6296
#[serde(rename_all = "camelCase")]
6397
pub struct DecomposedRegex {
64-
pub parts: Vec<RegexPartConfig>, // The parts of the regex configuration
65-
pub name: String, // The name of the decomposed regex
66-
pub max_match_length: usize, // The maximum length of the regex match
67-
pub max_haystack_length: usize, // The maximum length of the haystack
98+
#[serde(with = "regex_parts_serde")]
99+
pub parts: Vec<RegexPart>, // The parts of the regex configuration (using new RegexPart enum)
100+
pub name: String, // The name of the decomposed regex
101+
pub max_match_length: usize, // The maximum length of the regex match
102+
pub max_haystack_length: usize, // The maximum length of the haystack
68103
pub haystack_location: String, // The location where the regex is applied (e.g., header or body)
69104
pub regex_graph_json: String,
70105
pub proving_framework: ProvingFramework,
71106
}
72107

108+
impl std::fmt::Debug for DecomposedRegex {
109+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110+
f.debug_struct("DecomposedRegex")
111+
.field("name", &self.name)
112+
.field("max_match_length", &self.max_match_length)
113+
.field("max_haystack_length", &self.max_haystack_length)
114+
.field("haystack_location", &self.haystack_location)
115+
.field("regex_graph_json", &"<json>")
116+
.field("proving_framework", &self.proving_framework)
117+
.finish()
118+
}
119+
}
120+
121+
impl Clone for DecomposedRegex {
122+
fn clone(&self) -> Self {
123+
DecomposedRegex {
124+
parts: self
125+
.parts
126+
.iter()
127+
.map(|p| match p {
128+
RegexPart::Pattern(s) => RegexPart::Pattern(s.clone()),
129+
RegexPart::PublicPattern((s, n)) => RegexPart::PublicPattern((s.clone(), *n)),
130+
})
131+
.collect(),
132+
name: self.name.clone(),
133+
max_match_length: self.max_match_length,
134+
max_haystack_length: self.max_haystack_length,
135+
haystack_location: self.haystack_location.clone(),
136+
regex_graph_json: self.regex_graph_json.clone(),
137+
proving_framework: self.proving_framework,
138+
}
139+
}
140+
}
141+
142+
// Custom serde module for Vec<RegexPart>
143+
mod regex_parts_serde {
144+
use super::*;
145+
use serde::{Deserializer, Serializer};
146+
147+
pub fn serialize<S>(parts: &[RegexPart], serializer: S) -> Result<S::Ok, S::Error>
148+
where
149+
S: Serializer,
150+
{
151+
let serializable: Vec<SerializableRegexPart> = parts.iter().map(|p| p.into()).collect();
152+
serializable.serialize(serializer)
153+
}
154+
155+
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<RegexPart>, D::Error>
156+
where
157+
D: Deserializer<'de>,
158+
{
159+
let serializable: Vec<SerializableRegexPart> = Vec::deserialize(deserializer)?;
160+
Ok(serializable.into_iter().map(Into::into).collect())
161+
}
162+
}
163+
73164
/// Asynchronously generates the circuit input for an email.
74165
///
75166
/// This function processes an email and its associated account code along with optional
@@ -225,7 +316,7 @@ pub async fn generate_claim_input(
225316
account_code: &str,
226317
) -> Result<String> {
227318
// Convert the email address to a padded format
228-
let padded_email_address = PaddedEmailAddr::from_email_addr(email_address);
319+
let padded_email_address = PaddedEmailAddr::from_email_addr(email_address)?;
229320
// Collect the padded bytes into a vector
230321
let padded_email_addr_bytes = padded_email_address.padded_bytes;
231322

0 commit comments

Comments
 (0)