You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/vocs/docs/pages/book/acceleration-using-extensions/overview.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Our design for the configuration procedure above was inspired by the [EVMMAX pro
24
24
25
25
The `openvm` crate provides an `init!` macro to automate the **init** step:
26
26
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.
28
28
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.
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.
29
31
30
32
```rust
31
33
letvm_config=SdkVmConfig::builder()
@@ -35,10 +37,20 @@ The `SdkVmConfig` struct allows you to specify the extensions and system configu
> 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
+
:::
42
54
43
55
## Running a Program
44
56
@@ -52,14 +64,17 @@ To run your program and see the public value output, you can do the following:
52
64
53
65
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.
54
66
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
+
:::
57
71
58
72
## Generating and Verifying Proofs
59
73
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.
61
75
62
76
-[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
63
78
-[EVM Proof](#evm-proof): Generates a halo2 proof that can be posted on-chain
64
79
65
80
## App Proof
@@ -82,19 +97,44 @@ After generating a proof, you can verify it. To do so, you need your verifying k
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.
90
130
91
131
```bash
92
132
cargo openvm setup --evm
93
133
```
94
134
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
+
:::
98
138
99
139
<details>
100
140
<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
> 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
+
:::
120
161
121
162
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.
Copy file name to clipboardExpand all lines: docs/vocs/docs/pages/book/guest-libraries/verify-stark.mdx
+7-5Lines changed: 7 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,11 +28,13 @@ Proofs are expected to be passed via the [hintable key-value store](https://gith
28
28
29
29
The function will panic on failure. Successful STARK verification implies that the app execution was successful and terminated with exit code 0.
30
30
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.
Copy file name to clipboardExpand all lines: docs/vocs/docs/pages/book/writing-apps/compiling-a-program.mdx
+36-6Lines changed: 36 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,43 @@
1
1
# Compiling a Program
2
2
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.
4
6
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:
7
8
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.
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.
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
+
25
94
## Proof Generation
26
95
27
96
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`
42
111
43
112
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.
44
113
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`.
61
115
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).
0 commit comments