Skip to content

Commit fd362bc

Browse files
feat: update docs for SDK updates (#1990)
Closes INT-4553, INT-4750 --------- Co-authored-by: Jonathan Wang <[email protected]>
1 parent aad0172 commit fd362bc

File tree

16 files changed

+302
-167
lines changed

16 files changed

+302
-167
lines changed

docs/vocs/docs/pages/book/acceleration-using-extensions/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Our design for the configuration procedure above was inspired by the [EVMMAX pro
2424

2525
The `openvm` crate provides an `init!` macro to automate the **init** step:
2626
1. Call `openvm::init!()` exactly once in the code of the final program binary.
27-
2. When [compiling the program](/book/writing-apps/compiling), `cargo openvm build` will read the [configuration file](#configuration) to automatically generate the correct init code and write it to `<INIT_FILE_NAME>`, which defaults to `openvm_init.rs` in the manifest directory.
27+
2. When [compiling the program](/book/writing-apps/compiling-a-program), `cargo openvm build` will read the [configuration file](#configuration) to automatically generate the correct init code and write it to `<INIT_FILE_NAME>`, which defaults to `openvm_init.rs` in the manifest directory.
2828
3. The `openvm::init!()` macro will include the `openvm_init.rs` file into the final binary to complete the init process. You can call `openvm::init!(INIT_FILE_NAME)` to include init code from a different file if needed.
2929

3030
## Configuration

docs/vocs/docs/pages/book/advanced-usage/sdk.mdx

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ The SDK provides lower-level control over the building and transpiling process.
2323
// [!include ~/snippets/examples_sdk/sdk_stark.rs:transpilation]
2424
```
2525

26-
### Using `SdkVmConfig`
26+
### Customizing the VM Configuration
2727

28-
The `SdkVmConfig` struct allows you to specify the extensions and system configuration your VM will use. To customize your own configuration, you can use the `SdkVmConfig::builder()` method and set the extensions and system configuration you want.
28+
To use a custom VM configuration, you can construct your own `GenericSdk` object which includes the
29+
extensions and system configuration your VM will use. To do this, you can use the `SdkVmConfig::builder()`
30+
method and set the desired extensions and system configuration as in the example below.
2931

3032
```rust
3133
let vm_config = SdkVmConfig::builder()
@@ -35,10 +37,20 @@ The `SdkVmConfig` struct allows you to specify the extensions and system configu
3537
.io(Default::default())
3638
.build()
3739
.optimize();
40+
let sdk = Sdk::new(
41+
AppConfig::new(FriParameters::standard_fast(), vm_config)
42+
)?;
3843
```
3944

40-
> ℹ️
41-
> When using Rust to write the guest program, the VM system configuration should keep the default value `pointer_max_bits = 29` to match the hardcoded memory limit of the memory allocator. Otherwise, the guest program may fail due to out of bounds memory access in the VM.
45+
The following convenience methods are also available to construct a `GenericSdk` object:
46+
47+
- `Sdk::riscv32()` returns a `GenericSdk` supporting the RV32IM extension.
48+
- `Sdk::standard()` returns a `GenericSdk` supporting all default OpenVM extensions, including RV32IM.
49+
- `Sdk::new(Sdk::from_toml(openvm.toml))` returns a `GenericSdk` from a custom OpenVM configuration specified in an `openvm.toml` file.
50+
51+
:::info
52+
When using Rust to write the guest program, the VM system configuration should keep the default value `pointer_max_bits = 29` to match the hardcoded memory limit of the memory allocator. Otherwise, the guest program may fail due to out of bounds memory access in the VM.
53+
:::
4254

4355
## Running a Program
4456

@@ -52,14 +64,17 @@ To run your program and see the public value output, you can do the following:
5264

5365
The `StdIn` struct allows you to format any serializable type into a VM-readable format by passing in a reference to your struct into `StdIn::write` as above. You also have the option to pass in a `&[u8]` into `StdIn::write_bytes`, or a `&[F]` into `StdIn::write_field` where `F` is the `openvm_stark_sdk::p3_baby_bear::BabyBear` field type.
5466

55-
> **Generating CLI Bytes**
56-
> To get the VM byte representation of a serializable struct `data` (i.e. for use in the CLI), you can print out the result of `openvm::serde::to_vec(data).unwrap()` in a Rust host program.
67+
:::info
68+
**Generating CLI Bytes**
69+
To get the VM byte representation of a serializable struct `data` (i.e. for use in the CLI), you can print out the result of `openvm::serde::to_vec(data).unwrap()` in a Rust host program.
70+
:::
5771

5872
## Generating and Verifying Proofs
5973

60-
There are two types of proofs that you can generate, with the sections below continuing from this point.
74+
OpenVM supports generating three types of proofs. The sections below describe how to generate and verify each type of proof.
6175

6276
- [App Proof](#app-proof): Generates STARK proof(s) of the guest program
77+
- [STARK Proof](#stark-proof): Generates a STARK proof that can be posted on-chain
6378
- [EVM Proof](#evm-proof): Generates a halo2 proof that can be posted on-chain
6479

6580
## App Proof
@@ -82,19 +97,44 @@ After generating a proof, you can verify it. To do so, you need your verifying k
8297
// [!include ~/snippets/examples_sdk/sdk_stark.rs:verification]
8398
```
8499

100+
## STARK Proof
101+
102+
### Setup
103+
104+
To generate a STARK proof, you first need to generate proving and verification keys for STARK aggregation using the following command:
105+
106+
```bash
107+
cargo openvm setup
108+
```
109+
110+
### STARK Proof Generation and Verification
111+
112+
You can now run the aggregation keygen, proof, and verification functions for the STARK proof.
113+
114+
```rust
115+
// [!include ~/snippets/examples_sdk/sdk_stark.rs:proof_generation]
116+
```
117+
118+
Once the proof is generated, you can verify it using the SDK as follows:
119+
120+
```rust
121+
// [!include ~/snippets/examples_sdk/sdk_stark.rs:verification]
122+
```
123+
85124
## EVM Proof
86125

87126
### Setup
88127

89-
To generate an EVM proof, you'll first need to ensure that you have followed the [CLI installation steps](/book/getting-started/install). get the appropriate KZG params by running the following command.
128+
To generate an EVM proof, you'll first need to ensure that you have followed the [CLI installation steps](/book/getting-started/install)
129+
to generate proving and verification keys for EVM proving.
90130

91131
```bash
92132
cargo openvm setup --evm
93133
```
94134

95-
> ⚠️ **WARNING**
96-
>
97-
> `cargo openvm setup --evm` requires very large amounts of computation and memory (~200 GB).
135+
:::warning
136+
`cargo openvm setup --evm` requires a large amount of computation and memory (~70 GB).
137+
:::
98138

99139
<details>
100140
<summary>Also note that there are additional dependencies for the EVM Proof flow. Click here to view.</summary>
@@ -115,7 +155,8 @@ You can now run the aggregation keygen, proof, and verification functions for th
115155
// [!include ~/snippets/examples_sdk/sdk_evm.rs:evm_verification]
116156
```
117157

118-
> ⚠️ **WARNING**
119-
> The aggregation proving key `agg_pk` above is large. Avoid cloning it if possible.
158+
:::warning
159+
The halo2 aggregation proving key `agg_halo2.pk` used in the above example is large. Avoid cloning it if possible.
160+
:::
120161

121162
Note that `DEFAULT_PARAMS_DIR` is the directory where Halo2 parameters are stored by the `cargo openvm setup --evm` CLI command. For more information on the setup process, see the `EVM Level` section of the [verify](/book/writing-apps/verifying-proofs) doc.

docs/vocs/docs/pages/book/getting-started/install.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ rustup component add rust-src --toolchain nightly-2025-02-14
5252
# install build tools for Ubuntu
5353
sudo apt update
5454
sudo apt install -y build-essential # gcc, g++, make, libc headers
55+
56+
# install Solidity compiler, only needed for EVM proofs
57+
cargo install --version 0.5.7 svm-rs
58+
# Add the binary to your path
59+
export PATH="$HOME/.cargo/bin:$PATH"
60+
61+
# Install solc 0.8.19
62+
svm install 0.8.19
63+
svm use 0.8.19
5564
```
5665

5766
```bash [macOS]
@@ -66,4 +75,13 @@ rustup component add rust-src --toolchain nightly-2025-02-14
6675
# install build tools for macOS
6776
xcode-select --install
6877
brew install cmake git curl
78+
79+
# install Solidity compiler, only needed for EVM proofs
80+
cargo install --version 0.5.7 svm-rs
81+
# Add the binary to your path
82+
export PATH="$HOME/.cargo/bin:$PATH"
83+
84+
# Install solc 0.8.19
85+
svm install 0.8.19
86+
svm use 0.8.19
6987
```

docs/vocs/docs/pages/book/getting-started/quickstart.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,14 @@ To build the program, run:
4949
cargo openvm build
5050
```
5151

52-
This will output an OpenVM executable file to `./target/openvm/release/fibonacci.vmexe`.
52+
This will output:
53+
54+
- an RV32IM ELF containing [custom OpenVM instructions](/specs/reference/riscv-custom-code) at `./target/riscv32im-risc0-zkvm-elf/release/fibonacci`
55+
- an OpenVM executable binary at `./target/openvm/release/fibonacci.vmexe`
5356

5457
## Keygen
5558

56-
Before generating any proofs, we will also need to generate the proving and verification keys.
59+
Before generating proofs, we will also need to generate the proving and verification keys using:
5760

5861
```bash
5962
cargo openvm keygen
@@ -86,7 +89,7 @@ The process should exit with no errors.
8689

8790
## Runtime Execution
8891

89-
If necessary, the executable can also be run _without_ proof generation. This can be useful for testing purposes.
92+
The OpenVM binary can also be executed without generating a proof, which can be useful for testing purposes.
9093

9194
```bash
9295
cargo openvm run --input "0x010A00000000000000"

docs/vocs/docs/pages/book/guest-libraries/verify-stark.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ Proofs are expected to be passed via the [hintable key-value store](https://gith
2828

2929
The function will panic on failure. Successful STARK verification implies that the app execution was successful and terminated with exit code 0.
3030

31-
> ⚠️ For Advanced Users
32-
>
33-
> Note that if your guest program directly writes data to the native address space (address space 4), the `verify_stark` function will likely overwrite it. Any data the guest placed in the native address space should be persisted (or treated as corrupt) before invocations to `verify_stark`.
34-
>
35-
> This is not a concern if you are writing vanilla rust with the default RV32 I and M extensions.
31+
:::warning
32+
**For Advanced Users**
33+
34+
Note that if your guest program directly writes data to the native address space (address space 4), the `verify_stark` function will likely overwrite it. Any data the guest placed in the native address space should be persisted (or treated as corrupt) before invocations to `verify_stark`.
35+
36+
This is not a concern if you are writing vanilla rust with the default RV32 I and M extensions.
37+
:::
3638

3739
## Host
3840

docs/vocs/docs/pages/book/writing-apps/compiling.mdx renamed to docs/vocs/docs/pages/book/writing-apps/compiling-a-program.mdx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
11
# Compiling a Program
22

3-
First let's define some key terms used in cross-compilation:
3+
Once you have written a program to be proven by OpenVM, you need to compile it in a way
4+
which is compatible with OpenVM. This will involve **cross-compiling** the program by
5+
building it for a machine architecture which differs from the machine performing the build.
46

5-
- **host** - the machine you're compiling and/or proving on. Note that one can compile and prove on different machines, but they are both called _host_ as they are traditional machine architectures.
6-
- **guest** - the executable to be run in a different VM architecture (e.g. the OpenVM runtime, or Android app).
7+
To explain how this works for OpenVM, we will use the following key terms:
78

8-
The command `cargo openvm build` compiles the program on host to an executable for guest target.
9-
It first compiles the program normally on your _host_ platform with RISC-V and then transpiles it to a different target. See here for some explanation of [cross-compilation](https://rust-lang.github.io/rustup/cross-compilation.html).
10-
Right now we use `riscv32im-risc0-zkvm-elf` target which is available in the [Rust toolchain](https://doc.rust-lang.org/rustc/platform-support/riscv32im-risc0-zkvm-elf.html), but we will contribute an OpenVM target to Rust in the future.
9+
- **Host**: The machine architecture being used for building and proving. Though building and proving can be done on different machine architectures, they are both called **host** architectures since they are not the architecture used to specify the program.
10+
- **Guest**: The machine architecture being used to express the program to be proven, which is the OpenVM runtime in this case. We refer to programs written to be proven by OpenVM as **guest programs**.
11+
12+
## Building Guest Programs for OpenVM
13+
14+
To prove a guest program in OpenVM, we must build it for a RISC-V guest target and then transpile
15+
it to a format natively supported by OpenVM. We provide the following CLI command to do this:
16+
17+
```bash
18+
cargo openvm build
19+
```
20+
21+
The presently supported guest target is `riscv32im-risc0-zkvm-elf` due to its official support by
22+
the [Rust toolchain](https://doc.rust-lang.org/rustc/platform-support/riscv32im-risc0-zkvm-elf.html).
23+
We anticipate upstreaming an OpenVM-specific target to Rust in the future. More details about
24+
how cross-compilation works in Rust can be found in the [Rust docs](https://rust-lang.github.io/rustup/cross-compilation.html).
25+
26+
## Generating Commitments for Guest Programs
27+
28+
Once you have built the guest program, you can extract commitments to the program binary and
29+
the VM configuration using the following CLI command:
30+
31+
```bash
32+
cargo openvm commit
33+
```
34+
35+
This will generate a `*.commit.json` file in `${target_dir}/openvm/release/` containing:
36+
37+
- `app_exe_commit`: A commitment to the OpenVM program binary.
38+
- `app_vm_commit`: A commitment to the OpenVM configuration used for the program binary.
39+
40+
These values will be used later when verifying proofs generated by OpenVM for this program.
1141

1242
## Build Flags
1343

docs/vocs/docs/pages/book/writing-apps/generating-proofs.mdx

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
Generating a proof using the CLI is simple - first generate a key, then generate your proof. Using command defaults, this looks like:
44

55
```bash
6-
cargo openvm keygen
7-
cargo openvm prove [app | stark | evm]
6+
cargo openvm keygen # generate proving and verification keys for app proofs
7+
cargo openvm prove app # generate the app proof
8+
9+
cargo openvm setup # generate proving and verification keys for STARK aggregation
10+
cargo openvm prove stark # generate the STARK proof
11+
12+
cargo openvm setup --evm # generate proving and verification keys for EVM proofs
13+
cargo openvm prove evm # generate the EVM proof
814
```
915

10-
## Key Generation
16+
## Application Key Generation
1117

1218
The `keygen` command generates both an application proving and verification key.
1319

1420
```bash
15-
cargo openvm keygen
16-
--config <path_to_app_config>
21+
cargo openvm keygen --config <path_to_app_config>
1722
```
1823

1924
Similarly to `build`, `run`, and `prove`, options `--manifest-path`, `--target-dir`, and `--output-dir` are provided.
@@ -22,6 +27,70 @@ If `--config` is not specified, the command will search for `openvm.toml` in the
2227

2328
The proving and verification key will be written to `${target_dir}/openvm/` (and `--output-dir` if specified).
2429

30+
## STARK and EVM Key Generation
31+
32+
The `setup` command generates proving and verification keys for STARK aggregation and EVM proofs.
33+
34+
```bash
35+
cargo openvm setup [--evm]
36+
```
37+
38+
If called without the `--evm` flag, it will generate keys for the leaf, internal, and root STARK
39+
verifiers as detailed in the [specs](/specs/architecture/continuations). If called with the `--evm`
40+
flag, it will also generate keys for the [static verifier wrapper](/specs/architecture/continuations#static-verifier-wrapper).
41+
42+
### Details on EVM Verification
43+
44+
In addition to generating EVM proving and verification keys, `cargo openvm setup --evm` also
45+
generates a smart contract verifier for EVM chains. Upon a successful run, the command will write the files
46+
47+
- `agg_stark.pk`
48+
- `agg_stark.vk`
49+
- `agg_halo2.pk`
50+
- `halo2/src/[OPENVM_VERSION]/Halo2Verifier.sol`
51+
- `halo2/src/[OPENVM_VERSION]/OpenVmHalo2Verifier.sol`
52+
- `halo2/src/[OPENVM_VERSION]/interfaces/IOpenVmHalo2Verifier.sol`
53+
- `halo2/src/[OPENVM_VERSION]/verifier.bytecode.json`
54+
55+
to `~/.openvm/`, where `~` is the directory specified by environment variable `$HOME` and
56+
`OPENVM_VERSION` is the version of OpenVM. Every command that requires these files will
57+
look for them in this directory. The smart contract verifier is also available via the
58+
[OpenVM Solidity SDK](/book/writing-apps/solidity-sdk) for released versions of OpenVM.
59+
60+
The files `agg_stark.pk` and `agg_halo2.pk` are the STARK and Halo2 aggregation proving keys necessary to aggregate to a final EVM proof.
61+
The file `agg_stark.vk` is the STARK aggregation verification key.
62+
The `OpenVmHalo2Verifier.sol` file contains a Solidity contract to verify the final EVM proof. The contract is named `OpenVmHalo2Verifier` and it implements the `IOpenVmHalo2Verifier` interface.
63+
64+
```solidity [IOpenVmHalo2Verifier.sol]
65+
interface IOpenVmHalo2Verifier {
66+
function verify(bytes calldata publicValues, bytes calldata proofData, bytes32 appExeCommit, bytes32 appVmCommit)
67+
external
68+
view;
69+
}
70+
```
71+
72+
In addition, the command outputs a JSON file `verifier.bytecode.json` of the form
73+
74+
```json [verifier.bytecode.json]
75+
{
76+
"sol_compiler_version": "0.8.19",
77+
"sol_compiler_options": "",
78+
"bytecode": "0x..."
79+
}
80+
```
81+
82+
where `sol_compiler_version` is the Solidity compiler version used to compile the contract (currently `0.8.19`),
83+
`sol_compiler_options` are additional compiler options used, and
84+
`bytecode` is the compiled EVM bytecode as a hex string.
85+
86+
:::note
87+
Note that `cargo openvm setup --evm` downloads auxiliary files for halo2 KZG parameters from an AWS S3 bucket into `~/.openvm/`.
88+
:::
89+
90+
:::warning
91+
If the `$HOME` environment variable is not set, this command may fail. This command requires a large amount of compute and memory (~70 GB) and can take ~7mins on a `m6a.16xlarge` instance.
92+
:::
93+
2594
## Proof Generation
2695

2796
The `prove` CLI command, at its core, uses the options below. `prove` gets access to all of the options that `run` has (see [Running a Program](/book/writing-apps/running-a-program) for more information).
@@ -42,21 +111,10 @@ If your program doesn't require inputs, you can (and should) omit the `--input`
42111

43112
If `--proof` is not provided then the command will write the proof to `./${bin_name}.[app | stark | evm].proof` by default, where `bin_name` is the file stem of the executable run.
44113

45-
The `app` subcommand generates an application-level proof, the `stark` command generates an aggregated root-level proof, while the `evm` command generates an end-to-end EVM proof. For more information on aggregation, see [this specification](https://github.com/openvm-org/openvm/blob/bf8df90b13f4e80bb76dbb71f255a12154c84838/docs/specs/continuations.md).
46-
47-
> ⚠️ **WARNING**
48-
> In order to run the `evm` subcommand, you must have previously called the costly `cargo openvm setup --evm`, which requires very large amounts of computation and memory (~200 GB).
49-
50-
See [EVM Proof Format](./verifying-proofs#evm-proof-json-format) for details on the output format for `cargo openvm prove evm`.
51-
52-
## Commit Hashes
53-
54-
To see the commit hash for an executable, you may run:
55-
56-
```bash
57-
cargo openvm commit
58-
--app-pk <path_to_app_pk>
59-
--exe <path_to_transpiled_program>
60-
```
114+
The `app` subcommand generates an application-level proof, the `stark` command generates an aggregated root-level proof, while the `evm` command generates an end-to-end EVM proof. For more information on aggregation, see [this specification](https://github.com/openvm-org/openvm/blob/bf8df90b13f4e80bb76dbb71f255a12154c84838/docs/specs/continuations.md). See [EVM Proof Format](./verifying-proofs#evm-proof-json-format) for details on the output format for `cargo openvm prove evm`.
61115

62-
The `commit` command has all the auxiliary options that `prove` does, and outputs Bn254 commits for both your executable and VM. Commits are written to `${target_dir}/openvm/` (and `--output-dir` if specified).
116+
:::warning
117+
The `stark` subcommand requires STARK aggregation key generation to have been run via
118+
`cargo openvm setup`, and the `evm` subcommand requires EVM key generation to have been run via
119+
`cargo openvm setup --evm`, which has a large compute and memory requirement (~70 GB).
120+
:::

0 commit comments

Comments
 (0)