Skip to content

Commit ec82829

Browse files
authored
chore: book deploy workflow (#1933)
2 parents ba053c3 + cd8b076 commit ec82829

43 files changed

Lines changed: 2352 additions & 41 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/book.yml

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: book
55

66
on:
77
push:
8-
branches: [dev]
8+
branches: [main]
99
pull_request:
10-
branches: [dev]
10+
branches: [main]
1111
paths:
1212
- "book/**"
1313
merge_group:
@@ -17,51 +17,51 @@ defaults:
1717
working-directory: book
1818

1919
jobs:
20-
# build:
21-
# name: Build Docusaurus
22-
# runs-on: ubuntu-latest
23-
# steps:
24-
# - uses: actions/checkout@v4
25-
# with:
26-
# fetch-depth: 0
27-
# - uses: actions/setup-node@v4
28-
# with:
29-
# node-version: 18
30-
# cache: npm
31-
# cache-dependency-path: book/package-lock.json
20+
build:
21+
name: Build Docusaurus
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version: 18
30+
cache: npm
31+
cache-dependency-path: book/package-lock.json
3232

33-
# - name: Install dependencies
34-
# run: npm ci
33+
- name: Install dependencies
34+
run: npm ci
3535

36-
# - name: Create New Code Refrences
37-
# run: chmod +x gen-code-refs.sh && ./gen-code-refs.sh
36+
- name: Create New Code Refrences
37+
run: chmod +x gen-code-refs.sh && ./gen-code-refs.sh
3838

39-
# - name: Build website
40-
# run: npm run build
39+
- name: Build website
40+
run: npm run build
4141

42-
# - name: Upload Build Artifact
43-
# uses: actions/upload-pages-artifact@v3
44-
# with:
45-
# path: book/build
42+
- name: Upload Build Artifact
43+
uses: actions/upload-pages-artifact@v3
44+
with:
45+
path: book/build
4646

47-
# deploy:
48-
# # Only deploy if a push to main
49-
# if: github.ref_name == 'dev' && github.event_name == 'push'
50-
# runs-on: ubuntu-latest
51-
# needs: [build]
47+
deploy:
48+
# Only deploy if a push to main
49+
if: github.ref_name == 'dev' && github.event_name == 'push'
50+
runs-on: ubuntu-latest
51+
needs: [build]
5252

53-
# # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
54-
# permissions:
55-
# pages: write
56-
# id-token: write
53+
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
54+
permissions:
55+
pages: write
56+
id-token: write
5757

58-
# environment:
59-
# name: github-pages
60-
# url: ${{ steps.deployment.outputs.page_url }}
58+
environment:
59+
name: github-pages
60+
url: ${{ steps.deployment.outputs.page_url }}
6161

62-
# timeout-minutes: 60
62+
timeout-minutes: 60
6363

64-
# steps:
65-
# - name: Deploy to GitHub Pages
66-
# id: deployment
67-
# uses: actions/deploy-pages@v4
64+
steps:
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/deploy-pages@v4
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Common Issues
2+
3+
## Rust Version Errors
4+
5+
If you are using a library that has an MSRV specified, you may encounter an error like this when building your program.
6+
7+
```txt
8+
package `alloy cannot be built because it requires rustc 1.83 or newer, while the currently active rustc version is 1.81.0`
9+
```
10+
11+
This is due to the fact that your current Succinct Rust toolchain has been built with a lower version than the MSRV of the crates you are using.
12+
13+
You can check the version of your local Succinct Rust toolchain by running `cargo +succinct --version`. The latest release of the Succinct Rust toolchain is **1.81**. You can update to the latest version by running [`sp1up`](../getting-started/install.md).
14+
15+
```shell
16+
% sp1up
17+
% cargo +succinct --version
18+
cargo 1.81.0-dev (2dbb1af80 2024-08-20)
19+
```
20+
21+
A Succinct Rust toolchain with version **1.82** should work for all crates that have an MSRV of **1.82** or lower.
22+
23+
If the MSRV of your crate is higher than **1.82**, try the following:
24+
25+
- If using `cargo prove build` directly, pass the `--ignore-rust-version` flag:
26+
27+
```bash
28+
cargo prove build --ignore-rust-version
29+
```
30+
31+
- If using `build_program` in an `build.rs` file with the `sp1-build` crate, set `ignore_rust_version` to true inside the `BuildArgs` struct and use
32+
`build_program_with_args`:
33+
34+
```rust
35+
let args = BuildArgs {
36+
ignore_rust_version: true,
37+
..Default::default()
38+
};
39+
build_program_with_args("path/to/program", args);
40+
```
41+
42+
## `alloy_sol_types` Errors
43+
44+
If you are using a library that depends on `alloy_sol_types`, and encounter an error like this:
45+
46+
```txt
47+
perhaps two different versions of crate `alloy_sol_types` are being used?
48+
```
49+
50+
This is likely due to two different versions of `alloy_sol_types` being used. To fix this, you can set `default-features` to `false` for the `sp1-sdk` dependency in your `Cargo.toml`.
51+
52+
```toml
53+
[dependencies]
54+
sp1-sdk = { version = "4.0.0", default-features = false }
55+
```
56+
57+
This will configure out the `network` feature which will remove the dependency on `alloy_sol_types` and configure out the `NetworkProver`.
58+
59+
## Stack Overflow Errors + Bus Errors
60+
61+
If you encounter any of the following errors in a script using `sp1-sdk`:
62+
63+
```shell
64+
# Stack Overflow Error
65+
thread 'main' has overflowed its stack
66+
fatal runtime error: stack overflow
67+
68+
# Bus Error
69+
zsh: bus error
70+
71+
# Segmentation Fault
72+
Segmentation fault (core dumped)
73+
```
74+
75+
Run your script with the `--release` flag. SP1 currently only supports release builds. This is because
76+
the `sp1-core` library and `sp1-recursion` require being compiled with the `release` profile.
77+
78+
## C Binding Errors
79+
80+
If you are building a program that uses C bindings or has dependencies that use C bindings, you may encounter the following errors:
81+
82+
```txt
83+
cc did not execute successfully
84+
```
85+
86+
```txt
87+
Failed to find tool. Is `riscv32-unknown-elf-gcc` installed?
88+
```
89+
90+
To resolve this, re-install sp1 with the `--c-toolchain` flag:
91+
92+
```bash
93+
sp1up --c-toolchain
94+
```
95+
96+
This will install the C++ toolchain for RISC-V and set the `CC_riscv32im_succinct_zkvm_elf` environment
97+
variable to the path of the installed `riscv32-unknown-elf-gcc` binary. You can also use your own
98+
C++ toolchain be setting this variable manually:
99+
100+
```bash
101+
export CC_riscv32im_succinct_zkvm_elf=/path/to/toolchain
102+
```
103+
104+
## Compilation Errors with [`sp1-lib::syscall_verify_sp1_proof`](https://docs.rs/sp1-lib/latest/sp1_lib/fn.syscall_verify_sp1_proof.html)
105+
106+
If you are using the [`sp1-lib::syscall_verify_sp1_proof`](https://docs.rs/sp1-lib/latest/sp1_lib/fn.syscall_verify_sp1_proof.html) function, you may encounter compilation errors when building your program.
107+
108+
```bash
109+
[sp1] = note: rust-lld: error: undefined symbol: syscall_verify_sp1_proof
110+
[sp1] >>> referenced by sp1_lib.b593533d149f0f6e-cgu.0
111+
[sp1] >>> sp1_lib-8f5deb4c47d01871.sp1_lib.b593533d149f0f6e-cgu.0.rcgu.o:(sp1_lib::verify::verify_sp1_proof::h5c1bb38f11b3fe71) in ...
112+
[sp1]
113+
[sp1]
114+
[sp1] error: could not compile `package-name` (bin "package-name") due to 1 previous error
115+
```
116+
117+
To resolve this, ensure that you're importing both `sp1-lib` and `sp1-zkvm` with the verify feature enabled.
118+
119+
```toml
120+
[dependencies]
121+
sp1-lib = { version = "<VERSION>", features = ["verify"] }
122+
sp1-zkvm = { version = "<VERSION>", features = ["verify"] }
123+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Usage in CI
2+
3+
## Getting started
4+
5+
You may want to use SP1 in your [Github Actions](https://docs.github.com/en/actions) CI workflow.
6+
7+
You first need to have Rust installed, and you can use
8+
[actions-rs/toolchain](https://github.com/actions-rs/toolchain) for this:
9+
10+
```yaml
11+
- name: Install Rust Toolchain
12+
uses: actions-rs/toolchain@v1
13+
with:
14+
toolchain: 1.81.0
15+
profile: default
16+
override: true
17+
default: true
18+
components: llvm-tools, rustc-dev
19+
```
20+
21+
And then you can install the SP1 toolchain:
22+
23+
```yaml
24+
- name: Install SP1 toolchain
25+
run: |
26+
curl -L https://sp1.succinct.xyz | bash
27+
~/.sp1/bin/sp1up
28+
~/.sp1/bin/cargo-prove prove --version
29+
```
30+
31+
You might experience rate limiting from sp1up. Using a Github
32+
[Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) will help.
33+
34+
Try setting a github actions secret to your PAT, and then passing it into the `sp1up` command:
35+
36+
```yaml
37+
- name: Install SP1 toolchain
38+
run: |
39+
curl -L https://sp1.succinct.xyz | bash
40+
~/.sp1/bin/sp1up --token "${{ secrets.GH_PAT }}"
41+
~/.sp1/bin/cargo-prove prove --version
42+
```
43+
44+
## Speeding up your CI workflow
45+
46+
### Caching
47+
48+
To speed up your CI workflow, you can cache the Rust toolchain and Succinct toolchain. See this example
49+
from SP1's CI workflow, which caches the `~/.cargo` and parts of the `~/.sp1` directories.
50+
51+
```yaml
52+
- name: rust-cache
53+
uses: actions/cache@v3
54+
with:
55+
path: |
56+
~/.cargo/bin/
57+
~/.cargo/registry/index/
58+
~/.cargo/registry/cache/
59+
~/.cargo/git/db/
60+
target/
61+
~/.rustup/
62+
~/.sp1/circuits/plonk/ # Cache these if you're generating plonk proofs with docker in CI.
63+
~/.sp1/circuits/groth16/ # Cache these if you're generating groth16 proofs with docker in CI.
64+
key: rust-1.81.0-${{ hashFiles('**/Cargo.toml') }}
65+
restore-keys: rust-1.81.0-
66+
```
67+
68+
### `runs-on` for bigger instances
69+
70+
Since SP1 is a fairly large repository, it might be useful to use [`runs-on`](https://github.com/runs-on/runs-on)
71+
to specify a larger instance type.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import Compressed from "@site/static/examples_fibonacci_script_bin_compressed.rs.mdx";
2+
import Execute from "@site/static/examples_fibonacci_script_bin_execute.rs.mdx";
3+
4+
# Advanced
5+
6+
## Execution Only
7+
8+
We recommend that during the development of large programs (> 1 million cycles) you do not generate proofs each time.
9+
Instead, you should have your script only execute the program with the RISC-V runtime and read `public_values`. Here is an example:
10+
11+
<Execute />
12+
13+
If the execution of your program succeeds, then proof generation should succeed as well! (Unless there is a bug in our zkVM implementation.)
14+
15+
## Logging and Tracing Information
16+
17+
You can use `utils::setup_logger()` to enable logging information respectively. You should only use one or the other of these functions.
18+
19+
**Logging:**
20+
21+
```rust
22+
utils::setup_logger();
23+
```
24+
25+
You must run your command with:
26+
27+
```bash
28+
RUST_LOG=info cargo run --release
29+
```
30+
31+
## CPU Acceleration
32+
33+
To enable CPU acceleration, you can use the `RUSTFLAGS` environment variable to enable the `target-cpu=native` flag when running your script. This will enable the compiler to generate code that is optimized for your CPU.
34+
35+
```bash
36+
RUSTFLAGS='-C target-cpu=native' cargo run --release
37+
```
38+
39+
Currently there is support for AVX512 and NEON SIMD instructions. For NEON, you must also enable the `sp1-sdk` feature `neon` in your script crate's `Cargo.toml` file.
40+
41+
```toml
42+
sp1-sdk = { version = "...", features = ["neon"] }
43+
```
44+
45+
## Performance
46+
47+
For maximal performance, you should run proof generation with the following command and vary your `shard_size` depending on your program's number of cycles.
48+
49+
```rust
50+
SHARD_SIZE=4194304 RUST_LOG=info RUSTFLAGS='-C target-cpu=native' cargo run --release
51+
```
52+
53+
## Memory Usage
54+
55+
To reduce memory usage, set the `SHARD_BATCH_SIZE` environment variable depending on how much RAM
56+
your machine has. A higher number will use more memory, but will be faster.
57+
58+
```rust
59+
SHARD_BATCH_SIZE=1 SHARD_SIZE=2097152 RUST_LOG=info RUSTFLAGS='-C target-cpu=native' cargo run --release
60+
```
61+
62+
## Advanced Allocator
63+
64+
SP1 programs use a simple bump allocator by default, which just increments a pointer to allocate memory. Although this works for many cases, some programs can still run out of memory in the SP1 zkVM. To address this, you can enable the `embedded` allocator feature on the SP1 zkVM.
65+
66+
The embedded allocator uses the [`embedded-alloc` crate](https://crates.io/crates/embedded-alloc) and offers more flexible memory management, albeit with extra cycle overhead.
67+
68+
To enable it, add the following to your `sp1-zkvm` dependency in `Cargo.toml`:
69+
70+
```toml
71+
sp1-zkvm = { version = "...", features = ["embedded"] }
72+
```
73+
74+
Once enabled, the embedded allocator replaces the default bump allocator.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Example from "@site/static/examples_fibonacci_script_src_main.rs.mdx";
2+
3+
# Basics
4+
5+
All the methods you'll need for generating proofs are included in the `sp1_sdk` crate. Most importantly, you'll need to use the `ProverClient` to setup a proving key and verifying key for your program and then use the `execute`, `prove` and `verify` methods to execute your program, and generate and verify proofs.
6+
7+
To make this more concrete, let's walk through a simple example of generating a proof for a Fibonacci program inside the zkVM.
8+
9+
## Example: Fibonacci
10+
11+
<Example />
12+
13+
You can run the above script in the `script` directory with `RUST_LOG=info cargo run --release`. Note that running the above script will generate a proof locally.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Hardware Acceleration
2+
3+
SP1 supports hardware acceleration on the following platforms:
4+
- [AVX256/AVX512](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions) on x86 CPUs
5+
- [CUDA](https://en.wikipedia.org/wiki/CUDA) on Nvidia GPUs
6+
7+
To enable hardware acceleration, please refer to the platform specific instructions available in this section.

0 commit comments

Comments
 (0)