Giter Site home page Giter Site logo

zkp_proof_ai_model's Introduction

zkp_proof_ai_model

zkp_proof_ai_model is a tool designed to convert ONNX models into Circom circuits using the library onnx2circom, that calculates the hash with Poseidon formula and compute witness of the given circuit. The tool relies on an external repository:

  • onnx2circom: to transpile from onnx to circom
  • keras2circom: requested by onnx2circom
  • circomlib: for the single or double hash Poseidon
  • snarkjs: to compute the proof

Installation

First, clone the zkp_proof_ai_model repository:

git clone https://github.com/ValeMTo/zkp_proof_ai_model

Then, install the dependencies. You can use pip:

pip install -r requirements.txt

If you use conda, you can also create a new environment with the following command:

conda env create -f environment.yml

zkp_proof_ai_model also requires onnx2circom, keras2circom,circomlib,snarkjs: to compute the proof to function properly.

Here's how you can install:

  • onnx2circom

    git clone https://github.com/ValeMTo/onnx2circom.git
    
  • keras2circom

    git clone https://github.com/socathie/keras2circom.git
    
  • circomlib

    git clone https://github.com/iden3/circomlib.git
    
  • snarkjs

    git clone https://github.com/iden3/snarkjs.git
    

You may need to install additional dependencies due to external libraries. Refer to their own README file for specific installation instructions.

Usage

Circuit setup

After installing zkp_proof_ai_model, its dependencies and the related external libraries, you can convert your ONNX models into Circom circuits and compute hash.

For example, to transpile the model in model_dense.onnx into a circom circuit, you can run:

python conversion.py model_dense.onnx

Then, calculate witness with snarkjs:

cd ./hash_computation
snarkjs wtns export json witness.wtns witness.json
cd ../

and update the circuit with the hash and the template for the hash computation

python compile_circuit.py

The final circom circuit will be in the output directory.

If you want to transpile the model into a circom circuit with --verbose output, i.e. command line print of inputs and output of each layer, you can run:

python conversion.py model_dense.onnx -v

Moreover, if you want to transpile the model into a circom circuit with --raw output, i.e. no ArgMax at the end, you can run:

python conversion.py model_dense.onnx --raw

Circuit usage

After created the circuit, you can use it with the inputs.

python compute_witness.py input.json

export in json the witness with snarkjs:

cd ./output
snarkjs wtns export json witness.wtns witness.json
cd ../

then, check the result:

python compute_witness.py input.json

zkp_proof_ai_model's People

Contributors

valemto avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.