From d8658e5a8bd9a6fc69b412cade1e3eb12309375b Mon Sep 17 00:00:00 2001 From: Gautam Kumar <129857715+whoisgautxm@users.noreply.github.com> Date: Thu, 15 Aug 2024 02:27:19 +0530 Subject: [PATCH 1/4] Readme updated: Non-Linear Constraints in the email-wallet circuits --- README.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 71f43a7c..1a4c29a7 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,30 @@ This is a simplified flow, but underneath we use many parameters to ensure secur ## ☞ Directory structure This is a mono-repo that contains the circom circuits, smart contracts, the relayer and a prover server. +### Circuits and Constraints: +- **Main Circuits:** + - `Announcement.circom`: 459 constraints + - `Claim.circom`: 921 constraints + - `Email_sender.circom`: 1,895,054 constraints + - `Account_creation.circom`: 2,102,567 constraints + +- **Utils:** + - `Account_salt.circom`: 258 constraints + - `Bytes2ints.circom`: 0 constraints + - `Digit2int.circom`: 0 constraints + - `Email_addr_commit.circom`: 465 constraints + - `Email_nullifier.circom`: 213 constraints + - `Hash_sign.circom`: 213 constraints + - `Hext2int.circom`: 80 constraints + +- **Regex:** + - `Invitation_code_regex.circom`: 97 constraints + - `Invitation_code_with_prefix_regex.circom`: 105 constraints + +**Total Constraints Across All Circuits:** **3,999,432** + +
+ - `packages/circuits` contains the circom circuits, tests, scripts to generate zkeys, vkeys, and helper functions to generate circuit inputs. - `packages/contracts` contains the solidity contracts, tests, and scripts to deploy the wallet. - `packages/relayer` contains the relayer code - relayer listens to IMAP server, generate proof using prover server, and call the contract. @@ -124,13 +148,15 @@ saved here. ├ ├── /subgraph # indexing and querying events generated by circuits. - ``` +
## ☞ Building and Running +The total number of constraints across all circuits is **3,999,432**. + - Refer to the [circuit docs](./packages/circuits/README.md) for more details on building and testing circuits. - Refer to the [contract docs](./packages/contracts/README.md) for more details on building and testing contracts. - Refer to the [relayer docs](./packages/relayer/README.md) for more details on building and running relayer. @@ -148,7 +174,6 @@ And to serve the website: mdbook serve ``` - ## References 1. S. Suegami and K. Shibano, "Contract Wallet Using Emails," 2023 IEEE International Conference on Blockchain and Cryptocurrency (ICBC), Dubai, United Arab Emirates, 2023, pp. 1-2, doi: 10.1109/ICBC56567.2023.10174932. @@ -156,4 +181,4 @@ mdbook serve

