@@ -110,21 +110,15 @@ bool proveAndVerify(const std::string& bytecodePath, const bool recursive, const
110
110
}
111
111
112
112
template <IsUltraFlavor Flavor>
113
- bool proveAndVerifyHonkAcirFormat (acir_format::AcirFormat constraint_system,
114
- const bool recursive,
115
- acir_format::WitnessVector witness)
113
+ bool proveAndVerifyHonkAcirFormat (acir_format::AcirProgram program, acir_format::ProgramMetadata metadata)
116
114
{
117
115
using Builder = Flavor::CircuitBuilder;
118
116
using Prover = UltraProver_<Flavor>;
119
117
using Verifier = UltraVerifier_<Flavor>;
120
118
using VerificationKey = Flavor::VerificationKey;
121
119
122
- bool honk_recursion = false ;
123
- if constexpr (IsAnyOf<Flavor, UltraFlavor>) {
124
- honk_recursion = true ;
125
- }
126
120
// Construct a bberg circuit from the acir representation
127
- auto builder = acir_format::create_circuit<Builder>(constraint_system, recursive, 0 , witness, honk_recursion );
121
+ auto builder = acir_format::create_circuit<Builder>(program, metadata );
128
122
129
123
// Construct Honk proof
130
124
Prover prover{ builder };
@@ -149,15 +143,15 @@ bool proveAndVerifyHonkAcirFormat(acir_format::AcirFormat constraint_system,
149
143
template <IsUltraFlavor Flavor>
150
144
bool proveAndVerifyHonk (const std::string& bytecodePath, const bool recursive, const std::string& witnessPath)
151
145
{
152
- bool honk_recursion = false ;
153
- if constexpr (IsAnyOf<Flavor, UltraFlavor>) {
154
- honk_recursion = true ;
155
- }
146
+ constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor>;
147
+ const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = honk_recursion };
148
+
156
149
// Populate the acir constraint system and witness from gzipped data
157
- auto constraint_system = get_constraint_system (bytecodePath, honk_recursion);
158
- auto witness = get_witness (witnessPath);
150
+ acir_format::AcirProgram program;
151
+ program.constraints = get_constraint_system (bytecodePath, metadata.honk_recursion );
152
+ program.witness = get_witness (witnessPath);
159
153
160
- return proveAndVerifyHonkAcirFormat<Flavor>(constraint_system, recursive, witness );
154
+ return proveAndVerifyHonkAcirFormat<Flavor>(program, metadata );
161
155
}
162
156
163
157
/* *
@@ -171,14 +165,14 @@ bool proveAndVerifyHonk(const std::string& bytecodePath, const bool recursive, c
171
165
template <IsUltraFlavor Flavor>
172
166
bool proveAndVerifyHonkProgram (const std::string& bytecodePath, const bool recursive, const std::string& witnessPath)
173
167
{
174
- bool honk_recursion = false ;
175
- if constexpr (IsAnyOf<Flavor, UltraFlavor>) {
176
- honk_recursion = true ;
177
- }
178
- auto program_stack = acir_format::get_acir_program_stack (bytecodePath, witnessPath, honk_recursion);
168
+ constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor> ;
169
+ const acir_format::ProgramMetadata metadata{ . recursive = recursive, . honk_recursion = honk_recursion };
170
+
171
+ auto program_stack = acir_format::get_acir_program_stack (bytecodePath, witnessPath, metadata. honk_recursion );
172
+
179
173
while (!program_stack.empty ()) {
180
- auto stack_item = program_stack.back ();
181
- if (!proveAndVerifyHonkAcirFormat<Flavor>(stack_item. constraints , recursive, stack_item. witness )) {
174
+ auto program = program_stack.back ();
175
+ if (!proveAndVerifyHonkAcirFormat<Flavor>(program, metadata )) {
182
176
return false ;
183
177
}
184
178
program_stack.pop_back ();
@@ -329,25 +323,29 @@ void gateCount(const std::string& bytecodePath, bool recursive, bool honk_recurs
329
323
// All circuit reports will be built into the string below
330
324
std::string functions_string = " {\" functions\" : [\n " ;
331
325
auto constraint_systems = get_constraint_systems (bytecodePath, honk_recursion);
326
+
327
+ const acir_format::ProgramMetadata metadata{ .recursive = recursive,
328
+ .honk_recursion = honk_recursion,
329
+ .collect_gates_per_opcode = true };
332
330
size_t i = 0 ;
333
- for (auto constraint_system : constraint_systems) {
334
- auto builder = acir_format::create_circuit<Builder>(
335
- constraint_system, recursive, 0 , {}, honk_recursion, std::make_shared<bb::ECCOpQueue>(), true );
331
+ for (const auto & constraint_system : constraint_systems) {
332
+ acir_format::AcirProgram program{ constraint_system };
333
+ auto builder = acir_format::create_circuit<Builder>(program, metadata );
336
334
builder.finalize_circuit (/* ensure_nonzero=*/ true );
337
335
size_t circuit_size = builder.num_gates ;
338
336
vinfo (" Calculated circuit size in gateCount: " , circuit_size);
339
337
340
338
// Build individual circuit report
341
339
std::string gates_per_opcode_str;
342
- for (size_t j = 0 ; j < constraint_system .gates_per_opcode .size (); j++) {
343
- gates_per_opcode_str += std::to_string (constraint_system .gates_per_opcode [j]);
344
- if (j != constraint_system .gates_per_opcode .size () - 1 ) {
340
+ for (size_t j = 0 ; j < program. constraints .gates_per_opcode .size (); j++) {
341
+ gates_per_opcode_str += std::to_string (program. constraints .gates_per_opcode [j]);
342
+ if (j != program. constraints .gates_per_opcode .size () - 1 ) {
345
343
gates_per_opcode_str += " ," ;
346
344
}
347
345
}
348
346
349
347
auto result_string = format (" {\n \" acir_opcodes\" : " ,
350
- constraint_system .num_acir_opcodes ,
348
+ program. constraints .num_acir_opcodes ,
351
349
" ,\n \" circuit_size\" : " ,
352
350
circuit_size,
353
351
" ,\n \" gates_per_opcode\" : [" ,
@@ -713,17 +711,15 @@ UltraProver_<Flavor> compute_valid_prover(const std::string& bytecodePath,
713
711
using Builder = Flavor::CircuitBuilder;
714
712
using Prover = UltraProver_<Flavor>;
715
713
716
- bool honk_recursion = false ;
717
- if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor, UltraRollupFlavor>) {
718
- honk_recursion = true ;
719
- }
720
- auto constraint_system = get_constraint_system (bytecodePath, honk_recursion);
721
- acir_format::WitnessVector witness = {};
714
+ constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor, UltraRollupFlavor>;
715
+ const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = honk_recursion };
716
+
717
+ acir_format::AcirProgram program{ get_constraint_system (bytecodePath, metadata.honk_recursion ) };
722
718
if (!witnessPath.empty ()) {
723
- witness = get_witness (witnessPath);
719
+ program. witness = get_witness (witnessPath);
724
720
}
725
721
726
- auto builder = acir_format::create_circuit<Builder>(constraint_system, recursive, 0 , witness, honk_recursion );
722
+ auto builder = acir_format::create_circuit<Builder>(program, metadata );
727
723
auto prover = Prover{ builder };
728
724
init_bn254_crs (prover.proving_key ->proving_key .circuit_size );
729
725
return std::move (prover);
@@ -846,28 +842,23 @@ void write_vk_for_ivc(const std::string& bytecodePath, const std::string& output
846
842
using Prover = ClientIVC::MegaProver;
847
843
using DeciderProvingKey = ClientIVC::DeciderProvingKey;
848
844
using VerificationKey = ClientIVC::MegaVerificationKey;
845
+ using Program = acir_format::AcirProgram;
846
+ using ProgramMetadata = acir_format::ProgramMetadata;
849
847
850
848
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1163) set these dynamically
851
849
init_bn254_crs (1 << 20 );
852
850
init_grumpkin_crs (1 << 15 );
853
851
854
- auto constraints = get_constraint_system (bytecodePath, /* honk_recursion=*/ false );
855
- acir_format::WitnessVector witness = {} ;
852
+ Program program{ get_constraint_system (bytecodePath, /* honk_recursion=*/ false ), /* witness= */ {} } ;
853
+ auto & ivc_constraints = program. constraints . ivc_recursion_constraints ;
856
854
857
855
TraceSettings trace_settings{ E2E_FULL_TEST_STRUCTURE };
858
856
859
- // The presence of ivc recursion constraints determines whether or not the program is a kernel
860
- bool is_kernel = !constraints.ivc_recursion_constraints .empty ();
857
+ const ProgramMetadata metadata{ .ivc = ivc_constraints.empty ()
858
+ ? nullptr
859
+ : create_mock_ivc_from_constraints (ivc_constraints, trace_settings) };
860
+ Builder builder = acir_format::create_circuit<Builder>(program, metadata);
861
861
862
- Builder builder;
863
- if (is_kernel) {
864
- // Create a mock IVC instance based on the IVC recursion constraints in the kernel program
865
- ClientIVC mock_ivc = create_mock_ivc_from_constraints (constraints.ivc_recursion_constraints , trace_settings);
866
- builder = acir_format::create_kernel_circuit (constraints, mock_ivc, witness);
867
- } else {
868
- builder = acir_format::create_circuit<Builder>(
869
- constraints, /* recursive=*/ false , 0 , witness, /* honk_recursion=*/ false );
870
- }
871
862
// Add public inputs corresponding to pairing point accumulator
872
863
builder.add_pairing_point_accumulator (stdlib::recursion::init_default_agg_obj_indices<Builder>(builder));
873
864
@@ -907,10 +898,12 @@ void write_recursion_inputs_honk(const std::string& bytecodePath,
907
898
using VerificationKey = Flavor::VerificationKey;
908
899
using FF = Flavor::FF;
909
900
910
- bool honk_recursion = true ;
911
- auto constraints = get_constraint_system (bytecodePath, honk_recursion);
912
- auto witness = get_witness (witnessPath);
913
- auto builder = acir_format::create_circuit<Builder>(constraints, recursive, 0 , witness, honk_recursion);
901
+ const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = true };
902
+
903
+ acir_format::AcirProgram program;
904
+ program.constraints = get_constraint_system (bytecodePath, metadata.honk_recursion );
905
+ program.witness = get_witness (witnessPath);
906
+ auto builder = acir_format::create_circuit<Builder>(program, metadata);
914
907
915
908
// Construct Honk proof and verification key
916
909
Prover prover{ builder };
@@ -1058,15 +1051,13 @@ void prove_honk_output_all(const std::string& bytecodePath,
1058
1051
using Prover = UltraProver_<Flavor>;
1059
1052
using VerificationKey = Flavor::VerificationKey;
1060
1053
1061
- bool honk_recursion = false ;
1062
- if constexpr (IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor>) {
1063
- honk_recursion = true ;
1064
- }
1054
+ constexpr bool honk_recursion = IsAnyOf<Flavor, UltraFlavor, UltraKeccakFlavor>;
1055
+ const acir_format::ProgramMetadata metadata{ .recursive = recursive, .honk_recursion = honk_recursion };
1065
1056
1066
- auto constraint_system = get_constraint_system (bytecodePath, honk_recursion);
1067
- auto witness = get_witness (witnessPath);
1057
+ acir_format::AcirProgram program{ get_constraint_system (bytecodePath, metadata. honk_recursion ),
1058
+ get_witness (witnessPath) } ;
1068
1059
1069
- auto builder = acir_format::create_circuit<Builder>(constraint_system, recursive, 0 , witness, honk_recursion );
1060
+ auto builder = acir_format::create_circuit<Builder>(program, metadata );
1070
1061
1071
1062
// Construct Honk proof
1072
1063
Prover prover{ builder };
0 commit comments