Sailos
Tutorials

Halo2

Requires Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Setup the Project

Fork the template, https://github.com/anudit/halo2-template. It simplifies the process of compiling Halo2 circuits in a highly customizable way.

Your project structure should look something like this.

fib.rs
lib.rs
Cargo.toml
  • fib.rs contains a fibonacci circuit.
  • lib.rs contains the customizable C glue to run your circuit.

Understand the C Glue

pub extern "C" fn compute(
  public_inputs: *const c_char
) -> *const c_char {}

This signature should remain constant otherwise zk-expo won't pickup the function. The compute function contains the functions you need to parse inputs and return valid json.

Build and Test

Requires Rust to be on nightly : rustup nightly

Requires the WASM toolchain : rustup target add wasm32-unknown-unknown

cargo +nightly build --target wasm32-unknown-unknown --release

Optimize the wasm file,

brew install binaryen
wasm-opt -Oz -o optimized.wasm ./target/wasm32-unknown-unknown/release/hello_wasm.wasm

On-chain Verification

 

More Reading

On this page