A Plutus implementation of the Groth16 ZKP-verification algorithm.
Using snarkjs, the setup and proof parts of the Groth16 protocol generate the files:
verification.jsonproof.jsonpublic.json
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 developAfter 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 replThe REPL should open in module Test_BLS6_6.
Inside the REPL, execute:
testValidator1Change to module Test:
:m TestTo 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 .
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 toZKPVerification.hsexcept that imports BLS6_6 parameters.Test_BLS6_6: allows convenient testing of the validator in the REPL.
-
Directory
snarkjscontains output files that can be used to test the validator using the BN128 elliptic curve.- files in
snarkjs/test00were obtained implementing in snarkjs the 3-factorization problem described in [1]. - files in
snarkjs/test01,snarkjs/test02andsnarkjs/test03correspond to outputs generated by our ZK-Mastermind game.
- files in
-
Elliptic curve
BLS6_6is described in detail in [1]. Datum in fileTest_BLS6_6.hswas obtained from the ZK-SNARK setup and proof associated with the 3-factorization problem as explained in [1].