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
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/api/api_client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ void write_arbitrary_valid_client_ivc_proof_and_vk_to_file(const std::filesystem
// Construct and accumulate a series of mocked private function execution circuits
PrivateFunctionExecutionMockCircuitProducer circuit_producer;
for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
auto circuit = circuit_producer.create_next_circuit(ivc);
ivc.accumulate(circuit);
auto [circuit, vk] = circuit_producer.create_next_circuit_and_vk(ivc);
ivc.accumulate(circuit, vk);
}

ClientIVC::Proof proof = ivc.prove();
Expand Down
17 changes: 11 additions & 6 deletions barretenberg/cpp/src/barretenberg/bbapi/bbapi_client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,23 @@ static std::shared_ptr<ClientIVC::DeciderProvingKey> get_acir_program_decider_pr
ClientIVC::VerificationKey compute_civc_vk(const BBApiRequest& request, size_t num_public_inputs_in_final_circuit)
{
ClientIVC ivc{ /* num_circuits */ 2, request.trace_settings };
ClientIVCMockCircuitProducer circuit_producer;
PrivateFunctionExecutionMockCircuitProducer circuit_producer;

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

// Create another circuit and accumulate
MegaCircuitBuilder circuit_1 =
circuit_producer.create_next_circuit(ivc, SMALL_ARBITRARY_LOG_CIRCUIT_SIZE, num_public_inputs_in_final_circuit);
ivc.accumulate(circuit_1);
auto [circuit_1, vk_1] =
circuit_producer.create_next_circuit_and_vk(ivc,
{
.num_public_inputs = num_public_inputs_in_final_circuit,
.log2_num_gates = SMALL_ARBITRARY_LOG_CIRCUIT_SIZE,
});
ivc.accumulate(circuit_1, vk_1);

// Construct the hiding circuit and its VK (stored internally in the IVC)
ivc.construct_hiding_circuit_key();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ BENCHMARK_DEFINE_F(ClientIVCBench, VerificationOnly)(benchmark::State& state)
{
ClientIVC ivc{ /*num_circuits=*/2, { AZTEC_TRACE_STRUCTURE } };

ClientIVCMockCircuitProducer circuit_producer;
PrivateFunctionExecutionMockCircuitProducer circuit_producer;

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

// Create another circuit and accumulate
auto circuit_1 = circuit_producer.create_next_circuit(ivc);
ivc.accumulate(circuit_1);
auto [circuit_1, vk_1] = circuit_producer.create_next_circuit_and_vk(ivc);
ivc.accumulate(circuit_1, vk_1);

auto proof = ivc.prove();

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

for (auto _ : state) {
BB_REPORT_OP_COUNT_IN_BENCH(state);
perform_ivc_accumulation_rounds(total_num_circuits, ivc, mocked_vks, /* mock_vk */ true);
perform_ivc_accumulation_rounds(total_num_circuits, ivc, mocked_vks);
ivc.prove();
}
}
Expand All @@ -76,12 +76,12 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Ambient_17_in_20)(benchmark::State& state)

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

for (auto _ : state) {
BB_REPORT_OP_COUNT_IN_BENCH(state);
perform_ivc_accumulation_rounds(
total_num_circuits, ivc, mocked_vks, /* mock_vk */ true, /* large_first_app */ false);
perform_ivc_accumulation_rounds(total_num_circuits, ivc, mocked_vks, large_first_app);
ivc.prove();
}
}
Expand Down
22 changes: 4 additions & 18 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,17 @@ void ClientIVC::complete_kernel_circuit_logic(ClientCircuit& circuit)
* this case, just produce a Honk proof for that circuit and do no folding.
* @param precomputed_vk
*/
void ClientIVC::accumulate(ClientCircuit& circuit,
const std::shared_ptr<MegaVerificationKey>& precomputed_vk,
const bool mock_vk)
void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVerificationKey>& precomputed_vk)
{
BB_ASSERT_LT(
num_circuits_accumulated, num_circuits, "ClientIVC: Attempting to accumulate more circuits than expected.");

if (circuit.is_kernel) {
// Transcript to be shared across folding of K_{i} (kernel), A_{i+1,1} (app), .., A_{i+1, n} (app)
accumulation_transcript = std::make_shared<Transcript>();
}

ASSERT(precomputed_vk != nullptr, "ClientIVC::acumulate - VK expected for the provided circuit");

// Construct the proving key for circuit
std::shared_ptr<DeciderProvingKey> proving_key = std::make_shared<DeciderProvingKey>(circuit, trace_settings);

Expand All @@ -296,22 +295,9 @@ void ClientIVC::accumulate(ClientCircuit& circuit,
goblin.commitment_key = bn254_commitment_key;
}
proving_key->commitment_key = bn254_commitment_key;

vinfo("getting honk vk... precomputed?: ", precomputed_vk);
// Update the accumulator trace usage based on the present circuit
trace_usage_tracker.update(circuit);

// Set the verification key from precomputed if available, else compute it
{
PROFILE_THIS_NAME("ClientIVC::accumulate create MegaVerificationKey");
honk_vk =
precomputed_vk ? precomputed_vk : std::make_shared<MegaVerificationKey>(proving_key->get_precomputed());
}
// mock_vk is used in benchmarks to avoid any VK construction.
if (mock_vk) {
honk_vk->set_metadata(proving_key->get_metadata());
vinfo("set honk vk metadata");
}
honk_vk = precomputed_vk;

VerifierInputs queue_entry{ .honk_vk = honk_vk, .is_kernel = circuit.is_kernel };
if (num_circuits_accumulated == 0) { // First circuit in the IVC
Expand Down
4 changes: 1 addition & 3 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ class ClientIVC {
* set using the proving key produced from `circuit` in order to pass some assertions in the Oink prover.
* @param mock_vk A boolean to say whether the precomputed vk should have its metadata set.
*/
void accumulate(ClientCircuit& circuit,
const std::shared_ptr<MegaVerificationKey>& precomputed_vk = nullptr,
const bool mock_vk = false);
void accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVerificationKey>& precomputed_vk);

Proof prove();

Expand Down
Loading
Loading