Skip to content

Commit

Permalink
fixing the installation of risc0 in github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrwnaguib committed Nov 16, 2024
1 parent 65aab18 commit d82f667
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
rustup component add clippy --toolchain nightly-2023-12-21
rustup component add rustfmt --toolchain nightly-2023-12-21
curl -L https://risczero.com/install | bash
rzup install
~/.risc0/bin/rzup install
cargo risczero --version
# Run pre-commit hooks
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install Rust toolchain 1.74
run: rustup toolchain install nightly-2023-12-21
- name: Install Rust nightly (edition 2024 support)
run: |
rustup install nightly
rustup default nightly
- name: Set Rust nightly for edition 2024
run: rustup override set nightly

- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Run tests with coverage
run: cargo llvm-cov --all-features --workspace --html --output-dir=target/llvm-cov/html
run: cargo llvm-cov --all-features --workspace --html

- name: Upload coverage report
uses: actions/upload-artifact@v3
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ jobs:
- uses: actions/setup-python@v4

# Install Rust toolchain and components
- name: Install Rust toolchain (nightly-2023-12-21) with Clippy and Rustfmt
- name: Install Rust with Clippy and Rustfmt
run: |
rustup toolchain install nightly-2023-12-21
rustup component add clippy --toolchain nightly-2023-12-21
rustup component add rustfmt --toolchain nightly-2023-12-21
rustup install nightly
rustup default nightly
rustup override set nightly
rustup component add clippy
rustup component add rustfmt
curl -L https://risczero.com/install | bash
rzup install
~/.risc0/bin/rzup install
cargo risczero --version
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Cargo.lock

# Added by cargo

methods/guest/target
/target

methods/guest/Cargo.lock
Expand Down
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
cargo-features = ["edition2024"]

[package]
name = "zk-auctions"
version = "0.1.0"
edition = "2024"

[dependencies]
zk-auctions-methods = { path = "methods" }
risc0-zkvm = "v1.1.3"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[features]
cuda = ["risc0-zkvm/cuda"]
default = []
prove = ["risc0-zkvm/prove"]

[workspace]

resolver = "2"

members = [
"host",
"methods",
]

Expand Down
10 changes: 10 additions & 0 deletions 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 = "2024"

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

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

[workspace]

[dependencies]
risc0-zkvm = { version = "1.1.2", default-features = false, features = ['std'] }
13 changes: 13 additions & 0 deletions methods/guest/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use risc0_zkvm::guest::env;

fn main() {
// TODO: Implement your guest code here

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

// TODO: do something with the input

// write public output to the journal
env::commit(&input);
}
1 change: 1 addition & 0 deletions methods/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
56 changes: 56 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use methods::{
HELLO_GUEST_ELF, HELLO_GUEST_ID
};
use risc0_zkvm::{default_prover, ExecutorEnv};

fn main() {
// Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
.init();

// An executor environment describes the configurations for the zkVM
// including program inputs.
// An default ExecutorEnv can be created like so:
// `let env = ExecutorEnv::builder().build().unwrap();`
// However, this `env` does not have any inputs.
//
// To add guest input to the executor environment, use
// ExecutorEnvBuilder::write().
// To access this method, you'll need to use ExecutorEnv::builder(), which
// creates an ExecutorEnvBuilder. When you're done adding input, call
// ExecutorEnvBuilder::build().

// For example:
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();

// Proof information by proving the specified ELF binary.
// This struct contains the receipt along with statistics about execution of the guest
let prove_info = prover
.prove(env, HELLO_GUEST_ELF)
.unwrap();

// extract the receipt.
let receipt = prove_info.receipt;

// TODO: Implement code for retrieving receipt journal here.

// For example:
let _output: u32 = receipt.journal.decode().unwrap();

// The receipt was verified at the end of proving, but the below code is an
// example of how someone else could verify this receipt.
receipt
.verify(HELLO_GUEST_ID)
.unwrap();
}
32 changes: 32 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use hello_world::multiply;
use hello_world_methods::MULTIPLY_ID;

fn main() {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();

// Pick two numbers
let (receipt, _) = multiply(17, 23);

// Here is where one would send 'receipt' over the network...

// Verify receipt, panic if it's wrong
receipt.verify(MULTIPLY_ID).expect(
"Code you have proven should successfully verify; did you specify the correct image ID?",
);
}

0 comments on commit d82f667

Please sign in to comment.