From ebd1755f275479ee85ed83b5df022fb093736206 Mon Sep 17 00:00:00 2001 From: "xander.z" <162873981+xander42280@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:18:36 +0800 Subject: [PATCH] Feat/proving cycles (#42) * Add total_steps * Update install_mips_rust_tool * Update revme dependencies * Update README for install toolchain * Update version --- README.md | 8 ++++ guest-program/revme/Cargo.toml | 3 -- host-program/mem-alloc-vec/Cargo.toml | 2 +- host-program/revme/Cargo.toml | 2 +- host-program/sha2-go/Cargo.toml | 2 +- host-program/sha2-rust/Cargo.toml | 2 +- install_mips_rust_tool | 61 --------------------------- sdk/Cargo.toml | 2 +- sdk/src/local/stark.rs | 3 +- sdk/src/network/prover.rs | 1 + sdk/src/proto/stage.proto | 1 + sdk/src/prover.rs | 1 + 12 files changed, 18 insertions(+), 70 deletions(-) delete mode 100755 install_mips_rust_tool diff --git a/README.md b/README.md index fef4645f..ead5d772 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,14 @@ There are two ways to prove the guest program: ![image](assets/temp-run-diagram.png) +## Getting Started + +First to install zkm toolchain run the following command and follow the instructions: +```sh +curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/zkMIPS/toolchain/refs/heads/main/setup.sh | sh +source ~/.zkm-toolchain/env +``` + ## Template code structure > [!NOTE] diff --git a/guest-program/revme/Cargo.toml b/guest-program/revme/Cargo.toml index cdffb6a7..5629b459 100644 --- a/guest-program/revme/Cargo.toml +++ b/guest-program/revme/Cargo.toml @@ -17,9 +17,6 @@ serde = { version = "1.0", default-features = false, features = ["alloc", "deriv serde_json = { version = "1.0", default-features = false, features = ["alloc"] } k256 = { version = "0.13.3", features = ["ecdsa"], default-features = false } -# TODO can be removed once the powdr RISCV nightly is updated -ahash = { version = "=0.8.6", default-features = false } - libc = { version = "0.2" , features = ["extra_traits"] } [profile.dev] diff --git a/host-program/mem-alloc-vec/Cargo.toml b/host-program/mem-alloc-vec/Cargo.toml index b048f7e6..cb515a3b 100644 --- a/host-program/mem-alloc-vec/Cargo.toml +++ b/host-program/mem-alloc-vec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mem-alloc-vec" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/host-program/revme/Cargo.toml b/host-program/revme/Cargo.toml index a60f714d..fd77c127 100644 --- a/host-program/revme/Cargo.toml +++ b/host-program/revme/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revme" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/host-program/sha2-go/Cargo.toml b/host-program/sha2-go/Cargo.toml index c9a5b4ed..bc6e0a61 100644 --- a/host-program/sha2-go/Cargo.toml +++ b/host-program/sha2-go/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sha2-go" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/host-program/sha2-rust/Cargo.toml b/host-program/sha2-rust/Cargo.toml index 1b47a7fc..96ab0fb2 100644 --- a/host-program/sha2-rust/Cargo.toml +++ b/host-program/sha2-rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sha2-rust" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/install_mips_rust_tool b/install_mips_rust_tool deleted file mode 100755 index e7b722b4..00000000 --- a/install_mips_rust_tool +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -# Reference: https://github.com/foundry-rs/foundry/blob/master/foundryup/install - -set -e - -echo "🚀 Installing mips-linux-muslsf-cross..." && echo - -BASE_DIR=$HOME -MIPS_DIR=${MIPS_DIR-"$BASE_DIR/.mipsrust"} -MIPS_BIN_DIR="$MIPS_DIR/mips-linux-muslsf-cross/bin" - -MIPS_TOOL_URL="http://musl.cc/mips-linux-muslsf-cross.tgz" - -# Create the mips tool directory . -mkdir -p $MIPS_DIR - -echo && echo "Downloading $MIPS_TOOL_URL..." -wget "$MIPS_TOOL_URL" -O "mips-linux-muslsf-cross.tgz" - -if [ ! -f "mips-linux-muslsf-cross.tgz" ]; then - echo && echo "Download failed." - exit 1 -fi - -echo && echo "Unpacking to $MIPS_DIR..." -tar -xzf "mips-linux-muslsf-cross.tgz" -C "$MIPS_DIR" - -if [ ! -d "$MIPS_BIN_DIR" ]; then - echo && echo "Unpack failed." - exit 1 -fi - -echo && echo "Cleaning up..." -rm "mips-linux-muslsf-cross.tgz" - -CONFIG_FILE="$HOME/.cargo/config" - -touch $CONFIG_FILE - -TARGET_CONFIG="[target.mips-unknown-linux-musl] -linker = \"$MIPS_BIN_DIR/mips-linux-muslsf-gcc\" -rustflags = [\"--cfg\", 'target_os=\"zkvm\"',\"-C\", \"target-feature=+crt-static\", \"-C\", \"link-arg=-g\"]" - - -if [ -f "$CONFIG_FILE" ]; then - - if grep -q "target.mips-unknown-linux-musl" "$CONFIG_FILE"; then - echo && echo "Target configuration already exists in $CONFIG_FILE." - else - - echo && echo "$TARGET_CONFIG" >> "$CONFIG_FILE" - echo && echo "Target configuration added to $CONFIG_FILE." - fi -else - echo && echo "$CONFIG_FILE does not exists, please check your rust setting." - exit 1 -fi - -echo && echo "✅ Installation complete!" - diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 37d13000..3ef8a78c 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zkm-sdk" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/sdk/src/local/stark.rs b/sdk/src/local/stark.rs index 1c0dcfce..792fe2a9 100644 --- a/sdk/src/local/stark.rs +++ b/sdk/src/local/stark.rs @@ -20,8 +20,9 @@ pub fn prove_stark( state.input_stream.push(input.public_inputstream.clone()); state.input_stream.push(input.private_inputstream.clone()); - let (_total_steps, seg_num, state) = split_prog_into_segs(state, &seg_path, "", seg_size); + let (total_steps, seg_num, state) = split_prog_into_segs(state, &seg_path, "", seg_size); result.output_stream = state.public_values_stream.clone(); + result.total_steps = total_steps as u64; if input.execute_only { return Ok(false); } diff --git a/sdk/src/network/prover.rs b/sdk/src/network/prover.rs index eb463f6f..9f3617ab 100644 --- a/sdk/src/network/prover.rs +++ b/sdk/src/network/prover.rs @@ -160,6 +160,7 @@ impl Prover for NetworkProver { stark_proof: vec![], solidity_verifier: vec![], public_values: vec![], + total_steps: get_status_response.total_steps, }; if !get_status_response.stark_proof_url.is_empty() { proof_result.stark_proof = diff --git a/sdk/src/proto/stage.proto b/sdk/src/proto/stage.proto index 253e65cc..6fd87e4c 100644 --- a/sdk/src/proto/stage.proto +++ b/sdk/src/proto/stage.proto @@ -73,4 +73,5 @@ message GetStatusResponse { bytes output_stream = 7; int32 step = 8; // Step string public_values_url = 9; + uint64 total_steps = 10; } \ No newline at end of file diff --git a/sdk/src/prover.rs b/sdk/src/prover.rs index 61d2e114..af5756f4 100644 --- a/sdk/src/prover.rs +++ b/sdk/src/prover.rs @@ -28,6 +28,7 @@ pub struct ProverInput { #[derive(Debug, Default, Deserialize, Serialize, Clone)] pub struct ProverResult { + pub total_steps: u64, pub output_stream: Vec, pub proof_with_public_inputs: Vec, pub stark_proof: Vec,