halo2-wasm

Crates.iohalo2-wasm
lib.rshalo2-wasm
version0.3.4
sourcesrc
created_at2024-01-18 20:20:32.348223
updated_at2024-01-19 04:51:44.472012
descriptionWasm bindings for the halo2 circuit library.
homepage
repositoryhttps://github.com/axiom-crypto/halo2-browser/halo2-wasm
max_upload_size
id1104522
size224,081
Jonathan Wang (jonathanpwang)

documentation

README

halo2-wasm

This repository aims to streamline the process of building WASM modules from zero-knowledge proof circuits written on top of halo2-lib. To discuss or collaborate, join our community on Telegram.

Getting Started

For a brief overview on writing halo2-lib circuits, see this doc. In addition to the halo2-lib setup, you will need wasm-pack installed:

curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

The template folder includes everything you need to turn your circuit into a WASM bundle. In particular, template/src/lib.rs is an example of a simple circuit that uses the context of a Halo2Wasm struct. You can then build your WASM bundle (from the template subdirectory) with:

./scripts/build.sh <PLATFORM>

where <PLATFORM> is either nodejs or web.

Multithreading

Halo2 uses Rayon for multithreading, and we use wasm-bindgen-rayon to support this in the browser. It does not work outside the browser, however, so when nodejs is the compilation target, Rayon will be turned off (it is enabled using the rayon feature flag).

Setting up the WASM module in JS

Web

import {
  init,
  initThreadPool,
  initPanicHook,
  Halo2Wasm,
  MyCircuit,
} from "<IMPORT PATH>";

const main = async () => {
  //setup Halo2Wasm and MyCircuit
  await init();
  initPanicHook();
  await initThreadPool(numThreads);
  const halo2wasm = new Halo2Wasm();
  const myCircuit = new MyCircuit(halo2wasm);
};

Node.js

import { Halo2Wasm, initPanicHook, MyCircuit } from "<IMPORT PATH>";

const main = async () => {
  //setup Halo2Wasm and MyCircuit
  initPanicHook();
  const halo2wasm = new Halo2Wasm();
  const myCircuit = new MyCircuit(halo2wasm);
};

You can now run MyCircuit witness generation with myCircuit.run() (following the example in the template subdirectory). You can then call any of the Halo2Wasm operations (mock, keygen, prove, etc.),

halo2-js

halo2-js is a Typescript wrapper for easily using the halo2-wasm module's functions (ie. proving, keygen, etc). Check out the repo for more info.

Benchmarks

Coming soon!

Projects built with halo2-wasm

Acknowledgements

This work would not be possible without Nalin's guide on using raw halo2 in WASM. Check out his guide here.

Commit count: 0

cargo fmt