Skip to content
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

Saleels V4 #192

Merged
merged 83 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
447bb73
circuit: rename inputs on EmailVerifier
saleel Mar 28, 2024
6501d72
Merge remote-tracking branch 'origin/Docs-update' into feat/circuit-r…
saleel Mar 28, 2024
7747fc6
circuit: revert test email
saleel Mar 28, 2024
38ee1b6
circuit: update emailverifier doc
saleel Mar 28, 2024
a2316f0
helpers: update input generation to match new names
saleel Mar 28, 2024
561fa32
circuit: fix in emailverifier tests
saleel Mar 28, 2024
0e46fe1
circuits: move test circuits
saleel Mar 28, 2024
82ef70d
circuit: rename compiled-test-circuits
saleel Mar 28, 2024
018b454
circuit: merge email verifier tests to one file
saleel Mar 28, 2024
8102952
circuit: move test emails
saleel Mar 28, 2024
24d8158
circuit: remove circuit MakeAnonEmailSalt
saleel Mar 28, 2024
a38542a
circuit: move base64 to lib
saleel Mar 28, 2024
8e2a119
circuit: refactor rsa circuit
saleel Mar 28, 2024
61ded0b
circuit: refactor SHA circuit
saleel Mar 28, 2024
cf5cf72
circuit: fix test errors
saleel Mar 29, 2024
c1c18b8
circuit: add array utils
saleel Mar 30, 2024
85f95a6
circuit: rename bodyHash variable
saleel Mar 30, 2024
070bc4e
circuit: add bytes utils
saleel Mar 30, 2024
1a338ff
circuit: add ByteSubArrayToInts
saleel Mar 30, 2024
b14e346
circuit: update VarShiftLeft
saleel Mar 30, 2024
98ae7e5
circuit: refactor extract utils
saleel Mar 30, 2024
f60f6bf
circuit: add ByteSubArrayToInts (shift and pack)
saleel Mar 30, 2024
9f2d121
circuit: update EmailVerifier to use ExtractRegexReveal
saleel Mar 30, 2024
9fa6537
circuit: move AssertZeros to array utils
saleel Mar 30, 2024
b40c748
circuit: remove unused templates
saleel Mar 30, 2024
401694e
circuit: move DigitBytesToInt to bytes
saleel Mar 30, 2024
6df9f84
circuit: add docs for extract
saleel Mar 30, 2024
2346ed5
circuit: fix imports in sha
saleel Mar 30, 2024
36c4776
circuit: remove maxBlocksBits from SHA
saleel Mar 30, 2024
6d6a541
circuit: fix build errors
saleel Mar 30, 2024
848b6ff
circuit: fix test witness for pubkeyHash
saleel Mar 30, 2024
b9ce992
circuit: add util for PoseidonLarge
saleel Mar 30, 2024
0d29c5b
circuit: add email nullifier helper
saleel Mar 30, 2024
7ebfb17
Merge branch 'main' into feat/circuit-refactor
saleel Mar 30, 2024
a6898e8
circuit: delete redundant circuit
saleel Mar 30, 2024
e5c331c
circuit: update circom version to 2.1.6
saleel Mar 30, 2024
ea3da5d
circuit: add test eml to repo
saleel Mar 30, 2024
fd25b60
circuit: remove Dockerfile
saleel Apr 1, 2024
2879928
circuit: add SubArray selector
saleel Apr 1, 2024
a5b5340
circuit: use SubArraySelector in ByteSubArrayToInts
saleel Apr 1, 2024
e077475
circuit: rename to regex.cirocm
saleel Apr 1, 2024
2a72497
circuit: update comments
saleel Apr 1, 2024
84cad37
circuit: update deps, minor fix/cleanup
saleel Apr 1, 2024
7ad0460
Merge branch 'v4' into feat/circuit-refactor
saleel Apr 1, 2024
57a1564
circuit: remove unnecessary export from test
saleel Apr 1, 2024
92dde51
circuit: rename BytesToInts
saleel Apr 2, 2024
49109ea
circuit: rename array util templates
saleel Apr 2, 2024
2a72632
helpers: move mailauth lib to separate dir
saleel Apr 2, 2024
32c4cbf
helpers: apply sanitizations to email; add removeLabels
saleel Apr 2, 2024
73a907e
helpers: add test for labelRemove sanitization
saleel Apr 2, 2024
a319915
helpers: add sanitizer insert13Before10
saleel Apr 2, 2024
437eb36
helpers: move dkim types
saleel Apr 3, 2024
eeac9bb
helpers: add comments on dkim
saleel Apr 3, 2024
ee6fd33
helpers: move sha precompute to sha file
saleel Apr 3, 2024
3b24221
helpers: add generate-input from raw email
saleel Apr 3, 2024
11405f7
helpers: rename files
saleel Apr 3, 2024
fc382bc
helpers: add note on mailauth lib
saleel Apr 3, 2024
61a6231
helpers: add note on fast-sha lib
saleel Apr 3, 2024
35f3833
helpers: cleanup test files
saleel Apr 3, 2024
57257ec
helper: add input generation scripts
saleel Apr 3, 2024
2001fa6
circuit: fix tests to match new helper methods
saleel Apr 3, 2024
6fa7dfc
helpers: fix build errors
saleel Apr 3, 2024
9ac3840
circuits: move sdk files to package.json
saleel Apr 3, 2024
636fd0e
version: version bump to 4.0.0
saleel Apr 3, 2024
3d62353
helpers: add TAB sanitizer
saleel Apr 3, 2024
1d77190
helpers: clean test eml
saleel Apr 3, 2024
67d724d
changed readmes for main, contracts and circuits pkg
Metachaser24 Apr 4, 2024
66fea7a
Merge pull request #185 from zkemail/feat/circuit-refactor
saleel Apr 6, 2024
4aa2afa
Merge pull request #189 from zkemail/feat/helpers-improvements
saleel Apr 6, 2024
6002c2d
circuits: fix casing in rsa and base64
saleel Apr 6, 2024
4ca809e
contracts: add files to package.json
saleel Apr 6, 2024
a1524eb
docs: make logo compact
saleel Apr 6, 2024
ea76cd3
updated helpers, circuits and package overview README
Metachaser24 Apr 8, 2024
737871c
helpers: move external libs to lib dir
saleel Apr 15, 2024
f2fb77c
helpers: add eslint and lint files
saleel Apr 15, 2024
59bdba7
ciecuits: update docs format
saleel Apr 15, 2024
98dec79
circuits: improve helpers docs
saleel Apr 15, 2024
aa79dfa
Merge branch 'main' into v4
saleel Apr 15, 2024
2274bf5
Updated docs to be concise
Metachaser24 Apr 15, 2024
f620982
Changed email-nullifier code link
Metachaser24 Apr 15, 2024
8845daf
remove pgp check
Metachaser24 Apr 15, 2024
0cb90a3
Merge branch 'v4' into Docs-update
Metachaser24 Apr 15, 2024
65bd8a9
Merge pull request #191 from zkemail/Docs-update
saleel Apr 15, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Download Circom Binary v2.1.5
- name: Download Circom Binary v2.1.8
run: |
wget -qO /home/runner/work/circom https://github.com/iden3/circom/releases/download/v2.1.5/circom-linux-amd64
wget -qO /home/runner/work/circom https://github.com/iden3/circom/releases/download/v2.1.8/circom-linux-amd64
chmod +x /home/runner/work/circom
sudo mv /home/runner/work/circom /bin/circom

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ generate_input_log.txt
*.env
.vscode

