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

feat: Barretenberg C++ binary overhaul #11459

Merged
merged 159 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
90e1879
squash
codygunton Jan 23, 2025
ac0e31e
Works for both
codygunton Jan 23, 2025
c09eb0e
Make double_verify_proof work
codygunton Jan 23, 2025
7148768
Move into existing prove_then_verify flow
codygunton Jan 23, 2025
392b286
Use existing flag structure
codygunton Jan 23, 2025
b02ea01
Clean up and make prove_and_verify work
codygunton Jan 23, 2025
085a795
Uniformize civc proof and vk naming
codygunton Jan 23, 2025
5c71b37
Cleanup
codygunton Jan 24, 2025
bea60f3
Use use contract endpoint
codygunton Jan 24, 2025
ccf8ffc
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Jan 24, 2025
d187e30
Undelete things still needed
codygunton Jan 25, 2025
ea8239c
Pattern match _ in SYS
codygunton Jan 25, 2025
68d499b
Delete verify_ultra_honk
codygunton Jan 25, 2025
a305e48
Make "prove_and_verify_program" test real and convert
codygunton Jan 25, 2025
0db44f8
Try fix
codygunton Jan 25, 2025
1086fdd
Use deprecated
codygunton Jan 25, 2025
09a512d
Stream issue on prove-then-verify with vk writing
codygunton Jan 27, 2025
a951e7c
Works on folds and xor
codygunton Jan 27, 2025
d60e063
Add note
codygunton Jan 27, 2025
fd3a6c9
Add note on deprecated flow
codygunton Jan 27, 2025
ab19bd0
Trying to fix CIVC tests ECCVM on_curve verification error
codygunton Jan 27, 2025
0b4f53e
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Jan 27, 2025
8b89a12
Always return something
codygunton Jan 27, 2025
889f99c
Fix PI issue?
codygunton Jan 27, 2025
dfff8e9
Use tmp dir for confidence about changes
codygunton Jan 28, 2025
6a568d3
convert sol_honk flow modulo vk flow
codygunton Jan 28, 2025
c837d5c
Remove ultra keccak proving and set up ultra keccak verification
codygunton Jan 28, 2025
0706407
Add standalone test of keccak
codygunton Jan 28, 2025
1e95e1e
no_snake_case
codygunton Jan 28, 2025
1513ec5
more_camel_case
codygunton Jan 28, 2025
37bb3fb
make compiler analysis script idiomatic
codygunton Jan 28, 2025
892e904
passed wrong flag when making keccak test
codygunton Jan 28, 2025
09ed889
more_camel_case
codygunton Jan 28, 2025
714912d
Remove rollup honk proving and verification; IOU updates to ts caller
codygunton Jan 28, 2025
0e46aed
Refactor SerializedProofAndKey for --output_all
codygunton Jan 28, 2025
cfcf8b4
Use proper default
codygunton Jan 29, 2025
f7914be
Remove output_all commands
codygunton Jan 29, 2025
4e1428b
robust write_vk
codygunton Jan 29, 2025
04a914d
Merge commit 'c4892c640d' into cg/uh-api
codygunton Jan 29, 2025
8158a7d
Cut out meaningless folding tests
codygunton Jan 29, 2025
913cbcd
Pare down main; remaining are *_as fields, write_recursion_inputs, ga…
codygunton Jan 29, 2025
dd94fb6
fix sol_honk
codygunton Jan 29, 2025
9de3660
Systematic output type and output content handling
codygunton Jan 29, 2025
ecfadb7
Prevent fallthroughs for GCC
codygunton Jan 29, 2025
598c4dd
Was trying to write vk fields to stdout
codygunton Jan 30, 2025
ede02fb
does working serially help?
codygunton Jan 30, 2025
90cc060
Should have specified proof_and_vk
codygunton Jan 30, 2025
18333ba
Output proof and vk for sol_honk
codygunton Jan 30, 2025
c84b0ef
remove as_fields commands and shuffle main
codygunton Jan 30, 2025
e25c6bc
Get failure outputs again
codygunton Jan 30, 2025
bc3fb5f
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Jan 30, 2025
01d1c84
Noir compilation script outputs binary and json for merge
codygunton Jan 30, 2025
c616c0e
speed up write_vk flow
codygunton Jan 30, 2025
aa07579
Extend for root rollup but slow (5.5mins)
codygunton Jan 30, 2025
1471ad4
Write vk in bootstrap for civc
codygunton Jan 31, 2025
7e2f3a5
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Jan 31, 2025
55bf456
Add note on checking interface
codygunton Jan 31, 2025
379684a
Fix compilation
codygunton Jan 31, 2025
c319166
ALL UH STUFF MOVED EXCEPT TUBE
codygunton Jan 31, 2025
7ac9040
Fix writing rollup proof recursion inputs
codygunton Jan 31, 2025
db79cda
Revert binary used
codygunton Jan 31, 2025
e969792
No more optional strings and update contract call in bootstrap
codygunton Jan 31, 2025
c926333
fix ivc vk writing
codygunton Jan 31, 2025
a70d0cb
fix noir-contract vk writing in bootstrap
codygunton Jan 31, 2025
259f465
Fix root rollup vk gen
codygunton Jan 31, 2025
84f0b4e
bump fixed size for now
codygunton Jan 31, 2025
84eb7f2
Comments on --recursive
codygunton Feb 1, 2025
ff6580b
Fix vk gen in noir-bb-bench
codygunton Feb 1, 2025
a5cdc6f
Turn AVM back on
codygunton Feb 1, 2025
636b3dc
replace another instance of write_vk_for_ivc
codygunton Feb 1, 2025
aef3594
update bb prover calls
codygunton Feb 1, 2025
c88cadc
Fix native client ivc test
codygunton Feb 1, 2025
ae11d3d
formatting:fix
codygunton Feb 1, 2025
cfe64c4
Cacheing bug with bb version?
codygunton Feb 2, 2025
cd4c856
Fix prover-client tests (?)
codygunton Feb 3, 2025
a6833c3
No console.log
codygunton Feb 3, 2025
eba12df
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Feb 4, 2025
133a8f1
Try to get back to failing at prover-client and boxes
codygunton Feb 4, 2025
10f61f2
return signal 🤦
codygunton Feb 6, 2025
9e7ee19
Add note on failure tests
codygunton Feb 6, 2025
4f58dee
Merge branch 'master' into cg/uh-api
codygunton Feb 6, 2025
4c6d009
Cut out folding test for now
codygunton Feb 6, 2025
d97b83e
This makes folding test pass but write_vk version fails
codygunton Feb 6, 2025
cc140ad
Use write_vk flow
codygunton Feb 6, 2025
2d0a1a1
Revert change in UVCIVC
codygunton Feb 6, 2025
20a27a8
revert civc regression fix for now
codygunton Feb 7, 2025
b6b9a67
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Feb 8, 2025
030a78e
Merge commit '59b229a21b' into cg/uh-api
codygunton Feb 10, 2025
087136c
New CLI works for prove then verify uh double_verify_honk_proof
codygunton Feb 10, 2025
2e78abc
It just works for civc
codygunton Feb 10, 2025
42b9478
intentions
codygunton Feb 10, 2025
c59dd1d
Remove special functions from API
codygunton Feb 11, 2025
88c7625
pare down
codygunton Feb 11, 2025
d128345
Process subs working for VERBOSE=1 BIN=../cpp/build/bin/bb SYS=ultra_…
codygunton Feb 11, 2025
c1364a1
VERBOSE=1 SYS=ultra_honk FLOW=prove_then_verify ROLLUP=true BIN=../cp…
codygunton Feb 11, 2025
1742c90
Representative set passes
codygunton Feb 11, 2025
b94637d
Revert "Representative set passes"
codygunton Feb 11, 2025
dbc5233
Builds and outputs list of subcommands
codygunton Feb 11, 2025
9747a3f
Tidy grouping
codygunton Feb 11, 2025
91ace47
Bring bb11 in to bb...
codygunton Feb 11, 2025
3444743
Start making bootstrap in acir_tests work
codygunton Feb 11, 2025
fba5aea
sol test passes
codygunton Feb 12, 2025
42e5742
sol_honk passes
codygunton Feb 12, 2025
03ba884
sol_honk_zk tests
codygunton Feb 12, 2025
7110aa8
All cmds passes
codygunton Feb 12, 2025
d345b7f
plonk commands works
codygunton Feb 12, 2025
3fd7945
ACIR tests bootstrap _should work_...
codygunton Feb 12, 2025
5a08e75
prove tube is old api
codygunton Feb 12, 2025
d0e2136
Alright acir_tests really should pass now
codygunton Feb 12, 2025
5bca709
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Feb 12, 2025
fa0d0dd
try fixing popen build error (why?)
codygunton Feb 12, 2025
4094611
Update include too
codygunton Feb 12, 2025
e7d714a
fix wasm build
codygunton Feb 12, 2025
2de28a7
update include for avm test
codygunton Feb 12, 2025
6b85f9f
Unnest AVM commands
codygunton Feb 12, 2025
a3943d3
Remove unused commands
codygunton Feb 12, 2025
697a0da
Fix noir-contracts bootstrap write_vk issue
codygunton Feb 12, 2025
a05d020
fix noir protocol circuits bootstrap
codygunton Feb 12, 2025
24d2626
Revert stack experiment
codygunton Feb 12, 2025
596bb41
Squash cleanup and acir_tests fix (setting --init)
codygunton Feb 13, 2025
32fdefc
rename -initialize... flag
codygunton Feb 13, 2025
49ba707
Fix some AVM tests
codygunton Feb 13, 2025
6719ee6
Merge commit '370b37784fc766b477a2d1c9df3fd7782a1b65f9' into cg/uh-api
codygunton Feb 13, 2025
3e24a0e
Push through logging-off-only errors
codygunton Feb 13, 2025
d07eac4
Avoid empty string args :(
codygunton Feb 13, 2025
8256188
Fix noir-bb-bench
codygunton Feb 13, 2025
105dcef
Fix prover-client and probably boxes?
codygunton Feb 14, 2025
fff2e15
Try adding missing recursion flags
codygunton Feb 14, 2025
f2378ea
Merge remote-tracking branch 'origin/master' into cg/uh-api
codygunton Feb 14, 2025
f8b4735
revert lockfile
codygunton Feb 14, 2025
656d4f0
Remove bb11
codygunton Feb 14, 2025
d744390
Cleanup: acir_tests
codygunton Feb 14, 2025
e0fa8b0
Add issues; clean up contract function
codygunton Feb 14, 2025
6e09d68
Move plonk functions out
codygunton Feb 14, 2025
6dd1a05
Move everything else out
codygunton Feb 14, 2025
6da4134
Cleanup!
codygunton Feb 14, 2025
aef5f17
Cleanup
codygunton Feb 15, 2025
d7df1e8
Optimize vk writing (one circuit construction)
codygunton Feb 15, 2025
240594a
Respond to charlie, extend pattern in noir-bb-bench
codygunton Feb 15, 2025
b70d229
Apply suggestions from code review
codygunton Feb 16, 2025
0db4d59
Maybe this was intended?
codygunton Feb 16, 2025
34b85d3
Respond to some Adam comments
codygunton Feb 16, 2025
8e62a30
Try to move to source but libdeflate issue?
codygunton Feb 16, 2025
c6920b4
Relax assertion in write_vk
codygunton Feb 16, 2025
e310def
Locate libdeflate
codygunton Feb 16, 2025
9f7e5bb
Fix wasm configuring
codygunton Feb 16, 2025
99d6ac1
Split UltraHonk
codygunton Feb 16, 2025
4289384
Fix app vk writing
codygunton Feb 16, 2025
65a6696
Fix npc bootstrap
codygunton Feb 16, 2025
52520e4
contract ~> write_contract
codygunton Feb 17, 2025
a7504df
Fix npc bootstrap
codygunton Feb 17, 2025
5c49ada
Merge branch 'master' into cg/uh-api
codygunton Feb 19, 2025
909c1bf
Merge branch 'master' into cg/uh-api
codygunton Feb 19, 2025
f6f21c7
stray
codygunton Feb 19, 2025
490f4dd
Can't use std::formatfor mac builds yet https://stackoverflow.com/que…
codygunton Feb 19, 2025
d1e19ea
Try silencing warning
codygunton Feb 19, 2025
bbb8543
Respond to saleel
codygunton Feb 20, 2025
1bbf807
Fix noir test
codygunton Feb 20, 2025
8f5ed5b
Fix other noir example tests
codygunton Feb 20, 2025
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
2 changes: 1 addition & 1 deletion aztec-nargo/compile_then_postprocess.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for artifact in $artifacts_to_process; do

echo "Generating verification key for function $fn_name"
# BB outputs the verification key to stdout as raw bytes, however, we need to base64 encode it before storing it in the artifact
verification_key=$($BB write_vk_for_ivc -b ${fn_artifact_path} -o - | base64)
verification_key=$($BB write_vk --scheme client_ivc -b ${fn_artifact_path} -o - | base64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is immediately going to become confusing when we add a flow to write a CIVC VK. I wonder if this should just become the write_vk for mega honk..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about this but then it's the only mega honk command which seems weird. It think it makes sense to put it behind the --input_type flag in CIVC?

rm $fn_artifact_path
jq ".functions[$fn_index].verification_key = \"$verification_key\"" $artifact > $artifact.tmp
mv $artifact.tmp $artifact
Expand Down
30 changes: 14 additions & 16 deletions barretenberg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ Barretenberg (or `bb` for short) is an optimized elliptic curve library for the
- [Testing locally in docker](#testing-locally-in-docker)
- [Docs Build](#docs-build)
- [Benchmarks](#benchmarks)
- [x86\_64](#x86_64)
- [x86_64](#x86_64)
- [WASM](#wasm)
- [How to run](#how-to-run)
- [Debugging](#debugging)
- [Debugging Verification Failures](#debugging-verifification-failures)
- [Improving LLDB Debugging](#improving-lldb-debugging)
- [Using Tracy to Profile Memory/CPU](#using-tracy-to-profile-memorycpu)

> [!CAUTION]
> **This code is highly experimental, use at your own risk!**
> [!CAUTION] > **This code is highly experimental, use at your own risk!**

## Installation

Expand All @@ -66,14 +65,14 @@ All available `bb` commands:
Prove the valid execution of your program:

```bash
bb prove_ultra_honk -b ./target/hello_world.json -w ./target/witness-name.gz -o ./target/proof
bb prove --scheme ultra_honk -b ./target/hello_world.json -w ./target/witness-name.gz -o ./target/proof
```

You can then compute the verification key for your Noir program and verify the proof:

```bash
bb write_vk_ultra_honk -b ./target/hello_world.json -o ./target/vk
bb verify_ultra_honk -k ./target/vk -p ./target/proof
bb write_vk --scheme ultra_honk -b ./target/hello_world.json -o ./target/vk
bb verify --scheme ultra_honk -k ./target/vk -p ./target/proof

```

Expand All @@ -83,7 +82,7 @@ If successful, the verification will complete in silence.

The usage with MegaHonk is similar to the above UltraHonk. Refer to all the available `bb` commands, using the `bb <command>_mega_honk` syntax.

>[!WARNING]
> [!WARNING]
> MegaHonk generates insecure recursion circuits when Goblin recursive verifiers are not present.

### Solidity verifier
Expand All @@ -93,21 +92,20 @@ Barretenberg can generate a smart contract that verifies proofs in Solidity (i.e
First, prove the valid execution of your Noir program and export the verification key:

```bash
bb prove_ultra_keccak_honk -b ./target/hello_world.json -w ./target/witness-name.gz -o ./target/proof
bb write_vk_ultra_honk -b ./target/hello_world.json -o ./target/vk
bb prove --sceme ultra_honk -b ./target/hello_world.json -w ./target/witness-name.gz -o ./target/proof
bb write_vk --scheme ultra_honk -b ./target/hello_world.json -o ./target/vk
```

> [!IMPORTANT]
> `prove_ultra_keccak_honk` is used to generate UltraHonk proofs with Keccak hashes, making them gas-efficient. `prove_ultra_honk` in comparison generates proofs with Poseidon hashes, more efficient in recursions but not on-chain verifications.
> [!IMPORTANT] > `prove --scheme ultra_honk --oracle_hash keccak` is used to generate UltraHonk proofs with Keccak hashes, making them gas-efficient. `prove --scheme ultra_honk` in comparison generates proofs with Poseidon hashes, more efficient in recursions but not on-chain verifications.

You can now use the verification key to generate a Solidity verifier contract:

```bash
bb contract_ultra_honk -k ./target/vk -c $CRS_PATH -b ./target/hello_world.json -o ./target/Verifier.sol
bb write_contract --scheme ultra_honk -k ./target/vk -c $CRS_PATH -b ./target/hello_world.json -o ./target/Verifier.sol
```

>[!CAUTION]
> Solidity verifier contracts are work-in-progress. Expect significant optimizations and breaking changes, and *do NOT use it in production!*
> [!CAUTION]
> Solidity verifier contracts are work-in-progress. Expect significant optimizations and breaking changes, and _do NOT use it in production!_

## Development

Expand Down Expand Up @@ -270,7 +268,7 @@ Alternatively you can build separate test binaries, e.g. honk_tests or numeric_t

Code is formatted using `clang-format` and the `./cpp/format.sh` script which is called via a git pre-commit hook.

>[!TIP]
> [!TIP]
> A default configuration for VS Code is provided by the file [`barretenberg.code-workspace`](barretenberg.code-workspace). These settings can be overridden by placing configuration files in `.vscode/`.
> If you've installed the C++ Vscode extension, configure it to format on save!

Expand Down Expand Up @@ -410,7 +408,7 @@ Usage instructions:
Caveats:

- This works best for code that is not overly generic, i.e. where just the sequence of function calls carries a lot of information. It is possible to tag extra data along with the stack trace, this can be done as a followup, please leave feedback if desired.
- There are certain functions like `assert_equals` that can cause gates that occur *before* them to fail. If this would be useful to automatically report, please leave feedback.
- There are certain functions like `assert_equals` that can cause gates that occur _before_ them to fail. If this would be useful to automatically report, please leave feedback.

Example:

Expand Down
28 changes: 14 additions & 14 deletions barretenberg/acir_tests/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ function build {
echo "Regenerating verify_honk_proof and verify_rollup_honk_proof recursive inputs."
local bb=$(realpath ../cpp/build/bin/bb)
(cd ./acir_tests/assert_statement && \
$bb write_recursion_inputs_ultra_honk -b ./target/program.json -o ../verify_honk_proof --recursive && \
$bb write_recursion_inputs_rollup_honk -b ./target/program.json -o ../verify_rollup_honk_proof --recursive)
# TODO(https://github.com/AztecProtocol/barretenberg/issues/1253) Deprecate command and construct TOML (e.g., via yq or via conversion from a JSON)
$bb OLD_API write_recursion_inputs_ultra_honk -b ./target/program.json -o ../verify_honk_proof --recursive && \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's like you're trying to make the old way as ugly as possible :P

Copy link
Contributor Author

@codygunton codygunton Feb 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha well the prove command was taken by UltraPlonk so I needed to either break the old API, spend more time on and wrap the UP stuff more uniformly, do something like this...

$bb OLD_API write_recursion_inputs_ultra_honk --ipa_accumulation -b ./target/program.json -o ../verify_rollup_honk_proof --recursive)

cache_upload $tests_tar acir_tests
fi
Expand Down Expand Up @@ -69,9 +70,9 @@ function test_cmds {
# Paths are all relative to the repository root.
function test_cmds_internal {
local plonk_tests=$(find ./acir_tests -maxdepth 1 -mindepth 1 -type d | \
grep -vE 'verify_honk_proof|double_verify_honk_proof|verify_rollup_honk_proof')
grep -vE 'verify_honk_proof|double_verify_honk_proof|verify_rollup_honk_proof|fold')
local honk_tests=$(find ./acir_tests -maxdepth 1 -mindepth 1 -type d | \
grep -vE 'single_verify_proof|double_verify_proof|double_verify_nested_proof|verify_rollup_honk_proof')
grep -vE 'single_verify_proof|double_verify_proof|double_verify_nested_proof|verify_rollup_honk_proof|fold')

local run_test=$(realpath --relative-to=$root ./run_test.sh)
local run_test_browser=$(realpath --relative-to=$root ./run_test_browser.sh)
Expand Down Expand Up @@ -99,25 +100,23 @@ function test_cmds_internal {
# echo ecdsa_secp256r1_3x through bb.js on node to check 256k support.
echo BIN=$bbjs_bin FLOW=prove_then_verify $run_test ecdsa_secp256r1_3x
# echo the prove then verify flow for UltraHonk. This makes sure we have the same circuit for different witness inputs.
echo BIN=$bbjs_bin SYS=ultra_honk FLOW=prove_then_verify $run_test 6_array
# echo a single arbitrary test not involving recursion through bb.js for MegaHonk
echo BIN=$bbjs_bin SYS=mega_honk FLOW=prove_and_verify $run_test 6_array
echo BIN=$bbjs_bin SYS=ultra_honk_deprecated FLOW=prove_then_verify $run_test 6_array
# echo 1_mul through bb.js build, all_cmds flow, to test all cli args.
echo BIN=$bbjs_bin FLOW=all_cmds $run_test 1_mul

# barretenberg-acir-tests-bb:
# Fold and verify an ACIR program stack using ClientIvc, recursively verify as part of the Tube circuit and produce and verify a Honk proof
# Fold and verify an ACIR program stack using ClientIVC, recursively verify as part of the Tube circuit and produce and verify a Honk proof
echo FLOW=prove_then_verify_tube $run_test 6_array
# echo 1_mul through native bb build, all_cmds flow, to test all cli args.
echo FLOW=all_cmds $run_test 1_mul
echo NATIVE=1 FLOW=all_cmds $run_test 1_mul

# barretenberg-acir-tests-bb-ultra-plonk:
# Exclude honk tests.
for t in $plonk_tests; do
echo FLOW=prove_then_verify $run_test $(basename $t)
echo SYS=ultra_plonk_deprecated FLOW=prove_then_verify $run_test $(basename $t)
done
echo FLOW=prove_then_verify RECURSIVE=true $run_test assert_statement
echo FLOW=prove_then_verify RECURSIVE=true $run_test double_verify_proof
echo SYS=ultra_plonk_deprecated FLOW=prove_then_verify RECURSIVE=true $run_test assert_statement
echo SYS=ultra_plonk_deprecated FLOW=prove_then_verify RECURSIVE=true $run_test double_verify_proof

# barretenberg-acir-tests-bb-ultra-honk:
# Exclude plonk tests.
Expand All @@ -126,15 +125,16 @@ function test_cmds_internal {
done
echo SYS=ultra_honk FLOW=prove_then_verify RECURSIVE=true $run_test assert_statement
echo SYS=ultra_honk FLOW=prove_then_verify RECURSIVE=true $run_test double_verify_honk_proof
echo SYS=ultra_honk FLOW=prove_and_verify_program $run_test merkle_insert
echo SYS=ultra_rollup_honk FLOW=prove_then_verify $run_test verify_rollup_honk_proof
echo SYS=ultra_honk FLOW=prove_then_verify HASH=keccak $run_test assert_statement
echo SYS=ultra_honk FLOW=prove_then_verify ROLLUP=true $run_test verify_rollup_honk_proof

# barretenberg-acir-tests-bb-client-ivc:
echo FLOW=prove_then_verify_client_ivc $run_test 6_array
echo FLOW=prove_then_verify_client_ivc $run_test databus
echo FLOW=prove_then_verify_client_ivc $run_test databus_two_calldata
}

# TODO(https://github.com/AztecProtocol/barretenberg/issues/1254): More complete testing, including failure tests
function bench {
# TODO: Move to scripts dir along with run_test.sh.
LOG_FILE=bench-acir.jsonl ./bench_acir_tests.sh
Expand Down
20 changes: 12 additions & 8 deletions barretenberg/acir_tests/flows/all_cmds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ set -eu
VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"
# the commands called here are subcommands of the OLD_API command in the native bb binary,
# but no such refactoring was done to the node binary. This is because the node binary is
# deprecated and UltraPlonk is also deprecated.
MAYBE_OLD_API=${NATIVE:+OLD_API}

# Test we can perform the proof/verify flow.
$BIN gates $FLAGS $BFLAG > /dev/null
$BIN prove -o proof $FLAGS $BFLAG
$BIN write_vk -o vk $FLAGS $BFLAG
$BIN write_pk -o pk $FLAGS $BFLAG
$BIN verify -k vk -p proof $FLAGS
$BIN $MAYBE_OLD_API gates $FLAGS $BFLAG > /dev/null
$BIN $MAYBE_OLD_API prove -o proof $FLAGS $BFLAG
$BIN $MAYBE_OLD_API write_vk -o vk $FLAGS $BFLAG
$BIN $MAYBE_OLD_API write_pk -o pk $FLAGS $BFLAG
$BIN $MAYBE_OLD_API verify -k vk -p proof $FLAGS

# Check supplemental functions.
# Grep to determine success.
$BIN contract -k vk $BFLAG -o - | grep "Verification Key Hash" > /dev/null
$BIN $MAYBE_OLD_API contract -k vk $BFLAG -o - | grep "Verification Key Hash" > /dev/null
# Use jq to determine success, and also check result not empty.
OUTPUT=$($BIN proof_as_fields -k vk -p proof -o - | jq .)
OUTPUT=$($BIN $MAYBE_OLD_API proof_as_fields -p proof -k vk -o - | jq .)
[ -n "$OUTPUT" ] || exit 1
OUTPUT=$($BIN vk_as_fields -k vk -o - | jq .)
OUTPUT=$($BIN $MAYBE_OLD_API vk_as_fields -k vk -o - | jq .)
[ -n "$OUTPUT" ] || exit 1
8 changes: 6 additions & 2 deletions barretenberg/acir_tests/flows/prove_and_verify.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# prove_and_verify produces no output, so is parallel safe.
set -eu

Expand All @@ -11,7 +11,11 @@ case ${SYS:-} in
;;
"client_ivc")
cmd=prove_and_verify
flags+=" --scheme client_ivc --input_type ${INPUT_TYPE:-compiletime_stack}"
flags+=" --scheme client_ivc ${INPUT_TYPE:---input_type compiletime_stack}"
;;
"ultra_honk")
cmd=prove_and_verify
flags+=" --scheme ultra_honk ${INPUT_TYPE:---input_type compiletime_stack}"
;;
*)
cmd=prove_and_verify_$SYS
Expand Down
43 changes: 38 additions & 5 deletions barretenberg/acir_tests/flows/prove_then_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set -eu
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH ${VERBOSE:+-v}"
[ "${RECURSIVE}" = "true" ] && FLAGS+=" --recursive"
[ -n "${SYS:-}" ] && SYS="_$SYS" || SYS=""

# TODO: Use this when client ivc support write_vk. Currently it keeps its own flow.
# case ${SYS:-} in
Expand All @@ -16,7 +15,7 @@ FLAGS="-c $CRS_PATH ${VERBOSE:+-v}"
# "client_ivc")
# prove_cmd=prove
# verify_cmd=verify
# flags+=" --scheme client_ivc --input_type ${INPUT_TYPE:-compiletime_stack}"
# flags+=" --scheme client_ivc --input_type ${INPUT_TYPE:-single_circuit}"
# ;;
# *)
# prove_cmd=prove_$SYS
Expand All @@ -27,6 +26,40 @@ FLAGS="-c $CRS_PATH ${VERBOSE:+-v}"
# Test we can perform the proof/verify flow.
# This ensures we test independent pk construction through real/garbage witness data paths.
# We use process substitution pipes to avoid temporary files, which need cleanup, and can collide with parallelism.
$BIN verify$SYS $FLAGS \
-k <($BIN write_vk$SYS -o - $FLAGS $BFLAG) \
-p <($BIN prove$SYS -o - $FLAGS $BFLAG)

case ${SYS:-} in
"")
# Deprecated; used for old node cli
[ -n "${SYS:-}" ] && SYS="_$SYS" || SYS=""
$BIN verify$SYS $FLAGS \
-k <($BIN write_vk$SYS -o - $FLAGS $BFLAG) \
-p <($BIN prove$SYS -o - $FLAGS $BFLAG)
;;
"ultra_plonk_deprecated")
# This used to be the default but now it's on its way out.
$BIN OLD_API verify $FLAGS \
-k <($BIN OLD_API write_vk -o - $FLAGS $BFLAG) \
-p <($BIN OLD_API prove -o - $FLAGS $BFLAG)
;;
"ultra_honk")
FLAGS+=" --scheme $SYS --oracle_hash ${HASH:-poseidon2}"
[ "${ROLLUP:-false}" = "true" ] && FLAGS+=" --ipa_accumulation"
[ "${RECURSIVE}" = "true" ] && FLAGS+=" --init_kzg_accumulator"
$BIN verify $FLAGS \
-k <($BIN write_vk $FLAGS $BFLAG -o - ) \
-p <($BIN prove $FLAGS $BFLAG -o - )
;;
"ultra_honk_deprecated")
# deprecated flow is necessary until we finish C++ api refactor and then align ts api
SYS_DEP=_ultra_honk
$BIN verify$SYS_DEP $FLAGS \
-k <($BIN write_vk$SYS_DEP -o - $FLAGS $BFLAG) \
-p <($BIN prove$SYS_DEP -o - $FLAGS $BFLAG)
;;
*)
[ -n "${SYS:-}" ] && SYS="_$SYS" || SYS=""
$BIN verify$SYS $FLAGS \
-k <($BIN write_vk$SYS -o - $FLAGS $BFLAG) \
-p <($BIN prove$SYS -o - $FLAGS $BFLAG)
;;
esac
8 changes: 4 additions & 4 deletions barretenberg/acir_tests/flows/prove_then_verify_client_ivc.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Create intermediate state in a directory. Uses a temp dir to ensure parallel safe and cleansup on exit.
set -eu
set -eux

CRS_PATH=${CRS_PATH:-$HOME/.bb-crs}
BIN=$(realpath ${BIN:-../cpp/build/bin/bb})
Expand All @@ -10,7 +10,7 @@ BIN=$(realpath ${BIN:-../cpp/build/bin/bb})
outdir=$(mktemp -d)
trap "rm -rf $outdir" EXIT

flags="--scheme client_ivc -c $CRS_PATH ${VERBOSE:+-v} -o $outdir"
flags="--scheme client_ivc -c $CRS_PATH ${VERBOSE:+-v}"

$BIN prove $flags -b ./target/program.json --input_type ${INPUT_TYPE:-compiletime_stack}
$BIN verify $flags
$BIN prove $flags -b ./target/program.json ${INPUT_TYPE:---input_type compiletime_stack} -o $outdir
$BIN verify $flags -p $outdir/proof -k $outdir/vk
5 changes: 3 additions & 2 deletions barretenberg/acir_tests/flows/prove_then_verify_tube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trap "rm -rf $outdir" EXIT

flags="-c $CRS_PATH ${VERBOSE:+-v} -o $outdir"

$BIN write_arbitrary_valid_proof_and_vk_to_file --scheme client_ivc $flags
# TODO(https://github.com/AztecProtocol/barretenberg/issues/1252): deprecate in favor of normal proving flow
$BIN OLD_API write_arbitrary_valid_client_ivc_proof_and_vk_to_file $flags
$BIN prove_tube $flags
$BIN verify_tube $flags
$BIN verify_tube $flags
8 changes: 4 additions & 4 deletions barretenberg/acir_tests/flows/sol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export PROOF_AS_FIELDS="$PWD/sol_proof_fields.json"
export VK="$PWD/sol_vk"

# Create a proof, write the solidity contract, write the proof as fields in order to extract the public inputs
$BIN prove -o $PROOF $FLAGS
$BIN write_vk -o $VK $FLAGS
$BIN proof_as_fields -k $VK $FLAGS -p $PROOF
$BIN contract -k $VK $FLAGS $BFLAG -o Key.sol
$BIN OLD_API prove -o $PROOF $FLAGS
$BIN OLD_API write_vk -o $VK $FLAGS
$BIN OLD_API proof_as_fields -k $VK $FLAGS -p $PROOF
$BIN OLD_API contract -k $VK $FLAGS $BFLAG -o Key.sol

# Export the paths to the environment variables for the js test runner
export KEY_PATH="$PWD/Key.sol"
Expand Down
30 changes: 18 additions & 12 deletions barretenberg/acir_tests/flows/sol_honk.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
#!/bin/sh
set -eux
set -eu

VFLAG=${VERBOSE:+-v}
BFLAG="-b ./target/program.json"
FLAGS="-c $CRS_PATH $VFLAG"
FLAGS="-c $CRS_PATH $VFLAG --scheme ultra_honk"
[ "${RECURSIVE}" = "true" ] && FLAGS+=" --recursive"
PROVE_FLAGS="$FLAGS $BFLAG --oracle_hash keccak --output_data bytes_and_fields --output_content proof_and_vk --input_type single_circuit"
VERIFY_FLAGS="$FLAGS --oracle_hash keccak"

export PROOF="$PWD/sol_honk_proof"
export PROOF_AS_FIELDS="$PWD/sol_honk_proof_fields.json"
export VK="$PWD/sol_honk_vk"
outdir=$(mktemp -d)
trap "rm -rf $outdir" EXIT

# Export the paths to the environment variables for the js test runner
export PROOF="$outdir/proof"
export PROOF_AS_FIELDS="$outdir/proof_fields.json"
export VK="$outdir/vk"
export VERIFIER_CONTRACT="$outdir/Verifier.sol"

# Create a proof, write the solidity contract, write the proof as fields in order to extract the public inputs
$BIN prove_ultra_keccak_honk -o $PROOF $FLAGS $BFLAG
$BIN write_vk_ultra_keccak_honk -o $VK $FLAGS $BFLAG
$BIN verify_ultra_keccak_honk -k $VK -p $PROOF $FLAGS
$BIN proof_as_fields_honk $FLAGS -p $PROOF -o $PROOF_AS_FIELDS
$BIN contract_ultra_honk -k $VK $FLAGS -o Verifier.sol
$BIN prove $PROVE_FLAGS -o $outdir
$BIN verify $VERIFY_FLAGS -k $VK -p $PROOF
$BIN write_contract $FLAGS -k $VK -o $VERIFIER_CONTRACT

# Export the paths to the environment variables for the js test runner
export VERIFIER_PATH="$PWD/Verifier.sol"
export VERIFIER_PATH="$outdir/Verifier.sol"
export TEST_PATH=$(realpath "../../sol-test/HonkTest.sol")
export TESTING_HONK="true"

# Use solcjs to compile the generated key contract with the template verifier and test contract
# index.js will start an anvil, on a random port
# Deploy the verifier then send a test transaction
export TEST_NAME=$(basename $PWD)
export TEST_NAME=$(basename $outdir)
node ../../sol-test/src/index.js
Loading