From 9c4eab27d6a8a774d49f40ccea92faf305caf500 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Wed, 25 Oct 2023 04:42:49 +0100 Subject: [PATCH] chore(acir_tests): Add script to regenerate double_verify_proof inputs (#3005) The information below can also be found in the README edited as part of this PR: `double_verify_proof` has inputs that are proof system specific such as the circuit verification key and the proofs themselves which are being recursively verified. Certain proof system changes can sometimes lead to the key or inner proofs now being invalid. This means we have to generate the proof specific inputs using our backend and pass it back into `double_verify_proof` to regenerate the accurate witness. The following is a temporary solution to manually regenerate the inputs for `double_verify_proof` on a specific Noir branch. First find `acir_tests/gen_inner_proof_inputs.sh`. Change the $BRANCH env var to your working branch and $PROOF_NAME to your first input you want to recursively verify. The script is going to generate the proof system specific verification key output and proof for the `assert_statement` test. To run: ``` ./gen_inner_proof_inputs.sh ``` To generate a new input you can run the script again. To generate a new file under `assert_statement/proofs/` be sure to change the $PROOF_NAME inside of the script. You can then copy these inputs over to your working branch in Noir and regenerate the witness for `double_verify_proof`. You can then change the branch in `run_acir_tests.sh` to this Noir working branch as well and `double_verify_proof` should pass. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [X] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [X] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist). --- barretenberg/acir_tests/README.md | 16 ++++ .../acir_tests/flows/proof_as_fields.sh | 8 ++ barretenberg/acir_tests/flows/prove.sh | 21 +++++ barretenberg/acir_tests/flows/vk_as_fields.sh | 8 ++ barretenberg/acir_tests/flows/write_vk.sh | 8 ++ .../acir_tests/gen_inner_proof_inputs.sh | 78 +++++++++++++++++++ 6 files changed, 139 insertions(+) create mode 100755 barretenberg/acir_tests/flows/proof_as_fields.sh create mode 100755 barretenberg/acir_tests/flows/prove.sh create mode 100755 barretenberg/acir_tests/flows/vk_as_fields.sh create mode 100755 barretenberg/acir_tests/flows/write_vk.sh create mode 100755 barretenberg/acir_tests/gen_inner_proof_inputs.sh diff --git a/barretenberg/acir_tests/README.md b/barretenberg/acir_tests/README.md index a85d92b7cd5..8bdf7fa6585 100644 --- a/barretenberg/acir_tests/README.md +++ b/barretenberg/acir_tests/README.md @@ -42,3 +42,19 @@ The `all_cmds` flow tests all the supported commands on the binary. Slower, but ``` $ FLOW=all_cmds ./run_acir_tests.sh 1_mul ``` + +## Regenerating witness for `double_verify_proof` + +`double_verify_proof` has inputs that are proof system specific such as the circuit verification key and the proofs themselves which are being recursively verified. Certain proof system changes can sometimes lead to the key or inner proofs now being invalid. + +This means we have to generate the proof specific inputs using our backend and pass it back into `double_verify_proof` to regenerate the accurate witness. The following is a temporary solution to manually regenerate the inputs for `double_verify_proof` on a specific Noir branch. + +First find `acir_tests/gen_inner_proof_inputs.sh`. Change the $BRANCH env var to your working branch and $PROOF_NAME to your first input you want to recursively verify. The script is going to generate the proof system specific verification key output and proof for the `assert_statement` test. + +To run: +``` +./gen_inner_proof_inputs.sh +``` +To generate a new input you can run the script again. To generate a new file under `assert_statement/proofs/` be sure to change the $PROOF_NAME inside of the script. + +You can then copy these inputs over to your working branch in Noir and regenerate the witness for `double_verify_proof`. You can then change the branch in `run_acir_tests.sh` to this Noir working branch as well and `double_verify_proof` should pass. \ No newline at end of file diff --git a/barretenberg/acir_tests/flows/proof_as_fields.sh b/barretenberg/acir_tests/flows/proof_as_fields.sh new file mode 100755 index 00000000000..ce5772263ca --- /dev/null +++ b/barretenberg/acir_tests/flows/proof_as_fields.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +if [ -n "$VERBOSE" ]; then + $BIN proof_as_fields -v -c $CRS_PATH -p "./proofs/$PROOF_NAME" +else + $BIN proof_as_fields -c $CRS_PATH -p "./proofs/$PROOF_NAME" +fi \ No newline at end of file diff --git a/barretenberg/acir_tests/flows/prove.sh b/barretenberg/acir_tests/flows/prove.sh new file mode 100755 index 00000000000..e6a1d818761 --- /dev/null +++ b/barretenberg/acir_tests/flows/prove.sh @@ -0,0 +1,21 @@ +#!/bin/sh +set -eu + +echo -n "INSIDE PROVE SCRIPT" +echo -n "$RECURSIVE" + +if [ -n "$VERBOSE" ]; then + if [ -n "$RECURSIVE" ]; then + $BIN prove -v -c $CRS_PATH -b ./target/acir.gz -o "./proofs/$PROOF_NAME" -r + else + $BIN prove -v -c $CRS_PATH -b ./target/acir.gz -o "./proofs/$PROOF_NAME" + fi +else + if [ -n "$RECURSIVE" ]; then + echo -n "HERE" + + $BIN prove -v -c $CRS_PATH -b ./target/acir.gz -o "./proofs/$PROOF_NAME" -r + else + $BIN prove -c $CRS_PATH -b ./target/acir.gz -o "./proofs/$PROOF_NAME" + fi +fi \ No newline at end of file diff --git a/barretenberg/acir_tests/flows/vk_as_fields.sh b/barretenberg/acir_tests/flows/vk_as_fields.sh new file mode 100755 index 00000000000..e982ff6e354 --- /dev/null +++ b/barretenberg/acir_tests/flows/vk_as_fields.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +if [ -n "$VERBOSE" ]; then + $BIN vk_as_fields -v -c $CRS_PATH +else + $BIN vk_as_fields -c $CRS_PATH +fi \ No newline at end of file diff --git a/barretenberg/acir_tests/flows/write_vk.sh b/barretenberg/acir_tests/flows/write_vk.sh new file mode 100755 index 00000000000..e8dadf5e94a --- /dev/null +++ b/barretenberg/acir_tests/flows/write_vk.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu + +if [ -n "$VERBOSE" ]; then + $BIN write_vk -v -c $CRS_PATH -o +else + $BIN write_vk -c $CRS_PATH +fi \ No newline at end of file diff --git a/barretenberg/acir_tests/gen_inner_proof_inputs.sh b/barretenberg/acir_tests/gen_inner_proof_inputs.sh new file mode 100755 index 00000000000..70b02d320ac --- /dev/null +++ b/barretenberg/acir_tests/gen_inner_proof_inputs.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# Env var overrides: +# BIN: to specify a different binary to test with (e.g. bb.js or bb.js-dev). +set -eu + +BIN=${BIN:-../cpp/build/bin/bb} +WRITE_VK_FLOW=${FLOW:-write_vk} +VK_FIELDS_FLOW=${FLOW:-vk_as_fields} +PROVE_FLOW=${FLOW:-prove} +PROOF_FIELDS_FLOW=${FLOW:-proof_as_fields} +CRS_PATH=~/.bb-crs +BRANCH=master +VERBOSE=${VERBOSE:-} +RECURSIVE=true +PROOF_NAME="proof_a" + +WRITE_VK_FLOW_SCRIPT=$(realpath ./flows/${WRITE_VK_FLOW}.sh) +VK_FIELDS_FLOW_SCRIPT=$(realpath ./flows/${VK_FIELDS_FLOW}.sh) +PROVE_FLOW_SCRIPT=$(realpath ./flows/${PROVE_FLOW}.sh) +PROOF_FIELDS_FLOW_SCRIPT=$(realpath ./flows/${PROOF_FIELDS_FLOW}.sh) + +if [ -f $BIN ]; then + BIN=$(realpath $BIN) +else + BIN=$(realpath $(which $BIN)) +fi + +export BIN CRS_PATH VERBOSE RECURSIVE PROOF_NAME + +# Pull down the test vectors from the noir repo, if we don't have the folder already. +if [ ! -d acir_tests ]; then + if [ -n "${TEST_SRC:-}" ]; then + cp -R $TEST_SRC acir_tests + else + rm -rf noir + git clone -b $BRANCH --filter=blob:none --no-checkout https://github.com/noir-lang/noir.git + cd noir + git sparse-checkout init --cone + git sparse-checkout set tooling/nargo_cli/tests/acir_artifacts + git checkout + cd .. + mv noir/tooling/nargo_cli/tests/acir_artifacts acir_tests + rm -rf noir + fi +fi + +cd acir_tests + +cd assert_statement + +PROOF_DIR=$PWD/proofs +PROOF_PATH=$PROOF_DIR/$PROOF_NAME + +echo -e "Write VK to file for assert_statement..\n" +set +e +$WRITE_VK_FLOW_SCRIPT +set -eu + +echo -e "Write VK as fields for recursion...\n" +set +e +$VK_FIELDS_FLOW_SCRIPT +set -eu + +echo -e "Generate proof to file...\n" +set +e +if [ ! -d "$PROOF_DIR" ]; then + mkdir $PWD/proofs +fi +if [ ! -e "$PROOF_PATH" ]; then + touch $PROOF_PATH +fi +$PROVE_FLOW_SCRIPT +set -eu + +echo -e "Write proof as fields for recursion...\n" +set +e +$PROOF_FIELDS_FLOW_SCRIPT +set -eu