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

Completed installation and quickstart sections #1065

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
31 changes: 28 additions & 3 deletions book/src/getting-started/install.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
# Install

TODO: how to install `cargo-openvm`.
`cargo install --git <...>`
To use OpenVM for generating proofs, you must install the OpenVM cli tool `cargo-openvm`.
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved

`cargo-openvm` can be installed in two different ways. You can either install via git url or build from source.
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved

## Install Via Git Url (Recommended)
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved

```bash
cargo install --git ssh://[email protected]/openvm-org/openvm.git cargo-openvm --branch main --locked --force
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved
```

This will globally install `cargo-openvm`. You can validate a successful installation with:

```bash
cargo openvm --version
```

## Build from source

To build from source, you will need the nightly toolchain. You can install it with:

```bash
rustup toolchain install nightly
```

Then, clone the repository and begin the installation.

```bash
git clone https://github.com/openvm-org/openvm.git
cd openvm
cargo install --force --path crates/cli
```

## Toolchain
This will globally install `cargo-openvm`. You can validate a successful installation with:

```bash
cargo openvm --version
```
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 70 additions & 3 deletions book/src/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,36 @@ components = ["clippy", "rustfmt"]
In `Cargo.toml`, add the following dependency:

```toml
[dependencies]
openvm = { git = "https://github.com/openvm-org/openvm.git", features = ["std"] }
```

Note that `std` is not enabled by default, so explicitly enabling it is required.

You will also need to create a configuration file for the vm to use. This will tell OpenVM how to setup zk-specific parameters and which chips to plug in and make available for use by the program. We'll call ours `openvm.toml`.

```toml
# openvm.toml
[app_fri_params]
log_blowup = 2
num_queries = 42
proof_of_work_bits = 16

[app_vm_config.io]
[app_vm_config.rv32i]
[app_vm_config.rv32m]
range_tuple_checker_sizes = [256, 2048]
```

## The fibonacci program

The `read` function takes input from the stdin, and it also works with OpenVM runtime.
The `read` function takes input from the stdin (it also works with OpenVM runtime).

```rust
use openvm::io::read;
/// src/main.rs
use openvm::io::{read, reveal};

openvm::entry!(main);

fn main() {
let n: u64 = read();
Expand All @@ -41,6 +61,53 @@ fn main() {
a = b;
b = c;
}
println!("{}", a);
reveal(a as u32, 0);
reveal((a >> 32) as u32, 1);
}
```

## Build

To build the program, run:

```bash
cargo openvm build --transpile --transpiler-config openvm.toml --transpile-to outputs/fibonacci.vmexe
jonathanpwang marked this conversation as resolved.
Show resolved Hide resolved
```

The argument passed to `--transpile-to` is the name of the executable file to be generated.

## Keygen

Before generating any proofs, we will also need to generate the proving and verification keys.

```bash
cargo openvm keygen --config openvm.toml --output outputs/pk --vk-output outputs/vk
```

## Proof Generation

Now we are ready to generate a proof! Simply run:

```bash
cargo openvm prove app --app-pk outputs/pk --exe outputs/fibonacci.vmexe --input "0x0A00000000000000" --output outputs/proof
```

The `--input` field is passed to the program which receives it via the `io::read` function. Note that this value must be padded to 8 bytes (32 bits) _in little-endian format_ since it represents a field element on the Baby Bear field.

## Proof Verification

Finally, the proof can be verified.

```bash
cargo openvm verify app --app-vk outputs/vk --proof outputs/proof
```

The process should exit quite quickly with no errors.

## Runtime Execution

If necessary, the executable can also be run _without_ proof generation. This can be useful for testing purposes.

```bash
cargo openvm run --exe outputs/fibonacci.vmexe --config openvm.toml --input "0x0A00000000000000"
```