packages/circuits/tests/compiled-test-circuit/*
packages/circuits/tests/compiled-test-circuits/*


.vite
Expand Down
File renamed without changes.
194 changes: 17 additions & 177 deletions README.md

Large diffs are not rendered by default.

File renamed without changes
17 changes: 10 additions & 7 deletions docs/zk-email-docs/Installation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
- **Yarn**: Latest version recommended.

To get started with zk-email, install these three npm packages:
## **1. @zk-email/helpers**

## **1. @zk-email/circuits**
This package provides circuits for generating proofs and verifying DKIM signatures in emails.
```
yarn add @zk-email/circuits
```

## **2. @zk-email/helpers**
This package provides utility functions for email verification and cryptographic operations.
```
yarn add @zk-email/helpers
```

## **2. @zk-email/contracts**
## **3. @zk-email/contracts**
This package contains Solidity contracts for email verification.
```
yarn add @zk-email/contracts
```
## **3. @zk-email/circuits**
This package provides circuits for generating proofs and verifying DKIM signatures in emails.
```
yarn add @zk-email/circuits
```


[Package Overviews >](/docs/zkEmailDocs/Package%20Overviews/README.md)
201 changes: 10 additions & 191 deletions docs/zk-email-docs/Package Overviews/README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,6 @@
# Package Overviews
# Packages
This document provides an overview of the three main packages that make up ZK Email Verifier. Each package serves a specific purpose in the process of verifying DKIM signatures in emails using zero-knowledge proofs.


## zk-email/helpers
The `@zk-email/helpers` package provides a comprehensive suite of utility functions aimed at facilitating the creation of inputs for zk circuits.

**Key Considerations:**
- **Essential for Verification Circuits:** Vital in generating the inputs required for the verification circuits.
- **Functionality:** Includes functions for handling RSA signatures, public keys, email bodies, and hashes.
- **Core Function:** Developers are encouraged to become acquainted with the `generateCircuitInputs` function located in the `input.helpers.ts` file, a cornerstone of the SDK's operation.

#### Helper Files Overview

**binaryFormat.ts**
- **Purpose:** Contains utility functions for binary data manipulation, facilitating conversions between various data types and formats such as Uint8Array, BigInt, and character arrays.
- **Key Functions:**
- `bigIntToBin`: Converts a BigInt to a binary string.
- `binToBigInt`: Converts a binary string to a BigInt.
- `bigIntToUint8Array`: Converts a BigInt to a Uint8Array.
- `uint8ArrayToBigInt`: Converts a Uint8Array to a BigInt.

**constants.ts**
- **Purpose:** Defines constants utilized across the helper functions, specifying the maximum allowed lengths for the email header and body when padded.
- **Constants:**
- `MAX_HEADER_LENGTH`: Maximum length for the email header when padded.
- `MAX_BODY_LENGTH`: Maximum length for the email body when padded.

**dkim.ts**
- **Purpose:** Offers functions for parsing and verifying DKIM signatures within emails.
- **Key Functions:**
- `parseDKIMSignature`: Parses a DKIM signature from an email header.
- `verifyDKIMSignature`: Verifies a DKIM signature, extracting necessary information for the verification process.

**input-helpers.ts**
- **Purpose:** Houses the `generateCircuitInputs` function, pivotal to the SDK's functionality. This function is responsible for generating the necessary inputs for the zk circuits, including the RSA signature, public key, email body, and body hash.

**shaHash.ts**
- **Purpose:** Provides functions for SHA-256 hash management.
- **Key Functions:**
- `padSHA256Data`: Pads data to align with SHA-256 block requirements.
- `computePartialSHA256Hash`: Computes a partial SHA-256 hash for a specified input and initial hash value.
- `computeFullSHA256Hash`: Computes a full SHA-256 hash for a specified input.

**dkim/index.ts**

- **Purpose:** Provides functionality for verifying DKIM signatures within emails, crucial for authenticating the sender's domain and ensuring the email content's integrity.
- **Key Functions:**

**`verifyDKIMSignature`:** Attempts to verify the DKIM signature of an email to authenticate its sender and content. It can optionally revert common changes made by email forwarders that might cause the original DKIM signature to fail.
- **Parameters:**
- `email`: The email content to be verified, provided as a `Buffer` or a `string`
- `domain`: An optional domain name for verification, useful if the DKIM signature is signed by a different domain than the one in the email's From address.
- `tryRevertARCChanges`: A flag indicating whether to attempt reverting changes made by email forwarders, defaulting to true.
- **Returns:** A `Promise` resolving to a `DKIMVerificationResult` object, which includes details such as the public key, signature, message, body, and other relevant verification outcomes.

## zk-email/contracts

The @zk-email/contracts package contains the main contract of the SDK, `DKIMRegistry.sol`. This Solidity contract serves as a registry for storing the hash of the DomainKeys Identified Mail (DKIM) public key for each domain.

Key considerations:
- The `DKIMRegistry.sol` contract maintains a record of the DKIM key hashes for public domains. The hash is calculated by taking the Poseidon hash of the DKIM key split into 9 chunks of 242 bits each.

- The contract provides functions for registering, revoking, and validating DKIM public key hashes.

- It emits events upon successful registration (`DKIMPublicKeyHashRegistered`) and revocation (`DKIMPublicKeyHashRevoked`) of DKIM public key hashes.


- The `DKIMRegistry` contract is used in conjunction with the `EmailVerifier` circuit to verify emails. The `EmailVerifier` circuit checks the DKIM signature of an email against the DKIM public key hash stored in the `DKIMRegistry` contract for the email's domain.

## zk-email/circuits
The zk-email/circuits package provides pre-built circuits for generating proofs and verifying DKIM signatures. These circuits are designed to be used with the zk-email/helpers package to generate the necessary inputs.

Expand All @@ -77,136 +10,22 @@ Key considerations:
- By default, inputs are kept private unless stated otherwise, while outputs are always made public.
- Upon obtaining the vkey and zkey, you can establish a `verifier.sol `contract, enabling on-chain proof verification!

## **Circuit Helpers**
The `circuits` directory includes a `helpers` folder, which houses a variety of Circom helper templates. These templates are instrumental in constructing your primary circuit file.

### **base64.circom**:
The base64.circom file is a part of the zk-email/circuits package and provides functionality for decoding base64 encoded data within arithimetic circuits.

**Overview**

It includes two templates:
- Base64Lookup: Converts a base64 character into its 6-bit binary representation.

- Base64Decode: Decodes a base64 encoded string into binary data.

**Importing**

To use these templates in your Circom program, you need to import the base64.circom file. Here's how you can do it:

```bash
include "path/to/base64.circom"
```

Replace "path/to/base64.circom" with the actual path to the base64.circom file.

### **extract.circom**:

The extract.circom file is part of the zk-email/circuits package. It provides a set of utilities for manipulating signal arrays within arithmetic circuits.

**Overview**

The file includes several templates:

`PackBytes(max_in_signals, max_out_signals, pack_size)`
For further information, refer to the [circuits README](/packages/circuits/README.md).

A template that packs a number of chunks (i.e., number of char signals that fit into a signal) from the input signals into the output signals.

Inputs:

- in: An array of signals to be packed.
- max_in_signals: The maximum number of input signals.
- max_out_signals: The maximum number of output signals.
- pack_size: The number of chunks to be packed into a signal.

Outputs:

- out: An array of packed signals.

`VarShiftLeft(in_array_len, out_array_len)`

A template that shifts the input signals left by a variable size of bytes.

Inputs:

- in: An array of signals to be shifted.
- shift: The number of bytes to shift.
- in_array_len: The length of the input array.
- out_array_len: The length of the output array.

Outputs:

- out: An array of shifted signals.

`VarShiftMaskedStr(in_array_len, out_array_len)`

Similar to VarShiftLeft, but it assumes the input is the masked bytes and checks that shift is the first index of the non-masked bytes.

Inputs:

- in: An array of masked signals to be shifted.
- shift: The number of bytes to shift.
- in_array_len: The length of the input array.
- out_array_len: The length of the output array.

Outputs:

- out: An array of shifted signals.

`ClearSubarrayAfterEndIndex(n, nBits)`

A template that clears a subarray after a specified end index.

Inputs:

- in: An array of signals.
- end: The end index.

Outputs:

- out: An array of signals with the subarray after the end index cleared.

`ShiftAndPack(in_array_len, max_substr_len, pack_size)`

A template that shifts the input signals left by a variable size of bytes and packs the shifted bytes into fields under a specified pack size.

Inputs:

- in: An array of signals to be shifted and packed.
- shift: The number of bytes to shift.
- in_array_len: The length of the input array.
- max_substr_len: The maximum length of the substring.
- pack_size: The number of chunks to be packed into a signal.

Outputs:

- out: An array of shifted and packed signals.

`ShiftAndPackMaskedStr(in_array_len, max_substr_len, pack_size)`

Similar to ShiftAndPack, but it assumes the input is the masked bytes and checks that shift is the first index of the non-masked bytes.

Inputs:

- in: An array of masked signals to be shifted and packed.
- shift: The number of bytes to shift.
- in_array_len: The length of the input array.
- max_substr_len: The maximum length of the substring.
- pack_size: The number of chunks to be packed into a signal.

Outputs:
## zk-email/helpers
The `@zk-email/helpers` package provides a comprehensive suite of utility functions aimed at facilitating the creation of inputs for zk circuits. The main file is `input-generators.ts` which helps you generate the inputs to your circuit.

- out: An array of shifted and packed signals.
For further information, refer to the [helpers README](/packages/helpers/README.md).

**Importing**
## zk-email/contracts
The `@zk-email/contracts` package offers Solidity contracts and libraries for managing DKIM public key hashes and providing string manipulation utilities. Key files include:

To use these templates in your Circom program, you need to import the extract.circom file. Here's how you can do it:
- **DKIMRegistry.sol**: A contract for registering, validating, and revoking DKIM public key hashes to ensure email authenticity.
- **StringUtils.sol**: A library offering functions for string conversion, comparison, and manipulation, aiding in data handling across contracts.

```bash
include "path/to/extract.circom"
```
For further information, refer to the [contracts README](/packages/contracts/README.md).

Replace "path/to/extract.circom" with the actual path to the extract.circom file.

### Recent updates: zk-email-verify audit fixes

Expand Down
2 changes: 1 addition & 1 deletion docs/zk-email-docs/UsageGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Note: Increasing the `messageLength` or `BodyLength` sizes will increase the tim


## Step 3: Implementing the Circuits
Next, use `email-veriifier.circom` from the zk-email/circuits package to create your zk circuit to verify the DKIM signature.
Next, use `email-verifier.circom` from the zk-email/circuits package to create your zk circuit to verify the DKIM signature.


To set up your own circuit for the email-verifier, you can follow these steps:
Expand Down
Loading
Loading