Quick Start Example

Quick Start Example

The Project Template allows the developer to create an end-to-end zkMIPS project and the on-chain Solidity verifier.

Two provers have been provided:

  • Local Prover: Use your machine to run the prover and generate the proof by your end.
  • Network Prover: Use ZKM proof network to generate the proof via our Restful API.

Running diagram

Running diagram

Getting Started

First to install zkm toolchain run the following command and follow the instructions:

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

The SDK has a libary(libsnark) which supports local proving. If the libsnark is required, please specify the features = ["snark"] in your Cargo.toml. To disable libsnark, set the environment variable NO_USE_SNARK to true when compiling the SDK.

Local Proving Requirements

  • Hardware: X86_64 CPU, 32 cores, 13GB memory (minimum)
  • OS: Linux
  • Rust: 1.81.0-nightly
  • Go : 1.22.1
  • Set up a local node for some blockchain(eg, sepolia)

Network Proving Requirements

  • Hardware: X86_64 CPU, 8 cores, 8G memory
  • OS: Linux
  • Rust: 1.81.0-nightly
  • Go : 1.22.1
  • CA certificate: ca.pem, ca.key
  • Register (opens in a new tab) your address to use
  • RPC for a blockchain (eg, sepolia)

All actions are assumed to be from the base directory zkm-project-template

Running the project

0. Download the repo

git clone https://github.com/zkMIPS/zkm-project-template.git

1. Build the guest program ELF

Please refer to this (opens in a new tab) guide.

2. Build the host program

cd zkm-project-template
sh sdk/src/local/libsnark/compile.sh  # compile snark library
cargo build --release              # build host programs

If successfully, it will generate the binary files in target/release/mem-alloc-vec

You can run the guest program without generating a proof by setting the environmental variable EXECUTE_ONLY to "true".

You can set the ZKM_SKIP_PROGRAM_BUILD environment variable to true to skip building the guest program when use zkm_build::build_program.

3. Generate groth16 proof and verifier contract

The function of the environment variables can be found here: README (opens in a new tab)

Example: sha2-rust

This host program sends the private input pri_input = vec![5u8; 1024] and its hash (hash(pri_input)) to the guest program for verification of the hash value.

Local Proving

Make any edits to run-proving.sh (opens in a new tab) and run the program:

cd zkm-project-template/host-program
./run-proving.sh sha2-rust

The result proof and contract file will be in the contracts/verifier and contracts/src respectively.

Network Proving

The proving network may sometimes experience high traffic, causing proof tasks to be queued for hours.

The proving task requires several stages: queuing, splitting, proving, aggregating and finalizing. Each stage involves a varying duration.

Must set the PRIVATE_KEY and ZKM_PROVER=network in run-proving.sh (opens in a new tab) and run the program:

./run-proving.sh sha2-rust

The result proof and contract file will be in the contracts/verifier and contracts/src.

4. Deploy the Verifier Contract

If your system does not has Foundry, please install it:

curl -L https://foundry.paradigm.xyz | bash

Verify the snark proof generateing in the step 3

cd  zkm-project-template/contracts
forge test

Deploy the contract generateing in the step 3

Please edit the following parameters according your aim blockchain.

forge script script/verifier.s.sol:VerifierScript --rpc-url https://eth-sepolia.g.alchemy.com/v2/RH793ZL_pQkZb7KttcWcTlOjPrN0BjOW --private-key df4bc5647fdb9600ceb4943d4adff3749956a8512e5707716357b13d5ee687d9