Last active
May 24, 2024 03:03
-
-
Save katat/5d3d970750df196952e0d3376b379540 to your computer and use it in GitHub Desktop.
a convenient shell script to test generating a proof from .r1cs and .wtns files and verifying it via snarkjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if directory path argument is provided | |
if [ "$#" -lt 2 ]; then | |
echo "Usage: $0 <directory_path> <curve>" | |
exit 1 | |
fi | |
DIR_PATH=$1 | |
CURVE=$2 | |
NEW_PTAU=false | |
# Check for optional setup flag | |
for arg in "$@"; do | |
if [[ $arg == "--new" ]]; then | |
NEW_PTAU=true | |
fi | |
done | |
# Generate a proof and verify it via snarkjs | |
if $NEW_PTAU; then | |
snarkjs powersoftau new $CURVE 16 "pot_"$CURVE"_0000.ptau" -v | |
snarkjs powersoftau contribute "pot_"$CURVE"_0000.ptau" "pot_"$CURVE"_0001.ptau" --name="First contribution" -v | |
snarkjs powersoftau prepare phase2 "pot_"$CURVE"_0001.ptau" "pot_"$CURVE"_final.ptau" -v | |
fi | |
# Check the consistency between the witness and r1cs constraints via snarkjs | |
snarkjs wchk "$DIR_PATH/output.r1cs" "$DIR_PATH/output.wtns" | |
snarkjs groth16 setup "$DIR_PATH/output.r1cs" "pot_"$CURVE"_final.ptau" "test_"$CURVE"_0000.zkey" | |
snarkjs zkey contribute "test_"$CURVE"_0000.zkey" "test_"$CURVE"_0001.zkey" --name="1st Contributor Name" -v | |
snarkjs zkey export verificationkey "test_"$CURVE"_0001.zkey" "verification_key.json" | |
snarkjs groth16 prove "test_"$CURVE"_0001.zkey" "$DIR_PATH/output.wtns" "proof.json" "public.json" | |
snarkjs groth16 verify "verification_key.json" "public.json" "proof.json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment