Optimization of on-chain private machine learning (public model × private data).
All commands in this README
(except this section) are assumed to be called from the root directory.
# cd into this repo
$ cd zkml-optimization
Install all the dependencies using yarn
.
$ yarn
We have a demo ML model called demo.h5
in ./models
directory. This is a classical classification model for MNIST dataset, and is a slightly modified version of this model. If needed, you can take a look at its implementation from demo.ipynb
in ./models
directory.
We are using keras2circom as a way to convert model files (.h5
) into circom-compatible circuits. Follow the steps in keras2circom's README to convert models into circuits. The demo circuit files auto-generated from the demo model are demo-circuit.circom
and demo-circuit-json
in ./circuits/
directory.
We need a ptau file for our trusted-setup. Clone powersOfTau28_hez_final_17.ptau
from this repo, and place it in ./circuits
directory.
Go to ./model-developers
directory, and follow the instructions in README.md
for compiling demo circuit, generating zkeys from them, uploading files to IPFS, and registering the resulting hash to our custom verifier contract.
Go to ./provers
directory, and follow the instructions in README.md
for encoding testing results as a Merkle tree, generating Merkle proofs and ZKPs given the random challenge, and sending proofs to our custom verifier contract for revealing/verification.
To minimize side-effects of changes to packages, make sure to pin exact versions when adding packages.
# example: add package 'xxx' to root project as a dev dependency
$ yarn add -W -D -E xxx