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(acvm): Execute multiple circuits #5380

Merged
merged 208 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 175 commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
71998b8
call opcode and serialization
vezenovm Feb 26, 2024
d081ecc
uncomment serde in test:
vezenovm Feb 26, 2024
a70156e
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 4, 2024
dcb6d9e
pass noir fmt and clippy
vezenovm Mar 4, 2024
d822483
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 4, 2024
2376e16
fixup call comments
vezenovm Mar 4, 2024
10195f3
resovle merge conflcits w/ master'
vezenovm Mar 4, 2024
0792a08
cargo fmt
vezenovm Mar 4, 2024
9be6881
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 4, 2024
4c7f82e
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 6, 2024
96a719c
program and witness stack structure and respective serialization
vezenovm Mar 6, 2024
288a7ec
a little cleanup
vezenovm Mar 6, 2024
1f65f18
cargo fmt
vezenovm Mar 6, 2024
0dc8b38
fmt and clippy
vezenovm Mar 6, 2024
e602ecd
update avm-transpiler to handle new program structure
vezenovm Mar 6, 2024
c3d825d
import correct witness hpp file
vezenovm Mar 6, 2024
cd27e74
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 6, 2024
695d85e
Merge branch 'mv/acir-call-opcode' into mv/program-wit-stack-serialize
vezenovm Mar 6, 2024
e1757fd
serialize Program in acvm_js
vezenovm Mar 6, 2024
ba1369e
Merge remote-tracking branch 'origin/mv/program-wit-stack-serialize' …
vezenovm Mar 6, 2024
4c357ac
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 6, 2024
ad8129b
update public witness methods in acvm_js
vezenovm Mar 7, 2024
1dac703
add necessary clone
vezenovm Mar 7, 2024
14cea93
remove unused import
vezenovm Mar 7, 2024
fc7c8b7
updated serialization
vezenovm Mar 7, 2024
e45f50d
Merge branch 'mv/acir-call-opcode' into mv/program-wit-stack-serialize
TomAFrench Mar 7, 2024
3ac2c53
Merge branch 'master' into mv/acir-call-opcode
TomAFrench Mar 7, 2024
299d0dd
Merge branch 'mv/acir-call-opcode' into mv/program-wit-stack-serialize
TomAFrench Mar 7, 2024
9ceee33
compress wit correctly in noir js
vezenovm Mar 7, 2024
6d08e8a
change back to pinned bb.js
vezenovm Mar 7, 2024
d3b5032
update witness compression test
vezenovm Mar 8, 2024
94b4739
update Dockerfiles
vezenovm Mar 8, 2024
c01aa62
switch order of noir tests
vezenovm Mar 8, 2024
2023556
bb js before noir in the config file
vezenovm Mar 8, 2024
3a31504
specify bb.js dep
vezenovm Mar 8, 2024
0b5ab14
remove unnecessary prints
vezenovm Mar 8, 2024
babb483
uncomment one e2e test
vezenovm Mar 11, 2024
127e03f
remove old comment and try bootstrap_packages
vezenovm Mar 11, 2024
111089e
yarn inside bb ts
vezenovm Mar 11, 2024
4e361fe
appropriately serialize program for smart contract
vezenovm Mar 11, 2024
6905b96
disable simple_verifier_codegen in aztec_packages native CI
vezenovm Mar 11, 2024
6ddfd30
bring back install playwright for CI
vezenovm Mar 11, 2024
2b1639a
fix simple_verifier_codegen nextest expr
vezenovm Mar 11, 2024
a755f8a
and not or
vezenovm Mar 11, 2024
3b2a7e4
passing hardcoded contracts
vezenovm Mar 12, 2024
24749d9
skip recursion in acir tests
vezenovm Mar 12, 2024
5ce2b3e
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 12, 2024
c6cc631
merge conflicts w/ master
vezenovm Mar 12, 2024
d6707ca
Revert "merge conflicts w/ master"
vezenovm Mar 12, 2024
7748098
Reapply "merge conflicts w/ master"
vezenovm Mar 12, 2024
a2c7297
rearrange config
vezenovm Mar 12, 2024
de216d6
clippy
vezenovm Mar 12, 2024
fdae079
remove old import in transpiler
vezenovm Mar 12, 2024
0d6ed9d
add packages dep
vezenovm Mar 12, 2024
45040e4
bootstrap packages in packages-test
vezenovm Mar 12, 2024
441942e
upate circuits.js and protocol-contracts artifacts
vezenovm Mar 12, 2024
20d58ac
increase timeout
vezenovm Mar 12, 2024
a5b7d09
more timeout increase
vezenovm Mar 12, 2024
6ec4afd
dont bootstrap in packages tests
vezenovm Mar 12, 2024
a8ccd5c
remove noir-packages dep
vezenovm Mar 12, 2024
0c78c33
need packages dep in packages.test
vezenovm Mar 12, 2024
27359e8
test inrease counter timeout
vezenovm Mar 12, 2024
1d04bdb
switch order of config
vezenovm Mar 12, 2024
8ac7d2c
move acir tests after bberg in config
vezenovm Mar 12, 2024
a7ce531
bring back test
vezenovm Mar 12, 2024
576f092
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 12, 2024
ac72a93
fix native acvm cli interface
vezenovm Mar 12, 2024
9217b4a
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 12, 2024
1407de4
empty
vezenovm Mar 13, 2024
671cb93
yarn formatting
vezenovm Mar 13, 2024
b7f6609
acvm cli error update
vezenovm Mar 13, 2024
352c335
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 13, 2024
9624796
merge conflcits w/ parent
vezenovm Mar 13, 2024
9350526
yarn lock
vezenovm Mar 13, 2024
52b3773
update yarn lock
vezenovm Mar 13, 2024
88ad6cd
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 13, 2024
6177b62
update noir-pacakges to be dependent
vezenovm Mar 13, 2024
0ffc638
merge conflcits
vezenovm Mar 13, 2024
4bb76b6
update snapshots
vezenovm Mar 13, 2024
1200597
try pinned bb.js-dev
vezenovm Mar 13, 2024
42485d5
try linked bb.js
vezenovm Mar 13, 2024
25b3f4f
update bb.js path
vezenovm Mar 13, 2024
e02a4bc
move nargo backend path env set
vezenovm Mar 13, 2024
9180274
echo path
vezenovm Mar 13, 2024
914af07
use main.js and some of DSL readme
vezenovm Mar 13, 2024
c351300
update gitignore
vezenovm Mar 13, 2024
a418cb4
updated readme
vezenovm Mar 13, 2024
b665ff7
remove commitment to contracts
vezenovm Mar 13, 2024
a094e24
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 13, 2024
90cd0cf
cleanup
vezenovm Mar 13, 2024
a4d7ace
clippy
vezenovm Mar 13, 2024
210569f
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 13, 2024
dbfdb07
merge conflicts new snaps
vezenovm Mar 13, 2024
accc62a
empty
vezenovm Mar 13, 2024
db9eac3
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 13, 2024
15d7622
Merge branch 'mv/acir-call-opcode' into mv/program-wit-stack
vezenovm Mar 13, 2024
c9d5fa6
empty
vezenovm Mar 13, 2024
c786c7d
build all bb in config before noir-packages
vezenovm Mar 13, 2024
bc13ebe
fix yml indent
vezenovm Mar 13, 2024
1e59a4c
update snapshots in yarn project
vezenovm Mar 13, 2024
204ec20
change back to original timeouts
vezenovm Mar 13, 2024
0be14a1
more readme updates
vezenovm Mar 13, 2024
4ee6462
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 14, 2024
cf7cb11
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 14, 2024
f3a3533
initial fold attribute and inline type on SSA func
vezenovm Mar 14, 2024
99bee54
Update noir/noir-repo/acvm-repo/acvm_js/src/compression.rs
vezenovm Mar 14, 2024
9a57443
Update noir/noir-repo/acvm-repo/acvm_js/src/execute.rs
vezenovm Mar 14, 2024
f5327b7
Update noir/noir-repo/acvm-repo/acvm_js/src/public_witness.rs
vezenovm Mar 14, 2024
8612d41
Update noir/noir-repo/acvm-repo/acvm_js/src/public_witness.rs
vezenovm Mar 14, 2024
246adb2
rename remaining vars to
vezenovm Mar 14, 2024
61387df
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 14, 2024
5bc6d2f
add comment to witness_compression
vezenovm Mar 14, 2024
fc84eb6
merge conflcits w/ snapshots
vezenovm Mar 14, 2024
8c4fcde
update snapshots'
vezenovm Mar 14, 2024
9818d7e
fixup readme
vezenovm Mar 14, 2024
b515cf5
Merge branch 'master' into mv/acir-call-opcode
vezenovm Mar 14, 2024
cf91d52
Merge branch 'mv/acir-call-opcode' into mv/program-wit-stack
vezenovm Mar 14, 2024
fc4a158
re-run serde for acir after bad merge
vezenovm Mar 14, 2024
722b7dc
Merge remote-tracking branch 'origin/mv/program-wit-stack' into mv/pr…
vezenovm Mar 14, 2024
9ebf404
chore: add dependency on bb.js job to noir-packages jobs
TomAFrench Mar 14, 2024
aa6c430
chore: fix job name
TomAFrench Mar 14, 2024
d1c4bee
chore: `noir-packages-tests` depends on `noir-packages`
TomAFrench Mar 14, 2024
301f4b8
chore: modified wrong job
TomAFrench Mar 14, 2024
39b5068
Merge branch 'mv/program-wit-stack' into mv/non-inlined-acir-comptime
vezenovm Mar 15, 2024
8b17313
initial compilation of non-inlined acir functions working for basic c…
vezenovm Mar 19, 2024
c070c64
merge conflicts
vezenovm Mar 19, 2024
b7111cc
fix acir cpp after merge conflicts
vezenovm Mar 19, 2024
6dd0f09
do not acir gen non-brillig main funcs as they can contain references
vezenovm Mar 20, 2024
2ed634a
clippy and other fixups
vezenovm Mar 20, 2024
f3a210f
remove noir test with fold
vezenovm Mar 20, 2024
3dfb16f
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 20, 2024
5dedc1d
cargo fmt
vezenovm Mar 20, 2024
d7c9dbb
cargo clippy
vezenovm Mar 20, 2024
5394619
fmt and resulting clippy
vezenovm Mar 20, 2024
84f5495
remove unused label
vezenovm Mar 20, 2024
4cd1a7d
remove unused inline_type funcs
vezenovm Mar 20, 2024
34ad9e2
remove create_circuit for create_program
vezenovm Mar 20, 2024
0d0f02b
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 20, 2024
5e5285f
empty commit cause earthly is wokring locally
vezenovm Mar 20, 2024
2e54f20
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 20, 2024
36a9ec1
a bunch of cleanup
vezenovm Mar 21, 2024
a550de2
Merge remote-tracking branch 'origin/mv/non-inlined-acir-comptime' in…
vezenovm Mar 21, 2024
4b05cff
handle func_sigs correctly
vezenovm Mar 21, 2024
c938901
cleanup
vezenovm Mar 21, 2024
b882eb9
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 21, 2024
6c4222d
comment improvement
vezenovm Mar 21, 2024
f1a52bc
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 21, 2024
c2571b7
minor cleanup
vezenovm Mar 21, 2024
06aaae5
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 21, 2024
60b84d3
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 21, 2024
ec3fd6b
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 21, 2024
8e077d0
basic acir calls working in the ACVM:
vezenovm Mar 21, 2024
1702856
add bb-js for dep for flaky test in config and todo in acir mod
vezenovm Mar 21, 2024
0a76262
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 21, 2024
e97b152
nested calls working
vezenovm Mar 21, 2024
b913175
resolve merge conflicts w/ parent
vezenovm Mar 21, 2024
6ea3ba9
move WitnessStack returned from execute cmd
vezenovm Mar 21, 2024
7d7026a
Cargo fmt
vezenovm Mar 21, 2024
a512df1
cargo clippy
vezenovm Mar 21, 2024
1ad8b60
merge conflcits
vezenovm Mar 26, 2024
924e502
merge conflicts w/ master
vezenovm Mar 26, 2024
ff76db0
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 26, 2024
89452ba
cargo clippy
vezenovm Mar 26, 2024
8ef8408
cleanup
vezenovm Mar 26, 2024
7b504cc
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 26, 2024
905f830
test ultra_honk_program and use last witness stack item for existing …
vezenovm Mar 26, 2024
94f9188
Merge remote-tracking branch 'origin/mv/execute-multiple-circuits-com…
vezenovm Mar 26, 2024
4cc59d0
delete old comment
vezenovm Mar 26, 2024
f04e04a
some comments cleanup
vezenovm Mar 26, 2024
ae88590
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 26, 2024
29bd522
cleanup errors in acvm and reuse methods in acir_to_constraint_buf
vezenovm Mar 26, 2024
e8d3a9c
remove import from acir_to_constraint_buf and use real error in nargo…
vezenovm Mar 27, 2024
0c7113f
remove old dbg
vezenovm Mar 27, 2024
bef3d55
rename acir_call to call_info
vezenovm Mar 27, 2024
07ba82d
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 27, 2024
60c3294
Update noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/acir_…
vezenovm Mar 27, 2024
ff50bae
include foldable in type check
vezenovm Mar 27, 2024
a75a8f6
use mut ref in test
vezenovm Mar 27, 2024
5ad3e93
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 27, 2024
ea28bad
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 27, 2024
e0a975e
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 27, 2024
c1d6254
move bb solver and foreign call executor to ProgramExecutor
vezenovm Mar 27, 2024
608c61c
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 27, 2024
321d87d
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 28, 2024
14d8623
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 28, 2024
9ebb786
remove bit shifts on all funcs
vezenovm Mar 28, 2024
cfed014
flatten more than just main
vezenovm Mar 28, 2024
35e39cf
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 28, 2024
dac9961
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 28, 2024
37bd830
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 28, 2024
61a0d5a
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 28, 2024
999ef7a
Update noir/noir-repo/tooling/debugger/src/context.rs
vezenovm Mar 28, 2024
eb0dc2b
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 28, 2024
5e084e5
add links in TODOs
vezenovm Mar 28, 2024
aceb1ca
update stale comment
vezenovm Mar 28, 2024
69ce76c
update stale comment
vezenovm Mar 28, 2024
2af705a
another stale comment
vezenovm Mar 28, 2024
cce5a78
remove runtime arg from FunctionBuilder::new
vezenovm Mar 28, 2024
381cf35
add is_entry_point on RunTimeType
vezenovm Mar 28, 2024
67c4a90
Update noir/noir-repo/compiler/noirc_frontend/src/hir/type_check/mod.rs
vezenovm Mar 28, 2024
778e8d9
remove unnecessary field in type_check tests
vezenovm Mar 28, 2024
d51f128
Merge remote-tracking branch 'origin/mv/non-inlined-acir-comptime' in…
vezenovm Mar 28, 2024
56e9eb9
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 28, 2024
b1eff93
Merge branch 'master' into mv/non-inlined-acir-comptime
vezenovm Mar 29, 2024
9a5d8de
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 29, 2024
5cd9a93
missing set_runtime usage in brillig tests
vezenovm Mar 29, 2024
5edd4c0
Merge branch 'mv/non-inlined-acir-comptime' into mv/execute-multiple-…
vezenovm Mar 29, 2024
65810a1
Merge branch 'master' into mv/execute-multiple-circuits-comptime
vezenovm Mar 29, 2024
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,7 @@ workflows:
<<: *defaults
- noir-packages-tests:
requires:
- bb-js
- noir-ecr-manifest
- noir-packages
<<: *defaults
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/acir_tests/Dockerfile.bb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN FLOW=prove_then_verify ./run_acir_tests.sh
RUN FLOW=prove_and_verify_ultra_honk ./run_acir_tests.sh
# Construct and verify a Goblin UltraHonk (GUH) proof for a single arbitrary program
RUN FLOW=prove_and_verify_goblin_ultra_honk ./run_acir_tests.sh 6_array
# Construct and verify a UltraHonk proof for all ACIR programs using the new witness stack workflow
RUN FLOW=prove_and_verify_ultra_honk_program ./run_acir_tests.sh
# This is a "full" Goblin flow. It constructs and verifies four proofs: GoblinUltraHonk, ECCVM, Translator, and merge
RUN FLOW=prove_and_verify_goblin ./run_acir_tests.sh 6_array
# Run 1_mul through native bb build, all_cmds flow, to test all cli args.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -eu

