vivianjeng / zkSNARK-verifier-in-C

zkSNARK verifier in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZoKrates with C verifier

See Document. Based on ZoKrates and output verifiers with C language to deploy on OurChain.

Getting Started

Download the whole package and compile the code.

cd ZoKrates/
cargo +nightly build --release

Then cd target/release to execute ZoKrates

ZoKrates Example 1 -- Square Root

According to ZoKrates document:

  1. First, create the text-file root.zok and implement your program. In this example, we will prove knowledge of the square root a of a number b:
def main(private field a, field b) -> (field):
  field result = if a * a == b then 1 else 0 fi
  return result
  1. Compile
./zokrates compile -i root.zok
  1. Perform the setup phase
./zokrates setup
  1. (For verifiers) Export a solidity verifier
./zokrates export-verifier
  1. (For provers) Generate a proof of computation
# execute the program
./zokrates compute-witness -a 337 113569
# generate a proof of computation
./zokrates generate-proof

ZoKrates Example 2 -- SudokuChecker

Another example of ZoKrates: SudokuChecker

  1. create the text-file sudokuchecker.zok

  2. Compile

./zokrates compile -i sudokuchecker.zok
  1. Perform the setup phase
./zokrates setup
  1. (For verifiers) Export a solidity verifier
./zokrates export-verifier
  1. (For provers) Generate a proof of computation
# execute the program
./zokrates compute-witness -a 3 4 2 2 3 2 1 2 4 3 1 1 4 3 4 1
# generate a proof of computation
./zokrates generate-proof

On-chain Verifier Usage

  1. Compiling verifier.c on-chain
gcc verifier.c -lgmp
  1. Prover gets proof from ZoKrates output proof.json

  2. Prover calls the verifier program with the proof.

An example of SudokuChecker:

./a.out 12223361632793408695071575845139783748399099095148486551738160861113901529450 10773020487045276868139663904300449364583091909115903404377551147958337460347 11458271398869128052404652055082728846813650718352464338821092175948674322028 7377129170170691236169079245377746972165048032070197772644585782612415622023 9577223338187511070267836222101724545529135090815987419922695191044115707281 11564317194327007249052994800681576503120340472613585493085497052076914813118 19080400365662515268619738133110008210937427276810264496399607417116506797606 15466541046120039457992702990746787383814430749729372800776852616315204697252 3 4 2 2 3 2 1
  1. After executing of the verifier program, it will print "transaction verified" if proof is correct; otherwise it shows nothing.

About

zkSNARK verifier in C


Languages

Language:Rust 89.8%Language:C 5.3%Language:C++ 2.1%Language:Shell 1.2%Language:Solidity 1.0%Language:JavaScript 0.6%Language:Dockerfile 0.1%