From d82f667b85a21773053135180fa4786a4ff4931c Mon Sep 17 00:00:00 2001 From: ndrwnaguib <24280372+ndrwnaguib@users.noreply.github.com> Date: Fri, 15 Nov 2024 20:06:59 -0500 Subject: [PATCH] fixing the installation of risc0 in github workflows --- .github/workflows/static-analysis.yaml | 2 +- .github/workflows/test-coverage.yaml | 15 ++++--- .github/workflows/test.yaml | 12 +++--- .gitignore | 1 + Cargo.toml | 9 ++++- methods/Cargo.toml | 10 +++++ methods/build.rs | 3 ++ methods/guest/Cargo.toml | 9 +++++ methods/guest/src/main.rs | 13 ++++++ methods/src/lib.rs | 1 + src/lib.rs | 56 ++++++++++++++++++++++++++ src/main.rs | 32 +++++++++++++++ 12 files changed, 150 insertions(+), 13 deletions(-) create mode 100644 methods/Cargo.toml create mode 100644 methods/build.rs create mode 100644 methods/guest/Cargo.toml create mode 100644 methods/guest/src/main.rs create mode 100644 methods/src/lib.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index aa04588..77b9b4a 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -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 diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2a82100..f2e6c0e 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e31e810..c582250 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 2457c66..01de987 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ Cargo.lock # Added by cargo +methods/guest/target /target methods/guest/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index f6de7c2..9551dbe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", ] diff --git a/methods/Cargo.toml b/methods/Cargo.toml new file mode 100644 index 0000000..3a86bb0 --- /dev/null +++ b/methods/Cargo.toml @@ -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"] diff --git a/methods/build.rs b/methods/build.rs new file mode 100644 index 0000000..08a8a4e --- /dev/null +++ b/methods/build.rs @@ -0,0 +1,3 @@ +fn main() { + risc0_build::embed_methods(); +} diff --git a/methods/guest/Cargo.toml b/methods/guest/Cargo.toml new file mode 100644 index 0000000..b852049 --- /dev/null +++ b/methods/guest/Cargo.toml @@ -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'] } diff --git a/methods/guest/src/main.rs b/methods/guest/src/main.rs new file mode 100644 index 0000000..65a3f64 --- /dev/null +++ b/methods/guest/src/main.rs @@ -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); +} diff --git a/methods/src/lib.rs b/methods/src/lib.rs new file mode 100644 index 0000000..1bdb308 --- /dev/null +++ b/methods/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/methods.rs")); diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..c33939f --- /dev/null +++ b/src/lib.rs @@ -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(); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0b749ac --- /dev/null +++ b/src/main.rs @@ -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?", + ); +}