GithubHelp home page GithubHelp logo

sai-c / zkpy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sahilmahendrakar/zkpy

0.0 0.0 0.0 7.59 MB

A Python library that allows for easy compiling/proving/verifying of zk circuits.

License: Apache License 2.0

JavaScript 29.73% Python 61.85% Makefile 6.63% Circom 1.79%

zkpy's Introduction

zkpy

A Python library that allows for easy compiling/proving/verifying of zk circuits.

License GitHub issues example workflow codecov PyPI

Overview

ZKPy is a Python library that allows for easy compiling/proving/verifying of zk circuits. It is implemented as a wrapper of Circom or SnarkJS, allowing developers to incorporate zero knowledge proofs into Python projects.

Features:

  • Can perform trusted setup (Powers of Tau and Phase 2)
  • Can generate proofs for circuits written in Circom
  • Can verify proofs given witness file and verification key
  • Implements both Groth16 and PLONK proving schemes

Dependencies

zkpy requires Circom and snarkjs. You can find installation instructions here.

Installation

The recommended way to install zkpy is through pip.

pip install zkpy

Usage

Powers of Tau

Start by importing PTau:

from zkpy.ptau import PTau

Here is an example use case walking through a powers of tau ceremony: First, create PTau object:

ptau = PTau()

Initialize powers of tau ceremony:

ptau.start() 

Make first contribution:

ptau.contribute()

Make second contribution with a name and specified entropy:

ptau.contribute(name="second", entropy="random text") 

Apply beacon to finalize powers of tau ceremony:

ptau.beacon()

Prepare for phase 2:

ptau.prep_phase2()

The PTau object maintains an underlying powers of tau file throughout these operations. You can also import an existing ptau file:

ptau = PTau(ptau_file="ptau_file.ptau")

At any stage, we can verify the powers of tau file is valid:

ptau.verify()

Circuit

Start by importing Circuit:

from zkpy.circuit import Circuit, PLONK

This class uses a circuit defined in a circom file to generate and verify zk proofs.

Here is an example scenario walking through compiling a circuit, generating witnesses, generating a proof, and verifying the proof: First, create the circuit object:

circuit = Circuit("./circuit.circom")

Compile the circuit:

circuit.compile()

Get info about the circuit and print constraints:

circuit.get_info()
circuit.print_constraints()

Generate witness from an input file:

circuit.gen_witness("./example_circuits/input.json")

Setup proof (this requires a previous powers of tau ceremony):

circuit.setup(PLONK, ptau)

Generate the proof:

circuit.prove(PLONK)

Export verification key:

circuit.export_vkey()

Verify proof:

circuit.verify(PLONK, vkey_file="vkey.json", public_file="public.json", proof_file="proof.json")

Contributing

Help is always appreciated! Feel free to open an issue if you find a problem, or open a pull request if you've solved an issue.

See more at CONTRIBUTING.md

zkpy's People

Contributors

sahilmahendrakar 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.