Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
feat: inculde risc0-check to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Feb 13, 2024
1 parent 961696d commit c6a6bc1
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 20 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/risc0-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Check risc0 compatibility
on:
pull_request:
paths:
- .github/workflows/risc0-check.yml
- ci/risc0-check/**
- '**/Cargo.toml'
push:
branches: main
paths:
- .github/workflows/risc0-check.yml
- ci/risc0-check/**
- '**/Cargo.toml'

env:
CARGO_PROFILE_DEV_DEBUG: 1
CARGO_PROFILE_RELEASE_DEBUG: 1
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
RISC0_DEV_MODE: 1

jobs:
risc0-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Install cargo-risc0
run: cargo install cargo-risczero
- name: Install risc0-zkvm toolchain
run: cargo risczero install
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check risc0 compatibility
run: make check-risc0
26 changes: 14 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ on:
paths:
- .github/workflows/rust.yml
- Cargo.toml
- clients/**
- modules/**
- mocks/**
push:
branches: main
paths:
- .github/workflows/rust.yml
- Cargo.toml
- clients/**
- modules/**
- mocks/**

Expand All @@ -35,50 +37,50 @@ jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly # Since fmt uses unstable features for organizing imports
components: rustfmt
override: true
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

doc_all_features:
runs-on: ubuntu-latest
steps:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SOVEREIGN_DEPLOY_KEY }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/cargo@v1
with:
command: doc
args: --all-features --no-deps --release

clippy_all_features:
runs-on: ubuntu-latest
steps:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SOVEREIGN_DEPLOY_KEY }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -90,14 +92,14 @@ jobs:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SOVEREIGN_DEPLOY_KEY }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -110,13 +112,13 @@ jobs:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SOVEREIGN_DEPLOY_KEY }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/cargo@v1
with:
command: test
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/target
target/
/contracts

.idea/
target-path

.DS_Store
**/.DS_Store

demo_data/
/.vscode/*

/ci/**/*.lock
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rust-analyzer.linkedProjects": [
"./ci/risc0-check/methods/guest/Cargo.toml",
"./ci/risc0-check/host/Cargo.toml"
],
"cSpell.words": [
"jsonrpsee",
"Rollup"
]
}
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ members = [
"mocks",
]

exclude = [
"ci/risc0-check"
]

[workspace.package]
version = "0.1.0"
license = "MIT OR Apache-2.0"
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build: ## Build the the entire project
build-sov-celestia-cw: ## Build the WASM file for the sov-celestia-cw light client
@echo "Building the WASM file for the sov-celestia-cw light client"
@RUSTFLAGS='-C link-arg=-s' cargo build -p sov-celestia-client-cw --target wasm32-unknown-unknown --release --lib --locked
@mkdir -p contracts
@mkdir -p contracts
@cp target/wasm32-unknown-unknown/release/sov_celestia_client_cw.wasm contracts/

optimize-contracts: ## Optimize WASM files in contracts directory
Expand All @@ -27,7 +27,7 @@ optimize-contracts: ## Optimize WASM files in contracts directory
optimized_file="contracts/$$(basename $$wasm_file .wasm).opt.wasm"; \
wasm-opt "$$wasm_file" -o "$$optimized_file" -Os; \
done

clean: ## Cleans compiled
@cargo clean

Expand Down Expand Up @@ -57,3 +57,5 @@ test: ## Runs test suite using next test
docs: ## Generates documentation locally
cargo doc --all-features --no-deps --release --open

check-risc0: ## Checks that the project compiles with risc0
cd ci/risc0-check && RISC0_DEV_MODE=1 cargo run
17 changes: 17 additions & 0 deletions ci/risc0-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[workspace]
resolver = "2"
members = ["host", "methods"]

# Always optimize; building and running the guest takes much longer without optimization.
[profile.dev]
opt-level = 3

[profile.dev.build-override]
opt-level = 3

[profile.release]
debug = 1
lto = true

[profile.release.build-override]
opt-level = 3
10 changes: 10 additions & 0 deletions ci/risc0-check/host/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "host-sov-ibc"
version = "0.1.0"
edition = "2021"

[dependencies]
methods = { path = "../methods" }
risc0-zkvm = { version = "0.20.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
serde = "1.0"
23 changes: 23 additions & 0 deletions ci/risc0-check/host/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use methods::{GUEST_SOV_IBC_ELF, GUEST_SOV_IBC_ID};
use risc0_zkvm::{default_prover, ExecutorEnv};

fn main() {
// An example input
let input: u32 = 15 * u32::pow(2, 27) + 1;
let env = ExecutorEnv::builder()
.write(&input)
.unwrap()
.build()
.unwrap();

// Obtain the default prover.
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove(env, GUEST_SOV_IBC_ELF).unwrap();

// An example retrieval of the output from the receipt journal.
let _output: u32 = receipt.journal.decode().unwrap();

receipt.verify(GUEST_SOV_IBC_ID).unwrap();
}
10 changes: 10 additions & 0 deletions ci/risc0-check/methods/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "methods"
version = "0.1.0"
edition = "2021"

[build-dependencies]
risc0-build = { version = "0.20.1" }

[package.metadata.risc0]
methods = ["guest"]
3 changes: 3 additions & 0 deletions ci/risc0-check/methods/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
risc0_build::embed_methods();
}
12 changes: 12 additions & 0 deletions ci/risc0-check/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "guest-sov-ibc"
version = "0.1.0"
edition = "2021"

[workspace]

[dependencies]
sov-ibc = { path = "../../../../modules/sov-ibc" }
sov-ibc-transfer = { path = "../../../../modules/sov-ibc-transfer" }
sov-celestia-client = { path = "../../../../clients/sov-celestia" }
risc0-zkvm = { version = "0.20.1", default-features = false, features = ["std"] }
13 changes: 13 additions & 0 deletions ci/risc0-check/methods/guest/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![no_main]
#![no_std] // std support is experimental

use risc0_zkvm::guest::env;
risc0_zkvm::guest::entry!(main);

fn main() {
// read the input
let input: u32 = env::read();

// write public output to the journal
env::commit(&input);
}
1 change: 1 addition & 0 deletions ci/risc0-check/methods/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/methods.rs"));

0 comments on commit c6a6bc1

Please sign in to comment.