VFLAG=${VERBOSE:+-v}

$BIN prove_and_verify_ultra_honk_program $VFLAG -c $CRS_PATH -b ./target/acir.gz
73 changes: 61 additions & 12 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "barretenberg/bb/file_io.hpp"
#include "barretenberg/common/serialize.hpp"
#include "barretenberg/dsl/acir_format/acir_format.hpp"
#include "barretenberg/dsl/types.hpp"
#include "barretenberg/honk/proof_system/types/proof.hpp"
#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp"
Expand Down Expand Up @@ -83,6 +84,18 @@ acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path)
return acir_format::circuit_buf_to_acir_format(bytecode);
}

acir_format::WitnessVectorStack get_witness_stack(std::string const& witness_path)
{
auto witness_data = get_bytecode(witness_path);
return acir_format::witness_buf_to_witness_stack(witness_data);
}

std::vector<acir_format::AcirFormat> get_constraint_systems(std::string const& bytecode_path)
{
auto bytecode = get_bytecode(bytecode_path);
return acir_format::program_buf_to_acir_format(bytecode);
}

/**
* @brief Proves and Verifies an ACIR circuit
*
Expand Down Expand Up @@ -127,24 +140,14 @@ bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessP
return verified;
}

/**
* @brief Constructs and verifies a Honk proof for an acir-generated circuit
*
* @tparam Flavor
* @param bytecodePath Path to serialized acir circuit data
* @param witnessPath Path to serialized acir witness data
*/
template <IsUltraFlavor Flavor> bool proveAndVerifyHonk(const std::string& bytecodePath, const std::string& witnessPath)
template <IsUltraFlavor Flavor>
bool proveAndVerifyHonkAcirFormat(acir_format::AcirFormat constraint_system, acir_format::WitnessVector witness)
{
using Builder = Flavor::CircuitBuilder;
using Prover = UltraProver_<Flavor>;
using Verifier = UltraVerifier_<Flavor>;
using VerificationKey = Flavor::VerificationKey;

// Populate the acir constraint system and witness from gzipped data
auto constraint_system = get_constraint_system(bytecodePath);
auto witness = get_witness(witnessPath);

// Construct a bberg circuit from the acir representation
auto builder = acir_format::create_circuit<Builder>(constraint_system, 0, witness);

Expand All @@ -165,6 +168,49 @@ template <IsUltraFlavor Flavor> bool proveAndVerifyHonk(const std::string& bytec
return verifier.verify_proof(proof);
}

/**
* @brief Constructs and verifies a Honk proof for an acir-generated circuit
*
* @tparam Flavor
* @param bytecodePath Path to serialized acir circuit data
* @param witnessPath Path to serialized acir witness data
*/
template <IsUltraFlavor Flavor> bool proveAndVerifyHonk(const std::string& bytecodePath, const std::string& witnessPath)
{
// Populate the acir constraint system and witness from gzipped data
auto constraint_system = get_constraint_system(bytecodePath);
auto witness = get_witness(witnessPath);

return proveAndVerifyHonkAcirFormat<Flavor>(constraint_system, witness);
}

/**
* @brief Constructs and verifies multiple Honk proofs for an ACIR-generated program.
*
* @tparam Flavor
* @param bytecodePath Path to serialized acir program data. An ACIR program contains a list of circuits.
* @param witnessPath Path to serialized acir witness stack data. This dictates the execution trace the backend should
* follow.
*/
template <IsUltraFlavor Flavor>
bool proveAndVerifyHonkProgram(const std::string& bytecodePath, const std::string& witnessPath)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw @ledwards2225 this is the one change I made in bberg for now. Just wanted to test that we could also prove the full stack that we generated during execution.

{
auto constraint_systems = get_constraint_systems(bytecodePath);
auto witness_stack = get_witness_stack(witnessPath);

while (!witness_stack.empty()) {
auto witness_stack_item = witness_stack.back();
auto witness = witness_stack_item.second;
auto constraint_system = constraint_systems[witness_stack_item.first];

if (!proveAndVerifyHonkAcirFormat<Flavor>(constraint_system, witness)) {
return false;
}
witness_stack.pop_back();
}
return true;
}

/**
* @brief Proves and Verifies an ACIR circuit
*
Expand Down Expand Up @@ -576,6 +622,9 @@ int main(int argc, char* argv[])
if (command == "prove_and_verify_goblin_ultra_honk") {
return proveAndVerifyHonk<GoblinUltraFlavor>(bytecode_path, witness_path) ? 0 : 1;
}
if (command == "prove_and_verify_ultra_honk_program") {
return proveAndVerifyHonkProgram<UltraFlavor>(bytecode_path, witness_path) ? 0 : 1;
}
if (command == "prove_and_verify_goblin") {
return proveAndVerifyGoblin(bytecode_path, witness_path) ? 0 : 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "recursion_constraint.hpp"
#include "schnorr_verify.hpp"
#include "sha256_constraint.hpp"
#include <utility>

namespace acir_format {

Expand Down Expand Up @@ -93,6 +94,7 @@ struct AcirFormat {
};

using WitnessVector = std::vector<fr, ContainerSlabAllocator<fr>>;
using WitnessVectorStack = std::vector<std::pair<uint32_t, WitnessVector>>;

template <typename Builder = UltraCircuitBuilder>
Builder create_circuit(const AcirFormat& constraint_system, size_t size_hint = 0, WitnessVector const& witness = {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "barretenberg/plonk_honk_shared/arithmetization/gate_data.hpp"
#include "serde/index.hpp"
#include <iterator>
#include <utility>

namespace acir_format {

Expand Down Expand Up @@ -363,12 +364,8 @@ void handle_memory_op(Program::Opcode::MemoryOp const& mem_op, BlockConstraint&
block.trace.push_back(acir_mem_op);
}

AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit)
{
// TODO(maxim): Handle the new `Program` structure once ACVM supports a function call stack.
// For now we expect a single ACIR function
auto circuit = Program::Program::bincodeDeserialize(buf).functions[0];

AcirFormat af;
// `varnum` is the true number of variables, thus we add one to the index which starts at zero
af.varnum = circuit.current_witness_index + 1;
Expand Down Expand Up @@ -406,24 +403,28 @@ AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
return af;
}

AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
{
// TODO(maxim): Handle the new `Program` structure once ACVM supports a function call stack.
// For now we expect a single ACIR function
auto circuit = Program::Program::bincodeDeserialize(buf).functions[0];

return circuit_serde_to_acir_format(circuit);
}

/**
* @brief Converts from the ACIR-native `WitnessMap` format to Barretenberg's internal `WitnessVector` format.
*
* @param buf Serialized representation of a `WitnessMap`.
* @param witness_map ACIR-native `WitnessMap` deserialized from a buffer
* @return A `WitnessVector` equivalent to the passed `WitnessMap`.
* @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0.
* Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`.
*/
WitnessVector witness_buf_to_witness_data(std::vector<uint8_t> const& buf)
WitnessVector witness_map_to_witness_vector(WitnessStack::WitnessMap const& witness_map)
{
// TODO(maxim): Handle the new `WitnessStack` structure once ACVM supports a function call stack
// A `StackItem` contains an index to an ACIR circuit and its respective ACIR-native `WitnessMap`.
// For now we expect the `WitnessStack` to contain a single witness.
auto w = WitnessStack::WitnessStack::bincodeDeserialize(buf).stack[0].witness;

WitnessVector wv;
size_t index = 0;
for (auto& e : w.value) {
for (auto& e : witness_map.value) {
// ACIR uses a sparse format for WitnessMap where unused witness indices may be left unassigned.
// To ensure that witnesses sit at the correct indices in the `WitnessVector`, we fill any indices
// which do not exist within the `WitnessMap` with the dummy value of zero.
Expand All @@ -437,4 +438,48 @@ WitnessVector witness_buf_to_witness_data(std::vector<uint8_t> const& buf)
return wv;
}

/**
* @brief Converts from the ACIR-native `WitnessMap` format to Barretenberg's internal `WitnessVector` format.
*
* @param buf Serialized representation of a `WitnessMap`.
* @return A `WitnessVector` equivalent to the passed `WitnessMap`.
* @note This transformation results in all unassigned witnesses within the `WitnessMap` being assigned the value 0.
* Converting the `WitnessVector` back to a `WitnessMap` is unlikely to return the exact same `WitnessMap`.
*/
WitnessVector witness_buf_to_witness_data(std::vector<uint8_t> const& buf)
{
// TODO(maxim): Handle the new `WitnessStack` structure once ACVM supports a function call stack
// A `StackItem` contains an index to an ACIR circuit and its respective ACIR-native `WitnessMap`.
// For now we expect the `WitnessStack` to contain a single witness.
auto witness_stack = WitnessStack::WitnessStack::bincodeDeserialize(buf);
auto w = witness_stack.stack[witness_stack.stack.size() - 1].witness;

return witness_map_to_witness_vector(w);
}

std::vector<AcirFormat> program_buf_to_acir_format(std::vector<uint8_t> const& buf)
{
auto program = Program::Program::bincodeDeserialize(buf);

std::vector<AcirFormat> constraint_systems;
constraint_systems.reserve(program.functions.size());
for (auto const& function : program.functions) {
constraint_systems.emplace_back(circuit_serde_to_acir_format(function));
}

return constraint_systems;
}

WitnessVectorStack witness_buf_to_witness_stack(std::vector<uint8_t> const& buf)
{
auto witness_stack = WitnessStack::WitnessStack::bincodeDeserialize(buf);
WitnessVectorStack witness_vector_stack;
witness_vector_stack.reserve(witness_stack.stack.size());
for (auto const& stack_item : witness_stack.stack) {
witness_vector_stack.emplace_back(
std::make_pair(stack_item.index, witness_map_to_witness_vector(stack_item.witness)));
}
return witness_vector_stack;
}

} // namespace acir_format
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ impl std::fmt::Display for Opcode {
}
Opcode::Call { id, inputs, outputs } => {
write!(f, "CALL func {}: ", id)?;
writeln!(f, "inputs: {:?}", inputs)?;
writeln!(f, "outputs: {:?}", outputs)
write!(f, "inputs: {:?}, ", inputs)?;
write!(f, "outputs: {:?}", outputs)
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions noir/noir-repo/acvm-repo/acir/src/native_types/witness_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ pub struct StackItem {
pub witness: WitnessMap,
}

impl WitnessStack {
pub fn push(&mut self, index: u32, witness: WitnessMap) {
self.stack.push(StackItem { index, witness });
}

pub fn peek(&self) -> Option<&StackItem> {
self.stack.last()
}

pub fn length(&self) -> usize {
self.stack.len()
}
}

impl From<WitnessMap> for WitnessStack {
fn from(witness: WitnessMap) -> Self {
let stack = vec![StackItem { index: 0, witness }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ pub(super) fn transform_internal(
new_acir_opcode_positions.push(acir_opcode_positions[index]);
transformed_opcodes.push(opcode);
}
Opcode::Call { .. } => todo!("Handle Call opcodes in the ACVM"),
Opcode::Call { .. } => {
// `Call` does not write values to the `WitnessMap`
// A separate ACIR function should have its own respective `WitnessMap`
new_acir_opcode_positions.push(acir_opcode_positions[index]);
transformed_opcodes.push(opcode);
}
}
}

Expand Down
Loading
Loading