Skip to content

Commit

Permalink
feat: ACIR integration tests in Bb (#6607)
Browse files Browse the repository at this point in the history
This adds a GoogleTest suite for running the ACIR tests generated
through Noir. They currently run with GUH arithmetization but they could
easily be extended.

To handle a linker error (and because WASM compilation required this
through an implicit dependency not compiling) I move some function
definitions from a header to a source file and take the opportunity to
reduce the header size as well.
  • Loading branch information
codygunton authored May 23, 2024
1 parent c40f8df commit ca89670
Show file tree
Hide file tree
Showing 7 changed files with 997 additions and 617 deletions.
1 change: 1 addition & 0 deletions barretenberg/cpp/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ test:
COPY --dir +test-binaries/build build
FROM +preset-release-assert-test
COPY --dir ./srs_db/+build/. srs_db
COPY ../../noir/+build-acir-tests/ /usr/src/acir_tests/acir_tests/
# limit hardware concurrency, if provided
IF [ "$HARDWARE_CONCURRENCY" != "" ]
ENV HARDWARE_CONCURRENCY=$hardware_concurrency
Expand Down
13 changes: 5 additions & 8 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,15 @@ template <IsUltraFlavor Flavor> bool proveAndVerifyHonk(const std::string& bytec
template <IsUltraFlavor Flavor>
bool proveAndVerifyHonkProgram(const std::string& bytecodePath, const std::string& witnessPath)
{
auto constraint_systems = get_constraint_systems(bytecodePath);
auto witness_stack = get_witness_stack(witnessPath);
auto program_stack = acir_format::get_acir_program_stack(bytecodePath, 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];
while (!program_stack.empty()) {
auto stack_item = program_stack.back();

if (!proveAndVerifyHonkAcirFormat<Flavor>(constraint_system, witness)) {
if (!proveAndVerifyHonkAcirFormat<Flavor>(stack_item.constraints, stack_item.witness)) {
return false;
}
witness_stack.pop_back();
program_stack.pop_back();
}
return true;
}
Expand Down
30 changes: 30 additions & 0 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,36 @@ struct AcirFormat {
using WitnessVector = std::vector<fr, ContainerSlabAllocator<fr>>;
using WitnessVectorStack = std::vector<std::pair<uint32_t, WitnessVector>>;

struct AcirProgram {
AcirFormat constraints;
WitnessVector witness;
};

/**
* @brief Storage for constaint_systems/witnesses for a stack of acir programs
* @details In general the number of items in the witness stack will be equal or greater than the number of constraint
* systems because the program may consist of multiple calls to the same function.
*
*/
struct AcirProgramStack {
std::vector<AcirFormat> constraint_systems;
WitnessVectorStack witness_stack;

size_t size() const { return witness_stack.size(); }
bool empty() const { return witness_stack.empty(); }

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

return { constraint_system, witness };
}

void pop_back() { witness_stack.pop_back(); }
};

template <typename Builder = UltraCircuitBuilder>
Builder create_circuit(const AcirFormat& constraint_system,
size_t size_hint = 0,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,12 @@ template <typename FF_> class UltraArith {
void summarize() const
{
info("Gate blocks summary:");
info("pub inputs:\t", pub_inputs.size());
info("arithmetic:\t", arithmetic.size());
info("pub inputs :\t", pub_inputs.size());
info("arithmetic :\t", arithmetic.size());
info("delta range:\t", delta_range.size());
info("elliptic:\t", elliptic.size());
info("auxiliary:\t", aux.size());
info("lookups:\t", lookup.size());
info("");
info("elliptic :\t", elliptic.size());
info("auxiliary :\t", aux.size());
info("lookups :\t", lookup.size());
}

size_t get_total_structured_size()
Expand Down Expand Up @@ -349,16 +348,16 @@ template <typename FF_> class UltraHonkArith {
void summarize() const
{
info("Gate blocks summary: (actual gates / fixed capacity)");
info("goblin ecc op:\t", ecc_op.size(), "/", ecc_op.get_fixed_size());
info("pub inputs:\t", pub_inputs.size(), "/", pub_inputs.get_fixed_size());
info("arithmetic:\t", arithmetic.size(), "/", arithmetic.get_fixed_size());
info("delta range:\t", delta_range.size(), "/", delta_range.get_fixed_size());
info("elliptic:\t", elliptic.size(), "/", elliptic.get_fixed_size());
info("auxiliary:\t", aux.size(), "/", aux.get_fixed_size());
info("lookups:\t", lookup.size(), "/", lookup.get_fixed_size());
info("busread:\t", busread.size(), "/", busread.get_fixed_size());
info("poseidon ext:\t", poseidon_external.size(), "/", poseidon_external.get_fixed_size());
info("poseidon int:\t", poseidon_internal.size(), "/", poseidon_internal.get_fixed_size());
info("goblin ecc op :\t", ecc_op.size(), "/", ecc_op.get_fixed_size());
info("pub inputs :\t", pub_inputs.size(), "/", pub_inputs.get_fixed_size());
info("arithmetic :\t", arithmetic.size(), "/", arithmetic.get_fixed_size());
info("delta range :\t", delta_range.size(), "/", delta_range.get_fixed_size());
info("elliptic :\t", elliptic.size(), "/", elliptic.get_fixed_size());
info("auxiliary :\t", aux.size(), "/", aux.get_fixed_size());
info("lookups :\t", lookup.size(), "/", lookup.get_fixed_size());
info("busread :\t", busread.size(), "/", busread.get_fixed_size());
info("poseidon ext :\t", poseidon_external.size(), "/", poseidon_external.get_fixed_size());
info("poseidon int :\t", poseidon_internal.size(), "/", poseidon_internal.get_fixed_size());
info("");
}

Expand Down

0 comments on commit ca89670

Please sign in to comment.