Modulo-P / groth-validator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZK-SNARK proof verification in Plutus

A Plutus implementation of the Groth16 ZKP-verification algorithm.

Preliminaries

Using snarkjs, the setup and proof parts of the Groth16 protocol generate the files:

  • verification.json
  • proof.json
  • public.json

Testing instructions

We assume that you have cloned Plutus-Apps and have Nix installed and configured with the proper substituters. At the Plutus-Apps directory, execute

git checkout v1.2.0
nix develop

After allowing enough time for the nix-shell to start, go to the directory where you cloned this repo and then to ./onchain/. Then execute

cabal repl

The REPL should open in module Test_BLS6_6.

ZK-proof verification using the BLS6_6 elliptic curve

Inside the REPL, execute:

testValidator1

ZK-proof verification using the BN128 elliptic curve

Change to module Test:

:m Test

To test the validator you need to provide the snarkjs output files:

testValidator2 "pathTo/verification.json" "pathTo/proof.json" "pathTo/public.json"

You can find sample snarkjs output files in directory snarkjs .

Structure of the project (onchain code)

The onchain verification code is contained in the following files in directory src:

  • Params.hs : global parameters associated with elliptic curve BN128.
  • ParseDatum.hs : utility code for parsing the json files produced by snarkjs.
  • ZKPVerification.hs : implementation of the verification part of the Groth16 protocol and associated Plutus validator.
  • Test.hs : allows convenient testing of the validator in the REPL.

Additionally, directory src/BLS6_6 provides:

  • Params_BLS6_6 : global parameters associated with elliptic curve BLS6_6.
  • ZKPPVerification_BLS6_6 : identical to ZKPVerification.hs except that imports BLS6_6 parameters.
  • Test_BLS6_6 : allows convenient testing of the validator in the REPL.

Notes

  • Directory snarkjs contains output files that can be used to test the validator using the BN128 elliptic curve.

    • files in snarkjs/test00 were obtained implementing in snarkjs the 3-factorization problem described in [1].
    • files in snarkjs/test01, snarkjs/test02 and snarkjs/test03 correspond to outputs generated by our ZK-Mastermind game.
  • Elliptic curve BLS6_6 is described in detail in [1]. Datum in file Test_BLS6_6.hs was obtained from the ZK-SNARK setup and proof associated with the 3-factorization problem as explained in [1].

Reference

[1] The MoonMath Manual to zk-SNARKs .

About

License:GNU General Public License v2.0


Languages

Language:Haskell 98.8%Language:Shell 1.2%