Home

Awesome

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

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

Prerequisites

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

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,:])