Last active
May 29, 2024 03:57
-
-
Save katat/7482d07ae783a5b20a4e5f04dec4cb16 to your computer and use it in GitHub Desktop.
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" | |
# Export the verifier contract and calldata via snarkjs | |
snarkjs zkey export solidityverifier "test_"$CURVE"_0001.zkey" verifier.sol | |
echo "calldata to test:" | |
snarkjs zkey export soliditycalldata public.json proof.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment