Skip to content

Noir ZK Regex #85

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

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8ded16e
feat: initial noir support (#1)
olehmisar Sep 17, 2024
db2e129
Added gen_substrs support for Noir. This works both in decomposed & r…
ewynx Sep 17, 2024
33736ca
Set gen_substrs to false by default for raw.
ewynx Sep 17, 2024
f7ae186
Per state 1 or more substrings will be extracted, depending on the re…
ewynx Sep 19, 2024
3a853e7
Take transitions into account for extracting substrings.
ewynx Sep 26, 2024
8e6aa14
$ and ^ support
ewynx Sep 30, 2024
9f3acd6
Added the "reset" flow when a shortcut is made from any state to the …
ewynx Oct 1, 2024
4137890
Removed old code
ewynx Oct 1, 2024
cd14d89
Escape newline and carriage return characters in regex patterns
ewynx Oct 1, 2024
01231c2
Noir support edit
ewynx Dec 5, 2024
80df487
add explicit type for table
jp4g Jan 27, 2025
2d11aec
sparse array comptime
jp4g Jan 28, 2025
5965f1c
remove conditional access of s_next_temp for optimized gates
jp4g Jan 28, 2025
6e6a7f0
compiler issue
jp4g Jan 29, 2025
c895c92
poc
jp4g Feb 4, 2025
d717095
kinda works pretty well
jp4g Feb 4, 2025
d5568f6
update path
jp4g Feb 4, 2025
6184139
fix first char
jp4g Feb 4, 2025
8575a95
stash working fix to arr length 1 input
jp4g Feb 4, 2025
20e1c4f
handle length 1 failures
jp4g Feb 5, 2025
2d6d036
compiler fixes to past hc test suite
jp4g Feb 7, 2025
a1af188
upgraded for efficient arrays
jp4g Feb 9, 2025
524636c
optimized checks over substring construction
jp4g Feb 12, 2025
2afd271
passing with stronger constraints
jp4g Feb 12, 2025
cdf62fb
segregate logic and refactor codegen
jp4g Feb 16, 2025
9255c69
cli can optionally force match & generate common or not
jp4g Feb 16, 2025
d53b82e
to_addr_regex workin pretty well bruv
jp4g Feb 18, 2025
39adcf1
update to use match-only regexes where possible
jp4g Feb 18, 2025
b725d3a
from and to addr regex added
jp4g Feb 18, 2025
e9cbe2e
composite functions for perfect extraction of certain regexes
jp4g Feb 18, 2025
cdd6014
e2e zkemail integration fully working
jp4g Feb 18, 2025
2a79db9
add in conditional start to substr index if not first substr
jp4g Mar 3, 2025
20de93b
fix first condition set
jp4g Mar 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 210 additions & 0 deletions .latest_aztec_cli_vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
ACVM_BINARY_PATH
ACVM_WORKING_DIRECTORY
GOVERNANCE_CONTRACT_ADDRESS
API_KEY
API_PREFIX
ARCHIVER_MAX_LOGS
ARCHIVER_POLLING_INTERVAL_MS
ARCHIVER_URL
ARCHIVER_VIEM_POLLING_INTERVAL_MS
ARCHIVER_BATCH_SIZE
ASSUME_PROVEN_THROUGH_BLOCK_NUMBER
AZTEC_NODE_URL
AZTEC_PORT
BB_BINARY_PATH
BB_SKIP_CLEANUP
BB_WORKING_DIRECTORY
BOOTSTRAP_NODES
BLOB_SINK_PORT
BLOB_SINK_URL
BOT_DA_GAS_LIMIT
BOT_FEE_PAYMENT_METHOD
BOT_FLUSH_SETUP_TRANSACTIONS
BOT_FOLLOW_CHAIN
BOT_L2_GAS_LIMIT
BOT_MAX_PENDING_TXS
BOT_NO_START
BOT_NO_WAIT_FOR_TRANSFERS
BOT_PRIVATE_KEY
BOT_PRIVATE_TRANSFERS_PER_TX
BOT_PUBLIC_TRANSFERS_PER_TX
BOT_PXE_URL
BOT_RECIPIENT_ENCRYPTION_SECRET
BOT_SKIP_PUBLIC_SIMULATION
BOT_TOKEN_CONTRACT
BOT_TOKEN_SALT
BOT_TX_INTERVAL_SECONDS
BOT_TX_MINED_WAIT_SECONDS
BOT_MAX_CONSECUTIVE_ERRORS
BOT_STOP_WHEN_UNHEALTHY
COINBASE
DATA_DIRECTORY
DATA_STORE_MAP_SIZE_KB
DEBUG
DEPLOY_AZTEC_CONTRACTS_SALT
DEPLOY_AZTEC_CONTRACTS
ENFORCE_FEES
ETHEREUM_HOST
FEE_JUICE_CONTRACT_ADDRESS
FEE_JUICE_PORTAL_CONTRACT_ADDRESS
FEE_RECIPIENT
GOVERNANCE_PROPOSER_CONTRACT_ADDRESS
GOVERNANCE_PROPOSER_PAYLOAD_ADDRESS
INBOX_CONTRACT_ADDRESS
L1_CHAIN_ID
L1_CONSENSUS_HOST_URL
L1_CONSENSUS_HOST_API_KEY
L1_CONSENSUS_HOST_API_KEY_HEADER
L1_PRIVATE_KEY
L2_QUEUE_SIZE
LOG_ELAPSED_TIME
LOG_JSON
LOG_MULTILINE
LOG_LEVEL
MNEMONIC
NETWORK_NAME
NETWORK
NO_PXE
COIN_ISSUER_CONTRACT_ADDRESS
USE_GCLOUD_OBSERVABILITY
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
OTEL_SERVICE_NAME
OTEL_COLLECT_INTERVAL_MS
OTEL_EXCLUDE_METRICS
OTEL_EXPORT_TIMEOUT_MS
OUTBOX_CONTRACT_ADDRESS
P2P_BLOCK_CHECK_INTERVAL_MS
P2P_BLOCK_REQUEST_BATCH_SIZE
P2P_ENABLED
P2P_GOSSIPSUB_D
P2P_GOSSIPSUB_DHI
P2P_GOSSIPSUB_DLO
P2P_GOSSIPSUB_INTERVAL_MS
P2P_GOSSIPSUB_MCACHE_GOSSIP
P2P_GOSSIPSUB_MCACHE_LENGTH
P2P_GOSSIPSUB_TX_INVALID_MESSAGE_DELIVERIES_DECAY
P2P_GOSSIPSUB_TX_INVALID_MESSAGE_DELIVERIES_WEIGHT
P2P_GOSSIPSUB_TX_TOPIC_WEIGHT
P2P_L2_QUEUE_SIZE
P2P_MAX_PEERS
P2P_MIN_PEERS
P2P_PEER_CHECK_INTERVAL_MS
P2P_PEER_PENALTY_VALUES
P2P_QUERY_FOR_IP
P2P_REQRESP_INDIVIDUAL_REQUEST_TIMEOUT_MS
P2P_REQRESP_OVERALL_REQUEST_TIMEOUT_MS
P2P_SEVERE_PEER_PENALTY_BLOCK_LENGTH
P2P_TCP_LISTEN_ADDR
P2P_TCP_ANNOUNCE_ADDR
P2P_TX_POOL_KEEP_PROVEN_FOR
P2P_ATTESTATION_POOL_KEEP_FOR
P2P_TX_PROTOCOL
P2P_UDP_ANNOUNCE_ADDR
P2P_UDP_LISTEN_ADDR
P2P_ARCHIVED_TX_LIMIT
PEER_ID_PRIVATE_KEY
PROOF_VERIFIER_L1_START_BLOCK
PROOF_VERIFIER_POLL_INTERVAL_MS
PROVER_AGENT_ENABLED
PROVER_AGENT_CONCURRENCY
PROVER_AGENT_COUNT
PROVER_AGENT_PROOF_TYPES
PROVER_AGENT_POLL_INTERVAL_MS
PROVER_BROKER_HOST
PROVER_BROKER_ENABLED
PROVER_BROKER_JOB_TIMEOUT_MS
PROVER_BROKER_POLL_INTERVAL_MS
PROVER_BROKER_JOB_MAX_RETRIES
PROVER_COORDINATION_NODE_URL
PROVER_DISABLED
PROVER_FAILED_PROOF_STORE
PROVER_ID
PROVER_JOB_POLL_INTERVAL_MS
PROVER_JOB_TIMEOUT_MS
PROVER_NODE_POLLING_INTERVAL_MS
PROVER_NODE_MAX_PENDING_JOBS
PROVER_NODE_MAX_PARALLEL_BLOCKS_PER_EPOCH
PROVER_NODE_TX_GATHERING_TIMEOUT_MS
PROVER_NODE_TX_GATHERING_INTERVAL_MS
PROVER_NODE_TX_GATHERING_MAX_PARALLEL_REQUESTS
PROVER_PUBLISH_RETRY_INTERVAL_MS
PROVER_PUBLISHER_PRIVATE_KEY
PROVER_REAL_PROOFS
PROVER_REQUIRED_CONFIRMATIONS
PROVER_TEST_DELAY_MS
PXE_L2_STARTING_BLOCK
PXE_PROVER_ENABLED
QUOTE_PROVIDER_BASIS_POINT_FEE
QUOTE_PROVIDER_BOND_AMOUNT
QUOTE_PROVIDER_URL
PROVER_TARGET_ESCROW_AMOUNT
PROVER_MINIMUM_ESCROW_AMOUNT
REGISTRY_CONTRACT_ADDRESS
ROLLUP_CONTRACT_ADDRESS
SEQ_ALLOWED_SETUP_FN
SEQ_MAX_BLOCK_SIZE_IN_BYTES
SEQ_MAX_TX_PER_BLOCK
SEQ_MIN_TX_PER_BLOCK
SEQ_MAX_DA_BLOCK_GAS
SEQ_MAX_L2_BLOCK_GAS
SEQ_PUBLISH_RETRY_INTERVAL_MS
SEQ_PUBLISHER_PRIVATE_KEY
SEQ_REQUIRED_CONFIRMATIONS
SEQ_TX_POLLING_INTERVAL_MS
SEQ_ENFORCE_TIME_TABLE
SEQ_MAX_L1_TX_INCLUSION_TIME_INTO_SLOT
SLASH_FACTORY_CONTRACT_ADDRESS
STAKING_ASSET_CONTRACT_ADDRESS
REWARD_DISTRIBUTOR_CONTRACT_ADDRESS
TELEMETRY
TEST_ACCOUNTS
TX_GOSSIP_VERSION
TXE_PORT
VALIDATOR_ATTESTATIONS_POLLING_INTERVAL_MS
VALIDATOR_DISABLED
VALIDATOR_PRIVATE_KEY
VALIDATOR_REEXECUTE
VERSION
WS_BLOCK_CHECK_INTERVAL_MS
WS_PROVEN_BLOCKS_ONLY
WS_BLOCK_REQUEST_BATCH_SIZE
VERIFIER_VIEM_POLLING_INTERVAL_MS
L1_READER_VIEM_POLLING_INTERVAL_MS
PROVER_VIEM_POLLING_INTERVAL_MS
SEQ_VIEM_POLLING_INTERVAL_MS
WS_DB_MAP_SIZE_KB
WS_DATA_DIRECTORY
WS_NUM_HISTORIC_BLOCKS
ETHEREUM_SLOT_DURATION
AZTEC_SLOT_DURATION
AZTEC_EPOCH_DURATION
AZTEC_TARGET_COMMITTEE_SIZE
AZTEC_EPOCH_PROOF_CLAIM_WINDOW_IN_L2_SLOTS
AZTEC_MINIMUM_STAKE
AZTEC_SLASHING_QUORUM
AZTEC_SLASHING_ROUND_SIZE
AZTEC_GOVERNANCE_PROPOSER_QUORUM
AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE
L1_GAS_LIMIT_BUFFER_PERCENTAGE
L1_GAS_LIMIT_BUFFER_FIXED
L1_GAS_PRICE_MIN
L1_GAS_PRICE_MAX
L1_BLOB_FEE_PER_GAS_MAX
L1_PRIORITY_FEE_BUMP_PERCENTAGE
L1_PRIORITY_FEE_RETRY_BUMP_PERCENTAGE
L1_FIXED_PRIORITY_FEE_PER_GAS
L1_TX_MONITOR_MAX_ATTEMPTS
L1_TX_MONITOR_CHECK_INTERVAL_MS
L1_TX_MONITOR_STALL_TIME_MS
L1_TX_MONITOR_TX_TIMEOUT_MS
L1_TX_PROPAGATION_MAX_QUERY_ATTEMPTS
FAUCET_MNEMONIC_ACCOUNT_INDEX
FAUCET_ETH_AMOUNT
FAUCET_INTERVAL_MS
FAUCET_L1_ASSETS
K8S_POD_NAME
K8S_POD_UID
K8S_NAMESPACE_NAME
CUSTOM_FORWARDER_CONTRACT_ADDRESS
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["packages/*"]
exclude = ["packages/circom", "test"]
exclude = ["packages/circom", "test", "packages/noir"]

# [patch."https://github.com/stalwartlabs/mail-builder"]
# mail-builder = { version = "0.2.5", git = "https://github.com/stalwartlabs//mail-builder", tag = "0.2.5" }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# zk-regex

A library to compile regex verification in circom. Explained on [our blog post](https://prove.email/blog/zkregex). You can use regex to specify how to parse an email in a ZK Email proof when defining a new patterm on [the ZK Email SDK registry](https://sdk.prove.email/). Noir coming soon.
A library to compile regex verification in circom. Explained on [our blog post](https://prove.email/blog/zkregex). You can use regex to specify how to parse an email in a ZK Email proof when defining a new patterm on [the ZK Email SDK registry](https://sdk.prove.email/). Noir support is also available.

<!-- We've forked [min-dfa into a UI here](https://mindfa.onrender.com/min_dfa) to create a UI that converts existing regexes with [] support, as well as escapes \_, and the character classes a-z, A-Z, and 0-9. It also shows the DFA states very clearly so you can choose accept states easily. This should make converting regexes into DFA form way cleaner. -->

Expand Down
2 changes: 1 addition & 1 deletion packages/circom/tests/simple_regex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("Simple Regex", () => {
for (let idx = 0; idx < 64; ++idx) {
if (revealedIdx[substr_idx].includes(idx)) {
expect(BigInt(paddedStr[idx])).toEqual(
witness[2 + 64 * substr_idx + idx]
witness[2 + 64 * substr_idx + idx]
);
} else {
expect(0n).toEqual(witness[2 + 64 * substr_idx + idx]);
Expand Down
2 changes: 2 additions & 0 deletions packages/compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ regex = "=1.10.6"
getrandom = { version = "0.2", features = ["js"] }
wasm-bindgen = "0.2"
serde-wasm-bindgen = "0.6.5"
comptime = { git = "https://github.com/jp4g/sparse_array", branch = "feat/comptime-codegen" }
# comptime = { path = "../../../../aztec/sparse_array/comptime" }
36 changes: 34 additions & 2 deletions packages/compiler/src/bin/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,44 @@ enum Commands {
Decomposed {
#[arg(short, long)]
decomposed_regex_path: String,
#[arg(short, long)]
#[arg(long)]
halo2_dir_path: Option<String>,
#[arg(short, long)]
circom_file_path: Option<String>,
#[arg(short, long)]
template_name: Option<String>,
#[arg(long)]
noir_file_path: Option<String>,
#[arg(short, long)]
gen_substrs: Option<bool>,
#[arg(short, long)]
sparse_array: Option<bool>,
#[arg(short, long)]
force_match: Option<bool>,
#[arg(short, long)]
use_common: Option<String>,
},
Raw {
#[arg(short, long)]
raw_regex: String,
#[arg(short, long)]
substrs_json_path: Option<String>,
#[arg(short, long)]
#[arg(long)]
halo2_dir_path: Option<String>,
#[arg(short, long)]
circom_file_path: Option<String>,
#[arg(short, long)]
template_name: Option<String>,
#[arg(long)]
noir_file_path: Option<String>,
#[arg(short, long)]
gen_substrs: Option<bool>,
#[arg(short, long)]
sparse_array: Option<bool>,
#[arg(short, long)]
force_match: Option<bool>,
#[arg(short, long)]
use_common: Option<String>,
},
}

Expand All @@ -99,15 +115,23 @@ fn process_decomposed(cli: Cli) {
halo2_dir_path,
circom_file_path,
template_name,
noir_file_path,
gen_substrs,
sparse_array,
force_match,
use_common,
} = cli.command
{
if let Err(e) = gen_from_decomposed(
&decomposed_regex_path,
halo2_dir_path.as_deref(),
circom_file_path.as_deref(),
template_name.as_deref(),
noir_file_path.as_deref(),
gen_substrs,
sparse_array,
force_match,
use_common.as_deref(),
) {
eprintln!("Error: {}", e);
std::process::exit(1);
Expand All @@ -122,7 +146,11 @@ fn process_raw(cli: Cli) {
halo2_dir_path,
circom_file_path,
template_name,
noir_file_path,
gen_substrs,
sparse_array,
force_match,
use_common,
} = cli.command
{
if let Err(e) = gen_from_raw(
Expand All @@ -131,7 +159,11 @@ fn process_raw(cli: Cli) {
halo2_dir_path.as_deref(),
circom_file_path.as_deref(),
template_name.as_deref(),
noir_file_path.as_deref(),
gen_substrs,
sparse_array,
force_match,
use_common.as_deref(),
) {
eprintln!("Error: {}", e);
std::process::exit(1);
Expand Down
Loading