Skip to content

Commit 27787bb

Browse files
authored
doc: versioned doc (#219)
* doc: versioned doc * chore: change from `0.0.2` to `0.1.0`
1 parent d2e3630 commit 27787bb

18 files changed

+1220
-7
lines changed

docs/docs/intro.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ How? Mopro connects different adapters with different platforms. You can think o
1212

1313
Note that above is a work in progress, and the dashed lines indicate things that are still experimental and/or in an an early stage.
1414

15-
If you just want to get started using mopro, see [getting started](/docs/getting-started).
15+
If you just want to get started using mopro, see [getting started](getting-started/rust-setup).
1616

1717
## Overview
1818

docs/docusaurus.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const config: Config = {
2525
editUrl:
2626
'https://github.com/zkmopro/mopro/tree/main/docs',
2727
includeCurrentVersion: true,
28-
lastVersion: '0.0.1',
28+
lastVersion: '0.1.0',
2929
},
3030
theme: {
3131
customCss: './src/css/custom.css',

docs/versioned_docs/version-0.0.1/getting-started.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ sidebar_position: 3
44

55
# Getting Started
66

7-
We recommend you use [mopro-cli](/docs/mopro-cli) to create and maintain your application. Here's how you can get started with your example app in a few minutes.
7+
We recommend you use [mopro-cli](mopro-cli) to create and maintain your application. Here's how you can get started with your example app in a few minutes.
88

99
You can also watch this short (~5m) [tutorial](https://www.loom.com/share/6ff382b0497c47aea9d0ef8b6e790dd8).
1010

1111
## Install dependencies
1212

13-
First, make sure you've installed the [prerequisites](/docs/prerequisites).
13+
First, make sure you've installed the [prerequisites](prerequisites).
1414

1515
Then, run the following commands:
1616

@@ -121,5 +121,5 @@ Depending on what platforms you are targetting, you can run the following comman
121121

122122
Use `^R` (`control`+`R`) to execute a simulator.
123123

124-
> See [mopro-cli](/docs/mopro-cli) for more details on usage.
125-
> Edit [mopro configuration](/docs/circom/configuration) to build for device or build for other circuits.
124+
> See [mopro-cli](mopro-cli) for more details on usage.
125+
> Edit [mopro configuration](circom/configuration) to build for device or build for other circuits.

docs/versioned_docs/version-0.0.1/intro.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ How? Mopro connects different adapters with different platforms. You can think o
1212

1313
Note that above is a work in progress, and the dashed lines indicate things that are still experimental and/or in an an early stage.
1414

15-
If you just want to get started using mopro, see [getting started](/docs/getting-started).
15+
If you just want to get started using mopro, see [getting started](getting-started).
1616

1717
## Overview
1818

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
# FAQ
6+
7+
## What are the design goals of Mopro?
8+
9+
1. Modularity
10+
2. Developer-friendly
11+
3. Performance
12+
4. Multi-platform
13+
14+
See one of the recent [talks](/docs/community) for more details.
15+
16+
## What proof systems does Mopro support?
17+
18+
Currently Circom/Groth16, but due to its modular architecture it is easy to add support for new proof systems.
19+
20+
There's experimental support for Kimchi, a Plonkish proof system, that was done during a hackathon in this [PR](https://github.com/zkmopro/mopro/pull/34).
21+
22+
There's a grantee working on adding Halo2 support. Please see the [Telegram group](https://t.me/zkmopro) for more information.
23+
24+
We welcome people to contribute support for [more proof systems](https://github.com/zkmopro/mopro/issues/15).
25+
26+
## What platforms does Mopro support?
27+
28+
Mopro is multi-platform and aims to support as many platforms as possible. iOS, Android and Desktop (through Rust/CLI) are the main platforms supported.
29+
30+
There's also very experimental React Native support [here](https://github.com/anon-aadhaar/anon-aadhaar-react-native/commit/d6443316200cd3e1f17ad2679458cc6e6e9fe1f2). We aim to make this easier to consume.
31+
32+
We welcome people to contribute support for [more platforms](https://github.com/zkmopro/mopro/issues/16).
33+
34+
## Is Mopro just for verifying proofs on mobile?
35+
36+
Mopro is for both proving and verifying ZKPs on mobile.
37+
38+
## Does Mopro run natively on a phone?
39+
40+
Yes. Witness and proof generation happens natively in app.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Circom Adapter
2+
3+
Mopro supports the integration of Circom circuits. For this, you need to have pre-built `zkey` and `wasm` files for your circuits. You can find more information on how to generate these files in the [Circom documentation](https://docs.circom.io).
4+
5+
## Samples
6+
7+
Explore how the Circom adapter is implemented by checking out this sample project [mopro-app](https://github.com/vimwitch/mopro-app) or the [test-e2e](https://github.com/zkmopro/mopro/tree/main/test-e2e) where we maintain (and test) each adapter.
8+
9+
## Setup the rust project
10+
11+
You can follow the instructions in the [Rust Setup](/getting-started/rust-setup.md) guide to create a new Rust project that builds this library with Circom proofs.
12+
13+
In your `Cargo.toml` file, ensure the `circom` feature is activated for `mopro-ffi`:
14+
15+
```toml
16+
[features]
17+
default = ["mopro-ffi/circom"]
18+
```
19+
20+
## Witness Generation Functions
21+
22+
In order for the Mopro to be able to generate proofs for your chosen circom circuits, you need to provide a witness generation function for each of the circuits you plan to use to generate proofs for. This function handles the witness generation for your circuit. You can read more about witnesses for circom circuits [here](https://docs.circom.io/background/background/#witness).
23+
24+
The function signature should be:
25+
26+
```rust
27+
pub type WtnsFn = fn(HashMap<String, Vec<BigInt>>) -> Vec<BigInt>;
28+
```
29+
30+
## Implementing the Witness Function
31+
32+
For simplicity, you can use the `witness!` macro provided by the `rust-witness` crate. This macro generates a witness function for you given the circuit name. You can read more about the `witness!` macro [here](https://github.com/vimwitch/rust-witness).
33+
34+
#### Adding the `rust-witness` Crate Dependency
35+
36+
To use it, you must first add the `rust-witness` crate to your `Cargo.toml` regular and build dependencies:
37+
38+
```toml
39+
[dependencies]
40+
# ...
41+
rust-witness = { git = "https://github.com/vimwitch/rust-witness.git" }
42+
43+
[build-dependencies]
44+
# ...
45+
rust-witness = { git = "https://github.com/vimwitch/rust-witness.git" }
46+
```
47+
48+
#### Configuring the path to the `.wasm` circuit files in the `build.rs`
49+
50+
Then you need to add to the `build.rs` the call to `rust_witness::transpile::transpile_wasm` macro and pass it the path to the folder containing the `.wasm` files for the circom circuits. The path can be absolute or a relative to the location of the `build.rs` file. Note that the `.wasm` files can be recursively in subfolders of the specified folder, as in the example below.
51+
52+
For example, for the following project structure:
53+
54+
```text
55+
your-rust-project
56+
├── build.rs
57+
...
58+
test-vectors
59+
├── circom
60+
│ ├── multiplier
61+
│ │ ├── multiplier2.wasm
62+
│ │ └── multiplier3.wasm
63+
│ └── keccak256_256_test.wasm
64+
...
65+
```
66+
67+
You will need to add the following to the `build.rs` file:
68+
69+
```rust
70+
fn main() {
71+
// ...
72+
rust_witness::transpile::transpile_wasm("../test-vectors/circom".to_string());
73+
// ...
74+
}
75+
```
76+
77+
#### Automatically Generating Witness Functions
78+
79+
Then you can automatically generate the witness functions for all the circuits in the specified folder.
80+
81+
To do so, in the `lib.rs` file, you can add the following:
82+
83+
```rust
84+
rust_witness::witness!(multiplier2);
85+
rust_witness::witness!(multiplier3);
86+
rust_witness::witness!(keccak256256test);
87+
```
88+
89+
This will generate the witness function for the specified circuit following [the naming convention here](https://github.com/vimwitch/rust-witness?tab=readme-ov-file#rust-witness).
90+
91+
## Setting the Circom Circuits
92+
93+
To set Circom circuits you want to use on other platforms, you need to use the `set_circom_circuits!` macro provided by the `mopro-ffi` crate. This macro should be called in the `lib.rs` file of your project, after the `mopro_ffi::app()` macro call. You should pass it a list of tuples (pairs), where the first element is the name of the `zkey` file and the second element is the witness generation function.
94+
95+
For example:
96+
97+
```rust
98+
mopro_ffi::set_circom_circuits! {
99+
("multiplier2_final.zkey", multiplier2_witness),
100+
("multiplier3_final.zkey", multiplier3_witness),
101+
("keccak256_256_test_final.zkey", keccak256256test_witness),
102+
}
103+
```
104+
105+
Under the hood, the `set_circom_circuits!` macro will generate a `get_circom_wtns_fn` function that will be used to get the witness generation function for a given circuit `zkey` file.
106+
107+
### Manual Configuration
108+
109+
For advanced users, you can manually define the `get_circom_wtns_fn` function in the `lib.rs` file:
110+
111+
```rust
112+
fn get_circom_wtns_fn(circuit: &str) -> Result<mopro_ffi::WtnsFn, mopro_ffi::MoproError> {
113+
match circuit {
114+
"your_circuit.zkey" => Ok(your_circuit_wtns_gen_fn),
115+
_ => Err(mopro_ffi::MoproError::CircomError(format!("Unknown ZKEY: {}", circuit).to_string()))
116+
}
117+
}
118+
```
119+
120+
This might be useful if you want to have more control over the proving functions for each circuit.
121+
122+
## Using the Library
123+
124+
After you have specified the circuits you want to use, you can follow the usual steps to build the library and use it in your project.
125+
126+
### iOS API
127+
128+
The Circom adapter exposes the following functions to be used in the iOS project:
129+
130+
```swift
131+
// Generate a proof for a given circuit zkey, as well as the circuit inputs
132+
// Make sure that the name of the zkey file matches the one you set in the `set_circom_circuits!` macro
133+
generateCircomProof(zkeyPath: zkeyPath, circuitInputs: inputs) -> GenerateProofResult
134+
135+
// Verify a proof for a given circuit zkey
136+
// This works for arbitrary circuits, as long as the zkey file is valid
137+
verifyCircomProof(
138+
zkeyPath: zkeyPath, proof: generateProofResult.proof, publicInput: generateProofResult.inputs) -> Bool
139+
140+
// Convert a Circom proof to an Ethereum compatible proof
141+
toEthereumProof(proof: generateProofResult.proof) -> ProofCalldata
142+
143+
// Convert a Circom public input to an Ethereum compatible public input
144+
toEthereumInputs(inputs: generateProofResult.inputs) -> [String]
145+
```
146+
147+
As well as the following types:
148+
149+
```swift
150+
public struct G1 {
151+
public var x: String
152+
public var y: String
153+
}
154+
155+
public struct G2 {
156+
public var x: [String]
157+
public var y: [String]
158+
}
159+
160+
public struct ProofCalldata {
161+
public var a: G1
162+
public var b: G2
163+
public var c: G1
164+
}
165+
166+
public struct GenerateProofResult {
167+
public var proof: Data
168+
public var inputs: Data
169+
}
170+
```
171+
172+
### Android API
173+
174+
The Circom adapter exposes the equivalent functions and types to be used in the Android project.
175+
176+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Halo2 Adapter
2+
3+
Mopro supports the use of Halo2 circuits, allowing for both the Halo2 library from Zcash and the PSE's Halo2 fork. To effectively work with Halo2 circuits in Mopro, you will need to understand how to generate proving and verifying keys as well as how Halo2 circuits work, and have some experience in Rust. For more details, please refer to the [Halo2 documentation](https://zcash.github.io/halo2/).
4+
5+
## Samples
6+
7+
Explore how the Halo2 adapter is implemented by checking out this [Sample Mopro Halo2-Adapter Project](https://github.com/zkmopro/halo2-app) or the [test-e2e](https://github.com/zkmopro/mopro/tree/main/test-e2e) where we maintain (and test) each adapter.
8+
9+
## Setting Up the Rust Project
10+
11+
You can start by following the general instructions in the [Rust Setup Guide](/getting-started/rust-setup.md) to create a new Rust project for building libraries with Circom proofs. However, you will need to perform these specific adjustments for Halo2:
12+
13+
In your `Cargo.toml` file, ensure the `halo2` feature is activated for `mopro-ffi`:
14+
15+
```toml
16+
[features]
17+
default = ["mopro-ffi/halo2"]
18+
```
19+
20+
Then, remove the `rust-witness` dependency from `[dependencies]` and `[build-dependencies]` as it is unnecessary for Halo2 circuits.
21+
Likewise, remove the `rust_witness::transpile::transpile_wasm!` macro call from the `build.rs` file and any `rust_witness::witness!` and `mopro_ffi::set_circom_circuits!` calls from the `lib.rs`.
22+
23+
## Implementing the Halo2 Circuit
24+
25+
The design of the Halo2 adapter minimizes restrictions, allowing flexibility in how you implement your circuits while following a few conventions to ensure compatibility with Mopro.
26+
27+
### Proving Function
28+
29+
When generating a proof for a Halo2 circuit, the Mopro will do a call to the proving function that you provide. This function should have the following signature:
30+
31+
```rust
32+
pub type Halo2ProveFn = fn(&str, &str, HashMap<String, Vec<String>>) -> Result<GenerateProofResult, Box<dyn std::error::Error>>;
33+
```
34+
35+
The first two arguments are the path to the `srs` and `proving` key files, and the third argument is a map of the inputs for the circuit.
36+
37+
It is then your responsibility to load the keys from the path and set up the circuit, as well as to deserialize the inputs and generate the proof. You can use any serialization method you want, as long as you can serialize and deserialize the inputs on the target platform.
38+
39+
The result of the function should be a `GenerateProofResult` struct, which contains the proof and the public inputs in the form of `Vec<u8>`. It is up to you to serialize the proof and the public inputs in a way that you can deserialize.
40+
41+
You can find an example of a proving function in the [Halo2 Fibonacci circuit sample](https://github.com/ElusAegis/halo2-fibonacci-sample/blob/main/src/lib.rs).
42+
43+
### Verifying Function
44+
45+
When verifying a proof for a Halo2 circuit, the Mopro will do a call to the verifying function that you provide. This function should have the following signature:
46+
47+
```rust
48+
pub type Halo2VerifyFn = fn(&str, &str, Vec<u8>, Vec<u8>) -> Result<bool, Box<dyn std::error::Error>>;
49+
```
50+
51+
The first two arguments are the path to the `srs` and `verifying` key files, and the last two arguments are the serialised proof and the public inputs.
52+
53+
It is then your responsibility to load the keys from the path and set up the circuit, as well as to deserialize the proof and the public inputs and verify the proof.
54+
Make sure that your deserialization method is compatible with the serialization method you used in the proving function.
55+
56+
The result of the function should be a `bool`, which indicates whether the proof is valid or not.
57+
58+
You can find an example of a verifying function in the [Halo2 Fibonacci sample project](https://github.com/ElusAegis/halo2-fibonacci-sample/blob/main/src/lib.rs).
59+
60+
### Setting the Halo2 Circuits
61+
62+
To set the Halo2 circuits in your project, you need to use the `set_halo2_circuits!` macro. This macro should be called in the `lib.rs` file of your project, after the `mopro_ffi::app()` macro, and it should contain a list of tuples, where each tuple contains the name to the proving key file, the proving function, the name to the verifying key file, and the verifying function.
63+
64+
For example:
65+
66+
```rust
67+
mopro_ffi::set_halo2_circuits! {
68+
("fibonacci_pk.bin", halo2_fibonacci::prove, "fibonacci_vk.bin", halo2_fibonacci::verify),
69+
}
70+
```
71+
72+
Under the hood, the `set_halo2_circuits!` macro will generate two functions called `get_halo2_proving_circuit` and `get_halo2_verifying_circuit` that will be used by the Mopro to select and call the proving and verifying functions respectively for each circuit based on the provided proving or verifying key files.
73+
74+
### Manual Configuration
75+
76+
You can optionally set only the proving or verifying function for a circuit by manually setting the `get_halo2_proving_circuit` and `get_halo2_verifying_circuit` functions in the `lib.rs` file. However, this is exclusive with the `set_halo2_circuits!` macro, so you can't use both in the same project. Also, you must implement both functions, even if you only want to use one of them.
77+
78+
For example:
79+
80+
```rust
81+
fn get_halo2_proving_circuit(circuit: &str) -> Result<Halo2ProveFn, MoproError> {
82+
match circuit {
83+
"fibonacci_pk.bin" => Ok(halo2_fibonacci::prove),
84+
_ => Err(MoproError::CircuitNotFound),
85+
}
86+
}
87+
88+
fn get_halo2_verifying_circuit(circuit: &str) -> Result<Halo2VerifyFn, MoproError> {
89+
match circuit {
90+
"fibonacci_vk.bin" => Ok(halo2_fibonacci::verify),
91+
_ => Err(MoproError::CircuitNotFound),
92+
}
93+
}
94+
```
95+
96+
This might be useful if you want to have more control over the proving and verifying functions for each circuit or if you want to only add the proving or verifying function for a circuit.
97+
98+
## Using the Library
99+
100+
After you have specified the circuits you want to use, you can follow the usual steps to build the library and use it in your project.
101+
102+
### iOS API
103+
104+
The Halo2 adapter exposes the following functions to be used in the iOS project:
105+
106+
```swift
107+
// Generate a proof for a Halo2 circuit given the srs and proving key files, as well as the circuit inputs
108+
// Make sure that the key was set in the Rust library
109+
generateHalo2Proof(srsPath: srsPath, pkPath: pkPath, circuitInputs: inputs) -> GenerateProofResult
110+
111+
// Verify a proof for a Halo2 circuit given the srs and verifying key files, as well as the proof and public inputs
112+
// Make sure that the key was set in the Rust library
113+
verifyHalo2Proof(srsPath: srsPath, vkPath: vkPath, proof: generateProofResult.proof, publicInput: generateProofResult.inputs) -> Bool
114+
```
115+
116+
As well as the following types:
117+
118+
```swift
119+
public struct GenerateProofResult {
120+
public var proof: Data
121+
public var inputs: Data
122+
}
123+
```
124+
125+
### Android API
126+
127+
The Halo2 adapter exposes the equivalent functions and types to be used in the Android project.
128+
129+

0 commit comments

Comments
 (0)