Prove a SHA256 hash computation in circom zk learn more
- install circom
- study the circom getting started
- add circom lib to the working dir
cd ./ptau
./verify.sh
pragma circom 2.0.0;
include "./circomlib/circuits/sha256/sha256.circom";
template Birthday(){
component SHA = Sha256(16);
signal input d[16];
SHA.in <== d;
signal output d_out[256];
d_out <== SHA.out;
}
component main = Birthday();
- compile:
circom bday.circom --r1cs --wasm --sym --c
- compute the witness:
cd ./bday_js
node generate_witness.js bday.wasm ../input.json witness.wtns
- Powersoftau
cd ./ptau
snarkjs groth16 setup ../bday.r1cs powersOfTau28_hez_final_15.ptau bday_0000.zkey
snarkjs zkey contribute bday_0000.zkey bday_0001.zkey --name="1st Contributor Name" -v
snarkjs zkey export verificationkey bday_0001.zkey verification_key.json
- Generate a proof
snarkjs groth16 prove bday_0001.zkey ../bday_js/witness.wtns proof.json public.json
- Verify the proof
snarkjs groth16 verify verification_key.json public.json proof.json