Skip to main content

python_snarks

Project description

python-snarks

This is a Python implementation of zkSNARK schemes. This library is based on snarkjs, and uses the output from circom.

For now, it is for research purpose, not implemented for product.

Install

$ pip install python-snarks

Usage

import os
from python_snarks import Groth, Calculator, gen_proof, is_valid

def test_groth():
    ## 1. setup zkp
    print("1. setting up...")
    gr = Groth(os.path.dirname(os.path.realpath(__file__)) + "/circuit/circuit.r1cs")
    gr.setup_zk()

    ## 2. proving
    print("2. proving...")
    wasm_path = os.path.dirname(os.path.realpath(__file__)) + "/circuit/circuit.wasm"
    c = Calculator(wasm_path)
    witness = c.calculate({"a": 33, "b": 34})
    proof, publicSignals = gen_proof(gr.setup["vk_proof"], witness)
    print("#"*80)
    print(proof)
    print("#"*80)
    print(publicSignals)
    print("#"*80)

    ## 3. verifying
    print("3. verifying...")
    result = is_valid(gr.setup["vk_verifier"], proof, publicSignals)
    print(result)
    assert result == True

export solidity verifier

Groth class's export_solidity_verifier function creates solidity file. You can deploy it on ethereum network and use it as a verifier.

import os
from python_snarks import Groth, Calculator, gen_proof, is_valid

def test_groth():
    ## 1. setup zkp
    print("1. setting up...")
    gr = Groth(os.path.dirname(os.path.realpath(__file__)) + "/circuit/circuit.r1cs")
    gr.setup_zk()
    gr.export_solidity_verifier("verifier.sol")

verifying on contract

result = contract_instance.functions.verifyProof(
        ...proof and public signals...
    ).call()

Test

$ pytest tests/test_groth16.py

Supported platforms

The supported platforms currently support are set to the requirements of the wasmer-python.

TODO

  • Compatibility with the latest snarkjs, circom
  • Performance optimizing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-snarks, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size python_snarks-0.0.3-py3-none-any.whl (35.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size python-snarks-0.0.3.tar.gz (18.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page