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

[WIP] halo2 circuits #45

Open
wants to merge 28 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e44ef08
Clarify what the CLI commands do
pnyda Oct 22, 2023
4629079
Add rustfmt.toml
pnyda Nov 2, 2023
2a0b846
Calculate the identity commitment
pnyda Nov 4, 2023
a88b354
Make the test pass with LIMB_BITS=32
pnyda Nov 5, 2023
b97e074
aaaa
pnyda Nov 7, 2023
f723877
Split the commands
pnyda Nov 7, 2023
a381d79
ahahaha
pnyda Nov 7, 2023
c1472f9
WIP: 20231108
pnyda Nov 8, 2023
44f8aeb
Measure the gas cost
pnyda Nov 9, 2023
4d568ab
Test the circuit with just Halo2, without halo2-base
pnyda Nov 9, 2023
6fc2206
Feed TBSCertificate into the circuit by splitting it by 32bits each
pnyda Nov 9, 2023
1a0b757
Take a SHA256 hash on halo2 -> Sign it with RSA on halo2-base
pnyda Nov 17, 2023
962da74
Implement CLI commands to prove/verify a proof
pnyda Nov 19, 2023
f1c30a9
Refactoring
pnyda Nov 19, 2023
de66ba3
Implement a CLI command to generate a solidity code that verifies a p…
pnyda Nov 19, 2023
4a1eeaa
Refactoring
pnyda Nov 19, 2023
4f50859
Store the generated solidity
pnyda Nov 19, 2023
9d73733
bugfix: I've mistaken bytes as bits
pnyda Nov 23, 2023
b7b650c
Generate an identity commitment
pnyda Nov 24, 2023
b29f173
Reduce K
pnyda Nov 25, 2023
5d3482a
Store the generated calldata in a file
pnyda Nov 25, 2023
36869e8
Use BufWriter
pnyda Nov 26, 2023
e927353
Make the RSA circuit take the same height as the SHA256 circuit which…
pnyda Nov 26, 2023
5fe5e52
Refactoring
pnyda Nov 28, 2023
cfc2537
Stop depending on my local files
pnyda Nov 29, 2023
96fbf5a
Implement CircuitExt
pnyda Dec 7, 2023
3186cde
Refactor CLI
pnyda Dec 8, 2023
ace0c84
Implement CLI for aggregation
pnyda Dec 8, 2023
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
426 changes: 297 additions & 129 deletions Cargo.lock

Large diffs are not rendered by default.

756 changes: 445 additions & 311 deletions packages/halo2-circuits/Cargo.lock

Large diffs are not rendered by default.

33 changes: 12 additions & 21 deletions packages/halo2-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "halo2-circuits"
version = "0.1.0"
edition = "2021"
authors = ["hiroism007"]
authors = ["hiroism007", "chokermaxx"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -11,29 +11,17 @@ num-bigint = { version = "0.4", features = ["rand"] }
sha2 = "0.10.6"
rand = "0.8.5"
rsa = { version = "0.6.1", features = ["serde"] }
halo2-rsa = { branch = "main", default-features = false, features = [
"halo2-axiom",
"display",
], git = "https://github.com/MynaWallet/halo2-rsa.git" }
halo2-base = { branch = "community-edition", default-features = false, features = [
"halo2-axiom",
"display",
"test-utils",
], git = "https://github.com/axiom-crypto/halo2-lib.git" }
zkevm-hashes = { branch = "feat/zkevm-sha256", default-features = false, features = [
"halo2-axiom",
"display",
], git = "https://github.com/axiom-crypto/halo2-lib.git" }
halo2-sha256-unoptimized = { branch = "main", default-features = false, features = [
"halo2-axiom",
"display",
], git = "https://github.com/zkpdf/halo2-sha256-unoptimized.git" }
snark-verifier-sdk = { branch = "community-edition", default-features = false, features = [
halo2-rsa = { git = "https://github.com/MynaWallet/halo2-rsa.git" }
halo2-base = { git = "https://github.com/MynaWallet/halo2-lib.git", branch = "sha256" }
halo2-ecc = { git = "https://github.com/MynaWallet/halo2-lib.git", branch = "sha256" }
zkevm-hashes = { git = "https://github.com/MynaWallet/halo2-lib.git", branch = "sha256" }
snark-verifier-sdk = { default-features = false, features = [
"halo2-axiom",
"display",
"loader_evm",
"loader_halo2",
], git = "https://github.com/axiom-crypto/snark-verifier.git" }
"revm"
], git = "https://github.com/MynaWallet/snark-verifier.git", branch = "release-0.1.6-rc0" }
x509-parser = { version = "0.15", features = ["verify"] }
openssl = "0.10"
num-traits = "0.2.15"
Expand All @@ -50,6 +38,9 @@ tokio = { version = "1.16", features = [
"rt-multi-thread",
"macros",
] }
pse-poseidon = { git = "https://github.com/axiom-crypto/pse-poseidon.git" }
halo2-sha256-unoptimized = { git = "https://github.com/MynaWallet/halo2-sha256-unoptimized.git" }
bincode = "1"

[target.'cfg(target_family = "wasm")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand All @@ -65,4 +56,4 @@ criterion = "0.4"
default = ["halo2-axiom", "display"]
display = ["halo2-base/display"]
halo2-pse = ["halo2-base/halo2-pse"]
halo2-axiom = ["halo2-base/halo2-axiom"]
halo2-axiom = ["halo2-base/halo2-axiom"]
60 changes: 53 additions & 7 deletions packages/halo2-circuits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,69 @@ You can refer to these repos of RSA verification circuits.
- [zk-email-verify](https://github.com/zkemail/zk-email-verify)
- [zkCert](https://github.com/zkCert/halo2-zkcert)

## Example Usage
# Usage
## For off-chain verification
### Create the directory where proofs are stored
```bash
mkdir -p build/app
```

### Generate the common reference string
```bash
cargo run app trusted-setup
```

### Generate pk & vk
```bash
cargo run app keys
```

### Generate a proof
```bash
cargo run app prove
```

### Run the verification code written in Rust
```bash
cargo run app verify
```

### Run the verification code written in Solidity
This fails because of the big proof size.
```bash
cargo run app evm
```

## For on-chain verification
Run `cargo run app keys` first.

### Create the directory where proofs are stored
```bash
mkdir -p build/agg
```

### Generate a proof that's ready to be aggregated
```bash
cargo run app snark
```

### Generate pk & vk
```bash
# `k`: degree that expresses the size of circuit (i.e., 2^k is the number of rows in the circuit)
cargo run -r gen-params --k 17
cargo run agg keys
```

### Generate a proof
```bash
cargo run -r gen-rsa-keys # generate pk
cargo run agg prove
```

### Run the verification code written in Rust
```bash
cargo run -r prove-rsa # verify rsa locally
cargo run agg verify
```

You need to install solc 0.8.19 or 0.8.20 locally.
### Run the verification code written in Solidity
This succeeds because of the tiny proof size.
```bash
cargo run -r gen-rsa-verify-evm-proof # generate a verifier contract and proof inputs for evm
cargo run agg evm
```
14 changes: 14 additions & 0 deletions packages/halo2-circuits/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
edition = "2021"
version = "Two"
tab_spaces = 4
use_small_heuristics = "Max"
max_width = 120
wrap_comments = true
comment_width = 120
format_code_in_doc_comments = true
doc_comment_code_block_width = 120
normalize_doc_attributes = true
imports_granularity = "Crate"
hex_literal_case = "Upper"
condense_wildcard_suffixes = true
use_try_shorthand = true
Loading