Awesome
About
zk-MNIST: web frontend app + Jupyter notebook with ML model generation Authors: @horacepan @sunfishstanford @henripal
You can play with the webapp demo at: https://zkmnist.netlify.app/ (Note: mobile browsers not supported; wallet connected to Goerli testnet required to demonstrate ZK verifier.) Tutorial blog post: https://hackmd.io/Y7Y79_MtSoKdHNAEfZRXUg
This project is part of 0xPARC's winter 2021 applied zk learning group, and draws heavily from 0xJOF's zk learning in public repo and Wei Jie Koh's zk nft mint repo
Current Functionality:
- draw a digit or select an image of a hand-drawn digit
- pass the digit through 2 conv layers and 2 FC layers in browser, generating a dim 84 embedding
- generate a zkSNARK proof in browser that the embedding represents a given digit
- verify proof on-chain using ethers + snarkjs
How to run it locally:
Prerequisites: global install of circom 2.0
git clone
the repocd
into the directorynpm i
to install dependencies- generate powers of tau
yarn zk:ptau
- compile circuits: (yarn zk:compile doesn't work)
5a)
cd zk
5b)zsh compile.sh
5c)cd ..
(back to main directory) 5d) copy over some of the wasm filesmkdir public/static
mkdir public/static/js
cp node_modules/onnxruntime-web/dist/*.wasm public/static/js/
- compile the contracts
npx hardhat compile
- start a local ether node:
npx hardhat node
- switch to another terminal
- deploy the smart contract
npx hardhat run scripts/deploy.js --network localhost
- make a note of where the contract address has been deployed
- edit
verifierAddress
in./src/config.js
- start web app
npm start
Development loop:
ZK circuits
All zk circuits are in the zk
directory.
- generate basic powers of tau phase 1 with
yarn zk:ptau
- compile the circuits, generate the solidty validator with
yarn zk:compile
(but see 5a/5b above)