Skip to content

Commit

Permalink
constify all of the metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Dec 10, 2024
1 parent 2757b1c commit f6eb239
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 70 deletions.
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/bb/api_client_ivc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ClientIVCAPI : public API {
TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE };
auto ivc = std::make_shared<ClientIVC>(trace_settings, auto_verify);

ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };

// Accumulate the entire program stack into the IVC
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1116): remove manual setting of is_kernel
Expand Down
51 changes: 20 additions & 31 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,9 @@ bool proveAndVerifyHonkAcirFormat(acir_format::AcirProgram program, acir_format:
template <IsUltraFlavor Flavor>
bool proveAndVerifyHonk(const std::string& bytecodePath, const bool recursive, const std::string& witnessPath)
{
acir_format::ProgramMetadata metadata;
metadata.recursive = recursive;
if constexpr (IsAnyOf<Flavor, UltraFlavor>) {
metadata.honk_recursion = true;
}
constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor>;
const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = honk_recursion };

// Populate the acir constraint system and witness from gzipped data
acir_format::AcirProgram program;
program.constraints = get_constraint_system(bytecodePath, metadata.honk_recursion);
Expand All @@ -167,11 +165,9 @@ bool proveAndVerifyHonk(const std::string& bytecodePath, const bool recursive, c
template <IsUltraFlavor Flavor>
bool proveAndVerifyHonkProgram(const std::string& bytecodePath, const bool recursive, const std::string& witnessPath)
{
acir_format::ProgramMetadata metadata;
metadata.recursive = recursive;
if constexpr (IsAnyOf<Flavor, UltraFlavor>) {
metadata.honk_recursion = true;
}
constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor>;
const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = honk_recursion };

auto program_stack = acir_format::get_acir_program_stack(bytecodePath, witnessPath, metadata.honk_recursion);

while (!program_stack.empty()) {
Expand Down Expand Up @@ -328,10 +324,9 @@ void gateCount(const std::string& bytecodePath, bool recursive, bool honk_recurs
std::string functions_string = "{\"functions\": [\n ";
auto constraint_systems = get_constraint_systems(bytecodePath, honk_recursion);

acir_format::ProgramMetadata metadata;
metadata.recursive = recursive;
metadata.honk_recursion = honk_recursion;
metadata.collect_gates_per_opcode = true;
const acir_format::ProgramMetadata metadata{ .recursive = recursive,
.honk_recursion = honk_recursion,
.collect_gates_per_opcode = true };
size_t i = 0;
for (const auto& constraint_system : constraint_systems) {
acir_format::AcirProgram program{ constraint_system };
Expand Down Expand Up @@ -717,11 +712,9 @@ UltraProver_<Flavor> compute_valid_prover(const std::string& bytecodePath,
using Builder = Flavor::CircuitBuilder;
using Prover = UltraProver_<Flavor>;

acir_format::ProgramMetadata metadata;
metadata.recursive = recursive;
if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor, UltraRollupFlavor>) {
metadata.honk_recursion = true;
}
constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor, UltraRollupFlavor>;
const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = honk_recursion };

acir_format::AcirProgram program{ get_constraint_system(bytecodePath, metadata.honk_recursion) };
if (!witnessPath.empty()) {
program.witness = get_witness(witnessPath);
Expand Down Expand Up @@ -862,10 +855,9 @@ void write_vk_for_ivc(const std::string& bytecodePath, const std::string& output

TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE };

ProgramMetadata metadata{};
if (!ivc_constraints.empty()) {
metadata.ivc = create_mock_ivc_from_constraints(ivc_constraints, trace_settings);
}
const ProgramMetadata metadata{ .ivc = ivc_constraints.empty()
? nullptr
: create_mock_ivc_from_constraints(ivc_constraints, trace_settings) };
Builder builder = acir_format::create_circuit<Builder>(program, metadata);

// Add public inputs corresponding to pairing point accumulator
Expand Down Expand Up @@ -907,9 +899,8 @@ void write_recursion_inputs_honk(const std::string& bytecodePath,
using VerificationKey = Flavor::VerificationKey;
using FF = Flavor::FF;

acir_format::ProgramMetadata metadata;
metadata.recursive = recursive;
metadata.honk_recursion = true;
const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = true };

acir_format::AcirProgram program;
program.constraints = get_constraint_system(bytecodePath, metadata.honk_recursion);
program.witness = get_witness(witnessPath);
Expand Down Expand Up @@ -1061,11 +1052,9 @@ void prove_honk_output_all(const std::string& bytecodePath,
using Prover = UltraProver_<Flavor>;
using VerificationKey = Flavor::VerificationKey;

acir_format::ProgramMetadata metadata;
metadata.recursive = recursive;
if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor>) {
metadata.honk_recursion = true;
}
constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor>;
const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = honk_recursion };

acir_format::AcirProgram program{ get_constraint_system(bytecodePath, metadata.honk_recursion),
get_witness(witnessPath) };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,10 @@ UltraCircuitBuilder create_circuit(AcirFormat& constraint_system,
Builder builder{ size_hint, witness, constraint_system.public_inputs, constraint_system.varnum, recursive };

AcirProgram program{ constraint_system, witness };
ProgramMetadata metadata;
metadata.recursive = recursive;
metadata.honk_recursion = honk_recursion;
metadata.collect_gates_per_opcode = collect_gates_per_opcode;
metadata.size_hint = size_hint;
const ProgramMetadata metadata{ .recursive = recursive,
.honk_recursion = honk_recursion,
.collect_gates_per_opcode = collect_gates_per_opcode,
.size_hint = size_hint };
build_constraints(builder, program, metadata);

vinfo("created circuit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ TEST_F(AcirFormatTests, TestCollectsGateCounts)
mock_opcode_indices(constraint_system);
WitnessVector witness{ 5, 27, 32 };
AcirProgram program{ constraint_system, witness };
ProgramMetadata metadata;
metadata.collect_gates_per_opcode = true;
const ProgramMetadata metadata{ .collect_gates_per_opcode = true };
auto builder = create_circuit(program, metadata);

EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ 2, 1 }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ TEST_P(AcirIntegrationFoldingTest, DISABLED_FoldAndVerifyProgramStack)
TraceSettings trace_settings{ SMALL_TEST_STRUCTURE };
auto ivc = std::make_shared<ClientIVC>(trace_settings, /*auto_verify_mode=*/true);

acir_format::ProgramMetadata metadata{ ivc };
const acir_format::ProgramMetadata metadata{ ivc };

while (!program_stack.empty()) {
auto program = program_stack.back();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class IvcRecursionConstraintTest : public ::testing::Test {
auto mock_ivc = create_mock_ivc_from_constraints(program.constraints.ivc_recursion_constraints, trace_settings);

// Create kernel circuit from kernel program and the mocked IVC (empty witness mimics VK construction context)
ProgramMetadata metadata{ mock_ivc };
const ProgramMetadata metadata{ mock_ivc };
Builder kernel = acir_format::create_circuit<Builder>(program, metadata);
// Note: adding pairing point normally happens in accumulate()
kernel.add_pairing_point_accumulator(stdlib::recursion::init_default_agg_obj_indices<Builder>(kernel));
Expand Down Expand Up @@ -154,7 +154,7 @@ TEST_F(IvcRecursionConstraintTest, AccumulateTwo)
// Construct kernel consisting only of the kernel completion logic
AcirProgram program = construct_mock_kernel_program(ivc->verification_queue);

ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };
Builder kernel = acir_format::create_circuit<Builder>(program, metadata);

EXPECT_TRUE(CircuitChecker::check(kernel));
Expand All @@ -176,7 +176,7 @@ TEST_F(IvcRecursionConstraintTest, AccumulateFour)
Builder app_circuit_0 = construct_mock_app_circuit(ivc);
ivc->accumulate(app_circuit_0);

ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };

// Construct kernel_0; consists of a single oink recursive verification for app (plus databus/merge logic)
AcirProgram program_0 = construct_mock_kernel_program(ivc->verification_queue);
Expand Down Expand Up @@ -213,7 +213,7 @@ TEST_F(IvcRecursionConstraintTest, GenerateVK)

// Construct and accumulate kernel consisting only of the kernel completion logic
AcirProgram program = construct_mock_kernel_program(ivc->verification_queue);
ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };
Builder kernel = acir_format::create_circuit<Builder>(program, metadata);
ivc->accumulate(kernel);
expected_kernel_vk = ivc->verification_queue.back().honk_verification_key;
Expand All @@ -228,7 +228,7 @@ TEST_F(IvcRecursionConstraintTest, GenerateVK)

// Construct kernel consisting only of the kernel completion logic
AcirProgram program = construct_mock_kernel_program(ivc->verification_queue);
ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };
Builder kernel = acir_format::create_circuit<Builder>(program, metadata);
// Note that this would normally happen in accumulate()
kernel.add_pairing_point_accumulator(stdlib::recursion::init_default_agg_obj_indices<Builder>(kernel));
Expand Down Expand Up @@ -261,7 +261,7 @@ TEST_F(IvcRecursionConstraintTest, GenerateInitKernelVKFromConstraints)

// Construct and accumulate kernel consisting only of the kernel completion logic
AcirProgram program = construct_mock_kernel_program(ivc->verification_queue);
ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };
Builder kernel = acir_format::create_circuit<Builder>(program, metadata);

ivc->accumulate(kernel);
Expand Down Expand Up @@ -298,7 +298,7 @@ TEST_F(IvcRecursionConstraintTest, GenerateResetKernelVKFromConstraints)
{
auto ivc = std::make_shared<ClientIVC>(trace_settings);

ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };

// Construct and accumulate mock app_circuit
Builder app_circuit = construct_mock_app_circuit(ivc);
Expand Down Expand Up @@ -351,7 +351,7 @@ TEST_F(IvcRecursionConstraintTest, GenerateInnerKernelVKFromConstraints)
{
auto ivc = std::make_shared<ClientIVC>(trace_settings);

ProgramMetadata metadata{ ivc };
const ProgramMetadata metadata{ ivc };

{ // Construct and accumulate mock app_circuit
Builder app_circuit = construct_mock_app_circuit(ivc);
Expand Down
33 changes: 11 additions & 22 deletions barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
WASM_EXPORT void acir_get_circuit_sizes(
uint8_t const* acir_vec, bool const* recursive, bool const* honk_recursion, uint32_t* total, uint32_t* subgroup)
{
acir_format::ProgramMetadata metadata;
metadata.recursive = *recursive;
metadata.honk_recursion = *honk_recursion;
metadata.size_hint = 1 << 19;
const acir_format::ProgramMetadata metadata{ .recursive = *recursive,
.honk_recursion = *honk_recursion,
.size_hint = 1 << 19 };
acir_format::AcirProgram program{ acir_format::circuit_buf_to_acir_format(
from_buffer<std::vector<uint8_t>>(acir_vec), *honk_recursion) };
auto builder = acir_format::create_circuit(program, metadata);
Expand Down Expand Up @@ -69,9 +68,7 @@ WASM_EXPORT void acir_prove_and_verify_ultra_honk(uint8_t const* acir_vec,
uint8_t const* witness_vec,
bool* result)
{
acir_format::ProgramMetadata metadata;
metadata.recursive = *recursive;
metadata.honk_recursion = true;
const acir_format::ProgramMetadata metadata{ .recursive = *recursive, .honk_recursion = true };
acir_format::AcirProgram program{
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), metadata.honk_recursion),
acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec))
Expand Down Expand Up @@ -106,7 +103,7 @@ WASM_EXPORT void acir_fold_and_verify_program_stack(uint8_t const* acir_vec,
TraceSettings trace_settings{ SMALL_TEST_STRUCTURE };
auto ivc = std::make_shared<ClientIVC>(trace_settings, /*auto_verify_mode=*/true);

acir_format::ProgramMetadata metadata{ ivc, *recursive };
const acir_format::ProgramMetadata metadata{ ivc, *recursive };

bool is_kernel = false;
while (!program_stack.empty()) {
Expand All @@ -131,9 +128,7 @@ WASM_EXPORT void acir_prove_and_verify_mega_honk(uint8_t const* acir_vec,
uint8_t const* witness_vec,
bool* result)
{
acir_format::ProgramMetadata metadata;
metadata.recursive = *recursive;
metadata.honk_recursion = false;
const acir_format::ProgramMetadata metadata{ .recursive = *recursive, .honk_recursion = false };

acir_format::AcirProgram program{
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), metadata.honk_recursion),
Expand Down Expand Up @@ -247,7 +242,7 @@ WASM_EXPORT void acir_prove_and_verify_aztec_client(uint8_t const* acir_stack,
TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE };
auto ivc = std::make_shared<ClientIVC>(trace_settings, /*auto_verify_mode=*/true);

acir_format::ProgramMetadata metadata{ ivc };
const acir_format::ProgramMetadata metadata{ ivc };

// Accumulate the entire program stack into the IVC
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1116): remove manual setting of is_kernel once databus
Expand Down Expand Up @@ -305,7 +300,7 @@ WASM_EXPORT void acir_prove_aztec_client(uint8_t const* acir_stack,
TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE };
auto ivc = std::make_shared<ClientIVC>(trace_settings, /*auto_verify_mode=*/true);

acir_format::ProgramMetadata metadata{ ivc };
const acir_format::ProgramMetadata metadata{ ivc };

// Accumulate the entire program stack into the IVC
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1116): remove manual setting of is_kernel once databus
Expand Down Expand Up @@ -371,9 +366,7 @@ WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec,
uint8_t const* witness_vec,
uint8_t** out)
{
acir_format::ProgramMetadata metadata;
metadata.recursive = *recursive;
metadata.honk_recursion = true;
const acir_format::ProgramMetadata metadata{ .recursive = *recursive, .honk_recursion = true };

acir_format::AcirProgram program{
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), metadata.honk_recursion),
Expand Down Expand Up @@ -439,9 +432,7 @@ WASM_EXPORT void acir_write_vk_ultra_honk(uint8_t const* acir_vec, bool const* r
using DeciderProvingKey = DeciderProvingKey_<UltraFlavor>;
using VerificationKey = UltraFlavor::VerificationKey;

acir_format::ProgramMetadata metadata;
metadata.recursive = *recursive;
metadata.honk_recursion = true;
const acir_format::ProgramMetadata metadata{ .recursive = *recursive, .honk_recursion = true };

acir_format::AcirProgram program{ acir_format::circuit_buf_to_acir_format(
from_buffer<std::vector<uint8_t>>(acir_vec), metadata.honk_recursion) };
Expand All @@ -457,9 +448,7 @@ WASM_EXPORT void acir_write_vk_ultra_keccak_honk(uint8_t const* acir_vec, bool c
using DeciderProvingKey = DeciderProvingKey_<UltraKeccakFlavor>;
using VerificationKey = UltraKeccakFlavor::VerificationKey;

acir_format::ProgramMetadata metadata;
metadata.recursive = *recursive;
metadata.honk_recursion = true;
const acir_format::ProgramMetadata metadata{ .recursive = *recursive, .honk_recursion = true };

acir_format::AcirProgram program{ acir_format::circuit_buf_to_acir_format(
from_buffer<std::vector<uint8_t>>(acir_vec), metadata.honk_recursion) };
Expand Down

0 comments on commit f6eb239

Please sign in to comment.