Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 14 additions & 14 deletions barretenberg/cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ acir_format::WitnessVector get_witness(std::string const& witness_path)
return acir_format::witness_buf_to_witness_data(witness_data);
}

acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path)
acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path, bool honk_recursion)
{
auto bytecode = get_bytecode(bytecode_path);
return acir_format::circuit_buf_to_acir_format(bytecode);
return acir_format::circuit_buf_to_acir_format(bytecode, honk_recursion);
}

acir_format::WitnessVectorStack get_witness_stack(std::string const& witness_path)
Expand All @@ -90,10 +90,10 @@ acir_format::WitnessVectorStack get_witness_stack(std::string const& witness_pat
return acir_format::witness_buf_to_witness_stack(witness_data);
}

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

std::string proof_to_json(std::vector<bb::fr>& proof)
Expand Down Expand Up @@ -124,7 +124,7 @@ std::string vk_to_json(std::vector<bb::fr>& data)
*/
bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessPath)
{
auto constraint_system = get_constraint_system(bytecodePath);
auto constraint_system = get_constraint_system(bytecodePath, false);
auto witness = get_witness(witnessPath);

acir_proofs::AcirComposer acir_composer{ 0, verbose };
Expand Down Expand Up @@ -189,7 +189,7 @@ bool proveAndVerifyHonkAcirFormat(acir_format::AcirFormat constraint_system, aci
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 constraint_system = get_constraint_system(bytecodePath, true);
auto witness = get_witness(witnessPath);

return proveAndVerifyHonkAcirFormat<Flavor>(constraint_system, witness);
Expand Down Expand Up @@ -242,7 +242,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, const std::string& wi
init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack);

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

// Instantiate a Goblin acir composer and construct a bberg circuit from the acir representation
Expand Down Expand Up @@ -272,7 +272,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, const std::string& wi
*/
void prove(const std::string& bytecodePath, const std::string& witnessPath, const std::string& outputPath)
{
auto constraint_system = get_constraint_system(bytecodePath);
auto constraint_system = get_constraint_system(bytecodePath, false);
auto witness = get_witness(witnessPath);

acir_proofs::AcirComposer acir_composer{ 0, verbose };
Expand Down Expand Up @@ -302,7 +302,7 @@ void gateCount(const std::string& bytecodePath)
{
// All circuit reports will be built into the string below
std::string functions_string = "{\"functions\": [\n ";
auto constraint_systems = get_constraint_systems(bytecodePath);
auto constraint_systems = get_constraint_systems(bytecodePath, false);
size_t i = 0;
for (auto constraint_system : constraint_systems) {
acir_proofs::AcirComposer acir_composer(0, verbose);
Expand Down Expand Up @@ -371,7 +371,7 @@ bool verify(const std::string& proof_path, const std::string& vk_path)
*/
void write_vk(const std::string& bytecodePath, const std::string& outputPath)
{
auto constraint_system = get_constraint_system(bytecodePath);
auto constraint_system = get_constraint_system(bytecodePath, false);
acir_proofs::AcirComposer acir_composer{ 0, verbose };
acir_composer.create_circuit(constraint_system);
init_bn254_crs(acir_composer.get_dyadic_circuit_size());
Expand All @@ -389,7 +389,7 @@ void write_vk(const std::string& bytecodePath, const std::string& outputPath)

void write_pk(const std::string& bytecodePath, const std::string& outputPath)
{
auto constraint_system = get_constraint_system(bytecodePath);
auto constraint_system = get_constraint_system(bytecodePath, false);
acir_proofs::AcirComposer acir_composer{ 0, verbose };
acir_composer.create_circuit(constraint_system);
init_bn254_crs(acir_composer.get_dyadic_circuit_size());
Expand Down Expand Up @@ -583,7 +583,7 @@ void prove_honk(const std::string& bytecodePath, const std::string& witnessPath,
using Builder = Flavor::CircuitBuilder;
using Prover = UltraProver_<Flavor>;

auto constraint_system = get_constraint_system(bytecodePath);
auto constraint_system = get_constraint_system(bytecodePath, true);
auto witness = get_witness(witnessPath);

auto builder = acir_format::create_circuit<Builder>(constraint_system, 0, witness);
Expand Down Expand Up @@ -656,7 +656,7 @@ template <IsUltraFlavor Flavor> void write_vk_honk(const std::string& bytecodePa
using ProverInstance = ProverInstance_<Flavor>;
using VerificationKey = Flavor::VerificationKey;

auto constraint_system = get_constraint_system(bytecodePath);
auto constraint_system = get_constraint_system(bytecodePath, true);
auto builder = acir_format::create_circuit<Builder>(constraint_system, 0, {});

auto num_extra_gates = builder.get_num_gates_added_to_ensure_nonzero_polynomials();
Expand Down Expand Up @@ -744,7 +744,7 @@ template <IsUltraFlavor Flavor> void vk_as_fields_honk(const std::string& vk_pat
*/
void prove_output_all(const std::string& bytecodePath, const std::string& witnessPath, const std::string& outputPath)
{
auto constraint_system = get_constraint_system(bytecodePath);
auto constraint_system = get_constraint_system(bytecodePath, false);
auto witness = get_witness(witnessPath);

acir_proofs::AcirComposer acir_composer{ 0, verbose };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ void handle_memory_op(Program::Opcode::MemoryOp const& mem_op, BlockConstraint&
block.trace.push_back(acir_mem_op);
}

AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit)
AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit, bool honk_recursion)
{
static_cast<void>(honk_recursion);
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 @@ -507,14 +508,14 @@ AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit)
return af;
}

AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf, bool honk_recursion)
{
// TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just `program_buf_to_acir_format`
// once Honk fully supports all ACIR test flows
// For now the backend still expects to work with a single ACIR function
auto circuit = Program::Program::bincodeDeserialize(buf).functions[0];

return circuit_serde_to_acir_format(circuit);
return circuit_serde_to_acir_format(circuit, honk_recursion);
}

/**
Expand Down Expand Up @@ -562,14 +563,14 @@ WitnessVector witness_buf_to_witness_data(std::vector<uint8_t> const& buf)
return witness_map_to_witness_vector(w);
}

std::vector<AcirFormat> program_buf_to_acir_format(std::vector<uint8_t> const& buf)
std::vector<AcirFormat> program_buf_to_acir_format(std::vector<uint8_t> const& buf, bool honk_recursion)
{
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));
constraint_systems.emplace_back(circuit_serde_to_acir_format(function, honk_recursion));
}

return constraint_systems;
Expand All @@ -591,7 +592,7 @@ WitnessVectorStack witness_buf_to_witness_stack(std::vector<uint8_t> const& buf)
AcirProgramStack get_acir_program_stack(std::string const& bytecode_path, std::string const& witness_path)
{
auto bytecode = get_bytecode(bytecode_path);
auto constraint_systems = program_buf_to_acir_format(bytecode);
auto constraint_systems = program_buf_to_acir_format(bytecode, /*honk_recursion=*/false);

auto witness_data = get_bytecode(witness_path);
auto witness_stack = witness_buf_to_witness_stack(witness_data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace acir_format {

AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf);
AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf, bool honk_recursion);

/**
* @brief Converts from the ACIR-native `WitnessMap` format to Barretenberg's internal `WitnessVector` format.
Expand All @@ -16,7 +16,7 @@ AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf);
*/
WitnessVector witness_buf_to_witness_data(std::vector<uint8_t> const& buf);

std::vector<AcirFormat> program_buf_to_acir_format(std::vector<uint8_t> const& buf);
std::vector<AcirFormat> program_buf_to_acir_format(std::vector<uint8_t> const& buf, bool honk_recursion);

WitnessVectorStack witness_buf_to_witness_stack(std::vector<uint8_t> const& buf);

Expand Down
27 changes: 18 additions & 9 deletions barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

WASM_EXPORT void acir_get_circuit_sizes(uint8_t const* acir_vec, uint32_t* exact, uint32_t* total, uint32_t* subgroup)
{
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto builder = acir_format::create_circuit(constraint_system, 1 << 19);
*exact = htonl((uint32_t)builder.get_num_gates());
*total = htonl((uint32_t)builder.get_total_circuit_size());
Expand All @@ -40,7 +41,8 @@ WASM_EXPORT void acir_delete_acir_composer(in_ptr acir_composer_ptr)
WASM_EXPORT void acir_init_proving_key(in_ptr acir_composer_ptr, uint8_t const* acir_vec)
{
auto acir_composer = reinterpret_cast<acir_proofs::AcirComposer*>(*acir_composer_ptr);
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
acir_composer->create_circuit(constraint_system);

acir_composer->init_proving_key();
Expand All @@ -52,7 +54,8 @@ WASM_EXPORT void acir_create_proof(in_ptr acir_composer_ptr,
uint8_t** out)
{
auto acir_composer = reinterpret_cast<acir_proofs::AcirComposer*>(*acir_composer_ptr);
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec));

acir_composer->create_circuit(constraint_system, witness);
Expand All @@ -64,7 +67,8 @@ WASM_EXPORT void acir_create_proof(in_ptr acir_composer_ptr,

WASM_EXPORT void acir_prove_and_verify_ultra_honk(uint8_t const* acir_vec, uint8_t const* witness_vec, bool* result)
{
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec));

auto builder = acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, 0, witness);
Expand All @@ -80,7 +84,8 @@ WASM_EXPORT void acir_prove_and_verify_ultra_honk(uint8_t const* acir_vec, uint8

WASM_EXPORT void acir_prove_and_verify_mega_honk(uint8_t const* acir_vec, uint8_t const* witness_vec, bool* result)
{
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec));

auto builder = acir_format::create_circuit<MegaCircuitBuilder>(constraint_system, 0, witness);
Expand All @@ -100,7 +105,8 @@ WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr,
uint8_t** out)
{
auto acir_composer = reinterpret_cast<acir_proofs::GoblinAcirComposer*>(*acir_composer_ptr);
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec));

acir_composer->create_circuit(constraint_system, witness);
Expand Down Expand Up @@ -135,7 +141,8 @@ WASM_EXPORT void acir_get_verification_key(in_ptr acir_composer_ptr, uint8_t** o
WASM_EXPORT void acir_get_proving_key(in_ptr acir_composer_ptr, uint8_t const* acir_vec, uint8_t** out)
{
auto acir_composer = reinterpret_cast<acir_proofs::AcirComposer*>(*acir_composer_ptr);
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
acir_composer->create_circuit(constraint_system);
auto pk = acir_composer->init_proving_key();
// We flatten to a vector<uint8_t> first, as that's how we treat it on the calling side.
Expand Down Expand Up @@ -192,7 +199,8 @@ WASM_EXPORT void acir_serialize_verification_key_into_fields(in_ptr acir_compose

WASM_EXPORT void acir_prove_ultra_honk(uint8_t const* acir_vec, uint8_t const* witness_vec, uint8_t** out)
{
auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto witness = acir_format::witness_buf_to_witness_data(from_buffer<std::vector<uint8_t>>(witness_vec));

auto builder = acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, 0, witness);
Expand Down Expand Up @@ -222,7 +230,8 @@ WASM_EXPORT void acir_write_vk_ultra_honk(uint8_t const* acir_vec, uint8_t** out
using ProverInstance = ProverInstance_<UltraFlavor>;
using VerificationKey = UltraFlavor::VerificationKey;

auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec));
auto constraint_system =
acir_format::circuit_buf_to_acir_format(from_buffer<std::vector<uint8_t>>(acir_vec), /*honk_recursion=*/false);
auto builder = acir_format::create_circuit<UltraCircuitBuilder>(constraint_system, 0, {});

ProverInstance prover_inst(builder);
Expand Down