-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated .gitignore, added documentation, fixed typo in example comment
- Loading branch information
1 parent
a10250f
commit cd4dd6d
Showing
6 changed files
with
188 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
Prover.toml | ||
Verifier.toml | ||
Verifier.toml | ||
proofs | ||
lib.nr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19342440604102b52f14b0f87de5843660fcd75d80bf02b1e3d1a19ec2041ec30e73aad005e70aa5960820ea8d892073e626c9d1f784da9b450568bbd96ed84f094ffdc414c4bff828af65f8f9337ff56c30b525d2230b0ad49694b93ff7edb10421af5f3f654c811b7b50749dc594ed5c34928a7bbd5de159d8c294c5f6f0220074d2610d5800c865fd2dd91ea3b0bb0eb8c9696c773028e46585976ed6970c295455b7dc3d4cbcb66b046aa90f7dc6c131a48487b54b14b8bf1a8fac5dea601b18bee62f9ada54217593631ed8a7c0b0e3212e3bc5562cfab7f8c565468e0d0f05a84d749d41fc144140c31a0bd4824931f51e9843987542057e403ad2ac720b5ebaf074955b88a1f491a3043f46ffc817606f901c80ec1def23a6da97e6bf22af4ded3cc2979fcfbae78df92ff8aba420f29ccd24ffb33b1cd8125c621cb528275129c59191e7c0eeedee52810351c5394c53e0326561d10169be791f5bdb211a905b57e902c57ab3d0be0efbd287451577366f7137050de3fb6bef42ddd9155b3ffea3d919bb1367b559b6214d9ab8e0c9d8619e3750f7ef2cbff90538860af19e54a647c4353260aef5f7ea85843c7396f88495ce3b198b7fe90f64ced822fea70ece6f08e8623058e4e614dcaaf71d9fece6e8e599f4b5eb2f6d51042e0b0b97da63f59b282de5aac4cab8e8de907f288bea19c3907d2dff3c0589233c22c095efd68f36d1fc9270bfbafabbd2999d91610354bfd21358ad84d1a280d519f3cb041c3f9286f3ebab5f4609906943290e84f0224b71dc35cff6483862102b277500bcc11b5802b695818de50bb589de6ceba53d904478ccb41134976b2703d881d47496311c8ada54a5ab54c951045c5b7e3bf5fab798097f647712f62e159a72479f9d67df1787658ccd40bb9ba3ed718aea1ba3aa301b5afc818062c3096a41efa491e1b1e2924f77c27f65f10ec7144aea2e88b02c6c679b29ef917d293ce8d3b257bfdbdd3d80660c3ce6e43cd2da65a35734924bc2922d0e3c152021f7f08e7368354ae802b6c4c02c1f22246dd22beb4e55b7aeb06a7ec940a12e1a1e647e3489aa3884c6a5cf3a65de32e624fc91c2b9733ef6c3fca7fe49229c26c6133fbb593de8a5e763c348e519871ff42b7999fd4c6a37ab9ca329dbb0330946f258e1f71daf9c4cff683c4b11cd782505ca836696c34dde0c8ca425673924a2f57e041b03cb5316518fda6fb56fc63c069b34b65b5ce7aeb82516217c3021338e565236ddb0d88f7b8c970b73b8f63eb43c849c480f1946840589eae96f0d31ced6b34c7dd277da87b573b760c91b0764a4c7bbcacc732eaf379a6a5ff82885d76de6d4f001e943f2fef2f06a17730cfc9b9c78342e2abbb9faeb60d5cc06570fb363564d8c25005c86fc062679811dc7049ef661dfe7e08a07161a978f20c35b807869f8eec45a89ba2021ee6df276d668fca7472b5031196389bad3cd2a94ce243807bf60debcf9dcb2ab8a5ad64fd71ada216b6718c7f321c22ef2db121116f10e8b01ea5282bce4eeff281fba8b74d8430a2e4770817c34b6ebcfea2e28be5adda0dbf91a8002eeba205f9bb012802c2cfbb5d95e63dcd91f41d3cd1396f77605708cd8c95ff3f3fdfc2271c6c347e588f29cab104fda178176d534 | ||
2685d8f2fc10a22fd7247a01c690b9af4def865a18f79d7dcf4506ce6120bb4202de394b841036e74cec89d0e38cef889bc69ba3ec9e2cad493341558705c47309eeaf6e5ccb915203936a324582a347df1a5db0f39594df8aee7d702349a3de0650a9588f274085170036ebf50fbe29e7b26ff45779c337aa3b20d0408fa0882b6bffb3b1eee4bb460bf8bc423d663294e74248a20b1c98e6b7787f0c5628e2191a31182942f16f96de625b50b029cfab35ec51d2515abf051b69f8cbfbf85c0864411ac56011d62b6826c19e3b7228df2f669d165aaf542333dad6827e1c7d260891d58f91ae9ec956db7f5f326b89e53669baa35b2b1e977c81ff0a1653e00a6fcd03244acca32db612e4ca9ad5e756d79d98efd532c2a3b538dd10d621d9159934ff2dbbdffd7a232901e0f03dbe2907d49e581917d8dc540a1db487485711ff15b110e808a0de4889f65766dc20b6a1314caee0a7522c229bdc048087f51b7b2ab7fde2849bad62761ff3e6673e274712c4b464b3e5f2a6f976c20e3651065db0f72f2c27e1bc573592bb4bb3e7ef6f678a759bc057669bfc56a873d49c2c26055b7475757541222b37a1a0219316a655a1ae18a2f8729a5964f979409820a92cb8739432c4091fe98994ca8d921bb2da643a3edc20ace980ff330121250d826b4570bc284a8e700a24a1c6388760a8c38fbc1089d1ac32b0df2eda5a082011e13dcaf5f5e1c8d0fea2266dc747ea25ac079c675269676705116ec36a6707896cd35b17750dcc91d9c5b63d435835fd2b60a0173dc76f53fb35973194f72f8643499350ee7b25cf6f8749c352517f95c57579f110d09b36c9d53eeed4ae1b8c56307d8e309d790fe1e8f68e971fa24cc05c2d8d5c433878b1f3c771a7111a619ffa716f911ae8cdb5c264c2eeecc960f2124e5fd47bef19ef35e063cbdb0e1a2dd6a56adba977e4b48c80608dd71d2b74ceedbdb5e4ec639a4cd984ccfc21631ac3f936af9c36e48b2511a34d44e065d80682b0b66febfcb4eb599262741edf498d28aca31ce9da9f5e538e8ebdb8ce540543b634cd304e045440b5dd792d910af5034492b81a6cb76140a7a101449ef61c5673b57a70b337d77cfbc56a131d9937b3ed03f960fc03b50799248913e402463e81de61a8d06dadd01ab17820f0f8ee643fa93cbd0a813d31f46b72fe774b25bd8619379e77ead9597feee718851912740ad18329cd0d3b3517eaa2f7084bad3d1f804a8976393a4f8a3a8e108dcad40516c8202a7403cfdfd3f3c25fbbae671cf35fc0235db6cc065fc92f0b91847b9c4a3a31dc47485b61a94a2357bdd9a1cfec6b2b6b87f2202534eb1b286bdef1fa36a1b983568e1c4f755edb1f50b1d5c4acd08e55bd29db1052d2491061a4f81cccb70f90aaca701fc1d4d80f34df8a6d680f7ef24ac8b7c3933eab23b907dc6330fe9beebb3d13548793795be0562495ceef4ac934cbb670361b0d0a8536a8812f54f156fa875035eb2c12aa3d989288dea95d24599d26b675762e285ef8cd6edec02cc67087d0baf24fb282b5b0b10da6949bc0f4db86323cc76d162263e7d110dfe7531cbdfdc87791f53b95810040ca5efae49f12870c4550cb19b4742839cb65671a906cb05b4bd1f298a62a82ba1907ce49b100c60848343d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# SKProof | ||
## About | ||
SKProof [Python](https://python.org/) library enables generation of execution proofs for machine learning models found in [scikit-learn](https://scikit-learn.org/) library. Current version enable generation of proofs for multilayer perceptron neural network classifier ([MLPClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html)) but the following updates will include support for more models. The circuits are designed using [Noir](https://noir-lang.org/) language and the PLONK proofs are generated internally using [Nargo](https://noir-lang.org/getting_started/nargo.html) CLI tool, also used to generate Solidity smart contract verifiers for the models. For representing floating point values, we use our [ZKFloat](https://github.com/0x3327/zkfloat) library, written in [Noir](https://noir-lang.org/) 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](https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html), 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](https://github.com/0x3327/zkfloat) library methods for arithmetic operations over floating point numbers and written, along with the library code, into [Noir](https://noir-lang.org/) program. A user can select the instance for which the prediction proof should be generated and requests proof generation. The SKProof prover invokes [Nargo](https://noir-lang.org/getting_started/nargo.html) 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](https://noir-lang.org/) code to generate proofs for the [scikit-learn](https://scikit-learn.org/) models, so it is a requirement that you have installed: | ||
- scikit-learn library; install using pip with command `pip install sklearn` | ||
- noir library; Installation instructions can be found [here](https://noir-lang.org/getting_started/nargo/installation.html) | ||
|
||
## Installation | ||
Installing skproof package is done using pip with command `pip install skproof` | ||
|
||
## Example | ||
Example using Iris dataset and MLPClassifier | ||
```python | ||
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,:]) | ||
``` |
Oops, something went wrong.