Skip to content

Commit

Permalink
[book] update writing program (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang authored Dec 16, 2024
1 parent aea81bf commit 08e821d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 39 deletions.
14 changes: 14 additions & 0 deletions book/src/custom-extensions/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ On the other hand certain arithmetic operations, particularly modular arithmetic
These steps ensure both performance and security: performance because the modulus is known at compile time, and security because runtime checks confirm that the correct structures have been initialized.

Our design for the configuration procedure above was inspired by the [EVMMAX proposal](https://github.com/jwasinger/EIPs/blob/evmmax-2/EIPS/eip-6601.md).

## Configuration

To use these extensions, you must populate a `openvm.toml` in your package root directory (where the `Cargo.toml` file is located).
We will explain in each extension how to configure the `openvm.toml` file.

The template `openvm.toml` file is as follows:

```toml
[app_vm_config.rv32i]
[app_vm_config.rv32m]
[app_vm_config.io]
# ...
```
43 changes: 4 additions & 39 deletions book/src/writing-apps/write-program.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,6 @@ Even without std, `assert!` and `panic!` can work as normal. To use `std` featur
std = ["openvm/std"]
```

### Building and running

_TODO_: point to CLI installation instructions

First we need to build the program targeting the OpenVM runtime, and that requires some configuration. Put the following in `openvm.toml`:

```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]
```

And run the following command to build the program:

```bash
cargo openvm build --transpile --transpiler-config openvm.toml --transpile-to outputs/fibonacci.vmexe
```

Next we can keygen the generate the proving and verifying keys:

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

Now, to prove the program some input is needed. The input parameter is either a hex string or a file path. So for example if we want to compute the 10th fibonacci number, we can run:

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

No errors should be returned, and the proof should be correctly verified.

## Handling I/O

The program can take input from stdin, with some functions provided by `openvm::io`.
Expand All @@ -82,3 +43,7 @@ let n: u64 = read();
`openvm::io::reveal` sends public values to the final proof (to be read by the smart contract).

For debugging purposes, `openvm::io::print` and `openvm::io::println` can be used normally, but `println!` will only work if `std` is enabled.

### Building and running

See the [overview](./overview.md) on how to build and run the program.

0 comments on commit 08e821d

Please sign in to comment.