Skip to content

Commit

Permalink
Merge pull request #183 from zkemail/Docs-update
Browse files Browse the repository at this point in the history
Added utils templates and docs, ptau GCP link, and circom flag update
  • Loading branch information
saleel committed Mar 28, 2024
2 parents dca512e + 0107061 commit 29b0182
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 235 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -143,15 +145,20 @@ 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.

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:

```
snarkjs powersoftau new bn128 12 pot12_0000.ptau -v
```
// For projects with up to 2 million constraints:
wget https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_21.ptau
Then contribute to the ceremony by running:
```bash
snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" -v
// 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
Refer to this link for more details: https://github.com/iden3/snarkjs?tab=readme-ov-file#7-prepare-phase-2
```
### Phase 2

Expand Down
22 changes: 21 additions & 1 deletion packages/circuits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,26 @@ 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. 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, 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

Expand Down Expand Up @@ -82,3 +101,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.

128 changes: 0 additions & 128 deletions packages/circuits/emailtest.circom

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/circuits/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zk-email/circuits",
"version": "3.2.2",
"version": "3.2.4",
"scripts": {
"publish": "yarn npm publish --access=public",
"test": "NODE_OPTIONS=--max_old_space_size=8192 jest tests/*.ts"
Expand Down
18 changes: 0 additions & 18 deletions packages/circuits/utils/email_addr_commit.circom

This file was deleted.

18 changes: 0 additions & 18 deletions packages/circuits/utils/email_addr_pointer.circom

This file was deleted.

24 changes: 0 additions & 24 deletions packages/circuits/utils/email_nullifier.circom

This file was deleted.

38 changes: 0 additions & 38 deletions packages/circuits/utils/hash_sign.circom

This file was deleted.

14 changes: 14 additions & 0 deletions packages/helpers/src/dkim/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ export async function verifyDKIMSignature(
domain: string = "",
tryRevertARCChanges: boolean = true
): Promise<DKIMVerificationResult> {

const emailStr = email.toString();

const pgpMarkers = [
"BEGIN PGP MESSAGE",
"BEGIN PGP SIGNED MESSAGE",
];

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) {
Expand Down

0 comments on commit 29b0182

Please sign in to comment.