Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions barretenberg/cpp/src/barretenberg/api/acir_format_getters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,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, uint32_t honk_recursion)
acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path)
{
auto bytecode = get_bytecode(bytecode_path);
return acir_format::circuit_buf_to_acir_format(bytecode, honk_recursion);
return acir_format::circuit_buf_to_acir_format(bytecode);
}

acir_format::WitnessVectorStack get_witness_stack(std::string const& witness_path)
Expand All @@ -23,10 +23,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, uint32_t honk_recursion)
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, honk_recursion);
return acir_format::program_buf_to_acir_format(bytecode);
}

} // namespace bb
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/api/acir_format_getters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace bb {
acir_format::WitnessVector get_witness(std::string const& witness_path);
acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path, uint32_t honk_recursion);
acir_format::AcirFormat get_constraint_system(std::string const& bytecode_path);
acir_format::WitnessVectorStack get_witness_stack(std::string const& witness_path);
std::vector<acir_format::AcirFormat> get_constraint_systems(std::string const& bytecode_path, uint32_t honk_recursion);
std::vector<acir_format::AcirFormat> get_constraint_systems(std::string const& bytecode_path);
} // namespace bb
6 changes: 3 additions & 3 deletions barretenberg/cpp/src/barretenberg/api/api_client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void write_standalone_vk(const std::string& output_data_type,
init_bn254_crs(1 << CONST_PG_LOG_N);
init_grumpkin_crs(1 << CONST_ECCVM_LOG_N);

Program program{ get_constraint_system(bytecode_path, /*honk_recursion=*/0), /*witness=*/{} };
Program program{ get_constraint_system(bytecode_path), /*witness=*/{} };
auto& ivc_constraints = program.constraints.ivc_recursion_constraints;

TraceSettings trace_settings{ AZTEC_TRACE_STRUCTURE };
Expand Down Expand Up @@ -88,7 +88,7 @@ size_t get_num_public_inputs_in_final_circuit(const std::filesystem::path& input
auto steps = PrivateExecutionStepRaw::load_and_decompress(input_path);
const PrivateExecutionStepRaw& last_step = steps.back();
std::vector<uint8_t> bytecode_buf(last_step.bytecode.begin(), last_step.bytecode.end());
const AcirFormat constraints = circuit_buf_to_acir_format(bytecode_buf, /*honk_recursion=*/0);
const AcirFormat constraints = circuit_buf_to_acir_format(bytecode_buf);
return constraints.public_inputs.size();
}

Expand Down Expand Up @@ -246,7 +246,7 @@ void gate_count_for_ivc(const std::string& bytecode_path, bool include_gates_per
// All circuit reports will be built into the std::string below
std::string functions_string = "{\"functions\": [\n ";
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1181): Use enum for honk_recursion.
auto constraint_systems = get_constraint_systems(bytecode_path, /*honk_recursion=*/0);
auto constraint_systems = get_constraint_systems(bytecode_path);

// Initialize an SRS to make the ClientIVC constructor happy
init_bn254_crs(1 << CONST_PG_LOG_N);
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/api/api_ultra_honk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Circuit _compute_circuit(const std::string& bytecode_path, const std::string& wi
init_grumpkin_crs(1 << CONST_ECCVM_LOG_N);

const acir_format::ProgramMetadata metadata{ .honk_recursion = honk_recursion };
acir_format::AcirProgram program{ get_constraint_system(bytecode_path, metadata.honk_recursion) };
acir_format::AcirProgram program{ get_constraint_system(bytecode_path) };

if (!witness_path.empty()) {
program.witness = get_witness(witness_path);
Expand Down Expand Up @@ -271,7 +271,7 @@ void write_recursion_inputs_ultra_honk(const std::string& bytecode_path,
const acir_format::ProgramMetadata metadata{ .honk_recursion = honk_recursion };

acir_format::AcirProgram program;
program.constraints = get_constraint_system(bytecode_path, metadata.honk_recursion);
program.constraints = get_constraint_system(bytecode_path);
program.witness = get_witness(witness_path);
auto builder = acir_format::create_circuit<Builder>(program, metadata);

Expand Down
10 changes: 5 additions & 5 deletions barretenberg/cpp/src/barretenberg/api/api_ultra_plonk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void prove_ultra_plonk(const std::string& bytecode_path,
const std::string& output_path,
const bool recursive)
{
auto constraint_system = get_constraint_system(bytecode_path, /*honk_recursion=*/0);
auto constraint_system = get_constraint_system(bytecode_path);
auto witness = get_witness(witness_path);

acir_proofs::AcirComposer acir_composer{ 0, verbose_logging };
Expand Down Expand Up @@ -88,7 +88,7 @@ void prove_output_all_ultra_plonk(const std::string& bytecode_path,
const std::string& output_path,
const bool recursive)
{
auto constraint_system = get_constraint_system(bytecode_path, /*honk_recursion=*/0);
auto constraint_system = get_constraint_system(bytecode_path);
auto witness = get_witness(witness_path);

acir_proofs::AcirComposer acir_composer{ 0, verbose_logging };
Expand Down Expand Up @@ -172,7 +172,7 @@ bool prove_and_verify_ultra_plonk(const std::string& bytecode_path,
const bool recursive,
const std::string& witness_path)
{
auto constraint_system = get_constraint_system(bytecode_path, /*honk_recursion=*/0);
auto constraint_system = get_constraint_system(bytecode_path);
auto witness = get_witness(witness_path);

acir_proofs::AcirComposer acir_composer{ 0, verbose_logging };
Expand Down Expand Up @@ -234,7 +234,7 @@ void contract_ultra_plonk(const std::string& output_path, const std::string& vk_
*/
void write_vk_ultra_plonk(const std::string& bytecode_path, const std::string& output_path, const bool recursive)
{
auto constraint_system = get_constraint_system(bytecode_path, false);
auto constraint_system = get_constraint_system(bytecode_path);
acir_proofs::AcirComposer acir_composer{ 0, verbose_logging };
acir_composer.create_finalized_circuit(constraint_system, recursive);
acir_composer.finalize_circuit();
Expand All @@ -253,7 +253,7 @@ void write_vk_ultra_plonk(const std::string& bytecode_path, const std::string& o

void write_pk_ultra_plonk(const std::string& bytecode_path, const std::string& output_path, const bool recursive)
{
auto constraint_system = get_constraint_system(bytecode_path, /*honk_recursion=*/0);
auto constraint_system = get_constraint_system(bytecode_path);
acir_proofs::AcirComposer acir_composer{ 0, verbose_logging };
acir_composer.create_finalized_circuit(constraint_system, recursive);
acir_composer.finalize_circuit();
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/api/gate_count.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void gate_count(const std::string& bytecode_path,

// All circuit reports will be built into the string below
std::string functions_string = "{\"functions\": [\n ";
auto constraint_systems = get_constraint_systems(bytecode_path, honk_recursion);
auto constraint_systems = get_constraint_systems(bytecode_path);

const acir_format::ProgramMetadata metadata{ .recursive = recursive,
.honk_recursion = honk_recursion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ void PrivateExecutionSteps::parse(const std::vector<PrivateExecutionStepRaw>& st
// use spans instead of vectors.
std::vector<uint8_t> bytecode_buf(step.bytecode.begin(), step.bytecode.end());
std::vector<uint8_t> witness_buf(step.witness.begin(), step.witness.end());
acir_format::AcirFormat constraints =
acir_format::circuit_buf_to_acir_format(bytecode_buf, /*honk_recursion=*/0);
acir_format::AcirFormat constraints = acir_format::circuit_buf_to_acir_format(bytecode_buf);
acir_format::WitnessVector witness = acir_format::witness_buf_to_witness_data(witness_buf);

folding_stack.push_back({ constraints, witness });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,24 @@ class AcirIntegrationTest : public ::testing::Test {
}

// Function to check if a file exists
bool file_exists(const std::string& path)
static bool file_exists(const std::string& path)
{
std::ifstream file(path);
return file.good();
}

acir_format::AcirProgramStack get_program_stack_data_from_test_file(const std::string& test_program_name,
uint32_t honk_recursion = 0)
static acir_format::AcirProgramStack get_program_stack_data_from_test_file(const std::string& test_program_name)
{
std::string base_path = "../../acir_tests/acir_tests/" + test_program_name + "/target";
std::string bytecode_path = base_path + "/program.json";
std::string witness_path = base_path + "/witness.gz";

return acir_format::get_acir_program_stack(bytecode_path, witness_path, honk_recursion);
return acir_format::get_acir_program_stack(bytecode_path, witness_path);
}

acir_format::AcirProgram get_program_data_from_test_file(const std::string& test_program_name,
uint32_t honk_recursion = 0)
static acir_format::AcirProgram get_program_data_from_test_file(const std::string& test_program_name)
{
auto program_stack = get_program_stack_data_from_test_file(test_program_name, honk_recursion);
auto program_stack = get_program_stack_data_from_test_file(test_program_name);
ASSERT(program_stack.size() == 1); // Otherwise this method will not return full stack data

return program_stack.back();
Expand Down Expand Up @@ -148,10 +146,7 @@ TEST_P(AcirIntegrationSingleTest, DISABLED_ProveAndVerifyProgram)

std::string test_name = GetParam();
info("Test: ", test_name);
acir_format::AcirProgram acir_program = get_program_data_from_test_file(
test_name,
/*honk_recursion=*/0); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1013):
// Assumes Flavor is not UltraHonk
acir_format::AcirProgram acir_program = get_program_data_from_test_file(test_name);

// Construct a bberg circuit from the acir representation
Builder builder = acir_format::create_circuit<Builder>(acir_program);
Expand Down Expand Up @@ -371,9 +366,7 @@ TEST_P(AcirIntegrationFoldingTest, DISABLED_ProveAndVerifyProgramStack)
std::string test_name = GetParam();
info("Test: ", test_name);

auto program_stack = get_program_stack_data_from_test_file(
test_name, /*honk_recursion=*/0); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1013):
// Assumes Flavor is not UltraHonk
auto program_stack = get_program_stack_data_from_test_file(test_name);

while (!program_stack.empty()) {
auto program = program_stack.back();
Expand Down Expand Up @@ -479,9 +472,7 @@ TEST_F(AcirIntegrationTest, DISABLED_UpdateAcirCircuit)
using Builder = Flavor::CircuitBuilder;

std::string test_name = "6_array"; // arbitrary program with RAM gates
auto acir_program = get_program_data_from_test_file(
test_name, /*honk_recursion=*/0); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1013):
// Assumes Flavor is not UltraHonk
auto acir_program = get_program_data_from_test_file(test_name);

// Construct a bberg circuit from the acir representation
Builder circuit = acir_format::create_circuit<Builder>(acir_program);
Expand Down Expand Up @@ -514,12 +505,8 @@ TEST_F(AcirIntegrationTest, DISABLED_HonkRecursion)
using Flavor = UltraFlavor;
using Builder = Flavor::CircuitBuilder;

std::string test_name = "verify_honk_proof"; // arbitrary program with RAM gates
// Note: honk_recursion set to 1 here we are using the UltraFlavor.
// The honk_recursion flag determines whether a noir program will be recursively verified via Honk in a Noir
// program.
auto acir_program = get_program_data_from_test_file(test_name,
/*honk_recursion=*/1);
std::string test_name = "verify_honk_proof"; // program that recursively verifies a honk proof
auto acir_program = get_program_data_from_test_file(test_name);

// Construct a bberg circuit from the acir representation
Builder circuit = acir_format::create_circuit<Builder>(acir_program);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,7 @@ WitnessOrConstant<bb::fr> parse_input(Acir::FunctionInput input)
return result;
}

void handle_blackbox_func_call(Acir::Opcode::BlackBoxFuncCall const& arg,
AcirFormat& af,
uint32_t honk_recursion,
size_t opcode_index)
void handle_blackbox_func_call(Acir::Opcode::BlackBoxFuncCall const& arg, AcirFormat& af, size_t opcode_index)
{
std::visit(
[&](auto&& arg) {
Expand Down Expand Up @@ -722,17 +719,6 @@ void handle_blackbox_func_call(Acir::Opcode::BlackBoxFuncCall const& arg,
auto input_key = get_witness_from_function_input(arg.key_hash);

auto proof_type_in = arg.proof_type;
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1074): Eventually arg.proof_type will
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This the core change. I only noticed that we were still using the honk_recursion flag here because of a very curious error trying to enable pairing point objects in CIVC

// be the only means for setting the proof type. use of honk_recursion flag in this context can go
// away once all noir programs (e.g. protocol circuits) are updated to use the new pattern.
if (proof_type_in != HONK && proof_type_in != AVM && proof_type_in != ROLLUP_HONK &&
proof_type_in != ROOT_ROLLUP_HONK) {
if (honk_recursion == 1) {
proof_type_in = HONK;
} else if (honk_recursion == 2) {
proof_type_in = ROLLUP_HONK;
}
}

auto c = RecursionConstraint{
.key = transform::map(arg.verification_key,
Expand Down Expand Up @@ -888,7 +874,7 @@ void handle_memory_op(Acir::Opcode::MemoryOp const& mem_op, BlockConstraint& blo
block.trace.push_back(acir_mem_op);
}

AcirFormat circuit_serde_to_acir_format(Acir::Circuit const& circuit, uint32_t honk_recursion)
AcirFormat circuit_serde_to_acir_format(Acir::Circuit const& circuit)
{
AcirFormat af;
// `varnum` is the true number of variables, thus we add one to the index which starts at zero
Expand All @@ -907,7 +893,7 @@ AcirFormat circuit_serde_to_acir_format(Acir::Circuit const& circuit, uint32_t h
if constexpr (std::is_same_v<T, Acir::Opcode::AssertZero>) {
handle_arithmetic(arg, af, i);
} else if constexpr (std::is_same_v<T, Acir::Opcode::BlackBoxFuncCall>) {
handle_blackbox_func_call(arg, af, honk_recursion, i);
handle_blackbox_func_call(arg, af, i);
} else if constexpr (std::is_same_v<T, Acir::Opcode::MemoryInit>) {
auto block = handle_memory_init(arg);
uint32_t block_id = arg.block_id.value;
Expand All @@ -934,15 +920,15 @@ AcirFormat circuit_serde_to_acir_format(Acir::Circuit const& circuit, uint32_t h
return af;
}

AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf, uint32_t honk_recursion)
AcirFormat circuit_buf_to_acir_format(std::vector<uint8_t> const& buf)
{
// 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 program = deserialize_program(buf);
auto circuit = program.functions[0];

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

/**
Expand Down Expand Up @@ -982,14 +968,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, uint32_t honk_recursion)
std::vector<AcirFormat> program_buf_to_acir_format(std::vector<uint8_t> const& buf)
{
auto program = deserialize_program(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, honk_recursion));
constraint_systems.emplace_back(circuit_serde_to_acir_format(function));
}

return constraint_systems;
Expand All @@ -1006,16 +992,11 @@ WitnessVectorStack witness_buf_to_witness_stack(std::vector<uint8_t> const& buf)
return witness_vector_stack;
}

AcirProgramStack get_acir_program_stack(std::string const& bytecode_path,
std::string const& witness_path,
uint32_t honk_recursion)
AcirProgramStack get_acir_program_stack(std::string const& bytecode_path, std::string const& witness_path)
{
vinfo("in get_acir_program_stack; witness path is ", witness_path);
std::vector<uint8_t> bytecode = get_bytecode(bytecode_path);
std::vector<AcirFormat> constraint_systems =
program_buf_to_acir_format(bytecode,
honk_recursion); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1013):
// Remove honk recursion flag
std::vector<AcirFormat> constraint_systems = program_buf_to_acir_format(bytecode);
WitnessVectorStack witness_stack = [&]() {
if (witness_path.empty()) {
info("producing a stack of empties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ namespace acir_format {
*/
WitnessVector witness_buf_to_witness_data(std::vector<uint8_t> const& buf);

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

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

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,
uint32_t honk_recursion);
AcirProgramStack get_acir_program_stack(std::string const& bytecode_path, std::string const& witness_path);
} // namespace acir_format
Loading