SeiyaKobayashi / zkml-optimization

Optimization for on-chain private machine learning.
MIT License
13 stars 1 forks source link
blockchain ethereum machine-learning merkle-proof merkle-tree neural-network optimization-algorithms zk zk-snarks zkml zkp

zkml-optimization

Optimization of on-chain private machine learning (public model × private data).

Architecture Diagrams

Architecture Diagram of Verifier

Verifier

Architecture Diagram of Prover

Prover

Architecture Diagram of Model Developer

Model Developer

Prerequisites

All commands in this README (except this section) are assumed to be called from the root directory.

# cd into this repo
$ cd zkml-optimization

How to Use Demo CLI App

0. Installation

Install all the dependencies using yarn.

$ yarn

1. Steps for Model Developers

1-A. Demo Model & Circuit

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.

1-B. Circuit Compilation, ZKey Generation, IPFS, Model Registration

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.

2. Steps for Prover Clients

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.

Contributions

Adding Packages

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