diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index efbfd9baa84..0f7c839efd7 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -902,7 +902,6 @@ void avm_prove(const std::filesystem::path& bytecode_path, // Prove execution and return vk auto const [verification_key, proof] = avm_trace::Execution::prove(bytecode, calldata, public_inputs_vec, avm_hints); - vinfo("------- PROVING DONE -------"); // TODO(ilyas): <#4887>: Currently we only need these two parts of the vk, look into pcs_verification key reqs std::vector vk_vector = { verification_key.circuit_size, verification_key.num_public_inputs }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index 21401f2fe0a..14a87d089c8 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -11,6 +11,7 @@ #include "barretenberg/vm/avm_trace/avm_trace.hpp" #include "barretenberg/vm/avm_trace/aztec_constants.hpp" #include "barretenberg/vm/avm_trace/constants.hpp" +#include "barretenberg/vm/avm_trace/stats.hpp" #include "barretenberg/vm/generated/avm_circuit_builder.hpp" #include "barretenberg/vm/generated/avm_composer.hpp" @@ -64,7 +65,9 @@ std::tuple Execution::prove(std::vector returndata; - auto trace = gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); + std::vector trace; + AVM_TRACK_TIME("prove/gen_trace", + (trace = gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints))); if (!avm_dump_trace_path.empty()) { info("Dumping trace as CSV to: " + avm_dump_trace_path.string()); dump_trace_as_csv(trace, avm_dump_trace_path); @@ -72,12 +75,13 @@ std::tuple Execution::prove(std::vector Execution::gen_trace(std::vector const& instructio } } - return trace_builder.finalize(); + auto trace = trace_builder.finalize(); + vinfo("Final trace size: ", trace.size()); + return trace; } } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index eee16a419a1..292aeaea478 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -24,6 +24,7 @@ #include "barretenberg/vm/avm_trace/fixed_gas.hpp" #include "barretenberg/vm/avm_trace/fixed_powers.hpp" #include "barretenberg/vm/avm_trace/gadgets/avm_slice_trace.hpp" +#include "barretenberg/vm/avm_trace/stats.hpp" namespace bb::avm_trace { @@ -3772,6 +3773,31 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c gas_trace_size + 1, KERNEL_INPUTS_LENGTH, KERNEL_OUTPUTS_LENGTH, min_trace_size, fixed_gas_table.size(), slice_trace_size, calldata.size() }; + vinfo("Trace sizes before padding:", + "\n\tmain_trace_size: ", + main_trace_size, + "\n\tmem_trace_size: ", + mem_trace_size, + "\n\talu_trace_size: ", + alu_trace_size, + "\n\trange_check_size: ", + range_check_size, + "\n\tconv_trace_size: ", + conv_trace_size, + "\n\tlookup_table_size: ", + lookup_table_size, + "\n\tsha256_trace_size: ", + sha256_trace_size, + "\n\tposeidon2_trace_size: ", + poseidon2_trace_size, + "\n\tpedersen_trace_size: ", + pedersen_trace_size, + "\n\tgas_trace_size: ", + gas_trace_size, + "\n\tfixed_gas_table_size: ", + fixed_gas_table.size(), + "\n\tslice_trace_size: ", + slice_trace_size); auto trace_size = std::max_element(trace_sizes.begin(), trace_sizes.end()); // We only need to pad with zeroes to the size to the largest trace here, pow_2 padding is handled in the diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp index 23762777a9f..221b3cdee44 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp @@ -2,6 +2,7 @@ #include "barretenberg/commitment_schemes/claim.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" +#include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" @@ -16,27 +17,6 @@ namespace bb { using Flavor = AvmFlavor; using FF = Flavor::FF; -namespace { - -// Loops through LookupRelations and calculates the logderivatives. -// Metaprogramming is used to loop through the relations, because they are types. -template -void compute_logderivative_rel(const RelationParameters& relation_parameters, - PP& prover_polynomials, - size_t circuit_size) -{ - using Relation = std::tuple_element_t; - AVM_TRACK_TIME( - Relation::NAME + std::string("_ms"), - (compute_logderivative_inverse(prover_polynomials, relation_parameters, circuit_size))); - - if constexpr (relation_idx + 1 < std::tuple_size_v) { - compute_logderivative_rel(relation_parameters, prover_polynomials, circuit_size); - } -} - -} // namespace - /** * Create AvmProver from proving key, witness and manifest. * @@ -93,8 +73,16 @@ void AvmProver::execute_log_derivative_inverse_round() relation_parameters.gamma = gamm; auto prover_polynomials = ProverPolynomials(*key); - compute_logderivative_rel(relation_parameters, prover_polynomials, key->circuit_size); + bb::constexpr_for<0, std::tuple_size_v, 1>([&]() { + using Relation = std::tuple_element_t; + AVM_TRACK_TIME(Relation::NAME + std::string("_ms"), + (compute_logderivative_inverse( + prover_polynomials, relation_parameters, key->circuit_size))); + }); +} +void AvmProver::execute_log_derivative_inverse_commitments_round() +{ // Commit to all logderivative inverse polynomials for (auto [commitment, key_poly] : zip_view(witness_commitments.get_derived(), key->get_derived())) { commitment = commitment_key->commit(key_poly); @@ -154,18 +142,22 @@ HonkProof AvmProver::construct_proof() execute_preamble_round(); // Compute wire commitments - execute_wire_commitments_round(); + AVM_TRACK_TIME("prove/execute_wire_commitments_round_ms", execute_wire_commitments_round()); + + // Compute sorted list accumulator + AVM_TRACK_TIME("prove/execute_log_derivative_inverse_round_ms", execute_log_derivative_inverse_round()); - // Compute sorted list accumulator and commitment - execute_log_derivative_inverse_round(); + // Compute commitments to logderivative inverse polynomials + AVM_TRACK_TIME("prove/execute_log_derivative_inverse_commitments_round_ms", + execute_log_derivative_inverse_commitments_round()); // Fiat-Shamir: alpha // Run sumcheck subprotocol. - execute_relation_check_rounds(); + AVM_TRACK_TIME("prove/execute_relation_check_rounds_ms", execute_relation_check_rounds()); // Fiat-Shamir: rho, y, x, z // Execute Zeromorph multilinear PCS - execute_pcs_rounds(); + AVM_TRACK_TIME("prove/execute_pcs_rounds_ms", execute_pcs_rounds()); return export_proof(); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp index 892b11a525f..35d9f927cbb 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp @@ -29,6 +29,7 @@ class AvmProver { void execute_preamble_round(); void execute_wire_commitments_round(); void execute_log_derivative_inverse_round(); + void execute_log_derivative_inverse_commitments_round(); void execute_relation_check_rounds(); void execute_pcs_rounds(); diff --git a/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs index 47c681dc9bd..27ae98c7413 100644 --- a/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs @@ -161,7 +161,6 @@ class {{name}}CircuitBuilder { return true; } - [[nodiscard]] size_t get_num_gates() const { return rows.size(); } [[nodiscard]] size_t get_circuit_subgroup_size() const diff --git a/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs index 32474b361e4..53990fad42d 100644 --- a/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/prover.cpp.hbs @@ -2,6 +2,7 @@ #include "barretenberg/commitment_schemes/claim.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" +#include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" @@ -16,27 +17,6 @@ namespace bb { using Flavor = {{name}}Flavor; using FF = Flavor::FF; -namespace { - -// Loops through LookupRelations and calculates the logderivatives. -// Metaprogramming is used to loop through the relations, because they are types. -template -void compute_logderivative_rel(const RelationParameters& relation_parameters, - PP& prover_polynomials, - size_t circuit_size) -{ - using Relation = std::tuple_element_t; - AVM_TRACK_TIME( - Relation::NAME + std::string("_ms"), - (compute_logderivative_inverse(prover_polynomials, relation_parameters, circuit_size))); - - if constexpr (relation_idx + 1 < std::tuple_size_v) { - compute_logderivative_rel(relation_parameters, prover_polynomials, circuit_size); - } -} - -} // namespace - /** * Create {{name}}Prover from proving key, witness and manifest. * @@ -94,8 +74,16 @@ void {{name}}Prover::execute_log_derivative_inverse_round() relation_parameters.gamma = gamm; auto prover_polynomials = ProverPolynomials(*key); - compute_logderivative_rel(relation_parameters, prover_polynomials, key->circuit_size); + bb::constexpr_for<0, std::tuple_size_v, 1>([&]() { + using Relation = std::tuple_element_t; + AVM_TRACK_TIME(Relation::NAME + std::string("_ms"), + (compute_logderivative_inverse( + prover_polynomials, relation_parameters, key->circuit_size))); + }); +} +void {{name}}Prover::execute_log_derivative_inverse_commitments_round() +{ // Commit to all logderivative inverse polynomials for (auto [commitment, key_poly] : zip_view(witness_commitments.get_derived(), key->get_derived())) { commitment = commitment_key->commit(key_poly); @@ -155,18 +143,21 @@ HonkProof {{name}}Prover::construct_proof() execute_preamble_round(); // Compute wire commitments - execute_wire_commitments_round(); + AVM_TRACK_TIME("prove/execute_wire_commitments_round_ms", execute_wire_commitments_round()); + + // Compute sorted list accumulator + AVM_TRACK_TIME("prove/execute_log_derivative_inverse_round_ms", execute_log_derivative_inverse_round()); - // Compute sorted list accumulator and commitment - execute_log_derivative_inverse_round(); + // Compute commitments to logderivative inverse polynomials + AVM_TRACK_TIME("prove/execute_log_derivative_inverse_commitments_round_ms", execute_log_derivative_inverse_commitments_round()); // Fiat-Shamir: alpha // Run sumcheck subprotocol. - execute_relation_check_rounds(); + AVM_TRACK_TIME("prove/execute_relation_check_rounds_ms", execute_relation_check_rounds()); // Fiat-Shamir: rho, y, x, z // Execute Zeromorph multilinear PCS - execute_pcs_rounds(); + AVM_TRACK_TIME("prove/execute_pcs_rounds_ms", execute_pcs_rounds()); return export_proof(); } diff --git a/bb-pilcom/bb-pil-backend/templates/prover.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/prover.hpp.hbs index 8915a9d8f29..1ea0f418681 100644 --- a/bb-pilcom/bb-pil-backend/templates/prover.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/prover.hpp.hbs @@ -29,6 +29,7 @@ class {{name}}Prover { void execute_preamble_round(); void execute_wire_commitments_round(); void execute_log_derivative_inverse_round(); + void execute_log_derivative_inverse_commitments_round(); void execute_relation_check_rounds(); void execute_pcs_rounds();