Skip to content

Commit 5d75421

Browse files
AztecBotAztecBotmaramihali
authored
feat: merge-train/barretenberg (#16170)
See [merge-train-readme.md](https://github.com/AztecProtocol/aztec-packages/blob/next/.github/workflows/merge-train-readme.md). BEGIN_COMMIT_OVERRIDE chore: civc tests refactor (#16159) END_COMMIT_OVERRIDE --------- Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: maramihali <mara@aztec-labs.com>
1 parent 9ab0377 commit 5d75421

16 files changed

Lines changed: 290 additions & 369 deletions

barretenberg/cpp/src/barretenberg/api/api_client_ivc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ void write_arbitrary_valid_client_ivc_proof_and_vk_to_file(const std::filesystem
289289
// Construct and accumulate a series of mocked private function execution circuits
290290
PrivateFunctionExecutionMockCircuitProducer circuit_producer;
291291
for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
292-
auto circuit = circuit_producer.create_next_circuit(ivc);
293-
ivc.accumulate(circuit);
292+
auto [circuit, vk] = circuit_producer.create_next_circuit_and_vk(ivc);
293+
ivc.accumulate(circuit, vk);
294294
}
295295

296296
ClientIVC::Proof proof = ivc.prove();

barretenberg/cpp/src/barretenberg/bbapi/bbapi_client_ivc.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,23 @@ static std::shared_ptr<ClientIVC::DeciderProvingKey> get_acir_program_decider_pr
117117
ClientIVC::VerificationKey compute_civc_vk(const BBApiRequest& request, size_t num_public_inputs_in_final_circuit)
118118
{
119119
ClientIVC ivc{ /* num_circuits */ 2, request.trace_settings };
120-
ClientIVCMockCircuitProducer circuit_producer;
120+
PrivateFunctionExecutionMockCircuitProducer circuit_producer;
121121

122122
// Initialize the IVC with an arbitrary circuit
123123
// We segfault if we only call accumulate once
124124
static constexpr size_t SMALL_ARBITRARY_LOG_CIRCUIT_SIZE{ 5 };
125-
MegaCircuitBuilder circuit_0 = circuit_producer.create_next_circuit(ivc, SMALL_ARBITRARY_LOG_CIRCUIT_SIZE);
126-
ivc.accumulate(circuit_0);
125+
auto [circuit_0, vk_0] =
126+
circuit_producer.create_next_circuit_and_vk(ivc, { .log2_num_gates = SMALL_ARBITRARY_LOG_CIRCUIT_SIZE });
127+
ivc.accumulate(circuit_0, vk_0);
127128

128129
// Create another circuit and accumulate
129-
MegaCircuitBuilder circuit_1 =
130-
circuit_producer.create_next_circuit(ivc, SMALL_ARBITRARY_LOG_CIRCUIT_SIZE, num_public_inputs_in_final_circuit);
131-
ivc.accumulate(circuit_1);
130+
auto [circuit_1, vk_1] =
131+
circuit_producer.create_next_circuit_and_vk(ivc,
132+
{
133+
.num_public_inputs = num_public_inputs_in_final_circuit,
134+
.log2_num_gates = SMALL_ARBITRARY_LOG_CIRCUIT_SIZE,
135+
});
136+
ivc.accumulate(circuit_1, vk_1);
132137

133138
// Construct the hiding circuit and its VK (stored internally in the IVC)
134139
ivc.construct_hiding_circuit_key();

barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ BENCHMARK_DEFINE_F(ClientIVCBench, VerificationOnly)(benchmark::State& state)
3434
{
3535
ClientIVC ivc{ /*num_circuits=*/2, { AZTEC_TRACE_STRUCTURE } };
3636

37-
ClientIVCMockCircuitProducer circuit_producer;
37+
PrivateFunctionExecutionMockCircuitProducer circuit_producer;
3838

3939
// Initialize the IVC with an arbitrary circuit
40-
auto circuit_0 = circuit_producer.create_next_circuit(ivc);
41-
ivc.accumulate(circuit_0);
40+
auto [circuit_0, vk_0] = circuit_producer.create_next_circuit_and_vk(ivc);
41+
ivc.accumulate(circuit_0, vk_0);
4242

4343
// Create another circuit and accumulate
44-
auto circuit_1 = circuit_producer.create_next_circuit(ivc);
45-
ivc.accumulate(circuit_1);
44+
auto [circuit_1, vk_1] = circuit_producer.create_next_circuit_and_vk(ivc);
45+
ivc.accumulate(circuit_1, vk_1);
4646

4747
auto proof = ivc.prove();
4848

@@ -63,7 +63,7 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Full)(benchmark::State& state)
6363

6464
for (auto _ : state) {
6565
BB_REPORT_OP_COUNT_IN_BENCH(state);
66-
perform_ivc_accumulation_rounds(total_num_circuits, ivc, mocked_vks, /* mock_vk */ true);
66+
perform_ivc_accumulation_rounds(total_num_circuits, ivc, mocked_vks);
6767
ivc.prove();
6868
}
6969
}
@@ -76,12 +76,12 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Ambient_17_in_20)(benchmark::State& state)
7676

7777
auto total_num_circuits = 2 * static_cast<size_t>(state.range(0)); // 2x accounts for kernel circuits
7878
ClientIVC ivc{ total_num_circuits, { AZTEC_TRACE_STRUCTURE } };
79-
auto mocked_vks = mock_vks(total_num_circuits);
79+
const bool large_first_app = false;
80+
auto mocked_vks = mock_vks(total_num_circuits, large_first_app);
8081

8182
for (auto _ : state) {
8283
BB_REPORT_OP_COUNT_IN_BENCH(state);
83-
perform_ivc_accumulation_rounds(
84-
total_num_circuits, ivc, mocked_vks, /* mock_vk */ true, /* large_first_app */ false);
84+
perform_ivc_accumulation_rounds(total_num_circuits, ivc, mocked_vks, large_first_app);
8585
ivc.prove();
8686
}
8787
}

barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,17 @@ void ClientIVC::complete_kernel_circuit_logic(ClientCircuit& circuit)
273273
* this case, just produce a Honk proof for that circuit and do no folding.
274274
* @param precomputed_vk
275275
*/
276-
void ClientIVC::accumulate(ClientCircuit& circuit,
277-
const std::shared_ptr<MegaVerificationKey>& precomputed_vk,
278-
const bool mock_vk)
276+
void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVerificationKey>& precomputed_vk)
279277
{
280278
BB_ASSERT_LT(
281279
num_circuits_accumulated, num_circuits, "ClientIVC: Attempting to accumulate more circuits than expected.");
282-
283280
if (circuit.is_kernel) {
284281
// Transcript to be shared across folding of K_{i} (kernel), A_{i+1,1} (app), .., A_{i+1, n} (app)
285282
accumulation_transcript = std::make_shared<Transcript>();
286283
}
287284

285+
ASSERT(precomputed_vk != nullptr, "ClientIVC::acumulate - VK expected for the provided circuit");
286+
288287
// Construct the proving key for circuit
289288
std::shared_ptr<DeciderProvingKey> proving_key = std::make_shared<DeciderProvingKey>(circuit, trace_settings);
290289

@@ -296,22 +295,9 @@ void ClientIVC::accumulate(ClientCircuit& circuit,
296295
goblin.commitment_key = bn254_commitment_key;
297296
}
298297
proving_key->commitment_key = bn254_commitment_key;
299-
300-
vinfo("getting honk vk... precomputed?: ", precomputed_vk);
301-
// Update the accumulator trace usage based on the present circuit
302298
trace_usage_tracker.update(circuit);
303299

304-
// Set the verification key from precomputed if available, else compute it
305-
{
306-
PROFILE_THIS_NAME("ClientIVC::accumulate create MegaVerificationKey");
307-
honk_vk =
308-
precomputed_vk ? precomputed_vk : std::make_shared<MegaVerificationKey>(proving_key->get_precomputed());
309-
}
310-
// mock_vk is used in benchmarks to avoid any VK construction.
311-
if (mock_vk) {
312-
honk_vk->set_metadata(proving_key->get_metadata());
313-
vinfo("set honk vk metadata");
314-
}
300+
honk_vk = precomputed_vk;
315301

316302
VerifierInputs queue_entry{ .honk_vk = honk_vk, .is_kernel = circuit.is_kernel };
317303
if (num_circuits_accumulated == 0) { // First circuit in the IVC

barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ class ClientIVC {
225225
* set using the proving key produced from `circuit` in order to pass some assertions in the Oink prover.
226226
* @param mock_vk A boolean to say whether the precomputed vk should have its metadata set.
227227
*/
228-
void accumulate(ClientCircuit& circuit,
229-
const std::shared_ptr<MegaVerificationKey>& precomputed_vk = nullptr,
230-
const bool mock_vk = false);
228+
void accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVerificationKey>& precomputed_vk);
231229

232230
Proof prove();
233231

0 commit comments

Comments
 (0)