diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 3dfe90d88d1d..3ad94098b4dc 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -37,7 +37,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(circuit)); // Construct the prover instance for circuit - prover_instance = std::make_shared(circuit, trace_structure); + auto prover_instance = std::make_shared(circuit, trace_structure); // Track the maximum size of each block for all circuits porcessed (for debugging purposes only) max_block_size_tracker.update(circuit); @@ -67,7 +67,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr& eccvm_vk, const std::shared_ptr& translator_vk) { + ZoneScopedN("ClientIVC::verify"); // Goblin verification (merge, eccvm, translator) GoblinVerifier goblin_verifier{ eccvm_vk, translator_vk }; bool goblin_verified = goblin_verifier.verify(proof.goblin_proof); @@ -111,6 +112,7 @@ bool ClientIVC::verify(Proof& proof, const std::vector prover_accumulator; std::shared_ptr verifier_accumulator; - // Note: We need to save the last instance that was folded in order to compute its verification key, this will not - // be needed in the real IVC as they are provided as inputs - std::shared_ptr prover_instance; std::shared_ptr instance_vk; // A flag indicating whether or not to construct a structured trace in the ProverInstance diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index ae656e6f6995..6444e2630d28 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -38,6 +38,7 @@ class ClientIVCTests : public ::testing::Test { */ static bool prove_and_verify(ClientIVC& ivc) { + ZoneScopedN("ClientIVC::prove_and_verify"); auto proof = ivc.prove(); auto verifier_inst = std::make_shared(ivc.instance_vk); @@ -73,13 +74,33 @@ TEST_F(ClientIVCTests, Basic) { ClientIVC ivc; - // Initialize the IVC with an arbitrary circuit - Builder circuit_0 = create_mock_circuit(ivc); - ivc.accumulate(circuit_0); + { + // Initialize the IVC with an arbitrary circuit + Builder circuit_0 = create_mock_circuit(ivc); + ivc.accumulate(circuit_0); + } - // Create another circuit and accumulate - Builder circuit_1 = create_mock_circuit(ivc); - ivc.accumulate(circuit_1); + { + // Create another circuit and accumulate + Builder circuit_1 = create_mock_circuit(ivc); + ivc.accumulate(circuit_1); + } + + EXPECT_TRUE(prove_and_verify(ivc)); +}; + +/** + * @brief A simple-as-possible test demonstrating IVC for three mock circuits + * + */ +TEST_F(ClientIVCTests, BasicThree) +{ + ClientIVC ivc; + + for (size_t idx = 0; idx < 3; ++idx) { + Builder circuit = create_mock_circuit(ivc); + ivc.accumulate(circuit); + } EXPECT_TRUE(prove_and_verify(ivc)); }; diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp index b19261d153a4..73297e499ecb 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/mock_kernel_pinning.test.cpp @@ -37,5 +37,5 @@ TEST_F(MockKernelTest, PinFoldingKernelSizes) ivc.accumulate(circuit_2); ivc.accumulate(kernel_circuit); - EXPECT_EQ(ivc.prover_instance->proving_key.log_circuit_size, 17); + EXPECT_EQ(ivc.fold_output.accumulator->proving_key.log_circuit_size, 17); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp b/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp index d7a37ac15d97..3b861421b47f 100644 --- a/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp @@ -18,15 +18,20 @@ void ExecutionTrace_::populate(Builder& builder, typename Flavor::Provin proving_key.pub_inputs_offset = trace_data.pub_inputs_offset; } if constexpr (IsUltraPlonkOrHonk) { + ZoneScopedN("add_memory_records_to_proving_key"); add_memory_records_to_proving_key(trace_data, builder, proving_key); } if constexpr (IsGoblinFlavor) { + ZoneScopedN("add_ecc_op_wires_to_proving_key"); add_ecc_op_wires_to_proving_key(builder, proving_key); } // Compute the permutation argument polynomials (sigma/id) and add them to proving key - compute_permutation_argument_polynomials(builder, &proving_key, trace_data.copy_cycles); + { + ZoneScopedN("compute_permutation_argument_polynomials"); + compute_permutation_argument_polynomials(builder, &proving_key, trace_data.copy_cycles); + } } template @@ -50,6 +55,7 @@ template typename ExecutionTrace_::TraceData ExecutionTrace_::construct_trace_data( Builder& builder, typename Flavor::ProvingKey& proving_key, bool is_structured) { + ZoneScopedN("construct_trace_data"); TraceData trace_data{ builder, proving_key }; // Complete the public inputs execution trace block from builder.public_inputs @@ -73,15 +79,18 @@ typename ExecutionTrace_::TraceData ExecutionTrace_::construct_t // Update wire polynomials and copy cycles // NB: The order of row/column loops is arbitrary but needs to be row/column to match old copy_cycle code - for (uint32_t block_row_idx = 0; block_row_idx < block_size; ++block_row_idx) { - for (uint32_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) { - uint32_t var_idx = block.wires[wire_idx][block_row_idx]; // an index into the variables array - uint32_t real_var_idx = builder.real_variable_index[var_idx]; - uint32_t trace_row_idx = block_row_idx + offset; - // Insert the real witness values from this block into the wire polys at the correct offset - trace_data.wires[wire_idx][trace_row_idx] = builder.get_variable(var_idx); - // Add the address of the witness value to its corresponding copy cycle - trace_data.copy_cycles[real_var_idx].emplace_back(cycle_node{ wire_idx, trace_row_idx }); + { + ZoneScopedN("populating wires and copy_cycles"); + for (uint32_t block_row_idx = 0; block_row_idx < block_size; ++block_row_idx) { + for (uint32_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) { + uint32_t var_idx = block.wires[wire_idx][block_row_idx]; // an index into the variables array + uint32_t real_var_idx = builder.real_variable_index[var_idx]; + uint32_t trace_row_idx = block_row_idx + offset; + // Insert the real witness values from this block into the wire polys at the correct offset + trace_data.wires[wire_idx][trace_row_idx] = builder.get_variable(var_idx); + // Add the address of the witness value to its corresponding copy cycle + trace_data.copy_cycles[real_var_idx].emplace_back(cycle_node{ wire_idx, trace_row_idx }); + } } } @@ -117,8 +126,7 @@ typename ExecutionTrace_::TraceData ExecutionTrace_::construct_t template void ExecutionTrace_::populate_public_inputs_block(Builder& builder) { - ZoneScopedN("populate block"); - + ZoneScopedN("populate_public_inputs_block"); // Update the public inputs block for (auto& idx : builder.public_inputs) { for (size_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) { diff --git a/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.hpp b/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.hpp index 6e240a96a50f..93a907f69daf 100644 --- a/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.hpp @@ -31,43 +31,33 @@ template class ExecutionTrace_ { TraceData(Builder& builder, ProvingKey& proving_key) { - ZoneScopedN("TraceData construction"); + ZoneScopedN("TraceData constructor"); if constexpr (IsHonkFlavor) { - { - ZoneScopedN("wires initialization"); - // Initialize and share the wire and selector polynomials - for (auto [wire, other_wire] : zip_view(wires, proving_key.polynomials.get_wires())) { - wire = other_wire.share(); - } + // Initialize and share the wire and selector polynomials + for (auto [wire, other_wire] : zip_view(wires, proving_key.polynomials.get_wires())) { + wire = other_wire.share(); } - { - ZoneScopedN("selector initialization"); - for (auto [selector, other_selector] : - zip_view(selectors, proving_key.polynomials.get_selectors())) { - selector = other_selector.share(); - } + for (auto [selector, other_selector] : zip_view(selectors, proving_key.polynomials.get_selectors())) { + selector = other_selector.share(); } proving_key.polynomials.set_shifted(); // Ensure shifted wires are set correctly } else { - { - ZoneScopedN("wires initialization"); - // Initialize and share the wire and selector polynomials - for (size_t idx = 0; idx < NUM_WIRES; ++idx) { - wires[idx] = Polynomial(proving_key.circuit_size); - std::string wire_tag = "w_" + std::to_string(idx + 1) + "_lagrange"; - proving_key.polynomial_store.put(wire_tag, wires[idx].share()); - } + // Initialize and share the wire and selector polynomials + for (size_t idx = 0; idx < NUM_WIRES; ++idx) { + wires[idx] = Polynomial(proving_key.circuit_size); + std::string wire_tag = "w_" + std::to_string(idx + 1) + "_lagrange"; + proving_key.polynomial_store.put(wire_tag, wires[idx].share()); } - { - ZoneScopedN("selector initialization"); - for (size_t idx = 0; idx < NUM_USED_SELECTORS; ++idx) { - selectors[idx] = Polynomial(proving_key.circuit_size); - std::string selector_tag = builder.selector_names[idx] + "_lagrange"; - proving_key.polynomial_store.put(selector_tag, selectors[idx].share()); - } + for (size_t idx = 0; idx < Builder::Arithmetization::NUM_SELECTORS; ++idx) { + selectors[idx] = Polynomial(proving_key.circuit_size); + std::string selector_tag = builder.selector_names[idx] + "_lagrange"; + proving_key.polynomial_store.put(selector_tag, selectors[idx].share()); } } - copy_cycles.resize(builder.variables.size()); + { + ZoneScopedN("copy cycle initialization"); + copy_cycles.resize(builder.variables.size()); + } } }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 5b4a6e90390b..a0e6b43e6c41 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -126,7 +126,10 @@ template class ProvingKey_ { ProvingKey_() = default; ProvingKey_(const size_t circuit_size, const size_t num_public_inputs) { - this->commitment_key = std::make_shared(circuit_size + 1); + { + ZoneScopedN("init commitment key"); + this->commitment_key = std::make_shared(circuit_size + 1); + } this->evaluation_domain = bb::EvaluationDomain(circuit_size, circuit_size); this->circuit_size = circuit_size; this->log_circuit_size = numeric::get_msb(circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 1eeabc541926..ac19110f4c26 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -198,9 +198,16 @@ class GoblinProver { */ GoblinProof prove(MergeProof merge_proof_in = {}) { + ZoneScopedN("Goblin::prove"); goblin_proof.merge_proof = merge_proof_in.empty() ? std::move(merge_proof) : std::move(merge_proof_in); - prove_eccvm(); - prove_translator(); + { + ZoneScopedN("prove_eccvm"); + prove_eccvm(); + } + { + ZoneScopedN("prove_translator"); + prove_translator(); + } return goblin_proof; }; }; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp index 384a0efdb0df..f76769f69c1c 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/permutation_lib.hpp @@ -62,6 +62,7 @@ template struct PermutationMapping { */ PermutationMapping(size_t circuit_size) { + ZoneScopedN("PermutationMapping constructor"); for (uint8_t col_idx = 0; col_idx < NUM_WIRES; ++col_idx) { sigmas[col_idx].reserve(circuit_size); if constexpr (generalized) { @@ -109,13 +110,13 @@ PermutationMapping compute_permutation_mapping( // Go through each cycle size_t cycle_index = 0; - for (auto& copy_cycle : wire_copy_cycles) { + for (const auto& copy_cycle : wire_copy_cycles) { for (size_t node_idx = 0; node_idx < copy_cycle.size(); ++node_idx) { // Get the indices of the current node and next node in the cycle - cycle_node current_cycle_node = copy_cycle[node_idx]; + const cycle_node& current_cycle_node = copy_cycle[node_idx]; // If current node is the last one in the cycle, then the next one is the first one size_t next_cycle_node_index = (node_idx == copy_cycle.size() - 1 ? 0 : node_idx + 1); - cycle_node next_cycle_node = copy_cycle[next_cycle_node_index]; + const cycle_node& next_cycle_node = copy_cycle[next_cycle_node_index]; const auto current_row = current_cycle_node.gate_index; const auto next_row = next_cycle_node.gate_index; @@ -383,10 +384,16 @@ void compute_permutation_argument_polynomials(const typename Flavor::CircuitBuil } } else if constexpr (IsUltraFlavor) { // any UltraHonk flavor // Compute Honk-style sigma and ID polynomials from the corresponding mappings - compute_honk_style_permutation_lagrange_polynomials_from_mapping( - key->polynomials.get_sigmas(), mapping.sigmas, key); - compute_honk_style_permutation_lagrange_polynomials_from_mapping( - key->polynomials.get_ids(), mapping.ids, key); + { + ZoneScopedN("compute_honk_style_permutation_lagrange_polynomials_from_mapping"); + compute_honk_style_permutation_lagrange_polynomials_from_mapping( + key->polynomials.get_sigmas(), mapping.sigmas, key); + } + { + ZoneScopedN("compute_honk_style_permutation_lagrange_polynomials_from_mapping"); + compute_honk_style_permutation_lagrange_polynomials_from_mapping( + key->polynomials.get_ids(), mapping.ids, key); + } } } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 152e5f65db5f..036136563744 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -215,6 +215,7 @@ template void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, const std::string& domain_separator) { + ZoneScopedN("ProtoGalaxyProver::finalise_and_send_instance"); OinkProver oink_prover(instance->proving_key, transcript, domain_separator + '_'); auto [proving_key, relation_params, alphas] = oink_prover.prove(); @@ -408,6 +409,7 @@ template void ProtoGalaxyProver_::accum template FoldingResult ProtoGalaxyProver_::prove() { + ZoneScopedN("ProtogalaxyProver::prove"); BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove"); // Ensure instances are all of the same size for (size_t idx = 0; idx < ProverInstances::NUM - 1; ++idx) { diff --git a/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.cpp b/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.cpp index 967e4e3612af..823c3ebdc0c9 100644 --- a/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.cpp +++ b/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.cpp @@ -56,6 +56,7 @@ template std::shared_ptr> FileCrsFactory::get_prover_crs(size_t degree) { if (degree != degree_ || !prover_crs_) { + ZoneScopedN("get_prover_crs"); prover_crs_ = std::make_shared>(degree, path_); degree_ = degree; } diff --git a/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.hpp b/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.hpp index cf6b524d6f12..6e3aa283a27c 100644 --- a/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.hpp +++ b/barretenberg/cpp/src/barretenberg/srs/factories/file_crs_factory.hpp @@ -43,6 +43,7 @@ template class FileProverCrs : public ProverCrs { FileProverCrs(const size_t num_points, std::string const& path) : num_points(num_points) { + ZoneScopedN("FileProverCrs constructor"); monomials_ = scalar_multiplication::point_table_alloc(num_points); srs::IO::read_transcript_g1(monomials_.get(), num_points, path); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 926ad32f1c7e..b2a4afa86b04 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -551,6 +551,7 @@ class UltraFlavor { PartiallyEvaluatedMultivariates() = default; PartiallyEvaluatedMultivariates(const size_t circuit_size) { + ZoneScopedN("PartiallyEvaluatedMultivariates constructor"); // Storage is only needed after the first partial evaluation, hence polynomials of // size (n / 2) for (auto& poly : this->get_all()) { diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 9a814855092c..3335e59661cc 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -222,21 +222,26 @@ template class SumcheckProver { // compute_univariate also takes into account the zk_sumcheck_data. auto round_univariate = round.compute_univariate( round_idx, full_polynomials, relation_parameters, pow_univariate, alpha, zk_sumcheck_data); - // Place the evaluations of the round univariate into transcript. - transcript->send_to_verifier("Sumcheck:univariate_0", round_univariate); - FF round_challenge = transcript->template get_challenge("Sumcheck:u_0"); - multivariate_challenge.emplace_back(round_challenge); - // Prepare sumcheck book-keeping table for the next round - partially_evaluate(full_polynomials, multivariate_n, round_challenge); - // Prepare ZK Sumcheck data for the next round - if constexpr (Flavor::HasZK) { - update_zk_sumcheck_data(zk_sumcheck_data, round_challenge, round_idx); - }; - pow_univariate.partially_evaluate(round_challenge); - round.round_size = round.round_size >> 1; // TODO(#224)(Cody): Maybe partially_evaluate should do this and - // release memory? // All but final round - // We operate on partially_evaluated_polynomials in place. + { + ZoneScopedN("rest of sumcheck round 1"); + + // Place the evaluations of the round univariate into transcript. + transcript->send_to_verifier("Sumcheck:univariate_0", round_univariate); + FF round_challenge = transcript->template get_challenge("Sumcheck:u_0"); + multivariate_challenge.emplace_back(round_challenge); + // Prepare sumcheck book-keeping table for the next round + partially_evaluate(full_polynomials, multivariate_n, round_challenge); + // Prepare ZK Sumcheck data for the next round + if constexpr (Flavor::HasZK) { + update_zk_sumcheck_data(zk_sumcheck_data, round_challenge, round_idx); + }; + pow_univariate.partially_evaluate(round_challenge); + round.round_size = round.round_size >> 1; // TODO(#224)(Cody): Maybe partially_evaluate should do this and + // release memory? // All but final round + // We operate on partially_evaluated_polynomials in place. + } for (size_t round_idx = 1; round_idx < multivariate_d; round_idx++) { + ZoneScopedN("sumcheck loop"); // Write the round univariate to the transcript round_univariate = round.compute_univariate(round_idx, partially_evaluated_polynomials, diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 1e572c913047..2a0fad04e6bd 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -66,6 +66,7 @@ template class SumcheckProverRound { SumcheckProverRound(size_t initial_round_size) : round_size(initial_round_size) { + ZoneScopedN("SumcheckProverRound constructor"); // Initialize univariate accumulators to 0 Utils::zero_univariates(univariate_accumulators); } @@ -160,6 +161,7 @@ template class SumcheckProverRound { const RelationSeparator alpha, std::optional> zk_sumcheck_data = std::nullopt) // only submitted when Flavor HasZK { + ZoneScopedN("compute_univariate"); BB_OP_COUNT_TIME(); // Determine number of threads for multithreading. diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_prover.cpp index ab99b6b2b4f8..77e6d76b20b7 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_prover.cpp @@ -30,7 +30,10 @@ template void DeciderProver_::execute_relation_ch using Sumcheck = SumcheckProver; auto instance_size = accumulator->proving_key.circuit_size; auto sumcheck = Sumcheck(instance_size, transcript); - sumcheck_output = sumcheck.prove(accumulator); + { + ZoneScopedN("sumcheck.prove"); + sumcheck_output = sumcheck.prove(accumulator); + } } /**