Skip to content

Commit

Permalink
Merge pull request #7 from zkemail/feat/v2
Browse files Browse the repository at this point in the history
Feat/v2
  • Loading branch information
jp4g authored Sep 21, 2024
2 parents d83bbf0 + 56b0b4b commit 47c7ab1
Show file tree
Hide file tree
Showing 42 changed files with 6,406 additions and 2,239 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
target
*/node_modules
.env
dist
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 zk-email
Copyright (c) 2024 zk-email

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 0 additions & 9 deletions Nargo.toml

This file was deleted.

16 changes: 0 additions & 16 deletions Prover.toml

This file was deleted.

121 changes: 22 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,28 @@
# zkemail.nr
## ZKEmail.nr
ZKEmail written in NoirLang

Library for proving emails in Noir. Use the EML parser to generate a Prover.toml that
1. Authenticates the DKIM signature over an email header
2. Extracts the body hash from the authenticated body header
3. Authenticates a body that is hashed in circuit as matching the body hash in the header
4. Asserts the email is received by a specified domain (gmail.com as demo)
5. Outputs the pedersen hash of the DKIM pubkey modulus for verification

See [credits](#credits)

## Use
### Dependencies
0. Ensure you have `noirup` (circuit compiler) and `bbup` (circuit prover) installed:
```console
# Install noirup
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
# Install bbup
curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/barretenberg/cpp/installation/install | bash

# On Mac:
source ~/.zshrc
# On Linux 🗿:
source ~/.bashrc
```
1. Install the correct versions of `bb` and `nargo` (if later than shown below probably works)
```
# Install nargo
noirup -v 0.32.0
# Install bb
bbup -v 0.46.1
```
### Running ZKEmail.nr
1. Install the repository with `git clone https://github.com/mach-34/zkemail.nr && cd zkemail.nr`
2. The CLI is set up to read `src/demo.eml`. Change the email here if needed. You can generate a `Prover.toml` file by running the cli
```
cd eml_parser && cargo run --release && cd -
## OUTPUTS
global EMAIL_HEADER_LENGTH: u32 = 472;
global EMAIL_BODY_LENGTH: u32 = 24;
```
3. Shown above are outputs for exact header and body lengths for the emails. Eventually, a max size for each can be provided, but in the meantime, you must replace these in `main.nr`

4. Prove the circuit and verify the authenticity of an email:
```console
# Prove with ultraplonk (verifier-contract friendly)
./prove_ultraplonk.sh
# Prove with megahonk (quicker but non-constant proof size)
./prove_megahonk.sh
```

### Note on String Search
Use of string search will be highly application dependent. This repo shows a demonstration of using string search to match the to recipient (rather than from which is probably more useful but at index 0 of the header). Use the implementation as a guide to searching for the from domain, or searching for strings within the body.

## Benchmarks
Note that the proving is broken with string search due to instability around bb v0.46.1. Benchmarks do not include string search.
### Gates
(NO PARTIAL HASH, MATCHING RECIPIENT DOMAIN)

SMALL EMAIL GATES: `80125` + 16k gates to hash pubkey modulus

BIG EMAIL GATES: TODO


### 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
#### Small Email
* UltraPlonk: 8.0s witcalc, 8.4s proof gen
* MegaPlonk: 7.6s witcalc, 3.0s proof gen
#### Big Email
TODO
### M1 Bare Metal
#### Small Email
* UltraPlonk: TODO
* MegaPlonk: TODO
#### Big Email
TODO
### Wasm
## Using the Noir Library
TODO

## Todo:
## Using the Input Generation JS Library
TODO

Note that this is a very rough version of this utility and the rust is not built to be maintainable yet.
## Using ZKEmail.nr in EVM Smart Contracts
TODO

- [x] CLI for .eml parsing into noir inputs
- [x] Prover.toml generation script
- [ ] Ensure works with big email (Quoted Pritable Encoding) support
- [x] Full body hash
- [ ] Partial body hash
- [x] Prove recipient using string search
- [ ] CLI takes input to specific .eml file rather than hardcoded
- [ ] Max body and header length rather than hardcoded
- [ ] Simple body/ header parsing (currently uses relaxed by default)
- [x] Proving
- [x] Basic Benchmarking script
- [ ] Robust Benchmarking script (30 samples)
- [x] Publicly output the pubkey modulus to verify the email authenticity
[ ] EVM Contract Demo
[ ] Aztec Contract Demo
[ ] Hyle Aggregator Demo
## Using ZKEmail.nr in Aztec Smart Contracts
TODO

## Credits
[ZK Email](https://github.com/zkemail) - repo is derived entirely from this work
[Noir-RSA (V1)](https://github.com/richardliang/noir-rsa/) - body hash base64, insights into how to implement (i thought dkim was over body hash not header until reading this repo)
[Noir_RSA (V2)](https://github.com/noir_lang/noir_rsa) - Makes ZKEmail possible in reasonable amount of time in Noir
## Todo
- Negative Unit Testing
- Expected InputGen testing
- Robust from/ to string search implementation
- Contract/ testing for UltraPlonk reintegrated
- EVM Contract tests for email integration
- Aztec Contract tests for email integration
- 1024-bit key demo eml (current one is sensitive and cannot be provided in public repo)
- DKIM Key pedersen hash function
- Handle optional inputs (partial hashing, no body check, etc) gracefully again
- Partial SHA256 hashing
- Implementation with Regex
- test does not exit on completion?
Loading

0 comments on commit 47c7ab1

Please sign in to comment.