-☆ Built using [zk-email](https://github.com/zkemail/zk-email-verify) ☆ +☆ Built using [zk-email](https://github.com/zkemail/zk-email-verify) ☆ \ No newline at end of file From 3fe1dd04cf42916acb37ea8ee5f42a795701e77f Mon Sep 17 00:00:00 2001 From: Gautam Kumar <129857715+whoisgautxm@users.noreply.github.com> Date: Thu, 15 Aug 2024 02:36:51 +0530 Subject: [PATCH 2/4] Minor fixes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a4c29a7..c6acb51a 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,8 @@ This is a simplified flow, but underneath we use many parameters to ensure secur This is a mono-repo that contains the circom circuits, smart contracts, the relayer and a prover server. ### Circuits and Constraints: +*Total Constraints Across All Circuits*: **3,999,432** + - **Main Circuits:** - `Announcement.circom`: 459 constraints - `Claim.circom`: 921 constraints @@ -105,8 +107,6 @@ This is a mono-repo that contains the circom circuits, smart contracts, the rela - `Invitation_code_regex.circom`: 97 constraints - `Invitation_code_with_prefix_regex.circom`: 105 constraints -**Total Constraints Across All Circuits:** **3,999,432** -
- `packages/circuits` contains the circom circuits, tests, scripts to generate zkeys, vkeys, and helper functions to generate circuit inputs. From 4c6bc88f25ac3e535c1039590d72722174d51c9c Mon Sep 17 00:00:00 2001 From: Gautam Kumar <129857715+whoisgautxm@users.noreply.github.com> Date: Mon, 19 Aug 2024 02:33:59 +0530 Subject: [PATCH 3/4] Constraint breakdown of email_sender.circom --- README.md | 12 ------------ packages/circuits/README.md | 10 ++++++++++ packages/circuits/src/email_sender.circom | 13 ++++++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c6acb51a..0b83bf59 100644 --- a/README.md +++ b/README.md @@ -94,18 +94,6 @@ This is a mono-repo that contains the circom circuits, smart contracts, the rela - `Email_sender.circom`: 1,895,054 constraints - `Account_creation.circom`: 2,102,567 constraints -- **Utils:** - - `Account_salt.circom`: 258 constraints - - `Bytes2ints.circom`: 0 constraints - - `Digit2int.circom`: 0 constraints - - `Email_addr_commit.circom`: 465 constraints - - `Email_nullifier.circom`: 213 constraints - - `Hash_sign.circom`: 213 constraints - - `Hext2int.circom`: 80 constraints - -- **Regex:** - - `Invitation_code_regex.circom`: 97 constraints - - `Invitation_code_with_prefix_regex.circom`: 105 constraints
diff --git a/packages/circuits/README.md b/packages/circuits/README.md index 2b9ccbe3..561f98a2 100644 --- a/packages/circuits/README.md +++ b/packages/circuits/README.md @@ -104,6 +104,16 @@ Its instances are as follows: 7. a flag whether the subject contains the recipient's email address `has_email_recipient` (0 or 1). 8. the recipient's email address commitment `recipient_email_addr_commit`. 9. a timestamp in the email header `timestamp`. + +Constraint breakdown of the circuit is as follows: +1. this file is a standard template designed for email verification `email-verifier.circom : 669650 constraints` . +2. this circuit is designed to validate and extract email addresses from a given message `from_addr_regex.circom : 643296 constraints`. +3. this circuit is designed to verify if a given input message conforms to a specific regex pattern that checks for email subjects `subject_all_regex.circom : 99208 constraints`. +4. this circuit is designed to validate email addresses based on a specified regular expression. It checks if the input string (representing an email address) conforms to the defined pattern `email_addr_regex.circom : 92037 constraints`. +5. this circuit is designed to validate an invitation code that may have a prefix. It uses a regular expression to check if the input message conforms to a specific pattern, which includes optional spaces and the word "code" followed by a hexadecimal string `invitation_code_with_prefix_regex.circom : 43494 constraints`. +6. `email_domain_regex.circom : 38219 constraints`. +7. this circuit is designed to validate a specific format of a DKIM (DomainKeys Identified Mail) signature within a given message`timestamp_regex.circom : 233872 constraints`. + #### `announcement.circom` A circuit to verify that the given email address commitment is derived from the given email address and randomness. While it is not used in our core contracts, it is provided for third-party contracts to register unclaimed funds/states for the public email address and the randomness. diff --git a/packages/circuits/src/email_sender.circom b/packages/circuits/src/email_sender.circom index 502c0f71..d5c57c75 100644 --- a/packages/circuits/src/email_sender.circom +++ b/packages/circuits/src/email_sender.circom @@ -57,7 +57,7 @@ template EmailSender(n, k, max_header_bytes, max_subject_bytes) { signal output has_email_recipient; signal output recipient_email_addr_commit; - // Verify Email Signature + // VERIFY EMAIL SIGNATURE : 669650 constraints component email_verifier = EmailVerifier(max_header_bytes, 0, n, k, 1); email_verifier.in_padded <== in_padded; email_verifier.pubkey <== pubkey; @@ -66,19 +66,21 @@ template EmailSender(n, k, max_header_bytes, max_subject_bytes) { signal header_hash[256] <== email_verifier.sha; pubkey_hash <== email_verifier.pubkey_hash; - // FROM HEADER REGEX + // FROM HEADER REGEX : 643296 constraints signal from_regex_out, from_regex_reveal[max_header_bytes]; (from_regex_out, from_regex_reveal) <== FromAddrRegex(max_header_bytes)(in_padded); from_regex_out === 1; signal sender_email_addr[email_max_bytes]; sender_email_addr <== VarShiftMaskedStr(max_header_bytes, email_max_bytes)(from_regex_reveal, sender_email_idx); - // SUBJECT HEADER REGEX + // SUBJECT HEADER REGEX : 99208 constraints signal subject_regex_out, subject_regex_reveal[max_header_bytes]; (subject_regex_out, subject_regex_reveal) <== SubjectAllRegex(max_header_bytes)(in_padded); subject_regex_out === 1; signal subject_all[max_subject_bytes]; subject_all <== VarShiftMaskedStr(max_header_bytes, max_subject_bytes)(subject_regex_reveal, subject_idx); + + // EMAIL ADDRESS REGEX : 92037 constraints signal recipient_email_regex_out, recipient_email_regex_reveal[max_subject_bytes]; (recipient_email_regex_out, recipient_email_regex_reveal) <== EmailAddrRegex(max_subject_bytes)(subject_all); has_email_recipient <== IsZero()(recipient_email_regex_out-1); @@ -97,6 +99,7 @@ template EmailSender(n, k, max_header_bytes, max_subject_bytes) { recipient_email_addr[i] <== shifted_email_addr[i] * has_email_recipient; } + // INVITATION CODE REGEX WITH PREFIX : 43494 constraints signal code_regex_out, code_regex_reveal[max_subject_bytes]; (code_regex_out, code_regex_reveal) <== InvitationCodeWithPrefixRegex(max_subject_bytes)(subject_all); signal has_code <== IsZero()(code_regex_out-1); @@ -113,7 +116,7 @@ template EmailSender(n, k, max_header_bytes, max_subject_bytes) { } masked_subject_str <== Bytes2Ints(max_subject_bytes)(masked_subject_bytes); - // DOMAIN NAME HEADER REGEX + // DOMAIN NAME HEADER REGEX : 38219 constraints signal domain_regex_out, domain_regex_reveal[email_max_bytes]; (domain_regex_out, domain_regex_reveal) <== EmailDomainRegex(email_max_bytes)(sender_email_addr); domain_regex_out === 1; @@ -129,7 +132,7 @@ template EmailSender(n, k, max_header_bytes, max_subject_bytes) { email_nullifier <== EmailNullifier()(sign_hash); - // Timestamp regex + convert to decimal format + // Timestamp regex + convert to decimal format : 233872 constraints signal timestamp_regex_out, timestamp_regex_reveal[max_header_bytes]; (timestamp_regex_out, timestamp_regex_reveal) <== TimestampRegex(max_header_bytes)(in_padded); // timestamp_regex_out === 1; From 52e22dd2dc04e70d593a01d8b8ed91266eae4759 Mon Sep 17 00:00:00 2001 From: Gautam Kumar <129857715+whoisgautxm@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:18:14 +0530 Subject: [PATCH 4/4] Removed constraint breakdown from the Readme.md --- README.md | 6 ------ packages/circuits/README.md | 10 ---------- 2 files changed, 16 deletions(-) diff --git a/README.md b/README.md index 0b83bf59..12ceddfc 100644 --- a/README.md +++ b/README.md @@ -88,12 +88,6 @@ This is a mono-repo that contains the circom circuits, smart contracts, the rela ### Circuits and Constraints: *Total Constraints Across All Circuits*: **3,999,432** -- **Main Circuits:** - - `Announcement.circom`: 459 constraints - - `Claim.circom`: 921 constraints - - `Email_sender.circom`: 1,895,054 constraints - - `Account_creation.circom`: 2,102,567 constraints -
diff --git a/packages/circuits/README.md b/packages/circuits/README.md index 561f98a2..2b9ccbe3 100644 --- a/packages/circuits/README.md +++ b/packages/circuits/README.md @@ -104,16 +104,6 @@ Its instances are as follows: 7. a flag whether the subject contains the recipient's email address `has_email_recipient` (0 or 1). 8. the recipient's email address commitment `recipient_email_addr_commit`. 9. a timestamp in the email header `timestamp`. - -Constraint breakdown of the circuit is as follows: -1. this file is a standard template designed for email verification `email-verifier.circom : 669650 constraints` . -2. this circuit is designed to validate and extract email addresses from a given message `from_addr_regex.circom : 643296 constraints`. -3. this circuit is designed to verify if a given input message conforms to a specific regex pattern that checks for email subjects `subject_all_regex.circom : 99208 constraints`. -4. this circuit is designed to validate email addresses based on a specified regular expression. It checks if the input string (representing an email address) conforms to the defined pattern `email_addr_regex.circom : 92037 constraints`. -5. this circuit is designed to validate an invitation code that may have a prefix. It uses a regular expression to check if the input message conforms to a specific pattern, which includes optional spaces and the word "code" followed by a hexadecimal string `invitation_code_with_prefix_regex.circom : 43494 constraints`. -6. `email_domain_regex.circom : 38219 constraints`. -7. this circuit is designed to validate a specific format of a DKIM (DomainKeys Identified Mail) signature within a given message`timestamp_regex.circom : 233872 constraints`. - #### `announcement.circom` A circuit to verify that the given email address commitment is derived from the given email address and randomness. While it is not used in our core contracts, it is provided for third-party contracts to register unclaimed funds/states for the public email address and the randomness.