Skip to content
/ SKProof Public

Scikit-learn compatible Python library for generating ZK proofs of execution

Notifications You must be signed in to change notification settings

0x3327/SKProof

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SKProof

About

SKProof Python library enables generation of execution proofs for machine learning models found in scikit-learn library. Current version enable generation of proofs for multilayer perceptron neural network classifier (MLPClassifier) but the following updates will include support for more models. The circuits are designed using Noir language and the PLONK proofs are generated internally using Nargo CLI tool, also used to generate Solidity smart contract verifiers for the models. For representing floating point values, we use our ZKFloat library, written in Noir language for handling base 10 floating point values.

Supported models

  • MLPClassifier with ReLU activation function

How it works

The first step is ML model training, where the model parameters are determined. In case of MLPClassifier, the model parameters are weights between network nodes. The trained model is decomposed into simple addition and multiplication expression, as well as activation function calls. All expressions are converted into calls of ZKFloat library methods for arithmetic operations over floating point numbers and written, along with the library code, into Noir program. A user can select the instance for which the prediction proof should be generated and requests proof generation. The SKProof prover invokes Nargo CLI commands to compile the circuit and generate the proof for the prediction.

Planned improvements

  • Code optimization
  • Support for more models

Prerequisites

The library uses Noir code to generate proofs for the scikit-learn models, so it is a requirement that you have installed:

  • scikit-learn library; install using pip with command pip install scikit-learn
  • noir library; Installation instructions can be found here

Installation

Installing skproof package is done using pip with command pip install skproof

Example

Example using Iris dataset and MLPClassifier

from skproof.mlp.MLPClassifierProver import MLPClassifierProver
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import load_iris

print('Loading dataset...')

# Load test data
iris = load_iris()
X = iris.data
y = iris.target

print('Training MLPClassifier...')

# Train classifier
mlp = MLPClassifier((2,3), activation='relu', max_iter=2000)
mlp.fit(X, y)

# Generate proof for the first row
mlpcp = MLPClassifierProver(
    mlp,
    'src/main.nr',
    'Prover.toml',
    '../zkfloat/zkfloat.nr',
    7
)

mlpcp.prove(X[:1,:])

About

Scikit-learn compatible Python library for generating ZK proofs of execution

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published