Skip to main content

ZKCross Playground

Effortlessly submit your first zkWASM application

Working with zero-knowledge proofs (ZKPs) can be challenging, and developing applications that utilize ZKPs can be even more complex. Our team of engineers experienced these challenges firsthand while building ZKCross. To address this, we leveraged the contributions of the Rust community and integrated the Rust Playground with the ZKCross node to streamline the development of your ZK applications.

Explore the ZKCross Playground, an intuitive platform that allows you to write code online, compile it into zkWASM-compatible bytecode, sign it with your private key, and upload it to the ZKCross node. From there, our node handles the remaining tasks such as proof generation, proof storage, and store tx and proof into the Data Availability.

We will guide you through how to use the zkWASM playground to get your application submitted to the zkWASM prover cloud step by step.

  1. Edit your Rust code in the code block. Put the logic you need to verify using zero-knowledge proofs into the function zkmain(). Put the private parameter inputs into the function zkexec().

playground1

  1. Click the 'SHOW WASM' button to compile your code into WASM. Wait until the result appears at the bottom.

playground2

  1. Click the 'CONNECT WALLET' button to connect your Metamask wallet. Make sure your wallet is on Ethereum Sepolia testnet.

  2. Click the 'UPLOAD WASM' button and sign the transaction in Metamask. Then your WASM image is signed and uploaded to the ZKCross Node.

  3. The ZKCross Node will automatically submit your WASM image to the zkWASM prover network. Then the setup is ready. You can see your setup appears as the latest setups in the zkWASM task explorer.

playground3

  1. Then, you can use any tools, languages to submit request to ZKC node to use your wasm image, for example:
curl https://testrpc.zkcross.org/' -H 'Accept: application/json, text/plain, */*' -H 'Content-Type: application/json;charset=UTF-8' — data-raw '{“jsonrpc”: “2.0”, “method”: “submit-tx”, “params”: {“image_md5”: “FBE1ADD84935782493030FF335475D81”, “weight”: 100, “params”: [1,2]}}' — compressed ; 

This is an image already existing in both ZKC node and Delphinus Lab's ZK prover cloud. It will pass two parameters to the image on the ZKC node, which has a wasm runtime builtin. It takes the parameters from the user, executes the code, and submits the execution combined with the parameters as private and public input to Delphinus's zkWASM cloud.

  1. After the proof generated by the zkWASM cloud, the ZKC node will call the batcher to process tx, submit to the settlement layer and DA.

What does the ZKCross Node do?

  • Provides an RPC interface for applications to interact with the prover network (such as Delphinus Lab’s zkWASM cloud).
  • Facilitates the execution WebAssembly bytecode on node, making it very similar to running services on server side.
  • Provide adaptor layers to provide components required by a rollup, like ordering transactions, batch processing proofs, data availability, proof generation, etc.

To learn more about the ZKCross Node, please refer to more detailed documentation.

How to write a zkWASM compatible application with Rust?

Here is an example, the code below carries two mandatory functions, one is for zkWASM, the other is for executing the code on the ZKCross node.

mod utils;

extern crate zkwasm_rust_sdk;
use self::zkwasm_rust_sdk::{require, wasm_input};

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub unsafe fn zkexec(a: u64, b: u64) -> u64 {
a+b
}

#[wasm_bindgen]
pub unsafe fn zkmain() -> u64 {
let a = wasm_input(1);
let b = wasm_input(1);

let c = wasm_input(0);

require(a+b == c);

0
}