From 5c03019c9d09e66a49087977232a78400863e947 Mon Sep 17 00:00:00 2001 From: Metachaser24 Date: Mon, 18 Mar 2024 11:40:24 +0300 Subject: [PATCH 01/12] removed emailtest.circom --- packages/circuits/emailtest.circom | 128 ----------------------------- packages/circuits/package.json | 2 +- 2 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 packages/circuits/emailtest.circom diff --git a/packages/circuits/emailtest.circom b/packages/circuits/emailtest.circom deleted file mode 100644 index f369daf44..000000000 --- a/packages/circuits/emailtest.circom +++ /dev/null @@ -1,128 +0,0 @@ - -pragma circom 2.1.5; - -include "circomlib/circuits/bitify.circom"; -include "circomlib/circuits/comparators.circom"; -include "circomlib/circuits/poseidon.circom"; -include "@zk-email/circuits/email-verifier.circom"; -include "@zk-email/circuits/helpers/extract.circom"; -include "@zk-email/circuits/utils/constants.circom"; -include "@zk-email/circuits/utils/email_addr_pointer.circom"; -include "@zk-email/circuits/utils/email_addr_commit.circom"; -include "@zk-email/circuits/utils/hash_sign.circom"; -include "@zk-email/circuits/utils/email_nullifier.circom"; -include "./utils/bytes2ints.circom"; -include "./utils/digit2int.circom"; -include "@zk-email/zk-regex-circom/circuits/common/from_addr_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/email_addr_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/email_domain_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/subject_all_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/timestamp_regex.circom"; - -// Verify email from user (sender) and extract subject, timestmap, recipient email (commitment), etc. -// * n - the number of bits in each chunk of the RSA public key (modulust) -// * k - the number of chunks in the RSA public key (n * k > 2048) -// * max_header_bytes - max number of bytes in the email header -// * max_subject_bytes - max number of bytes in the email subject -template EmailSender(n, k, max_header_bytes, max_subject_bytes) { - signal input in_padded[max_header_bytes]; // email data (only header part) - signal input pubkey[k]; // RSA pubkey (modulus), k parts of n bits each. - signal input signature[k]; // RSA signature, k parts of n bits each. - signal input in_padded_len; // length of in email data including the padding - signal input sender_email_idx; // Index of the from email address (= sender email address) in the email header - signal input subject_idx; // Index of the subject in the header - signal input domain_idx; // Index of the domain name in the from email address - signal input timestamp_idx; // Index of the timestamp in the header - - var email_max_bytes = email_max_bytes_const(); - var email_max_len = compute_ints_size(email_max_bytes); - - var subject_field_len = compute_ints_size(max_subject_bytes); - - var domain_len = domain_len_const(); - var domain_filed_len = compute_ints_size(domain_len); - - var k2_chunked_size = k >> 1; - if(k % 2 == 1) { - k2_chunked_size += 1; - } - var timestamp_len = timestamp_len_const(); - - signal output masked_subject_str[subject_field_len]; - signal output domain_name[domain_filed_len]; - signal output hfrom[email_max_len]; - signal output hsubject[subject_field_len]; - signal output pubkey_hash; - signal output email_nullifier; - signal output sender_pointer; - signal output timestamp; - - // Verify Email Signature - component email_verifier = EmailVerifier(max_header_bytes, 0, n, k, 1); - email_verifier.in_padded <== in_padded; - email_verifier.pubkey <== pubkey; - email_verifier.signature <== signature; - email_verifier.in_len_padded_bytes <== in_padded_len; - signal header_hash[256] <== email_verifier.sha; - pubkey_hash <== email_verifier.pubkey_hash; - - // FROM HEADER REGEX - 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); - hfrom <== Bytes2Ints(email_max_bytes)(sender_email_addr); - - // SUBJECT HEADER REGEX - 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); - hsubject <== Bytes2Ints(max_subject_bytes)(subject_all); - - // DOMAIN NAME HEADER REGEX - 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; - signal domain_name_bytes[domain_len]; - domain_name_bytes <== VarShiftMaskedStr(email_max_bytes, domain_len)(domain_regex_reveal, domain_idx); - domain_name <== Bytes2Ints(domain_len)(domain_name_bytes); - - - // Email address pointer - /* - var num_email_addr_ints = compute_ints_size(email_max_bytes); - signal sender_email_addr_ints[num_email_addr_ints] <== Bytes2Ints(email_max_bytes)(sender_email_addr); - sender_pointer <== EmailAddrPointer(num_email_addr_ints)(sender_relayer_rand, sender_email_addr_ints); -*/ - - // Email address commitment - /*signal cm_rand_input[k2_chunked_size+1]; - for(var i=0; i Date: Wed, 20 Mar 2024 08:53:54 +0300 Subject: [PATCH 02/12] Added GCP download patu link --- docs/zkEmailDocs/UsageGuide/README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/zkEmailDocs/UsageGuide/README.md b/docs/zkEmailDocs/UsageGuide/README.md index 84557aaeb..e1100e2c6 100644 --- a/docs/zkEmailDocs/UsageGuide/README.md +++ b/docs/zkEmailDocs/UsageGuide/README.md @@ -108,10 +108,12 @@ To compile the circuit locally, you need to have Rust and Circom installed first ```bash circom MyCircuit.circom -o --r1cs --wasm --sym --c ``` -*Note: You can add -l to specify the directory where the directive `include` should look for the circuits indicated. For our repo use circom -l node_modules instead of circom. +*Note: You can add `-l` to specify the directory where the directive `include` should look for the circuits indicated. For our repo, use `circom -l node_modules` instead of `circom`. Additionally, we generally recommend using the `--O0` flag for optimization during compilation for beginners. However, if you're more experienced with Circom, feel free to use the `--O1` flag instead. It's important to avoid using the `--O2` flag as that is the default setting and it may lead to the deletion of additional constraints.* After running this command, the circuit will be compiled into a `.r1cs` file, a `.wasm` file, and a `.sym` file. These files are used in the next steps to generate the proving and verifying keys, and to compute the witness. + + ## Step 5: Compute the Witness The process of creating a proof involves ensuring that all signals in the file adhere to the existing constraints. This is achieved by computing the witness using the Wasm file generated during compilation. @@ -143,15 +145,11 @@ node --max-old-space-size=614400 ./../node_modules/.bin/snarkjs ### Powers of Tau -After obtaining the constraint size, find the next highest power of 2 and replace the '12' in the following command with that number. This command initiates the Powers of tau ceremony. -``` -snarkjs powersoftau new bn128 12 pot12_0000.ptau -v -``` +You can download the ptau file directly from Google Cloud Platform using the following command: -Then contribute to the ceremony by running: -```bash -snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" -v +``` +wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_22.ptau ``` ### Phase 2 From 217d7f965b08953eb4ac4d0fafce3c84b4bc2b50 Mon Sep 17 00:00:00 2001 From: Metachaser24 Date: Thu, 21 Mar 2024 11:57:12 +0300 Subject: [PATCH 03/12] Moved Utils to helper folder, and utils to docs --- packages/circuits/README.md | 21 +++++++++- .../{ => helpers}/utils/bytes2ints.circom | 0 .../{ => helpers}/utils/constants.circom | 0 .../{ => helpers}/utils/digit2int.circom | 0 .../{ => helpers}/utils/hex2int.circom | 0 .../circuits/helpers/{ => utils}/utils.circom | 0 .../circuits/utils/email_addr_commit.circom | 18 --------- .../circuits/utils/email_addr_pointer.circom | 18 --------- .../circuits/utils/email_nullifier.circom | 24 ------------ packages/circuits/utils/hash_sign.circom | 38 ------------------- 10 files changed, 20 insertions(+), 99 deletions(-) rename packages/circuits/{ => helpers}/utils/bytes2ints.circom (100%) rename packages/circuits/{ => helpers}/utils/constants.circom (100%) rename packages/circuits/{ => helpers}/utils/digit2int.circom (100%) rename packages/circuits/{ => helpers}/utils/hex2int.circom (100%) rename packages/circuits/helpers/{ => utils}/utils.circom (100%) delete mode 100644 packages/circuits/utils/email_addr_commit.circom delete mode 100644 packages/circuits/utils/email_addr_pointer.circom delete mode 100644 packages/circuits/utils/email_nullifier.circom delete mode 100644 packages/circuits/utils/hash_sign.circom diff --git a/packages/circuits/README.md b/packages/circuits/README.md index 673855501..1998bca0e 100644 --- a/packages/circuits/README.md +++ b/packages/circuits/README.md @@ -43,9 +43,28 @@ This template provides a partial implementation of the SHA-256 cryptographic has This template provides functionality for performing arithmetic operations in finite fields, fundamental for many cryptographic protocols. +## Utility templates + +### bytes2ints.circom + +This template converts an array of bytes into an array of integers. It is designed to handle inputs of any byte size and outputs integers based on the number of bytes specified. This is particularly useful for processing large binary data within arithmetic circuits. + +### constants.circom + +This file defines a set of constants used across various templates within the `circuits` package. These constants include maximum sizes for emails, domains, invitation codes, and timestamps, as well as specifications for packing bytes into field elements. + +### digit2int.circom + +The `Digit2Int` template converts an array of digit characters (0-9) into their corresponding integer representation. This is useful for processing numeric data that is input as a sequence of characters. + +### hex2int.circom + +This template provides functionality for converting hexadecimal strings into their integer representation. It supports conversion of both lowercase (a-f) and uppercase (A-F) hexadecimal characters. This is essential for processing hexadecimal data within arithmetic circuits. + ### utils.circom -This template includes a collection of utility functions used across multiple circuits, such as bit manipulation functions, comparison functions, or conversion functions. +The `utils.circom` file includes a collection of utility templates and functions that are used across multiple circuits. These utilities cover a wide range of functionalities, including bit manipulation, comparison, conversion, and arithmetic operations in finite fields. It serves as a foundational component for building complex arithmetic circuits. + ## Overview of email-verifier.circom diff --git a/packages/circuits/utils/bytes2ints.circom b/packages/circuits/helpers/utils/bytes2ints.circom similarity index 100% rename from packages/circuits/utils/bytes2ints.circom rename to packages/circuits/helpers/utils/bytes2ints.circom diff --git a/packages/circuits/utils/constants.circom b/packages/circuits/helpers/utils/constants.circom similarity index 100% rename from packages/circuits/utils/constants.circom rename to packages/circuits/helpers/utils/constants.circom diff --git a/packages/circuits/utils/digit2int.circom b/packages/circuits/helpers/utils/digit2int.circom similarity index 100% rename from packages/circuits/utils/digit2int.circom rename to packages/circuits/helpers/utils/digit2int.circom diff --git a/packages/circuits/utils/hex2int.circom b/packages/circuits/helpers/utils/hex2int.circom similarity index 100% rename from packages/circuits/utils/hex2int.circom rename to packages/circuits/helpers/utils/hex2int.circom diff --git a/packages/circuits/helpers/utils.circom b/packages/circuits/helpers/utils/utils.circom similarity index 100% rename from packages/circuits/helpers/utils.circom rename to packages/circuits/helpers/utils/utils.circom diff --git a/packages/circuits/utils/email_addr_commit.circom b/packages/circuits/utils/email_addr_commit.circom deleted file mode 100644 index 98a2a54d7..000000000 --- a/packages/circuits/utils/email_addr_commit.circom +++ /dev/null @@ -1,18 +0,0 @@ - -pragma circom 2.1.5; - -include "circomlib/circuits/poseidon.circom"; - -// email_addr_commit = hash(rand, emailAddr||0..0) -template EmailAddrCommit(num_ints) { - signal input rand; - signal input email_addr_ints[num_ints]; - signal output commit; - - component poseidon = Poseidon(1+num_ints); - poseidon.inputs[0] <== rand; - for(var i=0; i> 1; - if(k % 2 == 1) { - k2_chunked_size += 1; - } - signal output sign_ints[k2_chunked_size]; - - // signal pubkey_hash_input[k2_chunked_size]; - // for(var i = 0; i < k2_chunked_size; i++) { - // if(i==k2_chunked_size-1 && k2_chunked_size % 2 == 1) { - // pubkey_hash_input[i] <== pubkey[2*i]; - // } else { - // pubkey_hash_input[i] <== pubkey[2*i] + (1< Date: Thu, 21 Mar 2024 12:01:17 +0300 Subject: [PATCH 04/12] Moved utils file back to circuits folder --- packages/circuits/README.md | 7 ++++--- packages/circuits/{helpers/utils => }/utils.circom | 0 2 files changed, 4 insertions(+), 3 deletions(-) rename packages/circuits/{helpers/utils => }/utils.circom (100%) diff --git a/packages/circuits/README.md b/packages/circuits/README.md index 1998bca0e..17c8a788e 100644 --- a/packages/circuits/README.md +++ b/packages/circuits/README.md @@ -43,6 +43,10 @@ This template provides a partial implementation of the SHA-256 cryptographic has This template provides functionality for performing arithmetic operations in finite fields, fundamental for many cryptographic protocols. +### utils.circom + +The `utils.circom` file includes a collection of utility templates and functions that are used across multiple circuits. These utilities cover a wide range of functionalities, including bit manipulation, comparison, conversion, and arithmetic operations in finite fields. It serves as a foundational component for building complex arithmetic circuits. + ## Utility templates ### bytes2ints.circom @@ -61,9 +65,6 @@ The `Digit2Int` template converts an array of digit characters (0-9) into their This template provides functionality for converting hexadecimal strings into their integer representation. It supports conversion of both lowercase (a-f) and uppercase (A-F) hexadecimal characters. This is essential for processing hexadecimal data within arithmetic circuits. -### utils.circom - -The `utils.circom` file includes a collection of utility templates and functions that are used across multiple circuits. These utilities cover a wide range of functionalities, including bit manipulation, comparison, conversion, and arithmetic operations in finite fields. It serves as a foundational component for building complex arithmetic circuits. ## Overview of email-verifier.circom diff --git a/packages/circuits/helpers/utils/utils.circom b/packages/circuits/utils.circom similarity index 100% rename from packages/circuits/helpers/utils/utils.circom rename to packages/circuits/utils.circom From c6687b86ecf2f771c15bb50411dc3ac10afa0e61 Mon Sep 17 00:00:00 2001 From: Metachaser24 Date: Thu, 21 Mar 2024 12:11:43 +0300 Subject: [PATCH 05/12] added ptau, mv utils to helpers, utils docs --- docs/zkEmailDocs/UsageGuide/README.md | 10 +- packages/circuits/README.md | 23 +++- packages/circuits/emailtest.circom | 128 ------------------ .../{ => helpers}/utils/bytes2ints.circom | 0 .../{ => helpers}/utils/constants.circom | 0 .../{ => helpers}/utils/digit2int.circom | 0 .../{ => helpers}/utils/hex2int.circom | 0 .../circuits/utils/email_addr_commit.circom | 18 --- .../circuits/utils/email_addr_pointer.circom | 18 --- .../circuits/utils/email_nullifier.circom | 24 ---- packages/circuits/utils/hash_sign.circom | 38 ------ 11 files changed, 25 insertions(+), 234 deletions(-) delete mode 100644 packages/circuits/emailtest.circom rename packages/circuits/{ => helpers}/utils/bytes2ints.circom (100%) rename packages/circuits/{ => helpers}/utils/constants.circom (100%) rename packages/circuits/{ => helpers}/utils/digit2int.circom (100%) rename packages/circuits/{ => helpers}/utils/hex2int.circom (100%) delete mode 100644 packages/circuits/utils/email_addr_commit.circom delete mode 100644 packages/circuits/utils/email_addr_pointer.circom delete mode 100644 packages/circuits/utils/email_nullifier.circom delete mode 100644 packages/circuits/utils/hash_sign.circom diff --git a/docs/zkEmailDocs/UsageGuide/README.md b/docs/zkEmailDocs/UsageGuide/README.md index 84557aaeb..9171d87ee 100644 --- a/docs/zkEmailDocs/UsageGuide/README.md +++ b/docs/zkEmailDocs/UsageGuide/README.md @@ -143,15 +143,11 @@ node --max-old-space-size=614400 ./../node_modules/.bin/snarkjs ### Powers of Tau -After obtaining the constraint size, find the next highest power of 2 and replace the '12' in the following command with that number. This command initiates the Powers of tau ceremony. -``` -snarkjs powersoftau new bn128 12 pot12_0000.ptau -v -``` +You can download the ptau file directly from Google Cloud Platform using the following command: -Then contribute to the ceremony by running: -```bash -snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" -v +``` +wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_22.ptau ``` ### Phase 2 diff --git a/packages/circuits/README.md b/packages/circuits/README.md index 673855501..6df98a8e7 100644 --- a/packages/circuits/README.md +++ b/packages/circuits/README.md @@ -45,7 +45,27 @@ This template provides functionality for performing arithmetic operations in fin ### utils.circom -This template includes a collection of utility functions used across multiple circuits, such as bit manipulation functions, comparison functions, or conversion functions. +The `utils.circom` file includes a collection of utility templates and functions that are used across multiple circuits. These utilities cover a wide range of functionalities, including bit manipulation, comparison, conversion, and arithmetic operations in finite fields. It serves as a foundational component for building complex arithmetic circuits. + +## Utility templates + +### bytes2ints.circom + +This template converts an array of bytes into an array of integers. It is designed to handle inputs of any byte size and outputs integers based on the number of bytes specified. This is particularly useful for processing large binary data within arithmetic circuits. + +### constants.circom + +This file defines a set of constants used across various templates within the `circuits` package. These constants include maximum sizes for emails, domains, invitation codes, and timestamps, as well as specifications for packing bytes into field elements. + +### digit2int.circom + +The `Digit2Int` template converts an array of digit characters (0-9) into their corresponding integer representation. This is useful for processing numeric data that is input as a sequence of characters. + +### hex2int.circom + +This template provides functionality for converting hexadecimal strings into their integer representation. It supports conversion of both lowercase (a-f) and uppercase (A-F) hexadecimal characters. This is essential for processing hexadecimal data within arithmetic circuits. + + ## Overview of email-verifier.circom @@ -82,3 +102,4 @@ The template performs several operations: For a more in-depth understanding, please visit our zk Email Verify repository at https://github.com/zkemail/zk-email-verify. + diff --git a/packages/circuits/emailtest.circom b/packages/circuits/emailtest.circom deleted file mode 100644 index f369daf44..000000000 --- a/packages/circuits/emailtest.circom +++ /dev/null @@ -1,128 +0,0 @@ - -pragma circom 2.1.5; - -include "circomlib/circuits/bitify.circom"; -include "circomlib/circuits/comparators.circom"; -include "circomlib/circuits/poseidon.circom"; -include "@zk-email/circuits/email-verifier.circom"; -include "@zk-email/circuits/helpers/extract.circom"; -include "@zk-email/circuits/utils/constants.circom"; -include "@zk-email/circuits/utils/email_addr_pointer.circom"; -include "@zk-email/circuits/utils/email_addr_commit.circom"; -include "@zk-email/circuits/utils/hash_sign.circom"; -include "@zk-email/circuits/utils/email_nullifier.circom"; -include "./utils/bytes2ints.circom"; -include "./utils/digit2int.circom"; -include "@zk-email/zk-regex-circom/circuits/common/from_addr_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/email_addr_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/email_domain_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/subject_all_regex.circom"; -include "@zk-email/zk-regex-circom/circuits/common/timestamp_regex.circom"; - -// Verify email from user (sender) and extract subject, timestmap, recipient email (commitment), etc. -// * n - the number of bits in each chunk of the RSA public key (modulust) -// * k - the number of chunks in the RSA public key (n * k > 2048) -// * max_header_bytes - max number of bytes in the email header -// * max_subject_bytes - max number of bytes in the email subject -template EmailSender(n, k, max_header_bytes, max_subject_bytes) { - signal input in_padded[max_header_bytes]; // email data (only header part) - signal input pubkey[k]; // RSA pubkey (modulus), k parts of n bits each. - signal input signature[k]; // RSA signature, k parts of n bits each. - signal input in_padded_len; // length of in email data including the padding - signal input sender_email_idx; // Index of the from email address (= sender email address) in the email header - signal input subject_idx; // Index of the subject in the header - signal input domain_idx; // Index of the domain name in the from email address - signal input timestamp_idx; // Index of the timestamp in the header - - var email_max_bytes = email_max_bytes_const(); - var email_max_len = compute_ints_size(email_max_bytes); - - var subject_field_len = compute_ints_size(max_subject_bytes); - - var domain_len = domain_len_const(); - var domain_filed_len = compute_ints_size(domain_len); - - var k2_chunked_size = k >> 1; - if(k % 2 == 1) { - k2_chunked_size += 1; - } - var timestamp_len = timestamp_len_const(); - - signal output masked_subject_str[subject_field_len]; - signal output domain_name[domain_filed_len]; - signal output hfrom[email_max_len]; - signal output hsubject[subject_field_len]; - signal output pubkey_hash; - signal output email_nullifier; - signal output sender_pointer; - signal output timestamp; - - // Verify Email Signature - component email_verifier = EmailVerifier(max_header_bytes, 0, n, k, 1); - email_verifier.in_padded <== in_padded; - email_verifier.pubkey <== pubkey; - email_verifier.signature <== signature; - email_verifier.in_len_padded_bytes <== in_padded_len; - signal header_hash[256] <== email_verifier.sha; - pubkey_hash <== email_verifier.pubkey_hash; - - // FROM HEADER REGEX - 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); - hfrom <== Bytes2Ints(email_max_bytes)(sender_email_addr); - - // SUBJECT HEADER REGEX - 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); - hsubject <== Bytes2Ints(max_subject_bytes)(subject_all); - - // DOMAIN NAME HEADER REGEX - 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; - signal domain_name_bytes[domain_len]; - domain_name_bytes <== VarShiftMaskedStr(email_max_bytes, domain_len)(domain_regex_reveal, domain_idx); - domain_name <== Bytes2Ints(domain_len)(domain_name_bytes); - - - // Email address pointer - /* - var num_email_addr_ints = compute_ints_size(email_max_bytes); - signal sender_email_addr_ints[num_email_addr_ints] <== Bytes2Ints(email_max_bytes)(sender_email_addr); - sender_pointer <== EmailAddrPointer(num_email_addr_ints)(sender_relayer_rand, sender_email_addr_ints); -*/ - - // Email address commitment - /*signal cm_rand_input[k2_chunked_size+1]; - for(var i=0; i> 1; - if(k % 2 == 1) { - k2_chunked_size += 1; - } - signal output sign_ints[k2_chunked_size]; - - // signal pubkey_hash_input[k2_chunked_size]; - // for(var i = 0; i < k2_chunked_size; i++) { - // if(i==k2_chunked_size-1 && k2_chunked_size % 2 == 1) { - // pubkey_hash_input[i] <== pubkey[2*i]; - // } else { - // pubkey_hash_input[i] <== pubkey[2*i] + (1< Date: Thu, 21 Mar 2024 12:18:03 +0300 Subject: [PATCH 06/12] added utils.circom file --- packages/circuits/{ => helpers}/utils.circom | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/circuits/{ => helpers}/utils.circom (100%) diff --git a/packages/circuits/utils.circom b/packages/circuits/helpers/utils.circom similarity index 100% rename from packages/circuits/utils.circom rename to packages/circuits/helpers/utils.circom From 6e2d2474084fc9bd3bba704d43b0a345b659de6a Mon Sep 17 00:00:00 2001 From: Metachaser24 Date: Sat, 23 Mar 2024 08:16:31 +0300 Subject: [PATCH 07/12] added new test eml and pgp check --- packages/circuits/tests/test.eml | 25 +++++++++---------------- packages/helpers/src/dkim/index.ts | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/packages/circuits/tests/test.eml b/packages/circuits/tests/test.eml index d71ddad10..37e91dc57 100644 --- a/packages/circuits/tests/test.eml +++ b/packages/circuits/tests/test.eml @@ -1,18 +1,11 @@ -DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1693038337; bh=7xQMDuoVVU4m0W0WRVSrVXMeGSIASsnucK9dJsrc+vU=; h=from:Content-Type:Mime-Version:Subject:Message-Id:Date:to; b=EhLyVPpKD7d2/+h1nrnu+iEEBDfh6UWiAf9Y5UK+aPNLt3fAyEKw6Ic46v32NOcZD - M/zhXWucN0FXNiS0pz/QVIEy8Bcdy7eBZA0QA1fp8x5x5SugDELSRobQNbkOjBg7Mx - VXy7h4pKZMm/hKyhvMZXK4AX9fSoXZt4VGlAFymFNavfdAeKgg/SHXLds4lOPJV1wR - 2E21g853iz5m/INq3uK6SQKzTnz/wDkdyiq90gC0tHQe8HpDRhPIqgL5KSEpuvUYmJ - wjEOwwHqP6L3JfEeROOt6wyuB1ah7wgRvoABOJ81+qLYRn3bxF+y1BC+PwFd5yFWH5 - Ry43lwp1/3+sA== -from: runnier.leagues.0j@icloud.com -Content-Type: text/plain; charset=us-ascii -Content-Transfer-Encoding: 7bit -Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kKhuE5byXTQp33gguA7XPzgZSjri6T33WTIDBGZl1vI=; b=AKGfZHblJQeG0ltVB3xTRU5CfViO9sj6hiKBl2ywQ5STwvZOSJJuUacYTxdVjGz5ud7LwV/UJcz7JGtJ5rtxiyvJyYdrMHMpaktO5eNEes4iMeQjUtTACmcEtE2lXx8jO/KqTYYh0yyav68atRbO7OGz/ZA5bclu4OZZ44UC1htg0KYPfaoYt2T5ScUmOITGJRcfJOu9Xx40VTqEW7YiIvY0jtPVoUHVKKX8Zn3DsgaKIg91xHz/a0dR8AP5J9IslBwL9QTGY0PXQT/TS2aCez4Li9/alCG7C7InkRVnUufbZKfsOKoMq9AkkwDsyS+WRyALtlL5Kh1GayaeFRj/bQ== +From: gideon mukoro +Content-Type: text/plain; charset="iso-8859-1" +Content-Transfer-Encoding: quoted-printable +Mime-Version: 1.0 Subject: Hello -Message-Id: <8F819D32-B6AC-489D-977F-438BBC4CAB27@me.com> -Date: Sat, 26 Aug 2023 12:25:22 +0400 -to: zkewtest@gmail.com +Message-Id: +Date: Fri, 22 Mar 2024 09:13:55 +0000 +to: "zkemailverify@gmail.com" -Hello, - -How are you? \ No newline at end of file +Testing testing 123... \ No newline at end of file diff --git a/packages/helpers/src/dkim/index.ts b/packages/helpers/src/dkim/index.ts index d3350589b..d175a355c 100644 --- a/packages/helpers/src/dkim/index.ts +++ b/packages/helpers/src/dkim/index.ts @@ -20,6 +20,21 @@ export async function verifyDKIMSignature( domain: string = "", tryRevertARCChanges: boolean = true ): Promise { + + const emailStr = email.toString(); + + const pgpMarkers = [ + "BEGIN PGP MESSAGE", + "BEGIN PGP SIGNED MESSAGE", + "X-Pm-Content-Encryption: end-to-end", + ]; + + const isPGPEncoded = pgpMarkers.some(marker => emailStr.includes(marker)); + + if (isPGPEncoded) { + throw new Error("PGP encoded emails are not supported."); + } + let dkimResult = await tryVerifyDKIM(email, domain); if (dkimResult.status.result !== "pass" && tryRevertARCChanges) { From ddc05e3da673de8468ae18b9dc208cd44ff04ba3 Mon Sep 17 00:00:00 2001 From: Metachaser24 Date: Sat, 23 Mar 2024 19:53:40 +0300 Subject: [PATCH 08/12] added new test eml and pgp check --- packages/helpers/src/dkim/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/helpers/src/dkim/index.ts b/packages/helpers/src/dkim/index.ts index d175a355c..425198062 100644 --- a/packages/helpers/src/dkim/index.ts +++ b/packages/helpers/src/dkim/index.ts @@ -26,7 +26,6 @@ export async function verifyDKIMSignature( const pgpMarkers = [ "BEGIN PGP MESSAGE", "BEGIN PGP SIGNED MESSAGE", - "X-Pm-Content-Encryption: end-to-end", ]; const isPGPEncoded = pgpMarkers.some(marker => emailStr.includes(marker)); From 9bbf60bc8cb8015a7a40802f2a1428a09622012b Mon Sep 17 00:00:00 2001 From: Elo <104064497+Metachaser24@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:20:45 +0300 Subject: [PATCH 09/12] Add ptau links and add constraint message --- docs/zkEmailDocs/UsageGuide/README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/zkEmailDocs/UsageGuide/README.md b/docs/zkEmailDocs/UsageGuide/README.md index e1100e2c6..863b8228e 100644 --- a/docs/zkEmailDocs/UsageGuide/README.md +++ b/docs/zkEmailDocs/UsageGuide/README.md @@ -146,10 +146,17 @@ node --max-old-space-size=614400 ./../node_modules/.bin/snarkjs ### Powers of Tau -You can download the ptau file directly from Google Cloud Platform using the following command: +Based on the amount of constraints you have, there are different ptau files that you are able to download. You can download the ptau file directly from Google Cloud Platform using the following command: ``` -wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_22.ptau +// For projects with up to 2 million constraints: +wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_21.ptau + +// For projects with up to 4 million constraints: +wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_22.ptau + +// For projects with up to 8 million constraints: +wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_23.ptau ``` ### Phase 2 From 27c60d8e1e2cc27d1d1bf1870d7db5d70fccdd41 Mon Sep 17 00:00:00 2001 From: Elo <104064497+Metachaser24@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:23:22 +0300 Subject: [PATCH 10/12] add snarkjs link --- docs/zkEmailDocs/UsageGuide/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/zkEmailDocs/UsageGuide/README.md b/docs/zkEmailDocs/UsageGuide/README.md index 863b8228e..6858c0764 100644 --- a/docs/zkEmailDocs/UsageGuide/README.md +++ b/docs/zkEmailDocs/UsageGuide/README.md @@ -157,6 +157,8 @@ wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_22.ptau // For projects with up to 8 million constraints: wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_23.ptau + +Refer to this link for more details: https://github.com/iden3/snarkjs?tab=readme-ov-file#7-prepare-phase-2 ``` ### Phase 2 From a51b3be917f18c8172f7e2223efc49c31da6f592 Mon Sep 17 00:00:00 2001 From: Elo <104064497+Metachaser24@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:01:18 +0300 Subject: [PATCH 11/12] Added bytes information to docs --- packages/circuits/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/circuits/README.md b/packages/circuits/README.md index 6df98a8e7..21e5631a7 100644 --- a/packages/circuits/README.md +++ b/packages/circuits/README.md @@ -51,11 +51,10 @@ The `utils.circom` file includes a collection of utility templates and functions ### bytes2ints.circom -This template converts an array of bytes into an array of integers. It is designed to handle inputs of any byte size and outputs integers based on the number of bytes specified. This is particularly useful for processing large binary data within arithmetic circuits. - +This template converts an array of bytes into an array of integers. It is designed to handle inputs of any byte size and outputs integers based on the number of bytes specified. This is particularly useful for processing large binary data within arithmetic circuits. Specifically, the template is configured to transform 31 bytes into one integer, aligning with circoms maximum field value which is a 31-byte number. It uses little endian order for representation. ### constants.circom -This file defines a set of constants used across various templates within the `circuits` package. These constants include maximum sizes for emails, domains, invitation codes, and timestamps, as well as specifications for packing bytes into field elements. +This file defines a set of constants used across various templates within the `circuits` package. These constants include maximum sizes for emails, domains, and timestamps, as well as specifications for packing bytes into field elements. ### digit2int.circom From 010706184d2655f1bfa5d0ff4c13573829642b91 Mon Sep 17 00:00:00 2001 From: Metachaser24 Date: Thu, 28 Mar 2024 15:44:19 +0300 Subject: [PATCH 12/12] changed file name format for docs --- .../README.md | 0 .../twitterREADME.md | 0 .../Installation/README.md | 0 .../Package Overviews/README.md | 0 .../UsageGuide/README.md | 0 packages/circuits/tests/test.eml | 25 ++++++++++++------- 6 files changed, 16 insertions(+), 9 deletions(-) rename docs/{MiscellaniousDocs => miscellanious-docs}/README.md (100%) rename docs/{MiscellaniousDocs => miscellanious-docs}/twitterREADME.md (100%) rename docs/{zkEmailDocs => zk-email-docs}/Installation/README.md (100%) rename docs/{zkEmailDocs => zk-email-docs}/Package Overviews/README.md (100%) rename docs/{zkEmailDocs => zk-email-docs}/UsageGuide/README.md (100%) diff --git a/docs/MiscellaniousDocs/README.md b/docs/miscellanious-docs/README.md similarity index 100% rename from docs/MiscellaniousDocs/README.md rename to docs/miscellanious-docs/README.md diff --git a/docs/MiscellaniousDocs/twitterREADME.md b/docs/miscellanious-docs/twitterREADME.md similarity index 100% rename from docs/MiscellaniousDocs/twitterREADME.md rename to docs/miscellanious-docs/twitterREADME.md diff --git a/docs/zkEmailDocs/Installation/README.md b/docs/zk-email-docs/Installation/README.md similarity index 100% rename from docs/zkEmailDocs/Installation/README.md rename to docs/zk-email-docs/Installation/README.md diff --git a/docs/zkEmailDocs/Package Overviews/README.md b/docs/zk-email-docs/Package Overviews/README.md similarity index 100% rename from docs/zkEmailDocs/Package Overviews/README.md rename to docs/zk-email-docs/Package Overviews/README.md diff --git a/docs/zkEmailDocs/UsageGuide/README.md b/docs/zk-email-docs/UsageGuide/README.md similarity index 100% rename from docs/zkEmailDocs/UsageGuide/README.md rename to docs/zk-email-docs/UsageGuide/README.md diff --git a/packages/circuits/tests/test.eml b/packages/circuits/tests/test.eml index 37e91dc57..d71ddad10 100644 --- a/packages/circuits/tests/test.eml +++ b/packages/circuits/tests/test.eml @@ -1,11 +1,18 @@ -DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kKhuE5byXTQp33gguA7XPzgZSjri6T33WTIDBGZl1vI=; b=AKGfZHblJQeG0ltVB3xTRU5CfViO9sj6hiKBl2ywQ5STwvZOSJJuUacYTxdVjGz5ud7LwV/UJcz7JGtJ5rtxiyvJyYdrMHMpaktO5eNEes4iMeQjUtTACmcEtE2lXx8jO/KqTYYh0yyav68atRbO7OGz/ZA5bclu4OZZ44UC1htg0KYPfaoYt2T5ScUmOITGJRcfJOu9Xx40VTqEW7YiIvY0jtPVoUHVKKX8Zn3DsgaKIg91xHz/a0dR8AP5J9IslBwL9QTGY0PXQT/TS2aCez4Li9/alCG7C7InkRVnUufbZKfsOKoMq9AkkwDsyS+WRyALtlL5Kh1GayaeFRj/bQ== -From: gideon mukoro -Content-Type: text/plain; charset="iso-8859-1" -Content-Transfer-Encoding: quoted-printable -Mime-Version: 1.0 +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1693038337; bh=7xQMDuoVVU4m0W0WRVSrVXMeGSIASsnucK9dJsrc+vU=; h=from:Content-Type:Mime-Version:Subject:Message-Id:Date:to; b=EhLyVPpKD7d2/+h1nrnu+iEEBDfh6UWiAf9Y5UK+aPNLt3fAyEKw6Ic46v32NOcZD + M/zhXWucN0FXNiS0pz/QVIEy8Bcdy7eBZA0QA1fp8x5x5SugDELSRobQNbkOjBg7Mx + VXy7h4pKZMm/hKyhvMZXK4AX9fSoXZt4VGlAFymFNavfdAeKgg/SHXLds4lOPJV1wR + 2E21g853iz5m/INq3uK6SQKzTnz/wDkdyiq90gC0tHQe8HpDRhPIqgL5KSEpuvUYmJ + wjEOwwHqP6L3JfEeROOt6wyuB1ah7wgRvoABOJ81+qLYRn3bxF+y1BC+PwFd5yFWH5 + Ry43lwp1/3+sA== +from: runnier.leagues.0j@icloud.com +Content-Type: text/plain; charset=us-ascii +Content-Transfer-Encoding: 7bit +Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) Subject: Hello -Message-Id: -Date: Fri, 22 Mar 2024 09:13:55 +0000 -to: "zkemailverify@gmail.com" +Message-Id: <8F819D32-B6AC-489D-977F-438BBC4CAB27@me.com> +Date: Sat, 26 Aug 2023 12:25:22 +0400 +to: zkewtest@gmail.com -Testing testing 123... \ No newline at end of file +Hello, + +How are you? \ No newline at end of file