Crates.io | halo2-wasm |
lib.rs | halo2-wasm |
version | 0.3.4 |
source | src |
created_at | 2024-01-18 20:20:32.348223 |
updated_at | 2024-01-19 04:51:44.472012 |
description | Wasm bindings for the halo2 circuit library. |
homepage | |
repository | https://github.com/axiom-crypto/halo2-browser/halo2-wasm |
max_upload_size | |
id | 1104522 |
size | 224,081 |
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.
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
.
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).
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);
};
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
is a Typescript wrapper for easily using the halo2-wasm
module's functions (ie. proving, keygen, etc). Check out the repo for more info.
Coming soon!
halo2-wasm
This work would not be possible without Nalin's guide on using raw halo2 in WASM. Check out his guide here.