Skip to content

Commit

Permalink
Merge pull request #81 from zkonduit/sw/ezkl-docs-v2
Browse files Browse the repository at this point in the history
fix: documentation version 2.0
  • Loading branch information
alexander-camuto authored Oct 29, 2024
2 parents c11827a + 0a597a5 commit 3056db6
Show file tree
Hide file tree
Showing 33 changed files with 769 additions and 3,482 deletions.
5 changes: 5 additions & 0 deletions Advanced/Hardware Accleration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
icon: cpu
order: 90
visibility: hidden
---
5 changes: 5 additions & 0 deletions Advanced/Proof Aggregation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
icon: server
order: 89
visibility: hidden
---
5 changes: 5 additions & 0 deletions Advanced/Proof Splitting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
icon: git-merge
order: 88
visibility: hidden
---
10 changes: 10 additions & 0 deletions Advanced/Python Bindings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
icon: book
order: 90
---

# Python Bindings

PyO3 bindings were created for the Rust binary, do note that due to various interactions with Python the Python bindings will be less performant than using the Rust binary.

Python bindings are found on [https://pythonbindings.ezkl.xyz](https://pythonbindings.ezkl.xyz/)
5 changes: 5 additions & 0 deletions Advanced/Reusable Verifiers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
icon: git-compare
order: 87
visibility: hidden
---
5 changes: 5 additions & 0 deletions Advanced/Visibility Settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
icon: eye-closed
order: 91
visibility: hidden
---
5 changes: 5 additions & 0 deletions Advanced/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
icon: info
order: 92
expanded: true
---
64 changes: 64 additions & 0 deletions Getting Started/Installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
icon: tools
order: 96
---

+++ Local CLI
1. Install the binary with the following bash script.
```bash
curl https://raw.githubusercontent.com/zkonduit/ezkl/main/install_ezkl_cli.sh | bash
```

2. Alternatively, build from source:
```bash
git clone [email protected]:zkonduit/ezkl.git
cd ezkl
cargo install --force --path .
```
For detailed options, use `ezkl --help` or `ezkl <command> --help`.

+++ Python
Install EZKL using pip:
```bash
pip install ezkl
```
You may also need to install additional dependencies:
- `onnx` for exporting models
- PyTorch or TensorFlow for creating models

To use EZKL in your Python code:
```bash
import ezkl
```
+++ JavaScript
Install EZKL using npm:
```bash
npm install @ezkljs/engine
```
To use EZKL in your JavaScript code:
```bash
import { Engine } from '@ezkljs/engine';
```
+++ Remote CLI
1. Install `archon` with the following script
```bash
curl https://download.ezkl.xyz/download_archon.sh | bash
```
2. If your system settings block the installed binary you will need to allow your system to run the binary.
3. Set the server environment variable:
```bash
export ARCHON_SERVER_URL="https://archon-v0.ezkl.xyz"
```
4. Test the connection:
```bash
archon ping
```
+++
## Additional Notes
- While there is some support for Windows with the original `ezkl` repository, unfortunately Lilith does not work on Windows systems.
- EZKL uses your system's `solc` Solidity compiler. You may need to adjust it using `svm-rs` or `solc-select`.
- For rendering model circuits with EZKL, compile with the `render` feature and install required libraries (e.g., `libexpat1-dev` and `libfreetype6-dev` on Debian systems).
- For EZKL Rust documentation, use `cargo doc --open`.
100 changes: 100 additions & 0 deletions Getting Started/Prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
icon: device-desktop
order: 94
---
The lifecycle of an EZKL proof consists of three core components: Setup, Prove, and Verify. This page focuses on the Prove phase, which defines the rules for proof generation and verification. Recall that:
- **Setup**: Defines proof parameters and generates keys (performed by developers)
- **Prove**: Generates a proof based on the setup (performed by users)
- **Verify**: Checks the validity of a proof (performed by verifiers)

### Process
The setup process involves the following steps:
1. **Generate witness**: Creates a witness file from the input data and the compiled model.

A witness in this context is a comprehensive record of all the intermediate values and computations performed when running the input through the machine learning model. It includes:
* The input data
* All intermediate layer outputs
* The final output of the model
* Any additional data required for the proof (e.g., random numbers used in the computation)

The witness serves as a "trace" of the computation, allowing the prover to demonstrate knowledge of all the steps involved in running the input through the model without revealing the specific values.

2. **Generate proof**: Uses the witness, proving key, and other artifacts to create a zero-knowledge proof.

### Parameters
To generate a proof, you'll need the following:
- `network.ezkl`: compiled circuit file
- `input.json`: input data file
- `pk.key`: proving key
- `settings.json`: settings file
- `kzg.srs`: structured Reference String (SRS) file

Note that if you performed the Setup phase as instructed on the previous page, the CLI automatically pull from the correct paths and you should not have to specify the above parameters.

### Instructions
+++ Local CLI

1. Generate witness:
```bash
ezkl gen-witness
```
This creates a witness file from your input data and compiled model.

2. Generate proof:
``` bash
ezkl prove
```
This generates a zero-knowledge proof using the witness and other artifacts.

+++ Python

1. Generate witness:
```python
import ezkl

ezkl.gen_witness()
```
This creates a witness file from your input data and compiled model.

2. Generate proof:
```python
ezkl.prove()
```
This generates a zero-knowledge proof using the witness and other artifacts.

+++ JavaScript

1. Generate witness:
```javascript
import { Engine } from '@ezkljs/engine';

const engine = new Engine();
await engine.genWitness();
```
This creates a witness file from your input data and compiled model.

2. Generate proof:
```javascript
await engine.prove();
```
This generates a zero-knowledge proof using the witness and other artifacts.

+++ Remote CLI (Lilith)

1. Generate witness:
```bash
archon job -a test gen-witness
```
This creates a witness file from your input data and compiled model.

2. Generate proof:
```bash
archon job -a test prove
```
This generates a zero-knowledge proof using the witness and other artifacts.

+++
### Outputs
The proof generation process will produce the following:
- `witness.json`: intermediate values computed during the execution of the circuit
- `proof.json`: zero-knowledge proof artifact
165 changes: 165 additions & 0 deletions Getting Started/Setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---
icon: gear
order: 95
---
The lifecycle of an EZKL proof consists of three core components: Setup, Prove, and Verify. This page focuses on the Setup phase, which defines the rules for proof generation and verification. Recall that:
- **Setup**: Defines proof parameters and generates keys (performed by developers)
- **Prove**: Generates a proof based on the setup (performed by users)
- **Verify**: Checks the validity of a proof (performed by verifiers)

### Process
The setup process involves the following steps:
1. **Generate settings**: Creates a configuration file with default parameters for the circuit.
2. **Calibrate settings (optional)**: Fine-tunes the circuit parameters to optimize for either accuracy or resource usage.
3. **Compile the model**: Converts the ONNX model into a format optimized for zero-knowledge proofs.
4. **Run setup**: Generates the cryptographic keys needed for proving and verifying.

### Parameters
To perform the setup, you'll need to provide and/or create the following:

#### ONNX File

For PyTorch:
```python
import torch.onnx

dummy_input = torch.randn(1, 3, 224, 224) # Adjust input dimensions as needed
torch.onnx.export(model, dummy_input, "network.onnx", opset_version=10)
```
For TensorFlow:
```python
import tf2onnx

onnx_model, _ = tf2onnx.convert.from_keras(model)
with open("network.onnx", "wb") as f:
f.write(onnx_model.SerializeToString())
```
#### Structured Reference String (SRS)
The SRS is a common, public piece of cryptographic data. You can download it using the EZKL CLI:
```bash
ezkl get-srs
```
#### Configuration Options
These are defined in the `settings.json` file, which is generated and optionally calibrated during the setup process.

### Instructions
+++ Local CLI

1. Generate settings:
```bash
ezkl gen-settings
```
This creates a settings.json file with default parameters based on your ONNX model.

2. Calibrate settings (optional):
``` bash
ezkl calibrate-settings
```
This optimizes the settings for resource usage. You can also use `--target accuracy` to optimize for accuracy, and `--target resources` to optimize for resources.

3. Compile model:
```bash
ezkl compile-circuit
```
This converts your ONNX model into an optimized format for zero-knowledge proofs, creating the `network.ezkl` file.

4. Run setup:
```bash
ezkl setup
```
This generates the cryptographic keys needed for proving and verifying.

+++ Python

1. Generate settings:
```python
import ezkl

ezkl.gen_settings("network.onnx")
```
This creates a `settings.json` file with default parameters based on your ONNX model.

2. Calibrate settings (optional):
```python
ezkl.calibrate_settings("network.onnx", "settings.json", target="resources")
```
This optimizes the settings for resource usage. You can also use `target="accuracy"` to optimize for accuracy.

3. Compile model:
```python
ezkl.compile_circuit("network.onnx", "network.ezkl", "settings.json")
```
This converts your ONNX model into an optimized format for zero-knowledge proofs, creating the `network.ezkl` file.

4. Run setup:
```python
ezkl.setup("network.ezkl", "vk.key", "pk.key", "kzg.srs")
```
This generates the cryptographic keys needed for proving and verifying.

+++ JavaScript

1. Generate settings:
```javascript
import { Engine } from '@ezkljs/engine';

const engine = new Engine();
await engine.genSettings("network.onnx");
```
This creates a `settings.json` file with default parameters based on your ONNX model.

2. Calibrate settings (optional):
```javascript
await engine.calibrateSettings("network.onnx", "settings.json", { target: "resources" });
```
This optimizes the settings for resource usage. You can also use `{ target: "accuracy" }` to optimize for accuracy.

3. Compile model:
```javascript
await engine.compileCircuit("network.onnx", "network.ezkl", "settings.json");
```
This converts your ONNX model into an optimized format for zero-knowledge proofs, creating the `network.ezkl` file.

4. Run setup:
```javascript
await engine.setup("network.ezkl", "vk.key", "pk.key", "kzg.srs");
```
This generates the cryptographic keys needed for proving and verifying.

+++ Remote CLI (Lilith)
1. Upload your files,
```bash
archon create-artifact -a test -i input.json -m network.onnx -c calibration.json
```

2. Generate settings:
```bash
archon job -a test gen-settings
```
This creates a `settings.json` file with default parameters based on your ONNX model.

3. Calibrate settings (optional):
```bash
archon job -a test calibrate-settings
```
This optimizes the settings for resource usage. You can also use `--target accuracy` to optimize for accuracy, and `--target resources` to optimize for resources.

4. Compile model:
```bash
archon job -a test compile-circuit
```
This converts your ONNX model into an optimized format for zero-knowledge proofs, creating the `network.ezkl` file.

4. Run setup:
```bash
archon job -a test setup
```
This generates the cryptographic keys needed for proving and verifying.
+++
### Outputs
The setup process will generate the following:
- `network.onnx`: model in ONNX format
- `settings.json`: generated file which is optionally calibrated during the setup process
- `network.ezkl`: compiled circuit created from your ONNX model in step 3.
- `kzg.srs`: Structured Reference String (SRS), which you can download using `ezkl get-srs`.
- `vk.key` and `pk.key`: verification and proving keys generated during the setup process
Loading

0 comments on commit 3056db6

Please sign in to comment.