Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(acir_tests): Add script to regenerate double_verify_proof inputs #3005

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions barretenberg/acir_tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 8 additions & 0 deletions barretenberg/acir_tests/flows/proof_as_fields.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions barretenberg/acir_tests/flows/prove.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions barretenberg/acir_tests/flows/vk_as_fields.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions barretenberg/acir_tests/flows/write_vk.sh
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions barretenberg/acir_tests/gen_inner_proof_inputs.sh
Original file line number Diff line number Diff line change
@@ -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