From 560373c70ca9e57e1f79e75875c59ee74befb0c8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 14 Nov 2024 19:58:55 +0000 Subject: [PATCH 01/32] swapping in folding appears to work --- .../client_ivc/client_ivc.test.cpp | 29 ++++++++++++++ .../protogalaxy/protogalaxy_prover_impl.hpp | 10 +++++ .../ultra_honk/decider_proving_key.hpp | 3 ++ .../ultra_honk/mega_honk.test.cpp | 39 +++++++++++++++++++ .../ultra_honk/ultra_honk.test.cpp | 37 ++++++++++++++++++ 5 files changed, 118 insertions(+) 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 f61a6d786b3d..6c491740691d 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -414,5 +414,34 @@ TEST_F(ClientIVCTests, StructuredTraceOverflow) log2_num_gates += 1; } + EXPECT_TRUE(ivc.prove_and_verify()); +}; + +/** + * @brief Test dynamic structured trace overflow block mechanism + * @details + * + */ +TEST_F(ClientIVCTests, DynamicStructuredTraceOverflow) +{ + ClientIVC ivc; + + // Define trace settings with sufficient overflow capacity to accommodate each of the circuits to be accumulated + // uint32_t overflow_capacity = 1 << 16; + uint32_t overflow_capacity = 0; + ivc.trace_settings = { TraceStructure::SMALL_TEST, overflow_capacity }; + + MockCircuitProducer circuit_producer; + + size_t NUM_CIRCUITS = 2; + + // Construct and accumulate some circuits of varying size + size_t log2_num_gates = 14; + for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { + auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_gates); + ivc.accumulate(circuit); + log2_num_gates += 2; + } + EXPECT_TRUE(ivc.prove_and_verify()); }; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index bd7c0ee1701c..7fb12a9155f6 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -128,6 +128,16 @@ FoldingResult ProtogalaxyProver_target_sum = perturbator_evaluation * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient.evaluate(combiner_challenge); + // Check whether the incoming key has a larger trace overflow than the accumulator. If so, the memory structure of + // the accumulator polynomials will not be sufficient to contain the contribution from the incoming polynomials. The + // solution is to simply reorder the addition in the folding formula so that the accumulator is added into the + // incoming key rather than vice-versa. + if (keys[1]->overflow_size > result.accumulator->overflow_size) { + ASSERT(DeciderProvingKeys::NUM == 2); // this mechanism is not supported for the folding of multiple keys + std::swap(lagranges[0], lagranges[1]); // swap the lagrange coefficients so the sum is unchanged + std::swap(result.accumulator->proving_key.polynomials, keys[1]->proving_key.polynomials); // swap the polys + } + // Fold the proving key polynomials for (auto& poly : result.accumulator->proving_key.polynomials.get_unshifted()) { poly *= lagranges[0]; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp index 14f399503f84..665a4aaeb13a 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp @@ -47,6 +47,8 @@ template class DeciderProvingKey_ { size_t final_active_wire_idx{ 0 }; // idx of last non-trivial wire value in the trace + size_t overflow_size{ 0 }; // size of the structured execution trace overflow + DeciderProvingKey_(Circuit& circuit, TraceSettings trace_settings = TraceSettings{}, std::shared_ptr commitment_key = nullptr) @@ -63,6 +65,7 @@ template class DeciderProvingKey_ { circuit.blocks.set_fixed_block_sizes(trace_settings); // set the fixed sizes for each block circuit.blocks.summarize(); move_structured_trace_overflow_to_overflow_block(circuit); + overflow_size = circuit.blocks.overflow.size(); dyadic_circuit_size = compute_structured_dyadic_size(circuit); // set the dyadic size accordingly } else { dyadic_circuit_size = compute_dyadic_size(circuit); // set dyadic size directly from circuit block sizes diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp index 92159f626a64..c67d86472d55 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp @@ -314,3 +314,42 @@ TYPED_TEST(MegaHonkTests, StructuredTraceOverflow) EXPECT_TRUE(builder.blocks.has_overflow); } } + +TYPED_TEST(MegaHonkTests, PolySwap) +{ + using Flavor = TypeParam; + using Builder = Flavor::CircuitBuilder; + + TraceSettings trace_settings{ TraceStructure::SMALL_TEST }; + + // Construct a simple circuit and make a copy of it + Builder builder; + GoblinMockCircuits::construct_simple_circuit(builder); + auto builder_copy = builder; + + // Construct two identical proving keys + auto proving_key_1 = std::make_shared(builder, trace_settings); + auto proving_key_2 = std::make_shared(builder_copy, trace_settings); + + // Tamper with the polys of pkey 1 in such a way that verification should fail + proving_key_1->proving_key.polynomials.w_l.at(5) = 10; + + // Swap the polys of the two proving keys; result should be pkey 1 is valid and pkey 2 should fail + std::swap(proving_key_1->proving_key.polynomials, proving_key_2->proving_key.polynomials); + + { // Verification based on pkey 1 should succeed + typename TestFixture::Prover prover(proving_key_1); + auto verification_key = std::make_shared(proving_key_1->proving_key); + typename TestFixture::Verifier verifier(verification_key); + auto proof = prover.construct_proof(); + EXPECT_TRUE(verifier.verify_proof(proof)); + } + + { // Verification based on pkey 2 should fail + typename TestFixture::Prover prover(proving_key_2); + auto verification_key = std::make_shared(proving_key_2->proving_key); + typename TestFixture::Verifier verifier(verification_key); + auto proof = prover.construct_proof(); + EXPECT_FALSE(verifier.verify_proof(proof)); + } +} diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp index b8564e9ae75c..7f907d2d2c16 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp @@ -109,6 +109,43 @@ TYPED_TEST(UltraHonkTests, StructuredTrace) EXPECT_TRUE(verifier.verify_proof(proof)); } +TYPED_TEST(UltraHonkTests, PolySwap) +{ + size_t num_gates = 3; + TraceSettings trace_settings{ TraceStructure::SMALL_TEST }; + + // Construct a simple circuit and make a copy of it + UltraCircuitBuilder builder; + MockCircuits::add_arithmetic_gates_with_public_inputs(builder, num_gates); + auto builder_copy = builder; + + // Construct two identical proving keys + auto proving_key_1 = std::make_shared(builder, trace_settings); + auto proving_key_2 = std::make_shared(builder_copy, trace_settings); + + // Tamper with the polys of pkey 1 in such a way that verification should fail + proving_key_1->proving_key.polynomials.w_l.at(5) = 10; + + // Swap the polys of the two proving keys; result should be pkey 1 is valid and pkey 2 should fail + std::swap(proving_key_1->proving_key.polynomials, proving_key_2->proving_key.polynomials); + + { // Verification based on pkey 1 should succeed + typename TestFixture::Prover prover(proving_key_1); + auto verification_key = std::make_shared(proving_key_1->proving_key); + typename TestFixture::Verifier verifier(verification_key); + auto proof = prover.construct_proof(); + EXPECT_TRUE(verifier.verify_proof(proof)); + } + + { // Verification based on pkey 2 should fail + typename TestFixture::Prover prover(proving_key_2); + auto verification_key = std::make_shared(proving_key_2->proving_key); + typename TestFixture::Verifier verifier(verification_key); + auto proof = prover.construct_proof(); + EXPECT_FALSE(verifier.verify_proof(proof)); + } +} + /** * @brief Test simple circuit with public inputs * From 981074c3844edc638a115ca810027b1c14515882 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 15 Nov 2024 20:56:41 +0000 Subject: [PATCH 02/32] WiP; dyadic size bump tst failing without real clues --- .../client_ivc/client_ivc.test.cpp | 35 ++++++++++++++++--- .../barretenberg/polynomials/polynomial.hpp | 1 + .../shared_shifted_virtual_zeroes_array.hpp | 15 ++++++++ .../protogalaxy/protogalaxy_prover_impl.hpp | 32 +++++++++++++---- .../protogalaxy_prover_internal.hpp | 6 +++- .../stdlib_circuit_builders/mega_flavor.hpp | 7 ++++ .../stdlib_circuit_builders/ultra_flavor.hpp | 7 ++++ 7 files changed, 90 insertions(+), 13 deletions(-) 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 6c491740691d..b773ace7f7d2 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -422,14 +422,12 @@ TEST_F(ClientIVCTests, StructuredTraceOverflow) * @details * */ -TEST_F(ClientIVCTests, DynamicStructuredTraceOverflow) +TEST_F(ClientIVCTests, DynamicOverflow) { ClientIVC ivc; - // Define trace settings with sufficient overflow capacity to accommodate each of the circuits to be accumulated - // uint32_t overflow_capacity = 1 << 16; - uint32_t overflow_capacity = 0; - ivc.trace_settings = { TraceStructure::SMALL_TEST, overflow_capacity }; + // Define trace settings with zero overflow capacity + ivc.trace_settings = { TraceStructure::SMALL_TEST, /*overflow_capacity=*/0 }; MockCircuitProducer circuit_producer; @@ -443,5 +441,32 @@ TEST_F(ClientIVCTests, DynamicStructuredTraceOverflow) log2_num_gates += 2; } + EXPECT_TRUE(ivc.prove_and_verify()); +}; + +/** + * @brief Test dynamic trace overflow where the dyadic circuit size also increases + * @details + * + */ +TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) +{ + ClientIVC ivc; + + // Define trace settings with zero overflow capacity + ivc.trace_settings = { TraceStructure::SMALL_TEST, /*overflow_capacity=*/0 }; + + MockCircuitProducer circuit_producer; + + size_t NUM_CIRCUITS = 2; + + // Construct and accumulate some circuits of varying size + size_t log2_num_gates = 14; + for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { + auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_gates); + ivc.accumulate(circuit); + log2_num_gates += 4; + } + EXPECT_TRUE(ivc.prove_and_verify()); }; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp index c51597d2276c..a5cc3c93cf8d 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp @@ -251,6 +251,7 @@ template class Polynomial { std::size_t size() const { return coefficients_.size(); } std::size_t virtual_size() const { return coefficients_.virtual_size(); } + void increase_virtual_size(const size_t size_in) { coefficients_.increase_virtual_size(size_in); }; Fr* data() { return coefficients_.data(); } const Fr* data() const { return coefficients_.data(); } diff --git a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp index 7dd50a99c963..191080edbe8a 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/shared_shifted_virtual_zeroes_array.hpp @@ -1,6 +1,7 @@ #pragma once #include "barretenberg/common/assert.hpp" +#include "barretenberg/common/log.hpp" #include #include @@ -47,6 +48,14 @@ template struct SharedShiftedVirtualZeroesArray { const T& get(size_t index, size_t virtual_padding = 0) const { static const T zero{}; + if (index >= virtual_size_ + virtual_padding) { + info("BAD GET(): index = ", + index, + ", virtual_size_ = ", + virtual_size_, + ", virtual_padding = ", + virtual_padding); + } ASSERT(index < virtual_size_ + virtual_padding); if (index >= start_ && index < end_) { return data()[index - start_]; @@ -68,6 +77,12 @@ template struct SharedShiftedVirtualZeroesArray { // Getter for consistency with size(); size_t virtual_size() const { return virtual_size_; } + void increase_virtual_size(const size_t new_virtual_size) + { + ASSERT(new_virtual_size >= virtual_size_); // shrinking is not allowed + virtual_size_ = new_virtual_size; + } + T& operator[](size_t index) { ASSERT(index >= start_ && index < end_); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 7fb12a9155f6..6035e0110a16 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -135,7 +135,9 @@ FoldingResult ProtogalaxyProver_overflow_size > result.accumulator->overflow_size) { ASSERT(DeciderProvingKeys::NUM == 2); // this mechanism is not supported for the folding of multiple keys std::swap(lagranges[0], lagranges[1]); // swap the lagrange coefficients so the sum is unchanged - std::swap(result.accumulator->proving_key.polynomials, keys[1]->proving_key.polynomials); // swap the polys + std::swap(result.accumulator->proving_key.polynomials, keys[1]->proving_key.polynomials); // swap the polys + std::swap(result.accumulator->proving_key.circuit_size, keys[1]->proving_key.circuit_size); // swap circuit size + std::swap(result.accumulator->proving_key.log_circuit_size, keys[1]->proving_key.log_circuit_size); } // Fold the proving key polynomials @@ -171,13 +173,29 @@ FoldingResult ProtogalaxyProver_proving_key.circuit_size != keys_to_fold[idx + 1]->proving_key.circuit_size) { - info("ProtogalaxyProver: circuit size mismatch!"); - info("DeciderPK ", idx, " size = ", keys_to_fold[idx]->proving_key.circuit_size); - info("DeciderPK ", idx + 1, " size = ", keys_to_fold[idx + 1]->proving_key.circuit_size); - ASSERT(false); + size_t max_circuit_size = 0; + for (size_t idx = 0; idx < DeciderProvingKeys::NUM; ++idx) { + max_circuit_size = std::max(max_circuit_size, keys_to_fold[idx]->proving_key.circuit_size); + // if (keys_to_fold[idx]->proving_key.circuit_size != keys_to_fold[idx + 1]->proving_key.circuit_size) { + // info("ProtogalaxyProver: circuit size mismatch!"); + // info("DeciderPK ", idx, " size = ", keys_to_fold[idx]->proving_key.circuit_size); + // info("DeciderPK ", idx + 1, " size = ", keys_to_fold[idx + 1]->proving_key.circuit_size); + // // ASSERT(false); + // } + } + for (size_t idx = 0; idx < DeciderProvingKeys::NUM; ++idx) { + if (keys_to_fold[idx]->proving_key.circuit_size != max_circuit_size) { + info("ProtogalaxyProver: circuit size mismatch - increasing virtual size of key ", + idx, + " from ", + keys_to_fold[idx]->proving_key.circuit_size, + " to ", + max_circuit_size); + keys_to_fold[idx]->proving_key.polynomials.increase_polynomials_virtual_size(max_circuit_size); } + // for (auto poly : keys_to_fold[idx]->proving_key.polynomials.get_all()) { + // // info("poly.virtual_size = ", poly.virtual_size()); + // } } run_oink_prover_on_each_incomplete_key(); vinfo("oink prover on each incomplete key"); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index d02e63b47764..a07b2e16bc5e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -119,7 +119,8 @@ template class ProtogalaxyProverInternal { PROFILE_THIS_NAME("ProtogalaxyProver_::compute_row_evaluations"); - const size_t polynomial_size = polynomials.get_polynomial_size(); + // const size_t polynomial_size = polynomials.get_polynomial_size(); + const size_t polynomial_size = polynomials.q_c.virtual_size(); // DEBUG std::vector aggregated_relation_evaluations(polynomial_size); const std::array alphas = [&alphas_]() { @@ -598,6 +599,9 @@ template class ProtogalaxyProverInternal { size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified num_threads = num_threads > 0 ? num_threads : 1; // ensure num threads is >= 1 + // DEBUG: + num_threads = 1; + return num_threads; } }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 095840dc85d1..54942d7d4f5e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -410,6 +410,13 @@ class MegaFlavor { shifted = to_be_shifted.shifted(); } } + + void increase_polynomials_virtual_size(const size_t size_in) + { + for (auto& polynomial : this->get_all()) { + polynomial.increase_virtual_size(size_in); + } + } }; /** 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 4df8941fd538..3e63e8714064 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -331,6 +331,13 @@ class UltraFlavor { shifted = to_be_shifted.shifted(); } } + + void increase_polynomials_virtual_size(const size_t size_in) + { + for (auto& polynomial : this->get_all()) { + polynomial.increase_virtual_size(size_in); + } + } }; /** * @brief The proving key is responsible for storing the polynomials used by the prover. From d06c1e8d77c91fd6752a2b1f5688e1bffd7b7b1c Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 18 Nov 2024 17:14:17 +0000 Subject: [PATCH 03/32] changes from other PR; test passes if overflow is set in advance --- .../client_ivc/client_ivc.test.cpp | 2 +- .../execution_trace_usage_tracker.hpp | 60 ++++++++++--------- .../protogalaxy_prover_internal.hpp | 4 +- .../ultra_honk/ultra_honk.test.cpp | 37 ------------ 4 files changed, 34 insertions(+), 69 deletions(-) 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 5eca33e3f3b9..8b4cd9febe1e 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -438,7 +438,7 @@ TEST_F(ClientIVCTests, DynamicOverflow) */ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) { - ClientIVC ivc{ { SMALL_TEST_STRUCTURE, /*overflow_capacity=*/0 } }; + ClientIVC ivc{ { SMALL_TEST_STRUCTURE, /*overflow_capacity=*/1 << 18 } }; MockCircuitProducer circuit_producer; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp index f5d3ddf5fd9d..34e2895b0450 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp @@ -20,7 +20,10 @@ struct ExecutionTraceUsageTracker { TraceStructure max_sizes; // max utilization of each block MegaTraceFixedBlockSizes fixed_sizes; // fixed size of each block prescribed by structuring - MegaTraceActiveRanges active_ranges; // ranges utlized by the accumulator within the ambient structured trace + // Store active ranges based on the most current accumulator and those based on all but the most recently + // accumulated circuit. The former is needed for the combiner calculation and the latter for the perturbator. + std::vector active_ranges; + std::vector previous_active_ranges; std::vector thread_ranges; // ranges within the ambient space over which utilized space is evenly distibuted @@ -60,36 +63,37 @@ struct ExecutionTraceUsageTracker { max_tables_size = std::max(max_tables_size, circuit.get_tables_size()); // Update the active ranges of the trace based on max block utilization - for (auto [max_size, fixed_block, active_range] : - zip_view(max_sizes.get(), fixed_sizes.get(), active_ranges.get())) { + previous_active_ranges = active_ranges; // store active ranges based on all but the present circuit + active_ranges.clear(); + for (auto [max_size, fixed_block] : zip_view(max_sizes.get(), fixed_sizes.get())) { size_t start_idx = fixed_block.trace_offset; size_t end_idx = start_idx + max_size; - active_range = Range{ start_idx, end_idx }; + active_ranges.push_back(Range{ start_idx, end_idx }); } - // The active ranges for the databus and lookup relations (both based on log-deriv lookup argument) must - // incorporate both the lookup/read gate blocks as well as the rows containing the data that is being read. - // Update the corresponding ranges accordingly. (Note: tables are constructed at the 'bottom' of the trace). + // The active ranges must also include the rows where the actual databus and lookup table data are stored. + // (Note: lookup tables are constructed at the end of the trace; databus data is constructed at the start). size_t dyadic_circuit_size = fixed_sizes.get_structured_dyadic_size(); - active_ranges.busread.first = 0; // databus data is stored at the top of the trace - active_ranges.busread.second = std::max(max_databus_size, active_ranges.busread.second); - active_ranges.lookup.first = std::min(dyadic_circuit_size - max_tables_size, active_ranges.lookup.first); - active_ranges.lookup.second = dyadic_circuit_size; // lookups are stored at the bottom of the trace + + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1152): should be able to use simply Range{ 0, + // max_databus_size } but this breaks for certain choices of num_threads. + size_t databus_end = + std::max(max_databus_size, static_cast(fixed_sizes.busread.trace_offset + max_sizes.busread)); + active_ranges.push_back(Range{ 0, databus_end }); + active_ranges.push_back(Range{ dyadic_circuit_size - max_tables_size, dyadic_circuit_size }); } - // Check whether an index is contained within the active ranges - bool check_is_active(const size_t idx) + // Check whether an index is contained within the active ranges (or previous active ranges; needed for perturbator) + bool check_is_active(const size_t idx, bool use_prev_accumulator = false) { // If structured trace is not in use, assume the whole trace is active if (!trace_settings.structure) { return true; } - for (auto& range : active_ranges.get()) { - if (idx >= range.first && idx < range.second) { - return true; - } - } - return false; + std::vector ranges_to_check = use_prev_accumulator ? previous_active_ranges : active_ranges; + return std::any_of(ranges_to_check.begin(), ranges_to_check.end(), [idx](const auto& range) { + return idx >= range.first && idx < range.second; + }); } // For printing only. Must match the order of the members in the arithmetization @@ -117,7 +121,7 @@ struct ExecutionTraceUsageTracker { void print_active_ranges() { info("Active regions of accumulator: "); - for (auto [label, range] : zip_view(block_labels, active_ranges.get())) { + for (auto [label, range] : zip_view(block_labels, active_ranges)) { std::cout << std::left << std::setw(20) << (label + ":") << "(" << range.first << ", " << range.second << ")" << std::endl; } @@ -134,27 +138,25 @@ struct ExecutionTraceUsageTracker { } /** - * @brief Construct ranges of execution trace rows that evenly distribute the active content of the trace across a + * @brief Construct ranges of execution trace rows that evenly distribute the active content of the trace across a * given number of threads. * * @param num_threads Num ranges over which to distribute the data * @param full_domain_size Size of full domain; needed only for unstructured case + * @param use_prev_accumulator Base ranges on previous or current accumulator */ - void construct_thread_ranges(const size_t num_threads, const size_t full_domain_size) + void construct_thread_ranges(const size_t num_threads, + const size_t full_domain_size, + bool use_prev_accumulator = false) { - // Copy the ranges into a simple std container for processing by subsequent methods (cheap) - std::vector active_ranges_copy; - for (const auto& range : active_ranges.get()) { - active_ranges_copy.push_back(range); - } - // Convert the active ranges for each gate type into a set of sorted non-overlapping ranges (union of the input) std::vector simplified_active_ranges; if (!trace_settings.structure) { // If not using a structured trace, set the active range to the whole domain simplified_active_ranges.push_back(Range{ 0, full_domain_size }); } else { - simplified_active_ranges = construct_union_of_ranges(active_ranges_copy); + simplified_active_ranges = use_prev_accumulator ? construct_union_of_ranges(previous_active_ranges) + : construct_union_of_ranges(active_ranges); } // Determine ranges in the structured trace that even distibute the active content across threads diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index d78cdccec6c0..85bf0edbeac9 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -136,7 +136,7 @@ template class ProtogalaxyProverInternal { std::vector linearly_dependent_contribution_accumulators(num_threads); // Distribute the execution trace rows across threads so that each handles an equal number of active rows - trace_usage_tracker.construct_thread_ranges(num_threads, polynomial_size); + trace_usage_tracker.construct_thread_ranges(num_threads, polynomial_size, /*use_prev_accumulator=*/true); parallel_for(num_threads, [&](size_t thread_idx) { const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; @@ -144,7 +144,7 @@ template class ProtogalaxyProverInternal { for (size_t idx = start; idx < end; idx++) { // The contribution is only non-trivial at a given row if the accumulator is active at that row - if (trace_usage_tracker.check_is_active(idx)) { + if (trace_usage_tracker.check_is_active(idx, /*use_prev_accumulator=*/true)) { const AllValues row = polynomials.get_row(idx); // Evaluate all subrelations on given row. Separator is 1 since we are not summing across rows here. const RelationEvaluations evals = diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp index 51232dacf05e..b671c9fbb3af 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp @@ -87,43 +87,6 @@ TYPED_TEST(UltraHonkTests, ANonZeroPolynomialIsAGoodPolynomial) } } -// TYPED_TEST(UltraHonkTests, PolySwap) -// { -// size_t num_gates = 3; -// TraceSettings trace_settings{ TraceStructure::SMALL_TEST }; - -// // Construct a simple circuit and make a copy of it -// UltraCircuitBuilder builder; -// MockCircuits::add_arithmetic_gates_with_public_inputs(builder, num_gates); -// auto builder_copy = builder; - -// // Construct two identical proving keys -// auto proving_key_1 = std::make_shared(builder, trace_settings); -// auto proving_key_2 = std::make_shared(builder_copy, trace_settings); - -// // Tamper with the polys of pkey 1 in such a way that verification should fail -// proving_key_1->proving_key.polynomials.w_l.at(5) = 10; - -// // Swap the polys of the two proving keys; result should be pkey 1 is valid and pkey 2 should fail -// std::swap(proving_key_1->proving_key.polynomials, proving_key_2->proving_key.polynomials); - -// { // Verification based on pkey 1 should succeed -// typename TestFixture::Prover prover(proving_key_1); -// auto verification_key = std::make_shared(proving_key_1->proving_key); -// typename TestFixture::Verifier verifier(verification_key); -// auto proof = prover.construct_proof(); -// EXPECT_TRUE(verifier.verify_proof(proof)); -// } - -// { // Verification based on pkey 2 should fail -// typename TestFixture::Prover prover(proving_key_2); -// auto verification_key = std::make_shared(proving_key_2->proving_key); -// typename TestFixture::Verifier verifier(verification_key); -// auto proof = prover.construct_proof(); -// EXPECT_FALSE(verifier.verify_proof(proof)); -// } -// } - /** * @brief Test simple circuit with public inputs * From b4cb9de57e9f6e60cb2d77e4770599228e5fab00 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 18 Nov 2024 18:58:00 +0000 Subject: [PATCH 04/32] WiP debug with check circuit shows decider sumcheck failure --- .../cpp/src/barretenberg/client_ivc/client_ivc.cpp | 8 ++++++++ .../cpp/src/barretenberg/client_ivc/client_ivc.test.cpp | 2 +- .../protogalaxy/protogalaxy_prover_internal.hpp | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 9119e17f6ea3..c25adf0bcdf5 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -180,6 +180,9 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptrproving_key.commitment_key); } + // DEBUG + ASSERT(CircuitChecker::check(circuit)); + vinfo("getting honk vk... precomputed?: ", precomputed_vk); // Update the accumulator trace usage based on the present circuit trace_usage_tracker.update(circuit); @@ -279,6 +282,11 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() merge_verification_queue.emplace_back(merge_proof); auto decider_pk = std::make_shared(builder); + // WORKTODO: This fails in the dyanmic accum expansion case. investigation of this failure suggests failure in the + // decider recursive verifier at the first 'round.check_sum(round_univariate, dummy_round);' in sumcheck. Suggests + // that either one of the instances is not satisfying sumcheck or perhaps that theres something more fundamentally + // wrong with folding an accumlator that was dynamically expanded from its original size. + ASSERT(CircuitChecker::check(builder)); honk_vk = std::make_shared(decider_pk->proving_key); MegaProver prover(decider_pk); 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 8b4cd9febe1e..5eca33e3f3b9 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -438,7 +438,7 @@ TEST_F(ClientIVCTests, DynamicOverflow) */ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) { - ClientIVC ivc{ { SMALL_TEST_STRUCTURE, /*overflow_capacity=*/1 << 18 } }; + ClientIVC ivc{ { SMALL_TEST_STRUCTURE, /*overflow_capacity=*/0 } }; MockCircuitProducer circuit_producer; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 85bf0edbeac9..84400a61456d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -242,6 +242,10 @@ template class ProtogalaxyProverInternal { for (size_t idx = log_circuit_size; idx < CONST_PG_LOG_N; ++idx) { perturbator.emplace_back(FF(0)); } + info("Perturbator coeffs:"); + for (size_t idx = 0; idx < perturbator.size(); ++idx) { + info("idx = ", idx, ", val = ", perturbator[idx]); + } return Polynomial{ perturbator }; } From a7231ef63032c4fc45e69a4ea93682990a44a071 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 18 Nov 2024 23:42:19 +0000 Subject: [PATCH 05/32] add test that proves out dynamic virtual size increase --- .../ultra_honk/mega_honk.test.cpp | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp index 16202ce7e2a2..c3ec192f1886 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp @@ -71,6 +71,35 @@ template class MegaHonkTests : public ::testing::Test { return verified; } + // WORKTODO: move this to instance inspector or something + + /** + * @brief Check that a given relation is satified for a set of polynomials + * + * @tparam relation_idx Index into a tuple of provided relations + */ + template void check_relation(auto& polynomials, auto params) + { + for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { + // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to + // zero + using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; + SumcheckArrayOfValuesOverSubrelations result; + for (auto& element : result) { + element = 0; + } + + // Evaluate each constraint in the relation and check that each is satisfied + Relation::accumulate(result, polynomials.get_row(i), params, 1); + for (auto& element : result) { + if (element != 0) { + info("WARNING: Relation fails at row idx: ", i); + ASSERT(false); + } + } + } + } + /** * @brief Construct and verify a Goblin ECC op queue merge proof * @@ -128,6 +157,57 @@ TYPED_TEST(MegaHonkTests, BasicStructured) EXPECT_TRUE(verifier.verify_proof(proof)); } +/** + * @brief Test proof construction/verification for a structured execution trace + * + */ +TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) +{ + using Flavor = TypeParam; + typename Flavor::CircuitBuilder builder; + using FF = Flavor::FF; + using Prover = UltraProver_; + using Verifier = UltraVerifier_; + + GoblinMockCircuits::construct_simple_circuit(builder); + + auto builder_copy = builder; + + // Construct and verify Honk proof using a structured trace + TraceSettings trace_settings{ SMALL_TEST_STRUCTURE }; + auto proving_key = std::make_shared>(builder, trace_settings); + auto proving_key_copy = std::make_shared>(builder_copy, trace_settings); + auto circuit_size = proving_key->proving_key.circuit_size; + + auto doubled_circuit_size = 2 * circuit_size; + proving_key_copy->proving_key.polynomials.increase_polynomials_virtual_size(doubled_circuit_size); + // WARNING: updating circuit_size here would public input delta perm argument! + // proving_key_copy->proving_key.circuit_size = doubled_circuit_size; + + Prover prover(proving_key); + auto verification_key = std::make_shared(proving_key->proving_key); + + Prover prover_copy(proving_key_copy); + auto verification_key_copy = std::make_shared(proving_key_copy->proving_key); + + for (auto [entry, entry_copy] : zip_view(verification_key->get_all(), verification_key_copy->get_all())) { + EXPECT_EQ(entry, entry_copy); + } + + Verifier verifier(verification_key); + auto proof = prover.construct_proof(); + + this->template check_relation>(proving_key->proving_key.polynomials, + proving_key->relation_parameters); + EXPECT_TRUE(verifier.verify_proof(proof)); + + Verifier verifier_copy(verification_key_copy); + auto proof_copy = prover_copy.construct_proof(); + this->template check_relation>(proving_key_copy->proving_key.polynomials, + proving_key_copy->relation_parameters); + EXPECT_TRUE(verifier_copy.verify_proof(proof_copy)); +} + /** * @brief Test proof construction/verification for a circuit with ECC op gates, public inputs, and basic arithmetic * gates From 0cf37577f7edc0e56df73cc588f5c0c5cc6eafe4 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 18 Nov 2024 23:58:06 +0000 Subject: [PATCH 06/32] move relation checker to pk inspector --- .../proving_key_inspector.hpp | 33 ++++++++++++++++ .../ultra_honk/mega_honk.test.cpp | 38 +++---------------- 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp index 96f3bd65900a..e0d21d0198af 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp @@ -1,9 +1,42 @@ #pragma once +#include "barretenberg/common/assert.hpp" #include "barretenberg/common/log.hpp" namespace bb::proving_key_inspector { +// WORKTODO: add a check_relations method templated on Flavor that checks all realtions + +/** + * @brief Check that a given relation is satisfied for a set of polynomials + * + * @tparam Relation a linearly independent Relation to be checked + * @param polynomials prover polynomials + * @param params a RelationParameters instance + */ +template static void check_relation(auto& polynomials, auto params) +{ + for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { + // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for the relation and initialize to zero + using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; + SumcheckArrayOfValuesOverSubrelations result; + for (auto& element : result) { + element = 0; + } + + // Evaluate each constraint in the relation and check that each is satisfied + Relation::accumulate(result, polynomials.get_row(i), params, 1); + size_t subrelation_idx = 0; + for (auto& element : result) { + if (element != 0) { + info("WARNING: Relation fails subrelation: ", subrelation_idx, " at row idx: ", i); + ASSERT(false); + } + subrelation_idx++; + } + } +} + // Determine whether a polynomial has at least one non-zero coefficient bool is_non_zero(auto& polynomial) { diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp index c3ec192f1886..a3f258f9ef5d 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp @@ -5,6 +5,7 @@ #include "barretenberg/circuit_checker/circuit_checker.hpp" #include "barretenberg/common/log.hpp" #include "barretenberg/goblin/mock_circuits.hpp" +#include "barretenberg/plonk_honk_shared/proving_key_inspector.hpp" #include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" #include "barretenberg/ultra_honk/merge_prover.hpp" @@ -71,35 +72,6 @@ template class MegaHonkTests : public ::testing::Test { return verified; } - // WORKTODO: move this to instance inspector or something - - /** - * @brief Check that a given relation is satified for a set of polynomials - * - * @tparam relation_idx Index into a tuple of provided relations - */ - template void check_relation(auto& polynomials, auto params) - { - for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { - // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to - // zero - using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; - SumcheckArrayOfValuesOverSubrelations result; - for (auto& element : result) { - element = 0; - } - - // Evaluate each constraint in the relation and check that each is satisfied - Relation::accumulate(result, polynomials.get_row(i), params, 1); - for (auto& element : result) { - if (element != 0) { - info("WARNING: Relation fails at row idx: ", i); - ASSERT(false); - } - } - } - } - /** * @brief Construct and verify a Goblin ECC op queue merge proof * @@ -197,14 +169,14 @@ TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) Verifier verifier(verification_key); auto proof = prover.construct_proof(); - this->template check_relation>(proving_key->proving_key.polynomials, - proving_key->relation_parameters); + bb::proving_key_inspector::check_relation>(proving_key->proving_key.polynomials, + proving_key->relation_parameters); EXPECT_TRUE(verifier.verify_proof(proof)); Verifier verifier_copy(verification_key_copy); auto proof_copy = prover_copy.construct_proof(); - this->template check_relation>(proving_key_copy->proving_key.polynomials, - proving_key_copy->relation_parameters); + bb::proving_key_inspector::check_relation>(proving_key_copy->proving_key.polynomials, + proving_key_copy->relation_parameters); EXPECT_TRUE(verifier_copy.verify_proof(proof_copy)); } From f7e8fc77939fb12df5a092916b8d2dba644e46a8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 19 Nov 2024 16:38:44 +0000 Subject: [PATCH 07/32] add proper relation checker class --- .../proving_key_inspector.hpp | 32 ----- .../plonk_honk_shared/relation_checker.cpp | 3 + .../plonk_honk_shared/relation_checker.hpp | 120 ++++++++++++++++++ .../ultra_honk/mega_honk.test.cpp | 10 +- 4 files changed, 127 insertions(+), 38 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.cpp create mode 100644 barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp index e0d21d0198af..51f455a9b62d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/proving_key_inspector.hpp @@ -5,38 +5,6 @@ namespace bb::proving_key_inspector { -// WORKTODO: add a check_relations method templated on Flavor that checks all realtions - -/** - * @brief Check that a given relation is satisfied for a set of polynomials - * - * @tparam Relation a linearly independent Relation to be checked - * @param polynomials prover polynomials - * @param params a RelationParameters instance - */ -template static void check_relation(auto& polynomials, auto params) -{ - for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { - // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for the relation and initialize to zero - using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; - SumcheckArrayOfValuesOverSubrelations result; - for (auto& element : result) { - element = 0; - } - - // Evaluate each constraint in the relation and check that each is satisfied - Relation::accumulate(result, polynomials.get_row(i), params, 1); - size_t subrelation_idx = 0; - for (auto& element : result) { - if (element != 0) { - info("WARNING: Relation fails subrelation: ", subrelation_idx, " at row idx: ", i); - ASSERT(false); - } - subrelation_idx++; - } - } -} - // Determine whether a polynomial has at least one non-zero coefficient bool is_non_zero(auto& polynomial) { diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.cpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.cpp new file mode 100644 index 000000000000..20afcb4dc85e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.cpp @@ -0,0 +1,3 @@ +#include "relation_checker.hpp" + +// Hack to make the module compile. \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp new file mode 100644 index 000000000000..f876bb87f8bb --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp @@ -0,0 +1,120 @@ +#pragma once + +#include "barretenberg/common/assert.hpp" +#include "barretenberg/common/log.hpp" +#include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp" +#include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" + +namespace bb { + +/** + * @brief A debugging utility for checking whether a set of polynomials satisfies the relations for a given Flavor + * + * @tparam Flavor + */ +template class RelationChecker { + public: + /** + * @brief Check that the provided polynomials satisfy all relations for a given Flavor + */ + static void check_all([[maybe_unused]] const auto& polynomials, [[maybe_unused]] const auto& params) + { + // default; do nothing + } + + /** + * @brief Check that a single specified relation is satisfied for a set of polynomials + * + * @tparam Relation a linearly independent Relation to be checked + * @param polynomials prover polynomials + * @param params a RelationParameters instance + */ + template + static void check(const auto& polynomials, + const auto& params, + bool is_linearly_independent, + std::string label = "Relation") + { + // Define the appropriate accumulator type for the relation and initialize to zero + typename Relation::SumcheckArrayOfValuesOverSubrelations result; + for (auto& element : result) { + element = 0; + } + + for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { + if (is_linearly_independent) { + // Evaluate each constraint in the relation and check that each is satisfied + Relation::accumulate(result, polynomials.get_row(i), params, 1); + size_t subrelation_idx = 0; + for (auto& element : result) { + if (element != 0) { + info("RelationChecker: ", + label, + " relation (subrelation idx: ", + subrelation_idx, + ") failed at row idx: ", + i, + "."); + ASSERT(false); + } + subrelation_idx++; + } + } + } + + if (!is_linearly_independent) { + // Result accumulated across entire execution trace should be zero + for (auto& element : result) { + if (element != 0) { + info("RelationChecker: ", label, " relation (linearly indep.) failed."); + ASSERT(false); + } + } + } + } +}; + +// Specialization for Ultra +template <> class RelationChecker : public RelationChecker { + using Base = RelationChecker; + + public: + static void check_all(const auto& polynomials, const auto& params) + { + using FF = UltraFlavor::FF; + + // Linearly independent relations (must be satisfied at each row) + Base::check>(polynomials, params, true, "UltraArithmetic"); + Base::check>(polynomials, params, true, "UltraPermutation"); + Base::check>(polynomials, params, true, "DeltaRangeConstraint"); + Base::check>(polynomials, params, true, "Elliptic"); + Base::check>(polynomials, params, true, "Auxiliary"); + Base::check>(polynomials, params, true, "Poseidon2External"); + Base::check>(polynomials, params, true, "Poseidon2Internal"); + + // Linearly dependent relations (must be satisfied as a sum across all rows) + Base::check>(polynomials, params, false, "LogDerivLookup"); + } +}; + +// Specialization for Mega +template <> class RelationChecker : public RelationChecker { + using Base = RelationChecker; + + public: + static void check_all(const auto& polynomials, const auto& params) + { + // Check relations that are shared with Ultra + RelationChecker::check_all(polynomials, params); + + using FF = MegaFlavor::FF; + + // Linearly independent relations (must be satisfied at each row) + Base::check>(polynomials, params, true, "EccOpQueue"); + + // Linearly dependent relations (must be satisfied as a sum across all rows) + Base::check>(polynomials, params, false, "DatabusLookup"); + } +}; + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp index a3f258f9ef5d..6bd5953e1cca 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp @@ -5,7 +5,7 @@ #include "barretenberg/circuit_checker/circuit_checker.hpp" #include "barretenberg/common/log.hpp" #include "barretenberg/goblin/mock_circuits.hpp" -#include "barretenberg/plonk_honk_shared/proving_key_inspector.hpp" +#include "barretenberg/plonk_honk_shared/relation_checker.hpp" #include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" #include "barretenberg/ultra_honk/merge_prover.hpp" @@ -137,7 +137,6 @@ TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) { using Flavor = TypeParam; typename Flavor::CircuitBuilder builder; - using FF = Flavor::FF; using Prover = UltraProver_; using Verifier = UltraVerifier_; @@ -169,14 +168,13 @@ TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) Verifier verifier(verification_key); auto proof = prover.construct_proof(); - bb::proving_key_inspector::check_relation>(proving_key->proving_key.polynomials, - proving_key->relation_parameters); + RelationChecker::check_all(proving_key->proving_key.polynomials, proving_key->relation_parameters); EXPECT_TRUE(verifier.verify_proof(proof)); Verifier verifier_copy(verification_key_copy); auto proof_copy = prover_copy.construct_proof(); - bb::proving_key_inspector::check_relation>(proving_key_copy->proving_key.polynomials, - proving_key_copy->relation_parameters); + + RelationChecker::check_all(proving_key->proving_key.polynomials, proving_key->relation_parameters); EXPECT_TRUE(verifier_copy.verify_proof(proof_copy)); } From 35c15a0c3cdc7269d5ef618f46dca7a592412d44 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 19 Nov 2024 17:44:54 +0000 Subject: [PATCH 08/32] debug --- .../src/barretenberg/client_ivc/client_ivc.test.cpp | 3 ++- .../protogalaxy/protogalaxy_prover_impl.hpp | 7 ++++--- .../protogalaxy/protogalaxy_prover_internal.hpp | 12 ++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) 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 5eca33e3f3b9..98b89b89f137 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -438,7 +438,8 @@ TEST_F(ClientIVCTests, DynamicOverflow) */ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) { - ClientIVC ivc{ { SMALL_TEST_STRUCTURE, /*overflow_capacity=*/0 } }; + uint32_t overflow_capacity = 1 << 18; + ClientIVC ivc{ { SMALL_TEST_STRUCTURE, overflow_capacity } }; MockCircuitProducer circuit_producer; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 6035e0110a16..73526cf3133f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -1,5 +1,6 @@ #pragma once #include "barretenberg/common/op_count.hpp" +#include "barretenberg/plonk_honk_shared/relation_checker.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover_internal.hpp" #include "barretenberg/protogalaxy/prover_verifier_shared.hpp" #include "barretenberg/relations/relation_parameters.hpp" @@ -193,10 +194,10 @@ FoldingResult ProtogalaxyProver_proving_key.polynomials.increase_polynomials_virtual_size(max_circuit_size); } - // for (auto poly : keys_to_fold[idx]->proving_key.polynomials.get_all()) { - // // info("poly.virtual_size = ", poly.virtual_size()); - // } } + + // RelationChecker::check_all(keys_to_fold[0]->proving_key.polynomials, + // keys_to_fold[0]->relation_parameters); run_oink_prover_on_each_incomplete_key(); vinfo("oink prover on each incomplete key"); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 84400a61456d..9657bc43cc0c 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -242,10 +242,10 @@ template class ProtogalaxyProverInternal { for (size_t idx = log_circuit_size; idx < CONST_PG_LOG_N; ++idx) { perturbator.emplace_back(FF(0)); } - info("Perturbator coeffs:"); - for (size_t idx = 0; idx < perturbator.size(); ++idx) { - info("idx = ", idx, ", val = ", perturbator[idx]); - } + // info("Perturbator coeffs:"); + // for (size_t idx = 0; idx < perturbator.size(); ++idx) { + // info("idx = ", idx, ", val = ", perturbator[idx]); + // } return Polynomial{ perturbator }; } @@ -603,8 +603,8 @@ template class ProtogalaxyProverInternal { size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified num_threads = num_threads > 0 ? num_threads : 1; // ensure num threads is >= 1 - // DEBUG: - num_threads = 1; + // // DEBUG: + // num_threads = 1; return num_threads; } From 515fe8b9cbfc4a7caa85c2219cd84c8ee733bc5a Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 19 Nov 2024 18:38:35 +0000 Subject: [PATCH 09/32] WiP virtual size increase pg test --- .../protogalaxy/protogalaxy.test.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 29f80b807f07..45ea3781beaa 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -458,6 +458,34 @@ template class ProtogalaxyTests : public testing::Test { decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); } + /** + * @brief Testing two valid rounds of folding followed by the decider for a structured trace. + * + */ + static void test_fold_with_virtual_size_expansion() + { + TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, 1 << 18 }; + + std::vector> decider_pks; + std::vector> decider_vks; + + size_t log2_num_gates = 14; + for (size_t i = 0; i < 2; ++i) { + MegaCircuitBuilder builder; + MockCircuits::add_arithmetic_gates(builder, 1 << log2_num_gates); + + auto decider_proving_key = std::make_shared(builder, trace_settings); + auto verification_key = std::make_shared(decider_proving_key->proving_key); + auto decider_verification_key = std::make_shared(verification_key); + decider_pks.push_back(decider_proving_key); + decider_vks.push_back(decider_verification_key); + log2_num_gates += 4; + } + + auto [prover_accumulator, verifier_accumulator] = fold_and_verify(decider_pks, decider_vks); + check_accumulator_target_sum_manual(prover_accumulator, true); + } + /** * @brief Testing two valid rounds of folding followed by the decider for a structured trace. * @details Here we're interested in folding inhomogeneous circuits, i.e. circuits with different numbers of @@ -612,6 +640,12 @@ TYPED_TEST(ProtogalaxyTests, FullProtogalaxyStructuredTrace) { TestFixture::test_full_protogalaxy_structured_trace(); } + +TYPED_TEST(ProtogalaxyTests, VirtualSizeExpansion) +{ + TestFixture::test_fold_with_virtual_size_expansion(); +} + TYPED_TEST(ProtogalaxyTests, FullProtogalaxyStructuredTraceInhomogeneous) { TestFixture::test_full_protogalaxy_structured_trace_inhomogeneous_circuits(); From e07eb4db6959fbe4e0e40b4b28777c5f0e89219b Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 19 Nov 2024 21:17:34 +0000 Subject: [PATCH 10/32] basic pg test passes after replacing cir size with vir size --- .../plonk_honk_shared/relation_checker.hpp | 3 ++- .../src/barretenberg/protogalaxy/protogalaxy.test.cpp | 3 ++- .../protogalaxy/protogalaxy_prover_impl.hpp | 11 +++++------ .../protogalaxy/protogalaxy_prover_internal.hpp | 3 ++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp index f876bb87f8bb..37902dbd3447 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp @@ -41,7 +41,8 @@ template class RelationChecker { element = 0; } - for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { + // for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { + for (size_t i = 0; i < polynomials.w_l.virtual_size(); i++) { if (is_linearly_independent) { // Evaluate each constraint in the relation and check that each is satisfied Relation::accumulate(result, polynomials.get_row(i), params, 1); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 45ea3781beaa..4d6d75f51f65 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -464,7 +464,8 @@ template class ProtogalaxyTests : public testing::Test { */ static void test_fold_with_virtual_size_expansion() { - TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, 1 << 18 }; + uint32_t overflow_capacity = 0; // 1 << 18 + TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, overflow_capacity }; std::vector> decider_pks; std::vector> decider_vks; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 73526cf3133f..405af0fb279d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -177,12 +177,6 @@ FoldingResult ProtogalaxyProver_proving_key.circuit_size); - // if (keys_to_fold[idx]->proving_key.circuit_size != keys_to_fold[idx + 1]->proving_key.circuit_size) { - // info("ProtogalaxyProver: circuit size mismatch!"); - // info("DeciderPK ", idx, " size = ", keys_to_fold[idx]->proving_key.circuit_size); - // info("DeciderPK ", idx + 1, " size = ", keys_to_fold[idx + 1]->proving_key.circuit_size); - // // ASSERT(false); - // } } for (size_t idx = 0; idx < DeciderProvingKeys::NUM; ++idx) { if (keys_to_fold[idx]->proving_key.circuit_size != max_circuit_size) { @@ -201,6 +195,11 @@ FoldingResult ProtogalaxyProver_::check_all(keys_to_fold[0]->proving_key.polynomials, + // keys_to_fold[0]->relation_parameters); + // RelationChecker::check_all(keys_to_fold[1]->proving_key.polynomials, + // keys_to_fold[1]->relation_parameters); + std::tie(deltas, perturbator) = perturbator_round(accumulator); vinfo("perturbator round"); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 9657bc43cc0c..51c1a557140f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -348,7 +348,8 @@ template class ProtogalaxyProverInternal { constexpr bool skip_zero_computations = std::same_as; // Determine the number of threads over which to distribute the work - const size_t common_polynomial_size = keys[0]->proving_key.circuit_size; + // const size_t common_polynomial_size = keys[0]->proving_key.circuit_size; + const size_t common_polynomial_size = keys[0]->proving_key.polynomials.w_l.virtual_size(); const size_t num_threads = compute_num_threads(common_polynomial_size); // Univariates are optimised for usual PG, but we need the unoptimised version for tests (it's a version that From 7d4ba6355e66fc1b0e94b54cc5101a9f1f4470fe Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 19 Nov 2024 23:27:35 +0000 Subject: [PATCH 11/32] correctly set circuit size in pg verifier; pg decide test passes --- .../barretenberg/client_ivc/client_ivc.test.cpp | 3 ++- .../barretenberg/protogalaxy/protogalaxy.test.cpp | 3 ++- .../protogalaxy/protogalaxy_verifier.cpp | 5 +++++ .../protogalaxy_recursive_verifier.cpp | 3 +++ .../src/barretenberg/ultra_honk/decider_keys.hpp | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) 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 98b89b89f137..d2ddb68ffc62 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -438,7 +438,8 @@ TEST_F(ClientIVCTests, DynamicOverflow) */ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) { - uint32_t overflow_capacity = 1 << 18; + uint32_t overflow_capacity = 0; + // uint32_t overflow_capacity = 1 << 18; ClientIVC ivc{ { SMALL_TEST_STRUCTURE, overflow_capacity } }; MockCircuitProducer circuit_producer; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 4d6d75f51f65..5ea67a9192a1 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -464,7 +464,7 @@ template class ProtogalaxyTests : public testing::Test { */ static void test_fold_with_virtual_size_expansion() { - uint32_t overflow_capacity = 0; // 1 << 18 + uint32_t overflow_capacity = 0; // 1 << 18; TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, overflow_capacity }; std::vector> decider_pks; @@ -485,6 +485,7 @@ template class ProtogalaxyTests : public testing::Test { auto [prover_accumulator, verifier_accumulator] = fold_and_verify(decider_pks, decider_vks); check_accumulator_target_sum_manual(prover_accumulator, true); + decide_and_verify(prover_accumulator, verifier_accumulator, true); } /** diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index b0a8a27a6e8c..d2af1668a968 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -107,6 +107,11 @@ std::shared_ptr ProtogalaxyVerifier next_accumulator->verification_key = std::make_shared(*accumulator->verification_key); next_accumulator->is_accumulator = true; + // Set the accumulator circuit size data based on the max of the keys being accumulated + size_t accumulator_log_circuit_size = keys_to_fold.get_max_log_circuit_size(); + next_accumulator->verification_key->log_circuit_size = accumulator_log_circuit_size; + next_accumulator->verification_key->circuit_size = 1 << accumulator_log_circuit_size; + // Compute next folding parameters const auto [vanishing_polynomial_at_challenge, lagranges] = compute_vanishing_polynomial_and_lagrange_evaluations(combiner_challenge); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp index 566a8d83397a..5eb913c4cfa2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp @@ -48,6 +48,9 @@ std::shared_ptr ProtogalaxyRecursiv std::shared_ptr accumulator = keys_to_fold[0]; + // WORKTODO: need to correctly set the circuit size data in the accumulator->verification_key based on the largest + // circuit size of the keys being accumulated. See native pg verifier for analog. + // Perturbator round const FF delta = transcript->template get_challenge("delta"); const std::vector deltas = compute_round_challenge_pows(CONST_PG_LOG_N, delta); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp index 49b72bbd0e29..cb546c28c19a 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp @@ -108,6 +108,20 @@ template struct DeciderVerificationKeys_ { } }; + /** + * @brief Get the max log circuit size from the set of decider verification keys + * + * @return size_t + */ + size_t get_max_log_circuit_size() const + { + size_t max_log_circuit_size{ 0 }; + for (auto key : _data) { + max_log_circuit_size = std::max(max_log_circuit_size, key->verification_key->log_circuit_size); + } + return max_log_circuit_size; + } + /** * @brief Get the precomputed commitments grouped by commitment index * @example If the commitments are grouped as in From 559bb2ed09bb968421ddf191da0792fa4874b656 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 20 Nov 2024 16:40:21 +0000 Subject: [PATCH 12/32] turn off debugging check circuit calls --- barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index c25adf0bcdf5..752e8ffe4a1e 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -180,8 +180,8 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptrproving_key.commitment_key); } - // DEBUG - ASSERT(CircuitChecker::check(circuit)); + // // DEBUG + // ASSERT(CircuitChecker::check(circuit)); vinfo("getting honk vk... precomputed?: ", precomputed_vk); // Update the accumulator trace usage based on the present circuit @@ -286,7 +286,7 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() // decider recursive verifier at the first 'round.check_sum(round_univariate, dummy_round);' in sumcheck. Suggests // that either one of the instances is not satisfying sumcheck or perhaps that theres something more fundamentally // wrong with folding an accumlator that was dynamically expanded from its original size. - ASSERT(CircuitChecker::check(builder)); + // ASSERT(CircuitChecker::check(builder)); honk_vk = std::make_shared(decider_pk->proving_key); MegaProver prover(decider_pk); From 916fc9849ac04762a8400ecfbfa5324fc0dc0d8c Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 20 Nov 2024 17:12:22 +0000 Subject: [PATCH 13/32] comments and fix build error --- .../protogalaxy/protogalaxy.test.cpp | 17 ++++++++++++----- .../protogalaxy/protogalaxy_prover_internal.hpp | 4 ++-- .../barretenberg/ultra_honk/decider_keys.hpp | 3 ++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 5ea67a9192a1..fa8675bbffb6 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -459,30 +459,37 @@ template class ProtogalaxyTests : public testing::Test { } /** - * @brief Testing two valid rounds of folding followed by the decider for a structured trace. + * @brief Testing folding a larger circuit into a smaller one by increasing the virtual size of the first. + * @details Fold two circuits using a structured trace, where the second overflows the trace such that the dyadic + * size is doubled. The virtual size of the polynomials in the first key is increased internally in the PG prover to + * match the size of the second. * */ static void test_fold_with_virtual_size_expansion() { - uint32_t overflow_capacity = 0; // 1 << 18; + uint32_t overflow_capacity = 0; TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, overflow_capacity }; std::vector> decider_pks; std::vector> decider_vks; - size_t log2_num_gates = 14; + // define parameters for two circuits; the first fits within the structured trace, the second overflows + std::vector log2_num_gates = { 14, 18 }; for (size_t i = 0; i < 2; ++i) { MegaCircuitBuilder builder; - MockCircuits::add_arithmetic_gates(builder, 1 << log2_num_gates); + MockCircuits::add_arithmetic_gates(builder, 1 << log2_num_gates[i]); auto decider_proving_key = std::make_shared(builder, trace_settings); auto verification_key = std::make_shared(decider_proving_key->proving_key); auto decider_verification_key = std::make_shared(verification_key); decider_pks.push_back(decider_proving_key); decider_vks.push_back(decider_verification_key); - log2_num_gates += 4; } + // Ensure the dyadic size of the first key is strictly less than that of the second + EXPECT_TRUE(decider_pks[0]->proving_key.circuit_size < decider_pks[1]->proving_key.circuit_size); + + // The size discrepency should be automatically handled by the PG prover via a virtual size increase auto [prover_accumulator, verifier_accumulator] = fold_and_verify(decider_pks, decider_vks); check_accumulator_target_sum_manual(prover_accumulator, true); decide_and_verify(prover_accumulator, verifier_accumulator, true); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 51c1a557140f..11b63cb68dfc 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -119,8 +119,8 @@ template class ProtogalaxyProverInternal { PROFILE_THIS_NAME("ProtogalaxyProver_::compute_row_evaluations"); - // const size_t polynomial_size = polynomials.get_polynomial_size(); - const size_t polynomial_size = polynomials.q_c.virtual_size(); // DEBUG + const size_t polynomial_size = polynomials.get_polynomial_size(); + // const size_t polynomial_size = polynomials.q_c.virtual_size(); // DEBUG: dont think we need this std::vector aggregated_relation_evaluations(polynomial_size); const std::array alphas = [&alphas_]() { diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp index cb546c28c19a..770cede82977 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_keys.hpp @@ -117,7 +117,8 @@ template struct DeciderVerificationKeys_ { { size_t max_log_circuit_size{ 0 }; for (auto key : _data) { - max_log_circuit_size = std::max(max_log_circuit_size, key->verification_key->log_circuit_size); + max_log_circuit_size = + std::max(max_log_circuit_size, static_cast(key->verification_key->log_circuit_size)); } return max_log_circuit_size; } From b23cd91ad6e6cd2c10d9145fe843962aebc33623 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 20 Nov 2024 20:04:11 +0000 Subject: [PATCH 14/32] corrctly set circuit size in pg rec verifier --- .../barretenberg/client_ivc/client_ivc.cpp | 19 +++++++++++++++---- .../library/grand_product_delta.hpp | 8 ++++++++ .../protogalaxy/protogalaxy.test.cpp | 2 +- .../protogalaxy_recursive_verifier.cpp | 8 +++++--- .../recursive_decider_verification_keys.hpp | 16 ++++++++++++++++ 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 752e8ffe4a1e..5f02a31f2030 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -217,6 +217,16 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptrverification_key->circuit_size = fold_output.accumulator->proving_key.circuit_size; + // verifier_accumulator->verification_key->log_circuit_size = + // fold_output.accumulator->proving_key.log_circuit_size; + // Add fold proof and corresponding verification key to the verification queue verification_queue.push_back(bb::ClientIVC::VerifierInputs{ fold_output.proof, honk_vk, QUEUE_TYPE::PG }); } @@ -235,6 +245,10 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() ASSERT(verification_queue.size() == 1); ASSERT(merge_verification_queue.size() == 1); // ensure only a single merge proof remains in the queue + // // DEBUG: the circuit size of prover/verifier accumulators should agree + // ASSERT(fold_output.accumulator->proving_key.circuit_size == + // verifier_accumulator->verification_key->circuit_size); + FoldProof& fold_proof = verification_queue[0].proof; HonkProof decider_proof = decider_prove(); @@ -282,10 +296,7 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() merge_verification_queue.emplace_back(merge_proof); auto decider_pk = std::make_shared(builder); - // WORKTODO: This fails in the dyanmic accum expansion case. investigation of this failure suggests failure in the - // decider recursive verifier at the first 'round.check_sum(round_univariate, dummy_round);' in sumcheck. Suggests - // that either one of the instances is not satisfying sumcheck or perhaps that theres something more fundamentally - // wrong with folding an accumlator that was dynamically expanded from its original size. + // WORKTODO: This fails in the dynamic accum expansion case // ASSERT(CircuitChecker::check(builder)); honk_vk = std::make_shared(decider_pk->proving_key); MegaProver prover(decider_pk); diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp index b967dc0e93a9..cafcedab737b 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp @@ -48,6 +48,14 @@ typename Flavor::FF compute_public_input_delta(std::span class ProtogalaxyTests : public testing::Test { */ static void test_fold_with_virtual_size_expansion() { - uint32_t overflow_capacity = 0; + uint32_t overflow_capacity = 0; // consider the case where the overflow is not known until runtime TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, overflow_capacity }; std::vector> decider_pks; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp index 5eb913c4cfa2..2dd01739c42d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp @@ -48,9 +48,6 @@ std::shared_ptr ProtogalaxyRecursiv std::shared_ptr accumulator = keys_to_fold[0]; - // WORKTODO: need to correctly set the circuit size data in the accumulator->verification_key based on the largest - // circuit size of the keys being accumulated. See native pg verifier for analog. - // Perturbator round const FF delta = transcript->template get_challenge("delta"); const std::vector deltas = compute_round_challenge_pows(CONST_PG_LOG_N, delta); @@ -172,6 +169,11 @@ std::shared_ptr ProtogalaxyRecursiv perturbator_evaluation * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient_at_challenge; accumulator->gate_challenges = update_gate_challenges(perturbator_challenge, accumulator->gate_challenges, deltas); + // Set the accumulator circuit size data based on the max of the keys being accumulated + size_t accumulator_log_circuit_size = keys_to_fold.get_max_log_circuit_size(); + accumulator->verification_key->log_circuit_size = accumulator_log_circuit_size; + accumulator->verification_key->circuit_size = 1 << accumulator_log_circuit_size; + // Fold the relation parameters for (auto [combination, to_combine] : zip_view(accumulator->alphas, keys_to_fold.get_alphas())) { combination = linear_combination(to_combine, lagranges); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp index 6e75211df15f..9a2361b7a9bf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_keys.hpp @@ -35,6 +35,22 @@ template struct RecursiveDeciderVerific idx++; } } + + /** + * @brief Get the max log circuit size from the set of decider verification keys + * + * @return size_t + */ + size_t get_max_log_circuit_size() const + { + size_t max_log_circuit_size{ 0 }; + for (auto key : _data) { + max_log_circuit_size = + std::max(max_log_circuit_size, static_cast(key->verification_key->log_circuit_size)); + } + return max_log_circuit_size; + } + /** * @brief Get the precomputed commitments grouped by commitment index * @example If the commitments are grouped as in From 864ee3a14e3ca58dac3381d1e86fd4753466584c Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 20 Nov 2024 20:31:58 +0000 Subject: [PATCH 15/32] comments and cleanup --- .../client_ivc/client_ivc.test.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) 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 d2ddb68ffc62..26a59b056a56 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -408,7 +408,9 @@ TEST_F(ClientIVCTests, StructuredTraceOverflow) /** * @brief Test dynamic structured trace overflow block mechanism - * @details + * @details Tests the case where the required overflow capacity is not known until runtime. Accumulates two circuits, + * the second of which overflows the trace but not enough to change the dyadic circuit size and thus there is no need + * for a virtual size increase of the first key. * */ TEST_F(ClientIVCTests, DynamicOverflow) @@ -420,12 +422,12 @@ TEST_F(ClientIVCTests, DynamicOverflow) size_t NUM_CIRCUITS = 2; - // Construct and accumulate some circuits of varying size - size_t log2_num_gates = 14; + // define parameters for two circuits; the first fits within the structured trace, the second overflows + std::vector log2_num_arith_gates = { 14, 16 }; + // Accumulate for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { - auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_gates); + auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_arith_gates[idx]); ivc.accumulate(circuit); - log2_num_gates += 2; } EXPECT_TRUE(ivc.prove_and_verify()); @@ -433,7 +435,9 @@ TEST_F(ClientIVCTests, DynamicOverflow) /** * @brief Test dynamic trace overflow where the dyadic circuit size also increases - * @details + * @details Accumulates two circuits, the second of which overflows the trace structure and leads to an increased dyadic + * circuit size. This requires the virtual size of the polynomials in the first key to be increased accordingly which + * should be handled automatically in PG/ClientIvc. * */ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) @@ -446,12 +450,12 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) size_t NUM_CIRCUITS = 2; - // Construct and accumulate some circuits of varying size - size_t log2_num_gates = 14; + // define parameters for two circuits; the first fits within the structured trace, the second overflows + std::vector log2_num_arith_gates = { 14, 18 }; + // Accumulate for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { - auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_gates); + auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_arith_gates[idx]); ivc.accumulate(circuit); - log2_num_gates += 4; } EXPECT_TRUE(ivc.prove_and_verify()); From bfb2a7016a41fbba8246fca60a56002c0390c379 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 20 Nov 2024 21:52:18 +0000 Subject: [PATCH 16/32] add some debug utility in ivc tests --- .../client_ivc/client_ivc.test.cpp | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) 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 26a59b056a56..f335a91bdace 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -31,6 +31,41 @@ class ClientIVCTests : public ::testing::Test { using DeciderVerificationKeys = DeciderVerificationKeys_; using FoldingVerifier = ProtogalaxyVerifier_; + // WORKTODO: duplicate of similar logic in pg test suite; put in some more central location for use by all modules + static void check_accumulator_target_sum_consistency(const std::shared_ptr& accumulator) + { + ProtogalaxyProverInternal pg_internal; + auto expected_honk_evals = pg_internal.compute_row_evaluations( + accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); + // Construct pow(\vec{betas*}) as in the paper + GateSeparatorPolynomial expected_gate_separators(accumulator->gate_challenges, + accumulator->gate_challenges.size()); + + // Compute the corresponding target sum and create a dummy accumulator + FF expected_target_sum{ 0 }; + for (size_t idx = 0; idx < accumulator->proving_key.circuit_size; idx++) { + expected_target_sum += expected_honk_evals[idx] * expected_gate_separators[idx]; + } + EXPECT_TRUE(accumulator->target_sum == expected_target_sum); + } + + // WORKTODO: similar to above, this doesnt really belong here + static void fold_verify_then_decider_prove_and_verify(const ClientIVC& ivc) + { + const auto& queue_entry = ivc.verification_queue.back(); + const auto& fold_proof = queue_entry.proof; + auto key_to_fold = std::make_shared(queue_entry.honk_verification_key); + const auto& prover_accumulator = ivc.fold_output.accumulator; + + ClientIVC::FoldingVerifier folding_verifier({ ivc.verifier_accumulator, key_to_fold }); + auto verifier_accumulator = folding_verifier.verify_folding_proof(fold_proof); + + DeciderProver decider_prover(prover_accumulator); + DeciderVerifier decider_verifier(verifier_accumulator); + HonkProof decider_proof = decider_prover.construct_proof(); + EXPECT_TRUE(decider_verifier.verify_proof(decider_proof)); + } + /** * @brief Construct mock circuit with arithmetic gates and goblin ops * @details Defaulted to add 2^16 gates (which will bump to next power of two with the addition of dummy gates). @@ -430,6 +465,12 @@ TEST_F(ClientIVCTests, DynamicOverflow) ivc.accumulate(circuit); } + // DEBUG: check consistency of the target sum computed internal to ivc + check_accumulator_target_sum_consistency(ivc.fold_output.accumulator); + + // DEBUG: run native pg verifier then native decider prover/verifier + fold_verify_then_decider_prove_and_verify(ivc); + EXPECT_TRUE(ivc.prove_and_verify()); }; @@ -458,5 +499,11 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) ivc.accumulate(circuit); } - EXPECT_TRUE(ivc.prove_and_verify()); + // DEBUG: check consistency of the target sum computed internal to ivc + check_accumulator_target_sum_consistency(ivc.fold_output.accumulator); + + // DEBUG: run native pg verifier then native decider prover/verifier + fold_verify_then_decider_prove_and_verify(ivc); + + // EXPECT_TRUE(ivc.prove_and_verify()); }; \ No newline at end of file From 2494af1a7bf422de2f19f656058cfb0ccc0ffe72 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 20 Nov 2024 22:59:52 +0000 Subject: [PATCH 17/32] debug stuff --- .../src/barretenberg/client_ivc/client_ivc.test.cpp | 2 +- .../protogalaxy/protogalaxy_prover_impl.hpp | 11 +++++++---- .../protogalaxy/protogalaxy_prover_internal.hpp | 8 +++++++- 3 files changed, 15 insertions(+), 6 deletions(-) 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 f335a91bdace..af26bba6c472 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -503,7 +503,7 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) check_accumulator_target_sum_consistency(ivc.fold_output.accumulator); // DEBUG: run native pg verifier then native decider prover/verifier - fold_verify_then_decider_prove_and_verify(ivc); + // fold_verify_then_decider_prove_and_verify(ivc); // EXPECT_TRUE(ivc.prove_and_verify()); }; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 405af0fb279d..4d8e365e7b1a 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -131,12 +131,15 @@ FoldingResult ProtogalaxyProver_overflow_size > result.accumulator->overflow_size) { - ASSERT(DeciderProvingKeys::NUM == 2); // this mechanism is not supported for the folding of multiple keys + ASSERT(DeciderProvingKeys::NUM == 2); // this mechanism is not supported for the folding of multiple keys + // DEBUG: At this point the virtual sizes of the polynomials should already agree + ASSERT(result.accumulator->proving_key.polynomials.w_l.virtual_size() == + keys[1]->proving_key.polynomials.w_l.virtual_size()); + std::swap(result.accumulator->proving_key.polynomials, keys[1]->proving_key.polynomials); // swap the polys std::swap(lagranges[0], lagranges[1]); // swap the lagrange coefficients so the sum is unchanged - std::swap(result.accumulator->proving_key.polynomials, keys[1]->proving_key.polynomials); // swap the polys std::swap(result.accumulator->proving_key.circuit_size, keys[1]->proving_key.circuit_size); // swap circuit size std::swap(result.accumulator->proving_key.log_circuit_size, keys[1]->proving_key.log_circuit_size); } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 11b63cb68dfc..4fb8ec582230 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -119,6 +119,10 @@ template class ProtogalaxyProverInternal { PROFILE_THIS_NAME("ProtogalaxyProver_::compute_row_evaluations"); + // DEBUG: at this point the size() of the polynomials may be less than the virtual_size() but we don't need to + // use virtual size because this calculation uses the accumulator computed on the previous round whose polys are + // zero everywhere in the expanded portion of the domain. This is not the case for the combiner because that + // calculation includes the incoming key which has ontrivial values on the larger domain. const size_t polynomial_size = polynomials.get_polynomial_size(); // const size_t polynomial_size = polynomials.q_c.virtual_size(); // DEBUG: dont think we need this std::vector aggregated_relation_evaluations(polynomial_size); @@ -348,7 +352,9 @@ template class ProtogalaxyProverInternal { constexpr bool skip_zero_computations = std::same_as; // Determine the number of threads over which to distribute the work - // const size_t common_polynomial_size = keys[0]->proving_key.circuit_size; + // WORKTODO: here we need the virtual size (as opposed to size()/circuit_size) since the computation includes + // the incoming key which has nontrivial values on the larger domain. const size_t common_polynomial_size = + // keys[0]->proving_key.circuit_size; const size_t common_polynomial_size = keys[0]->proving_key.polynomials.w_l.virtual_size(); const size_t num_threads = compute_num_threads(common_polynomial_size); From 531c0d1e1d70d0975e183a09e9c0500031a5fad8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 20 Nov 2024 23:13:46 +0000 Subject: [PATCH 18/32] comments --- .../cpp/src/barretenberg/client_ivc/client_ivc.cpp | 14 -------------- .../src/barretenberg/ultra_honk/mega_honk.test.cpp | 12 ++++++++++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 5f02a31f2030..6ab85dcfa453 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -217,16 +217,6 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptrverification_key->circuit_size = fold_output.accumulator->proving_key.circuit_size; - // verifier_accumulator->verification_key->log_circuit_size = - // fold_output.accumulator->proving_key.log_circuit_size; - // Add fold proof and corresponding verification key to the verification queue verification_queue.push_back(bb::ClientIVC::VerifierInputs{ fold_output.proof, honk_vk, QUEUE_TYPE::PG }); } @@ -245,10 +235,6 @@ HonkProof ClientIVC::construct_and_prove_hiding_circuit() ASSERT(verification_queue.size() == 1); ASSERT(merge_verification_queue.size() == 1); // ensure only a single merge proof remains in the queue - // // DEBUG: the circuit size of prover/verifier accumulators should agree - // ASSERT(fold_output.accumulator->proving_key.circuit_size == - // verifier_accumulator->verification_key->circuit_size); - FoldProof& fold_proof = verification_queue[0].proof; HonkProof decider_proof = decider_prove(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp index 6bd5953e1cca..855c2459ca1c 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp @@ -130,7 +130,8 @@ TYPED_TEST(MegaHonkTests, BasicStructured) } /** - * @brief Test proof construction/verification for a structured execution trace + * @brief Test that increasing the virtual size of a valid set of prover polynomials still results in a valid Megahonk + * proof * */ TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) @@ -152,7 +153,7 @@ TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) auto doubled_circuit_size = 2 * circuit_size; proving_key_copy->proving_key.polynomials.increase_polynomials_virtual_size(doubled_circuit_size); - // WARNING: updating circuit_size here would public input delta perm argument! + // WARNING: updating circuit_size here would break public input delta perm argument! // proving_key_copy->proving_key.circuit_size = doubled_circuit_size; Prover prover(proving_key); @@ -365,6 +366,13 @@ TYPED_TEST(MegaHonkTests, StructuredTraceOverflow) } } +/** + * @brief A sanity check that a simple std::swap on a ProverPolynomials object works as expected + * @details Constuct two valid proving keys. Tamper with the prover_polynomials of one key then swap the + * prover_polynomials of the two keys. The key who received the tampered polys leads to a failed verification while the + * other succeeds. + * + */ TYPED_TEST(MegaHonkTests, PolySwap) { using Flavor = TypeParam; From 0b582ebd4c57cca23257fbc4a572bf204f32e527 Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 13:01:55 +0000 Subject: [PATCH 19/32] loads of cleanup and execution trace tracker needs fixing --- .../barretenberg/client_ivc/client_ivc.cpp | 16 ++-- .../client_ivc/client_ivc.test.cpp | 8 +- .../proof_system/logderivative_library.hpp | 4 +- .../protogalaxy/protogalaxy.test.cpp | 3 + .../protogalaxy/protogalaxy_prover_impl.hpp | 4 +- .../protogalaxy_prover_internal.hpp | 96 ++++++++++--------- .../relations/logderiv_lookup_relation.hpp | 5 +- .../stdlib_circuit_builders/mega_flavor.hpp | 4 +- .../stdlib_circuit_builders/mock_circuits.hpp | 2 +- .../stdlib_circuit_builders/ultra_flavor.hpp | 1 + .../ultra_honk/decider_proving_key.hpp | 8 +- .../barretenberg/ultra_honk/oink_prover.cpp | 1 + 12 files changed, 92 insertions(+), 60 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 6ab85dcfa453..a6e5360e55aa 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -162,7 +162,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr proving_key; if (!initialized) { proving_key = std::make_shared(circuit, trace_settings); - trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); + // trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); } else { proving_key = std::make_shared( circuit, trace_settings, fold_output.accumulator->proving_key.commitment_key); @@ -185,7 +185,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(proving_key->proving_key); @@ -197,10 +197,11 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr oink_prover{ proving_key }; - vinfo("computing oink proof..."); + info("computing oink proof..."); oink_prover.prove(); - vinfo("oink proof constructed"); + info("oink proof constructed"); proving_key->is_accumulator = true; // indicate to PG that it should not run oink on this key + proving_key->target_sum = 0; // Initialize the gate challenges to zero for use in first round of folding proving_key->gate_challenges = std::vector(CONST_PG_LOG_N, 0); @@ -212,10 +213,11 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr& accumulator) + { + info("in check accumulator target sum consistency, size: ", accumulator->proving_key.circuit_size); ProtogalaxyProverInternal pg_internal; auto expected_honk_evals = pg_internal.compute_row_evaluations( accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); @@ -46,6 +48,8 @@ class ClientIVCTests : public ::testing::Test { for (size_t idx = 0; idx < accumulator->proving_key.circuit_size; idx++) { expected_target_sum += expected_honk_evals[idx] * expected_gate_separators[idx]; } + info("expected target sum: ", expected_target_sum); + info("acc target sum: ", accumulator->target_sum); EXPECT_TRUE(accumulator->target_sum == expected_target_sum); } @@ -484,7 +488,7 @@ TEST_F(ClientIVCTests, DynamicOverflow) TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) { uint32_t overflow_capacity = 0; - // uint32_t overflow_capacity = 1 << 18; + // uint32_t overflow_capacity = 1 << 1; ClientIVC ivc{ { SMALL_TEST_STRUCTURE, overflow_capacity } }; MockCircuitProducer circuit_producer; @@ -499,8 +503,8 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) ivc.accumulate(circuit); } - // DEBUG: check consistency of the target sum computed internal to ivc check_accumulator_target_sum_consistency(ivc.fold_output.accumulator); + // DEBUG: check consistency of the target sum computed internal to ivc // DEBUG: run native pg verifier then native decider prover/verifier // fold_verify_then_decider_prove_and_verify(ivc); diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp index 940c88c8c6d4..009fd6eb7f64 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp @@ -29,7 +29,8 @@ void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_para using Accumulator = typename Relation::ValueAccumulator0; constexpr size_t READ_TERMS = Relation::READ_TERMS; constexpr size_t WRITE_TERMS = Relation::WRITE_TERMS; - + info("in logderivative inverse"); + static_cast(circuit_size); auto& inverse_polynomial = Relation::template get_inverse_polynomial(polynomials); for (size_t i = 0; i < circuit_size; ++i) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. @@ -38,6 +39,7 @@ void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_para if (!has_inverse) { continue; } + info(i); FF denominator = 1; bb::constexpr_for<0, READ_TERMS, 1>([&] { auto denominator_term = diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 7ac6d7be8d59..b3cd4e114b78 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -93,6 +93,8 @@ template class ProtogalaxyTests : public testing::Test { static void check_accumulator_target_sum_manual(std::shared_ptr& accumulator, bool expected_result) { + + info("in the test"); size_t accumulator_size = accumulator->proving_key.circuit_size; PGInternal pg_internal; auto expected_honk_evals = pg_internal.compute_row_evaluations( @@ -477,6 +479,7 @@ template class ProtogalaxyTests : public testing::Test { std::vector log2_num_gates = { 14, 18 }; for (size_t i = 0; i < 2; ++i) { MegaCircuitBuilder builder; + MockCircuits::add_arithmetic_gates(builder, 1 << log2_num_gates[i]); auto decider_proving_key = std::make_shared(builder, trace_settings); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 4d8e365e7b1a..0cefc4568696 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -14,7 +14,7 @@ void ProtogalaxyProver_::run_oink_prover_on_one_incomplete_k { PROFILE_THIS_NAME("ProtogalaxyProver::run_oink_prover_on_one_incomplete_key"); - + info("oinking from PG"); OinkProver oink_prover(keys, transcript, domain_separator + '_'); oink_prover.prove(); } @@ -31,6 +31,7 @@ void ProtogalaxyProver_::run_oink_prover_on_each_incomplete_ run_oink_prover_on_one_incomplete_key(key, domain_separator); key->target_sum = 0; key->gate_challenges = std::vector(CONST_PG_LOG_N, 0); + key->is_accumulator = true; } idx++; @@ -62,6 +63,7 @@ ProtogalaxyProver_::perturbator_round( // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is // different for (size_t idx = 1; idx <= CONST_PG_LOG_N; idx++) { + // info("Perturbator at ", idx, " ", perturbator transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 4fb8ec582230..85fa4baeb48f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -77,7 +77,8 @@ template class ProtogalaxyProverInternal { */ inline static FF process_subrelation_evaluations(const RelationEvaluations& evals, const std::array& challenges, - FF& linearly_dependent_contribution) + FF& linearly_dependent_contribution, + size_t row = 0) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/1115): Iniitalize with first subrelation value to // avoid Montgomery allocating 0 and doing a mul. This is about 60ns per row. @@ -92,6 +93,9 @@ template class ProtogalaxyProverInternal { linearly_independent_contribution += contribution; } else { linearly_dependent_contribution += contribution; + if (contribution != 0) { + info("contribution: ", contribution, " at row: ", row); + } } idx++; }; @@ -124,6 +128,7 @@ template class ProtogalaxyProverInternal { // zero everywhere in the expanded portion of the domain. This is not the case for the combiner because that // calculation includes the incoming key which has ontrivial values on the larger domain. const size_t polynomial_size = polynomials.get_polynomial_size(); + info(polynomial_size); // const size_t polynomial_size = polynomials.q_c.virtual_size(); // DEBUG: dont think we need this std::vector aggregated_relation_evaluations(polynomial_size); @@ -135,33 +140,36 @@ template class ProtogalaxyProverInternal { }(); // Determine the number of threads over which to distribute the work - const size_t num_threads = compute_num_threads(polynomial_size); - - std::vector linearly_dependent_contribution_accumulators(num_threads); - - // Distribute the execution trace rows across threads so that each handles an equal number of active rows - trace_usage_tracker.construct_thread_ranges(num_threads, polynomial_size, /*use_prev_accumulator=*/true); - - parallel_for(num_threads, [&](size_t thread_idx) { - const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; - const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; - - for (size_t idx = start; idx < end; idx++) { - // The contribution is only non-trivial at a given row if the accumulator is active at that row - if (trace_usage_tracker.check_is_active(idx, /*use_prev_accumulator=*/true)) { - const AllValues row = polynomials.get_row(idx); - // Evaluate all subrelations on given row. Separator is 1 since we are not summing across rows here. - const RelationEvaluations evals = - RelationUtils::accumulate_relation_evaluations(row, relation_parameters, FF(1)); - - // Sum against challenges alpha - aggregated_relation_evaluations[idx] = process_subrelation_evaluations( - evals, alphas, linearly_dependent_contribution_accumulators[thread_idx]); - } - } - }); + // const size_t num_threads = compute_num_threads(polynomial_size); + + // std::vector linearly_dependent_contribution_accumulators(num_threads); + + // // Distribute the execution trace rows across threads so that each handles an equal number of active rows + // trace_usage_tracker.construct_thread_ranges(num_threads, polynomial_size, /*use_prev_accumulator=*/true); + FF linearly_dependent_contribution{ 0 }; + + // parallel_for(num_threads, [&](size_t thread_idx) { + // const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; + // const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; + + for (size_t idx = 0; idx < polynomial_size; idx++) { + // The contribution is only non-trivial at a given row if the accumulator is active at that row + // if (trace_usage_tracker.check_is_active(idx, /*use_prev_accumulator=*/true)) { + const AllValues row = polynomials.get_row(idx); + // Evaluate all subrelations on given row. Separator is 1 since we are not summing across rows here. + const RelationEvaluations evals = + RelationUtils::accumulate_relation_evaluations(row, relation_parameters, FF(1)); + + // Sum against challenges alpha + aggregated_relation_evaluations[idx] = process_subrelation_evaluations( + evals, alphas, linearly_dependent_contribution /*_accumulators[thread_idx]*/, idx); + // } + } + // }); - aggregated_relation_evaluations[0] += sum(linearly_dependent_contribution_accumulators); + info("linearly dependent contribution: ", linearly_dependent_contribution); + aggregated_relation_evaluations[0] += + linearly_dependent_contribution; // sum(linearly_dependent_contribution_accumulators); return aggregated_relation_evaluations; } @@ -384,23 +392,23 @@ template class ProtogalaxyProverInternal { const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; for (size_t idx = start; idx < end; idx++) { - if (trace_usage_tracker.check_is_active(idx)) { - // Instantiate univariates, possibly with skipping toto ignore computation in those indices (they - // are still available for skipping relations, but all derived univariate will ignore those - // evaluations) No need to initialise extended_univariates to 0, as it's assigned to. - constexpr size_t skip_count = skip_zero_computations ? DeciderPKs::NUM - 1 : 0; - extend_univariates(extended_univariates[thread_idx], keys, idx); - - const FF pow_challenge = gate_separators[idx]; - - // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to - // this function have already been folded. Moreover, linear-dependent relations that act over the - // entire execution trace rather than on rows, will not be multiplied by the pow challenge. - accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], - extended_univariates[thread_idx], - relation_parameters, // these parameters have already been folded - pow_challenge); - } + // if (trace_usage_tracker.check_is_active(idx)) { + // Instantiate univariates, possibly with skipping toto ignore computation in those indices (they + // are still available for skipping relations, but all derived univariate will ignore those + // evaluations) No need to initialise extended_univariates to 0, as it's assigned to. + constexpr size_t skip_count = skip_zero_computations ? DeciderPKs::NUM - 1 : 0; + extend_univariates(extended_univariates[thread_idx], keys, idx); + + const FF pow_challenge = gate_separators[idx]; + + // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to + // this function have already been folded. Moreover, linear-dependent relations that act over the + // entire execution trace rather than on rows, will not be multiplied by the pow challenge. + accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], + extended_univariates[thread_idx], + relation_parameters, // these parameters have already been folded + pow_challenge); + // } } }); diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index afd1326a91da..6fa1665cb374 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -156,10 +156,12 @@ template class LogDerivLookupRelationImpl { const size_t circuit_size) { auto& inverse_polynomial = get_inverse_polynomial(polynomials); - + info("HEREEEE"); + info("in log derivative"); for (size_t i = 0; i < circuit_size; ++i) { // We only compute the inverse if this row contains a lookup gate or data that has been looked up if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { + info("rows at which we deal with log derivative: ", i); // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! auto value = compute_read_term(row, relation_parameters) * @@ -169,6 +171,7 @@ template class LogDerivLookupRelationImpl { } // Compute inverse polynomial I in place by inverting the product at each row FF::batch_invert(inverse_polynomial.coeffs()); + info(inverse_polynomial.size()); }; /** diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 005db228440f..d24d35115d30 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -78,7 +78,7 @@ class MegaFlavor { static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); - static_assert(MAX_TOTAL_RELATION_LENGTH == 11); + // static_assert(MAX_TOTAL_RELATION_LENGTH == 11); // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation // length = 3 @@ -1043,4 +1043,4 @@ class MegaFlavor { using Transcript = Transcript_; }; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp index 070046f3f150..0b2e3a206a40 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp @@ -148,7 +148,7 @@ class MockCircuits { // TODO(https://github.com/AztecProtocol/barretenberg/issues/902) static constexpr size_t OFFSET_HACK = 10; - // to prevent underflow of the loop upper limit; target size >= 16 should suffice + // // to prevent underflow of the loop upper limit; target size >= 16 should suffice ASSERT(target_dyadic_size > OFFSET_HACK + num_preamble_gates); size_t num_gates_to_add = target_dyadic_size - OFFSET_HACK - 1 - num_preamble_gates; 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 d19d9ffa826a..e4b42e26c3b1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -411,6 +411,7 @@ class UltraFlavor { */ void compute_logderivative_inverses(const RelationParameters& relation_parameters) { + info("about to compute logderivative inverse"); // Compute inverses for conventional lookups compute_logderivative_inverse>( this->polynomials, relation_parameters, this->circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp index 27250d7174ba..5ffa20fa1fdf 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp @@ -104,6 +104,7 @@ template class DeciderProvingKey_ { proving_key = ProvingKey(dyadic_circuit_size, circuit.public_inputs.size(), commitment_key); // If not using structured trace OR if using structured trace but overflow has occurred (overflow block in // use), allocate full size polys + // is_structured = false; if ((IsMegaFlavor && !is_structured) || (is_structured && circuit.blocks.has_overflow)) { // Allocate full size polynomials proving_key.polynomials = typename Flavor::ProverPolynomials(dyadic_circuit_size); @@ -212,6 +213,7 @@ template class DeciderProvingKey_ { typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset); proving_key.polynomials.lookup_read_tags = typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset); + info("lookup_read_tags size: ", max_tables_size, " table_offsets: ", table_offset); } { ZoneScopedN("allocating lookup and databus inverses"); @@ -229,6 +231,10 @@ template class DeciderProvingKey_ { table_offset + MAX_LOOKUP_TABLES_SIZE)); proving_key.polynomials.lookup_inverses = Polynomial( lookup_inverses_end - lookup_inverses_start, dyadic_circuit_size, lookup_inverses_start); + info("lookup_inverses start: ", + lookup_inverses_start, + " actual size", + lookup_inverses_end - lookup_inverses_start); if constexpr (HasDataBus) { const size_t q_busread_end = circuit.blocks.busread.trace_offset + circuit.blocks.busread.get_fixed_size(is_structured); @@ -257,7 +263,7 @@ template class DeciderProvingKey_ { proving_key.polynomials.lagrange_first = Polynomial( /* size=*/1, /*virtual size=*/dyadic_circuit_size, /*start_idx=*/0); - // Even though lagrange_last has a singe non-zero element, we cannot set its size to 0 as different + // Even though lagrange_last has a single non-zero element, we cannot set its size to 0 as different // keys being folded might have lagrange_last set at different indexes and folding does not work // correctly unless the polynomial is allocated in the correct range to accomodate this proving_key.polynomials.lagrange_last = Polynomial( diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index cbea1470ab5e..f2b30f52a1b9 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -14,6 +14,7 @@ namespace bb { template void OinkProver::prove() { if (proving_key->proving_key.commitment_key == nullptr) { + info("initialising proving_key with circuit size: ", proving_key->proving_key.circuit_size); proving_key->proving_key.commitment_key = std::make_shared(proving_key->proving_key.circuit_size); } From d781974b2dbef5872942affd95c6046c8e018309 Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 16:07:56 +0000 Subject: [PATCH 20/32] fixed --- .../barretenberg/client_ivc/client_ivc.cpp | 17 ++- .../client_ivc/client_ivc.test.cpp | 6 +- .../ivc_recursion_constraint.test.cpp | 2 +- .../proof_system/logderivative_library.hpp | 2 - .../execution_trace_usage_tracker.hpp | 33 ++++- .../execution_trace/mega_execution_trace.hpp | 17 ++- .../protogalaxy/protogalaxy.test.cpp | 23 +++- .../protogalaxy/protogalaxy_prover_impl.hpp | 11 +- .../protogalaxy_prover_internal.hpp | 115 ++++++++---------- .../relations/logderiv_lookup_relation.hpp | 4 - .../stdlib_circuit_builders/ultra_flavor.hpp | 1 - .../ultra_honk/decider_proving_key.hpp | 5 - 12 files changed, 123 insertions(+), 113 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index a6e5360e55aa..55634be627a8 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -174,18 +174,17 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr proving_key; if (!initialized) { proving_key = std::make_shared(circuit, trace_settings); - // trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); + trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); } else { proving_key = std::make_shared( circuit, trace_settings, fold_output.accumulator->proving_key.commitment_key); } - // // DEBUG - // ASSERT(CircuitChecker::check(circuit)); + ASSERT(CircuitChecker::check(circuit)); vinfo("getting honk vk... precomputed?: ", precomputed_vk); // Update the accumulator trace usage based on the present circuit - // trace_usage_tracker.update(circuit); + trace_usage_tracker.update(circuit); // Set the verification key from precomputed if available, else compute it honk_vk = precomputed_vk ? precomputed_vk : std::make_shared(proving_key->proving_key); @@ -197,11 +196,10 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr oink_prover{ proving_key }; - info("computing oink proof..."); + vinfo("computing oink proof..."); oink_prover.prove(); - info("oink proof constructed"); + vinfo("oink proof constructed"); proving_key->is_accumulator = true; // indicate to PG that it should not run oink on this key - proving_key->target_sum = 0; // Initialize the gate challenges to zero for use in first round of folding proving_key->gate_challenges = std::vector(CONST_PG_LOG_N, 0); @@ -213,9 +211,8 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(builder); // WORKTODO: This fails in the dynamic accum expansion case - // ASSERT(CircuitChecker::check(builder)); + ASSERT(CircuitChecker::check(builder)); honk_vk = std::make_shared(decider_pk->proving_key); MegaProver prover(decider_pk); 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 36178c6d0559..7f586f33d45d 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -496,7 +496,7 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) size_t NUM_CIRCUITS = 2; // define parameters for two circuits; the first fits within the structured trace, the second overflows - std::vector log2_num_arith_gates = { 14, 18 }; + std::vector log2_num_arith_gates = { 14, 18, 16 }; // Accumulate for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_arith_gates[idx]); @@ -507,7 +507,7 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) // DEBUG: check consistency of the target sum computed internal to ivc // DEBUG: run native pg verifier then native decider prover/verifier - // fold_verify_then_decider_prove_and_verify(ivc); + fold_verify_then_decider_prove_and_verify(ivc); - // EXPECT_TRUE(ivc.prove_and_verify()); + EXPECT_TRUE(ivc.prove_and_verify()); }; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp index 94ada7d9950c..e41186a4ccf5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp @@ -213,7 +213,7 @@ TEST_F(IvcRecursionConstraintTest, GenerateVK) // Construct kernel consisting only of the kernel completion logic AcirProgram program = construct_mock_kernel_program(ivc.verification_queue, { num_app_public_inputs }); Builder kernel = acir_format::create_kernel_circuit(program.constraints, ivc); - // WORKTODO: this would normally happen in accumulate() + // Mimic what would normally happen in accumulate() kernel.add_pairing_point_accumulator(stdlib::recursion::init_default_agg_obj_indices(kernel)); auto proving_key = std::make_shared>(kernel, trace_settings); diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp index 009fd6eb7f64..b4426e0e9517 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp @@ -29,7 +29,6 @@ void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_para using Accumulator = typename Relation::ValueAccumulator0; constexpr size_t READ_TERMS = Relation::READ_TERMS; constexpr size_t WRITE_TERMS = Relation::WRITE_TERMS; - info("in logderivative inverse"); static_cast(circuit_size); auto& inverse_polynomial = Relation::template get_inverse_polynomial(polynomials); for (size_t i = 0; i < circuit_size; ++i) { @@ -39,7 +38,6 @@ void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_para if (!has_inverse) { continue; } - info(i); FF denominator = 1; bb::constexpr_for<0, READ_TERMS, 1>([&] { auto denominator_term = diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp index 7b9b1fadb6bc..5ee40713ab0a 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp @@ -18,8 +18,9 @@ struct ExecutionTraceUsageTracker { using MegaTraceActiveRanges = MegaTraceBlockData; using MegaTraceFixedBlockSizes = MegaExecutionTraceBlocks; - TraceStructure max_sizes; // max utilization of each block - MegaTraceFixedBlockSizes fixed_sizes; // fixed size of each block prescribed by structuring + TraceStructure max_sizes; // max utilization of each block + // Fixed size of each block prescribed by strucuring and the highest size of an overflow block encountered + MegaTraceFixedBlockSizes fixed_sizes; // Store active ranges based on the most current accumulator and those based on all but the most recently // accumulated circuit. The former is needed for the combiner calculation and the latter for the perturbator. std::vector active_ranges; @@ -48,7 +49,7 @@ struct ExecutionTraceUsageTracker { } // Update the max block utilization and active trace ranges based on the data from a provided circuit - void update(const Builder& circuit) + void update(Builder& circuit) { // Update the max utilization of each gate block for (auto [block, max_size] : zip_view(circuit.blocks.get(), max_sizes.get())) { @@ -72,8 +73,11 @@ struct ExecutionTraceUsageTracker { } // The active ranges must also include the rows where the actual databus and lookup table data are stored. - // (Note: lookup tables are constructed at the end of the trace; databus data is constructed at the start). - size_t dyadic_circuit_size = fixed_sizes.get_structured_dyadic_size(); + // (Note: lookup tables are constructed at the end of the trace; databus data is constructed at the start) so we + // need to determine the dyadic size for this. We call the size function on the current circuit which will have + // the same fixed block sizes but might also have an overflow block potentially influencing the dyadic circuit + // size. + size_t dyadic_circuit_size = circuit.blocks.get_structured_dyadic_size(); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1152): should be able to use simply Range{ 0, // max_databus_size } but this breaks for certain choices of num_threads. @@ -111,6 +115,13 @@ struct ExecutionTraceUsageTracker { "lookup", "overflow" }; + std::vector active_ranges_labels = [this] { + std::vector result = block_labels; + result.push_back("databus table data"); + result.push_back("lookup table data"); + return result; + }(); + void print() { info("Minimum required block sizes for structured trace: "); @@ -123,7 +134,17 @@ struct ExecutionTraceUsageTracker { void print_active_ranges() { info("Active regions of accumulator: "); - for (auto [label, range] : zip_view(block_labels, active_ranges)) { + for (auto [label, range] : zip_view(active_ranges_labels, active_ranges)) { + std::cout << std::left << std::setw(20) << (label + ":") << "(" << range.first << ", " << range.second + << ")" << std::endl; + } + info(""); + } + + void print_previous_active_ranges() + { + info("Active regions of previous accumulator: "); + for (auto [label, range] : zip_view(active_ranges_labels, previous_active_ranges)) { std::cout << std::left << std::setw(20) << (label + ":") << "(" << range.first << ", " << range.second << ")" << std::endl; } diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp index a30a879142b8..4f0232d97356 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp @@ -30,10 +30,17 @@ template struct MegaTraceBlockData { std::vector get_labels() const { - return { "ecc_op", "pub_inputs", "busread", - "arithmetic", "delta_range", "elliptic", - "aux", "poseidon2_external", "poseidon2_internal", - "lookup" }; + return { "ecc_op", + "pub_inputs", + "busread", + "arithmetic", + "delta_range", + "elliptic", + "aux", + "poseidon2_external", + "poseidon2_internal", + "lookup", + "overflow" }; } auto get() @@ -174,7 +181,6 @@ class MegaExecutionTraceBlocks : public MegaTraceBlockData { this->overflow.fixed_size = settings.overflow_capacity; } - // WORKTODO: use or remove MegaExecutionTraceBlocks(const TraceSettings& settings) : MegaExecutionTraceBlocks() { @@ -217,6 +223,7 @@ class MegaExecutionTraceBlocks : public MegaTraceBlockData { for (auto block : this->get()) { total_size += block.get_fixed_size(); } + info("total size: "); auto log2_n = static_cast(numeric::get_msb(total_size)); if ((1UL << log2_n) != (total_size)) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index b3cd4e114b78..0514c40bd96c 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -90,11 +90,22 @@ template class ProtogalaxyTests : public testing::Test { return { prover_accumulator, verifier_accumulator }; } + static std::tuple, std::shared_ptr> fold_and_verify( + const std::vector>& proving_keys, + const std::vector>& verification_keys, + ExecutionTraceUsageTracker trace_usage_tracker) + { + FoldingProver folding_prover(proving_keys, trace_usage_tracker); + FoldingVerifier folding_verifier(verification_keys); + + auto [prover_accumulator, folding_proof] = folding_prover.prove(); + auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof); + return { prover_accumulator, verifier_accumulator }; + } + static void check_accumulator_target_sum_manual(std::shared_ptr& accumulator, bool expected_result) { - - info("in the test"); size_t accumulator_size = accumulator->proving_key.circuit_size; PGInternal pg_internal; auto expected_honk_evals = pg_internal.compute_row_evaluations( @@ -471,6 +482,7 @@ template class ProtogalaxyTests : public testing::Test { { uint32_t overflow_capacity = 0; // consider the case where the overflow is not known until runtime TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, overflow_capacity }; + ExecutionTraceUsageTracker trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); std::vector> decider_pks; std::vector> decider_vks; @@ -483,17 +495,22 @@ template class ProtogalaxyTests : public testing::Test { MockCircuits::add_arithmetic_gates(builder, 1 << log2_num_gates[i]); auto decider_proving_key = std::make_shared(builder, trace_settings); + trace_usage_tracker.update(builder); auto verification_key = std::make_shared(decider_proving_key->proving_key); auto decider_verification_key = std::make_shared(verification_key); decider_pks.push_back(decider_proving_key); decider_vks.push_back(decider_verification_key); } + // trace_usage_tracker.print_previous_active_ranges(); + // trace_usage_tracker.print_active_ranges(); + // Ensure the dyadic size of the first key is strictly less than that of the second EXPECT_TRUE(decider_pks[0]->proving_key.circuit_size < decider_pks[1]->proving_key.circuit_size); // The size discrepency should be automatically handled by the PG prover via a virtual size increase - auto [prover_accumulator, verifier_accumulator] = fold_and_verify(decider_pks, decider_vks); + auto [prover_accumulator, verifier_accumulator] = + fold_and_verify(decider_pks, decider_vks, trace_usage_tracker); check_accumulator_target_sum_manual(prover_accumulator, true); decide_and_verify(prover_accumulator, verifier_accumulator, true); } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 0cefc4568696..6fbd2e47dc0a 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -14,7 +14,7 @@ void ProtogalaxyProver_::run_oink_prover_on_one_incomplete_k { PROFILE_THIS_NAME("ProtogalaxyProver::run_oink_prover_on_one_incomplete_key"); - info("oinking from PG"); + OinkProver oink_prover(keys, transcript, domain_separator + '_'); oink_prover.prove(); } @@ -31,7 +31,6 @@ void ProtogalaxyProver_::run_oink_prover_on_each_incomplete_ run_oink_prover_on_one_incomplete_key(key, domain_separator); key->target_sum = 0; key->gate_challenges = std::vector(CONST_PG_LOG_N, 0); - key->is_accumulator = true; } idx++; @@ -63,7 +62,6 @@ ProtogalaxyProver_::perturbator_round( // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is // different for (size_t idx = 1; idx <= CONST_PG_LOG_N; idx++) { - // info("Perturbator at ", idx, " ", perturbator transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); } @@ -195,16 +193,9 @@ FoldingResult ProtogalaxyProver_::check_all(keys_to_fold[0]->proving_key.polynomials, - // keys_to_fold[0]->relation_parameters); run_oink_prover_on_each_incomplete_key(); vinfo("oink prover on each incomplete key"); - // RelationChecker::check_all(keys_to_fold[0]->proving_key.polynomials, - // keys_to_fold[0]->relation_parameters); - // RelationChecker::check_all(keys_to_fold[1]->proving_key.polynomials, - // keys_to_fold[1]->relation_parameters); - std::tie(deltas, perturbator) = perturbator_round(accumulator); vinfo("perturbator round"); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 85fa4baeb48f..8c0f37e4a4c1 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -77,8 +77,7 @@ template class ProtogalaxyProverInternal { */ inline static FF process_subrelation_evaluations(const RelationEvaluations& evals, const std::array& challenges, - FF& linearly_dependent_contribution, - size_t row = 0) + FF& linearly_dependent_contribution) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/1115): Iniitalize with first subrelation value to // avoid Montgomery allocating 0 and doing a mul. This is about 60ns per row. @@ -93,9 +92,6 @@ template class ProtogalaxyProverInternal { linearly_independent_contribution += contribution; } else { linearly_dependent_contribution += contribution; - if (contribution != 0) { - info("contribution: ", contribution, " at row: ", row); - } } idx++; }; @@ -117,7 +113,8 @@ template class ProtogalaxyProverInternal { */ std::vector compute_row_evaluations(const ProverPolynomials& polynomials, const RelationSeparator& alphas_, - const RelationParameters& relation_parameters) + const RelationParameters& relation_parameters, + bool use_prev_accumulator = false) { @@ -128,7 +125,6 @@ template class ProtogalaxyProverInternal { // zero everywhere in the expanded portion of the domain. This is not the case for the combiner because that // calculation includes the incoming key which has ontrivial values on the larger domain. const size_t polynomial_size = polynomials.get_polynomial_size(); - info(polynomial_size); // const size_t polynomial_size = polynomials.q_c.virtual_size(); // DEBUG: dont think we need this std::vector aggregated_relation_evaluations(polynomial_size); @@ -140,36 +136,33 @@ template class ProtogalaxyProverInternal { }(); // Determine the number of threads over which to distribute the work - // const size_t num_threads = compute_num_threads(polynomial_size); - - // std::vector linearly_dependent_contribution_accumulators(num_threads); - - // // Distribute the execution trace rows across threads so that each handles an equal number of active rows - // trace_usage_tracker.construct_thread_ranges(num_threads, polynomial_size, /*use_prev_accumulator=*/true); - FF linearly_dependent_contribution{ 0 }; - - // parallel_for(num_threads, [&](size_t thread_idx) { - // const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; - // const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; - - for (size_t idx = 0; idx < polynomial_size; idx++) { - // The contribution is only non-trivial at a given row if the accumulator is active at that row - // if (trace_usage_tracker.check_is_active(idx, /*use_prev_accumulator=*/true)) { - const AllValues row = polynomials.get_row(idx); - // Evaluate all subrelations on given row. Separator is 1 since we are not summing across rows here. - const RelationEvaluations evals = - RelationUtils::accumulate_relation_evaluations(row, relation_parameters, FF(1)); - - // Sum against challenges alpha - aggregated_relation_evaluations[idx] = process_subrelation_evaluations( - evals, alphas, linearly_dependent_contribution /*_accumulators[thread_idx]*/, idx); - // } - } - // }); + const size_t num_threads = compute_num_threads(polynomial_size); + + std::vector linearly_dependent_contribution_accumulators(num_threads); + + // Distribute the execution trace rows across threads so that each handles an equal number of active rows + trace_usage_tracker.construct_thread_ranges(num_threads, polynomial_size, /*use_prev_accumulator=*/true); + + parallel_for(num_threads, [&](size_t thread_idx) { + const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; + const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; - info("linearly dependent contribution: ", linearly_dependent_contribution); - aggregated_relation_evaluations[0] += - linearly_dependent_contribution; // sum(linearly_dependent_contribution_accumulators); + for (size_t idx = start; idx < end; idx++) { + // The contribution is only non-trivial at a given row if the accumulator is active at that row + if (trace_usage_tracker.check_is_active(idx, use_prev_accumulator)) { + const AllValues row = polynomials.get_row(idx); + // Evaluate all subrelations on given row. Separator is 1 since we are not summing across rows here. + const RelationEvaluations evals = + RelationUtils::accumulate_relation_evaluations(row, relation_parameters, FF(1)); + + // Sum against challenges alpha + aggregated_relation_evaluations[idx] = process_subrelation_evaluations( + evals, alphas, linearly_dependent_contribution_accumulators[thread_idx]); + } + } + }); + + aggregated_relation_evaluations[0] += sum(linearly_dependent_contribution_accumulators); return aggregated_relation_evaluations; } @@ -240,7 +233,7 @@ template class ProtogalaxyProverInternal { { PROFILE_THIS(); auto full_honk_evaluations = compute_row_evaluations( - accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); + accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters, true); const auto betas = accumulator->gate_challenges; ASSERT(betas.size() == deltas.size()); const size_t log_circuit_size = accumulator->proving_key.log_circuit_size; @@ -254,10 +247,6 @@ template class ProtogalaxyProverInternal { for (size_t idx = log_circuit_size; idx < CONST_PG_LOG_N; ++idx) { perturbator.emplace_back(FF(0)); } - // info("Perturbator coeffs:"); - // for (size_t idx = 0; idx < perturbator.size(); ++idx) { - // info("idx = ", idx, ", val = ", perturbator[idx]); - // } return Polynomial{ perturbator }; } @@ -361,10 +350,9 @@ template class ProtogalaxyProverInternal { // Determine the number of threads over which to distribute the work // WORKTODO: here we need the virtual size (as opposed to size()/circuit_size) since the computation includes - // the incoming key which has nontrivial values on the larger domain. const size_t common_polynomial_size = - // keys[0]->proving_key.circuit_size; + // the incoming key which could have nontrivial values on the larger domain in case of overflow. const size_t common_polynomial_size = keys[0]->proving_key.polynomials.w_l.virtual_size(); - const size_t num_threads = compute_num_threads(common_polynomial_size); + const size_t num_threads = 1; // compute_num_threads(common_polynomial_size); // Univariates are optimised for usual PG, but we need the unoptimised version for tests (it's a version that // doesn't skip computation), so we need to define types depending on the template instantiation @@ -388,27 +376,28 @@ template class ProtogalaxyProverInternal { // Accumulate the contribution from each sub-relation parallel_for(num_threads, [&](size_t thread_idx) { - const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; - const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; + const size_t start = 0; // trace_usage_tracker.thread_ranges[thread_idx].first; + const size_t end = common_polynomial_size; + // const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; for (size_t idx = start; idx < end; idx++) { - // if (trace_usage_tracker.check_is_active(idx)) { - // Instantiate univariates, possibly with skipping toto ignore computation in those indices (they - // are still available for skipping relations, but all derived univariate will ignore those - // evaluations) No need to initialise extended_univariates to 0, as it's assigned to. - constexpr size_t skip_count = skip_zero_computations ? DeciderPKs::NUM - 1 : 0; - extend_univariates(extended_univariates[thread_idx], keys, idx); - - const FF pow_challenge = gate_separators[idx]; - - // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to - // this function have already been folded. Moreover, linear-dependent relations that act over the - // entire execution trace rather than on rows, will not be multiplied by the pow challenge. - accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], - extended_univariates[thread_idx], - relation_parameters, // these parameters have already been folded - pow_challenge); - // } + if (trace_usage_tracker.check_is_active(idx)) { + // Instantiate univariates, possibly with skipping toto ignore computation in those indices (they + // are still available for skipping relations, but all derived univariate will ignore those + // evaluations) No need to initialise extended_univariates to 0, as it's assigned to. + constexpr size_t skip_count = skip_zero_computations ? DeciderPKs::NUM - 1 : 0; + extend_univariates(extended_univariates[thread_idx], keys, idx); + + const FF pow_challenge = gate_separators[idx]; + + // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to + // this function have already been folded. Moreover, linear-dependent relations that act over the + // entire execution trace rather than on rows, will not be multiplied by the pow challenge. + accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], + extended_univariates[thread_idx], + relation_parameters, // these parameters have already been folded + pow_challenge); + } } }); diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 6fa1665cb374..6e5437509683 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -156,12 +156,9 @@ template class LogDerivLookupRelationImpl { const size_t circuit_size) { auto& inverse_polynomial = get_inverse_polynomial(polynomials); - info("HEREEEE"); - info("in log derivative"); for (size_t i = 0; i < circuit_size; ++i) { // We only compute the inverse if this row contains a lookup gate or data that has been looked up if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { - info("rows at which we deal with log derivative: ", i); // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! auto value = compute_read_term(row, relation_parameters) * @@ -171,7 +168,6 @@ template class LogDerivLookupRelationImpl { } // Compute inverse polynomial I in place by inverting the product at each row FF::batch_invert(inverse_polynomial.coeffs()); - info(inverse_polynomial.size()); }; /** 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 e4b42e26c3b1..d19d9ffa826a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -411,7 +411,6 @@ class UltraFlavor { */ void compute_logderivative_inverses(const RelationParameters& relation_parameters) { - info("about to compute logderivative inverse"); // Compute inverses for conventional lookups compute_logderivative_inverse>( this->polynomials, relation_parameters, this->circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp index 5ffa20fa1fdf..6766b57a745a 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp @@ -213,7 +213,6 @@ template class DeciderProvingKey_ { typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset); proving_key.polynomials.lookup_read_tags = typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset); - info("lookup_read_tags size: ", max_tables_size, " table_offsets: ", table_offset); } { ZoneScopedN("allocating lookup and databus inverses"); @@ -231,10 +230,6 @@ template class DeciderProvingKey_ { table_offset + MAX_LOOKUP_TABLES_SIZE)); proving_key.polynomials.lookup_inverses = Polynomial( lookup_inverses_end - lookup_inverses_start, dyadic_circuit_size, lookup_inverses_start); - info("lookup_inverses start: ", - lookup_inverses_start, - " actual size", - lookup_inverses_end - lookup_inverses_start); if constexpr (HasDataBus) { const size_t q_busread_end = circuit.blocks.busread.trace_offset + circuit.blocks.busread.get_fixed_size(is_structured); From 0b714d2ee23dc1679b4ebe9c6dc5041fdf1a1542 Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 16:26:59 +0000 Subject: [PATCH 21/32] cleanup and enable parallelisation --- .../cpp/src/barretenberg/client_ivc/client_ivc.cpp | 4 +--- .../protogalaxy/protogalaxy_prover_internal.hpp | 12 +++--------- .../relations/logderiv_lookup_relation.hpp | 1 + .../stdlib_circuit_builders/mega_flavor.hpp | 2 +- .../stdlib_circuit_builders/mock_circuits.hpp | 2 +- .../src/barretenberg/ultra_honk/mega_honk.test.cpp | 1 + .../cpp/src/barretenberg/ultra_honk/oink_prover.cpp | 1 - 7 files changed, 8 insertions(+), 15 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 55634be627a8..59004c9921a1 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -162,7 +162,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptrproving_key.commitment_key); } - ASSERT(CircuitChecker::check(circuit)); - vinfo("getting honk vk... precomputed?: ", precomputed_vk); // Update the accumulator trace usage based on the present circuit trace_usage_tracker.update(circuit); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 8c0f37e4a4c1..6b77c7d57b67 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -120,12 +120,7 @@ template class ProtogalaxyProverInternal { PROFILE_THIS_NAME("ProtogalaxyProver_::compute_row_evaluations"); - // DEBUG: at this point the size() of the polynomials may be less than the virtual_size() but we don't need to - // use virtual size because this calculation uses the accumulator computed on the previous round whose polys are - // zero everywhere in the expanded portion of the domain. This is not the case for the combiner because that - // calculation includes the incoming key which has ontrivial values on the larger domain. const size_t polynomial_size = polynomials.get_polynomial_size(); - // const size_t polynomial_size = polynomials.q_c.virtual_size(); // DEBUG: dont think we need this std::vector aggregated_relation_evaluations(polynomial_size); const std::array alphas = [&alphas_]() { @@ -349,7 +344,7 @@ template class ProtogalaxyProverInternal { constexpr bool skip_zero_computations = std::same_as; // Determine the number of threads over which to distribute the work - // WORKTODO: here we need the virtual size (as opposed to size()/circuit_size) since the computation includes + // The polynomial size is given by the virtual size since the computation includes // the incoming key which could have nontrivial values on the larger domain in case of overflow. const size_t common_polynomial_size = keys[0]->proving_key.polynomials.w_l.virtual_size(); const size_t num_threads = 1; // compute_num_threads(common_polynomial_size); @@ -376,9 +371,8 @@ template class ProtogalaxyProverInternal { // Accumulate the contribution from each sub-relation parallel_for(num_threads, [&](size_t thread_idx) { - const size_t start = 0; // trace_usage_tracker.thread_ranges[thread_idx].first; - const size_t end = common_polynomial_size; - // const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; + const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; + const size_t end = trace_usage_tracker.thread_ranges[thread_idx].second; for (size_t idx = start; idx < end; idx++) { if (trace_usage_tracker.check_is_active(idx)) { diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 6e5437509683..afd1326a91da 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -156,6 +156,7 @@ template class LogDerivLookupRelationImpl { const size_t circuit_size) { auto& inverse_polynomial = get_inverse_polynomial(polynomials); + for (size_t i = 0; i < circuit_size; ++i) { // We only compute the inverse if this row contains a lookup gate or data that has been looked up if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index d24d35115d30..cb05518cb101 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -78,7 +78,7 @@ class MegaFlavor { static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); - // static_assert(MAX_TOTAL_RELATION_LENGTH == 11); + static_assert(MAX_TOTAL_RELATION_LENGTH == 11); // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation // length = 3 diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp index 0b2e3a206a40..070046f3f150 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp @@ -148,7 +148,7 @@ class MockCircuits { // TODO(https://github.com/AztecProtocol/barretenberg/issues/902) static constexpr size_t OFFSET_HACK = 10; - // // to prevent underflow of the loop upper limit; target size >= 16 should suffice + // to prevent underflow of the loop upper limit; target size >= 16 should suffice ASSERT(target_dyadic_size > OFFSET_HACK + num_preamble_gates); size_t num_gates_to_add = target_dyadic_size - OFFSET_HACK - 1 - num_preamble_gates; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp index 855c2459ca1c..bf7f68c8d2e1 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp @@ -154,6 +154,7 @@ TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) auto doubled_circuit_size = 2 * circuit_size; proving_key_copy->proving_key.polynomials.increase_polynomials_virtual_size(doubled_circuit_size); // WARNING: updating circuit_size here would break public input delta perm argument! + // TODO() // proving_key_copy->proving_key.circuit_size = doubled_circuit_size; Prover prover(proving_key); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index f2b30f52a1b9..cbea1470ab5e 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -14,7 +14,6 @@ namespace bb { template void OinkProver::prove() { if (proving_key->proving_key.commitment_key == nullptr) { - info("initialising proving_key with circuit size: ", proving_key->proving_key.circuit_size); proving_key->proving_key.commitment_key = std::make_shared(proving_key->proving_key.circuit_size); } From c9e6af05d4d39451d3ca3e376bdd633b995c6bb2 Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 16:34:17 +0000 Subject: [PATCH 22/32] create todos --- .../plonk_honk_shared/library/grand_product_delta.hpp | 9 ++------- .../cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp | 3 +-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp index cafcedab737b..49aeb0edd77c 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_delta.hpp @@ -49,13 +49,8 @@ typename Flavor::FF compute_public_input_delta(std::spanproving_key.polynomials.increase_polynomials_virtual_size(doubled_circuit_size); - // WARNING: updating circuit_size here would break public input delta perm argument! - // TODO() + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1158) // proving_key_copy->proving_key.circuit_size = doubled_circuit_size; Prover prover(proving_key); From 90277ab83d8c2b0f0f296f4986563203ad024a73 Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 17:23:13 +0000 Subject: [PATCH 23/32] make a folding test utils --- .../barretenberg/client_ivc/client_ivc.cpp | 4 +- .../client_ivc/client_ivc.test.cpp | 57 ++-------------- .../proof_system/logderivative_library.hpp | 2 +- .../execution_trace/mega_execution_trace.hpp | 1 - .../protogalaxy/protogalaxy.test.cpp | 67 +++++-------------- .../protogalaxy_prover_internal.hpp | 18 ++--- 6 files changed, 34 insertions(+), 115 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 59004c9921a1..8b866ced44e8 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -209,10 +209,10 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr using namespace bb; @@ -31,45 +31,6 @@ class ClientIVCTests : public ::testing::Test { using DeciderVerificationKeys = DeciderVerificationKeys_; using FoldingVerifier = ProtogalaxyVerifier_; - // WORKTODO: duplicate of similar logic in pg test suite; put in some more central location for use by all modules - static void check_accumulator_target_sum_consistency(const std::shared_ptr& accumulator) - - { - info("in check accumulator target sum consistency, size: ", accumulator->proving_key.circuit_size); - ProtogalaxyProverInternal pg_internal; - auto expected_honk_evals = pg_internal.compute_row_evaluations( - accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); - // Construct pow(\vec{betas*}) as in the paper - GateSeparatorPolynomial expected_gate_separators(accumulator->gate_challenges, - accumulator->gate_challenges.size()); - - // Compute the corresponding target sum and create a dummy accumulator - FF expected_target_sum{ 0 }; - for (size_t idx = 0; idx < accumulator->proving_key.circuit_size; idx++) { - expected_target_sum += expected_honk_evals[idx] * expected_gate_separators[idx]; - } - info("expected target sum: ", expected_target_sum); - info("acc target sum: ", accumulator->target_sum); - EXPECT_TRUE(accumulator->target_sum == expected_target_sum); - } - - // WORKTODO: similar to above, this doesnt really belong here - static void fold_verify_then_decider_prove_and_verify(const ClientIVC& ivc) - { - const auto& queue_entry = ivc.verification_queue.back(); - const auto& fold_proof = queue_entry.proof; - auto key_to_fold = std::make_shared(queue_entry.honk_verification_key); - const auto& prover_accumulator = ivc.fold_output.accumulator; - - ClientIVC::FoldingVerifier folding_verifier({ ivc.verifier_accumulator, key_to_fold }); - auto verifier_accumulator = folding_verifier.verify_folding_proof(fold_proof); - - DeciderProver decider_prover(prover_accumulator); - DeciderVerifier decider_verifier(verifier_accumulator); - HonkProof decider_proof = decider_prover.construct_proof(); - EXPECT_TRUE(decider_verifier.verify_proof(decider_proof)); - } - /** * @brief Construct mock circuit with arithmetic gates and goblin ops * @details Defaulted to add 2^16 gates (which will bump to next power of two with the addition of dummy gates). @@ -469,12 +430,7 @@ TEST_F(ClientIVCTests, DynamicOverflow) ivc.accumulate(circuit); } - // DEBUG: check consistency of the target sum computed internal to ivc - check_accumulator_target_sum_consistency(ivc.fold_output.accumulator); - - // DEBUG: run native pg verifier then native decider prover/verifier - fold_verify_then_decider_prove_and_verify(ivc); - + EXPECT_EQ(check_accumulator_target_sum_manual(ivc.fold_output.accumulator), true); EXPECT_TRUE(ivc.prove_and_verify()); }; @@ -496,18 +452,13 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) size_t NUM_CIRCUITS = 2; // define parameters for two circuits; the first fits within the structured trace, the second overflows - std::vector log2_num_arith_gates = { 14, 18, 16 }; + std::vector log2_num_arith_gates = { 14, 18 }; // Accumulate for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_arith_gates[idx]); ivc.accumulate(circuit); } - check_accumulator_target_sum_consistency(ivc.fold_output.accumulator); - // DEBUG: check consistency of the target sum computed internal to ivc - - // DEBUG: run native pg verifier then native decider prover/verifier - fold_verify_then_decider_prove_and_verify(ivc); - + EXPECT_EQ(check_accumulator_target_sum_manual(ivc.fold_output.accumulator), true); EXPECT_TRUE(ivc.prove_and_verify()); }; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp index b4426e0e9517..940c88c8c6d4 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp @@ -29,7 +29,7 @@ void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_para using Accumulator = typename Relation::ValueAccumulator0; constexpr size_t READ_TERMS = Relation::READ_TERMS; constexpr size_t WRITE_TERMS = Relation::WRITE_TERMS; - static_cast(circuit_size); + auto& inverse_polynomial = Relation::template get_inverse_polynomial(polynomials); for (size_t i = 0; i < circuit_size; ++i) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp index 4f0232d97356..20259a3cc3ac 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp @@ -223,7 +223,6 @@ class MegaExecutionTraceBlocks : public MegaTraceBlockData { for (auto block : this->get()) { total_size += block.get_fixed_size(); } - info("total size: "); auto log2_n = static_cast(numeric::get_msb(total_size)); if ((1UL << log2_n) != (total_size)) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 0514c40bd96c..744d16d6324c 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -1,5 +1,6 @@ #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/polynomials/gate_separator.hpp" +#include "barretenberg/protogalaxy/folding_test_utils.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover_internal.hpp" #include "barretenberg/protogalaxy/protogalaxy_verifier.hpp" @@ -78,22 +79,10 @@ template class ProtogalaxyTests : public testing::Test { return keys; } - static std::tuple, std::shared_ptr> fold_and_verify( - const std::vector>& proving_keys, - const std::vector>& verification_keys) - { - FoldingProver folding_prover(proving_keys); - FoldingVerifier folding_verifier(verification_keys); - - auto [prover_accumulator, folding_proof] = folding_prover.prove(); - auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof); - return { prover_accumulator, verifier_accumulator }; - } - static std::tuple, std::shared_ptr> fold_and_verify( const std::vector>& proving_keys, const std::vector>& verification_keys, - ExecutionTraceUsageTracker trace_usage_tracker) + ExecutionTraceUsageTracker trace_usage_tracker = ExecutionTraceUsageTracker{}) { FoldingProver folding_prover(proving_keys, trace_usage_tracker); FoldingVerifier folding_verifier(verification_keys); @@ -103,25 +92,6 @@ template class ProtogalaxyTests : public testing::Test { return { prover_accumulator, verifier_accumulator }; } - static void check_accumulator_target_sum_manual(std::shared_ptr& accumulator, - bool expected_result) - { - size_t accumulator_size = accumulator->proving_key.circuit_size; - PGInternal pg_internal; - auto expected_honk_evals = pg_internal.compute_row_evaluations( - accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); - // Construct pow(\vec{betas*}) as in the paper - GateSeparatorPolynomial expected_gate_separators(accumulator->gate_challenges, - accumulator->gate_challenges.size()); - - // Compute the corresponding target sum and create a dummy accumulator - FF expected_target_sum{ 0 }; - for (size_t idx = 0; idx < accumulator_size; idx++) { - expected_target_sum += expected_honk_evals[idx] * expected_gate_separators[idx]; - } - EXPECT_EQ(accumulator->target_sum == expected_target_sum, expected_result); - } - static void decide_and_verify(std::shared_ptr& prover_accumulator, std::shared_ptr& verifier_accumulator, bool expected_result) @@ -344,7 +314,7 @@ template class ProtogalaxyTests : public testing::Test { // Perform prover and verifier folding auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(keys), get<1>(keys)); - check_accumulator_target_sum_manual(prover_accumulator, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); // Run decider decide_and_verify(prover_accumulator, verifier_accumulator, true); @@ -427,9 +397,9 @@ template class ProtogalaxyTests : public testing::Test { auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(keys), get<1>(keys)); // Expect failure in manual target sum check and decider - bool expected_result = false; - check_accumulator_target_sum_manual(prover_accumulator, expected_result); - decide_and_verify(prover_accumulator, verifier_accumulator, expected_result); + EXPECT_FALSE(check_accumulator_target_sum_manual(prover_accumulator)); + + decide_and_verify(prover_accumulator, verifier_accumulator, false); } /** @@ -440,12 +410,12 @@ template class ProtogalaxyTests : public testing::Test { { TupleOfKeys insts = construct_keys(2); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(insts), get<1>(insts)); - check_accumulator_target_sum_manual(prover_accumulator, true); + EXPECT_TRUE(prover_accumulator); TupleOfKeys insts_2 = construct_keys(1); // just one key pair auto [prover_accumulator_2, verifier_accumulator_2] = fold_and_verify({ prover_accumulator, get<0>(insts_2)[0] }, { verifier_accumulator, get<1>(insts_2)[0] }); - check_accumulator_target_sum_manual(prover_accumulator_2, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator_2)); decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); } @@ -460,13 +430,13 @@ template class ProtogalaxyTests : public testing::Test { TupleOfKeys keys_1 = construct_keys(2, trace_settings); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(keys_1), get<1>(keys_1)); - check_accumulator_target_sum_manual(prover_accumulator, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); TupleOfKeys keys_2 = construct_keys(1, trace_settings); // just one key pair auto [prover_accumulator_2, verifier_accumulator_2] = fold_and_verify({ prover_accumulator, get<0>(keys_2)[0] }, { verifier_accumulator, get<1>(keys_2)[0] }); - check_accumulator_target_sum_manual(prover_accumulator_2, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator_2)); info(prover_accumulator_2->proving_key.circuit_size); decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); } @@ -511,7 +481,7 @@ template class ProtogalaxyTests : public testing::Test { // The size discrepency should be automatically handled by the PG prover via a virtual size increase auto [prover_accumulator, verifier_accumulator] = fold_and_verify(decider_pks, decider_vks, trace_usage_tracker); - check_accumulator_target_sum_manual(prover_accumulator, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); decide_and_verify(prover_accumulator, verifier_accumulator, true); } @@ -545,7 +515,7 @@ template class ProtogalaxyTests : public testing::Test { // Fold the first two pairs auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(keys_1), get<1>(keys_1)); - check_accumulator_target_sum_manual(prover_accumulator, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); // Construct the decider key pair for the third circuit TupleOfKeys keys_2; @@ -554,7 +524,7 @@ template class ProtogalaxyTests : public testing::Test { // Fold 3rd pair of keys into their respective accumulators auto [prover_accumulator_2, verifier_accumulator_2] = fold_and_verify({ prover_accumulator, get<0>(keys_2)[0] }, { verifier_accumulator, get<1>(keys_2)[0] }); - check_accumulator_target_sum_manual(prover_accumulator_2, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator_2)); info(prover_accumulator_2->proving_key.circuit_size); // Decide on final accumulator @@ -569,7 +539,7 @@ template class ProtogalaxyTests : public testing::Test { { TupleOfKeys insts = construct_keys(2); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(insts), get<1>(insts)); - check_accumulator_target_sum_manual(prover_accumulator, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); // Tamper with a commitment verifier_accumulator->witness_commitments.w_l = Projective(Affine::random_element()); @@ -577,7 +547,7 @@ template class ProtogalaxyTests : public testing::Test { TupleOfKeys insts_2 = construct_keys(1); // just one decider key pair auto [prover_accumulator_2, verifier_accumulator_2] = fold_and_verify({ prover_accumulator, get<0>(insts_2)[0] }, { verifier_accumulator, get<1>(insts_2)[0] }); - check_accumulator_target_sum_manual(prover_accumulator_2, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator_2)); decide_and_verify(prover_accumulator_2, verifier_accumulator_2, false); } @@ -591,11 +561,11 @@ template class ProtogalaxyTests : public testing::Test { { TupleOfKeys insts = construct_keys(2); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(insts), get<1>(insts)); - check_accumulator_target_sum_manual(prover_accumulator, true); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); // Tamper with an accumulator polynomial prover_accumulator->proving_key.polynomials.w_l.at(1) = FF::random_element(); - check_accumulator_target_sum_manual(prover_accumulator, false); + EXPECT_FALSE(check_accumulator_target_sum_manual(prover_accumulator)); TupleOfKeys insts_2 = construct_keys(1); // just one decider key pair auto [prover_accumulator_2, verifier_accumulator_2] = @@ -615,8 +585,7 @@ template class ProtogalaxyTests : public testing::Test { auto [prover_accumulator, folding_proof] = folding_prover.prove(); auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof); - check_accumulator_target_sum_manual(prover_accumulator, true); - + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); decide_and_verify(prover_accumulator, verifier_accumulator, true); } }; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 6b77c7d57b67..13a42518dd31 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -114,7 +114,7 @@ template class ProtogalaxyProverInternal { std::vector compute_row_evaluations(const ProverPolynomials& polynomials, const RelationSeparator& alphas_, const RelationParameters& relation_parameters, - bool use_prev_accumulator = false) + bool use_prev_accumulator_tracker = false) { @@ -136,7 +136,8 @@ template class ProtogalaxyProverInternal { std::vector linearly_dependent_contribution_accumulators(num_threads); // Distribute the execution trace rows across threads so that each handles an equal number of active rows - trace_usage_tracker.construct_thread_ranges(num_threads, polynomial_size, /*use_prev_accumulator=*/true); + trace_usage_tracker.construct_thread_ranges( + num_threads, polynomial_size, /*use_prev_accumulator_tracker=*/true); parallel_for(num_threads, [&](size_t thread_idx) { const size_t start = trace_usage_tracker.thread_ranges[thread_idx].first; @@ -144,7 +145,7 @@ template class ProtogalaxyProverInternal { for (size_t idx = start; idx < end; idx++) { // The contribution is only non-trivial at a given row if the accumulator is active at that row - if (trace_usage_tracker.check_is_active(idx, use_prev_accumulator)) { + if (trace_usage_tracker.check_is_active(idx, use_prev_accumulator_tracker)) { const AllValues row = polynomials.get_row(idx); // Evaluate all subrelations on given row. Separator is 1 since we are not summing across rows here. const RelationEvaluations evals = @@ -227,8 +228,10 @@ template class ProtogalaxyProverInternal { const std::vector& deltas) { PROFILE_THIS(); - auto full_honk_evaluations = compute_row_evaluations( - accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters, true); + auto full_honk_evaluations = compute_row_evaluations(accumulator->proving_key.polynomials, + accumulator->alphas, + accumulator->relation_parameters, + /*use_prev_accumulator_tracker=*/true); const auto betas = accumulator->gate_challenges; ASSERT(betas.size() == deltas.size()); const size_t log_circuit_size = accumulator->proving_key.log_circuit_size; @@ -347,7 +350,7 @@ template class ProtogalaxyProverInternal { // The polynomial size is given by the virtual size since the computation includes // the incoming key which could have nontrivial values on the larger domain in case of overflow. const size_t common_polynomial_size = keys[0]->proving_key.polynomials.w_l.virtual_size(); - const size_t num_threads = 1; // compute_num_threads(common_polynomial_size); + const size_t num_threads = compute_num_threads(common_polynomial_size); // Univariates are optimised for usual PG, but we need the unoptimised version for tests (it's a version that // doesn't skip computation), so we need to define types depending on the template instantiation @@ -601,9 +604,6 @@ template class ProtogalaxyProverInternal { size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified num_threads = num_threads > 0 ? num_threads : 1; // ensure num threads is >= 1 - // // DEBUG: - // num_threads = 1; - return num_threads; } }; From 9f05f0bacc3df5acb0ff830e38df56a8cf8e4059 Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 17:30:20 +0000 Subject: [PATCH 24/32] undo comment --- .../execution_trace/execution_trace_usage_tracker.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp index 5ee40713ab0a..4cf653233b45 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp @@ -18,9 +18,8 @@ struct ExecutionTraceUsageTracker { using MegaTraceActiveRanges = MegaTraceBlockData; using MegaTraceFixedBlockSizes = MegaExecutionTraceBlocks; - TraceStructure max_sizes; // max utilization of each block - // Fixed size of each block prescribed by strucuring and the highest size of an overflow block encountered - MegaTraceFixedBlockSizes fixed_sizes; + TraceStructure max_sizes; // max utilization of each block + MegaTraceFixedBlockSizes fixed_sizes; // fixed size of each block prescribed by structuring // Store active ranges based on the most current accumulator and those based on all but the most recently // accumulated circuit. The former is needed for the combiner calculation and the latter for the perturbator. std::vector active_ranges; From c13923bc5a03c58283a23c3be7f99406ed27d5ae Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 17:47:16 +0000 Subject: [PATCH 25/32] revert submodule changes --- l1-contracts/lib/forge-std | 2 +- l1-contracts/lib/openzeppelin-contracts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/l1-contracts/lib/forge-std b/l1-contracts/lib/forge-std index 75f1746c949a..0e7097750918 160000 --- a/l1-contracts/lib/forge-std +++ b/l1-contracts/lib/forge-std @@ -1 +1 @@ -Subproject commit 75f1746c949ae56377611e5f2128aa93d381431f +Subproject commit 0e7097750918380d84dd3cfdef595bee74dabb70 diff --git a/l1-contracts/lib/openzeppelin-contracts b/l1-contracts/lib/openzeppelin-contracts index 7222a31d5486..448efeea6640 160000 --- a/l1-contracts/lib/openzeppelin-contracts +++ b/l1-contracts/lib/openzeppelin-contracts @@ -1 +1 @@ -Subproject commit 7222a31d548695998a475c9661fa159ef45a0e88 +Subproject commit 448efeea6640bbbc09373f03fbc9c88e280147ba From 48052d06a0cf6eef9f090b096dc1ecf25838e2e3 Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 18:05:18 +0000 Subject: [PATCH 26/32] some constifying --- .../barretenberg/client_ivc/client_ivc.test.cpp | 8 ++++---- .../execution_trace_usage_tracker.hpp | 4 ++-- .../execution_trace/mega_execution_trace.hpp | 4 ++-- .../protogalaxy/folding_test_utils.hpp | 6 +++--- .../barretenberg/protogalaxy/protogalaxy.test.cpp | 14 +++++--------- .../protogalaxy/protogalaxy_prover_internal.hpp | 2 +- .../protogalaxy/protogalaxy_verifier.cpp | 2 +- .../protogalaxy_recursive_verifier.cpp | 2 +- 8 files changed, 19 insertions(+), 23 deletions(-) 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 082d2c0cfb06..215154b3dfbe 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -420,10 +420,10 @@ TEST_F(ClientIVCTests, DynamicOverflow) MockCircuitProducer circuit_producer; - size_t NUM_CIRCUITS = 2; + const size_t NUM_CIRCUITS = 2; // define parameters for two circuits; the first fits within the structured trace, the second overflows - std::vector log2_num_arith_gates = { 14, 16 }; + const std::vector log2_num_arith_gates = { 14, 16 }; // Accumulate for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_arith_gates[idx]); @@ -449,10 +449,10 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) MockCircuitProducer circuit_producer; - size_t NUM_CIRCUITS = 2; + const size_t NUM_CIRCUITS = 2; // define parameters for two circuits; the first fits within the structured trace, the second overflows - std::vector log2_num_arith_gates = { 14, 18 }; + const std::vector log2_num_arith_gates = { 14, 18 }; // Accumulate for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { auto circuit = circuit_producer.create_next_circuit(ivc, log2_num_arith_gates[idx]); diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp index 4cf653233b45..55ce5512a69d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp @@ -48,7 +48,7 @@ struct ExecutionTraceUsageTracker { } // Update the max block utilization and active trace ranges based on the data from a provided circuit - void update(Builder& circuit) + void update(const Builder& circuit) { // Update the max utilization of each gate block for (auto [block, max_size] : zip_view(circuit.blocks.get(), max_sizes.get())) { @@ -76,7 +76,7 @@ struct ExecutionTraceUsageTracker { // need to determine the dyadic size for this. We call the size function on the current circuit which will have // the same fixed block sizes but might also have an overflow block potentially influencing the dyadic circuit // size. - size_t dyadic_circuit_size = circuit.blocks.get_structured_dyadic_size(); + const size_t dyadic_circuit_size = circuit.blocks.get_structured_dyadic_size(); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1152): should be able to use simply Range{ 0, // max_databus_size } but this breaks for certain choices of num_threads. diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp index 46a1242074e0..a24d4131a93e 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/mega_execution_trace.hpp @@ -227,10 +227,10 @@ class MegaExecutionTraceBlocks : public MegaTraceBlockData { info(""); } - size_t get_structured_dyadic_size() + size_t get_structured_dyadic_size() const { size_t total_size = 1; // start at 1 because the 0th row is unused for selectors for Honk - for (auto block : this->get()) { + for (const auto& block : this->get()) { total_size += block.get_fixed_size(); } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp index 04b02985ce34..c2581d53ba86 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp @@ -11,14 +11,14 @@ namespace bb { * to attest correctness. */ template -static bool check_accumulator_target_sum_manual(std::shared_ptr>& accumulator) +static bool check_accumulator_target_sum_manual(const std::shared_ptr>& accumulator) { using DeciderProvingKeys = DeciderProvingKeys_; using PGInternal = ProtogalaxyProverInternal; - size_t accumulator_size = accumulator->proving_key.circuit_size; + const size_t accumulator_size = accumulator->proving_key.circuit_size; PGInternal pg_internal; - auto expected_honk_evals = pg_internal.compute_row_evaluations( + const auto expected_honk_evals = pg_internal.compute_row_evaluations( accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); // Construct pow(\vec{betas*}) as in the paper GateSeparatorPolynomial expected_gate_separators(accumulator->gate_challenges, accumulator->gate_challenges.size()); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 744d16d6324c..a3139c781dbb 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -92,8 +92,8 @@ template class ProtogalaxyTests : public testing::Test { return { prover_accumulator, verifier_accumulator }; } - static void decide_and_verify(std::shared_ptr& prover_accumulator, - std::shared_ptr& verifier_accumulator, + static void decide_and_verify(const std::shared_ptr& prover_accumulator, + const std::shared_ptr& verifier_accumulator, bool expected_result) { DeciderProver decider_prover(prover_accumulator); @@ -398,7 +398,6 @@ template class ProtogalaxyTests : public testing::Test { // Expect failure in manual target sum check and decider EXPECT_FALSE(check_accumulator_target_sum_manual(prover_accumulator)); - decide_and_verify(prover_accumulator, verifier_accumulator, false); } @@ -410,7 +409,7 @@ template class ProtogalaxyTests : public testing::Test { { TupleOfKeys insts = construct_keys(2); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(insts), get<1>(insts)); - EXPECT_TRUE(prover_accumulator); + EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); TupleOfKeys insts_2 = construct_keys(1); // just one key pair auto [prover_accumulator_2, verifier_accumulator_2] = @@ -458,7 +457,7 @@ template class ProtogalaxyTests : public testing::Test { std::vector> decider_vks; // define parameters for two circuits; the first fits within the structured trace, the second overflows - std::vector log2_num_gates = { 14, 18 }; + const std::vector log2_num_gates = { 14, 18 }; for (size_t i = 0; i < 2; ++i) { MegaCircuitBuilder builder; @@ -472,14 +471,11 @@ template class ProtogalaxyTests : public testing::Test { decider_vks.push_back(decider_verification_key); } - // trace_usage_tracker.print_previous_active_ranges(); - // trace_usage_tracker.print_active_ranges(); - // Ensure the dyadic size of the first key is strictly less than that of the second EXPECT_TRUE(decider_pks[0]->proving_key.circuit_size < decider_pks[1]->proving_key.circuit_size); // The size discrepency should be automatically handled by the PG prover via a virtual size increase - auto [prover_accumulator, verifier_accumulator] = + const auto [prover_accumulator, verifier_accumulator] = fold_and_verify(decider_pks, decider_vks, trace_usage_tracker); EXPECT_TRUE(check_accumulator_target_sum_manual(prover_accumulator)); decide_and_verify(prover_accumulator, verifier_accumulator, true); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 13a42518dd31..76be5b175cd4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -114,7 +114,7 @@ template class ProtogalaxyProverInternal { std::vector compute_row_evaluations(const ProverPolynomials& polynomials, const RelationSeparator& alphas_, const RelationParameters& relation_parameters, - bool use_prev_accumulator_tracker = false) + const bool use_prev_accumulator_tracker = false) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index d2af1668a968..3d7cbec843d6 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -108,7 +108,7 @@ std::shared_ptr ProtogalaxyVerifier next_accumulator->is_accumulator = true; // Set the accumulator circuit size data based on the max of the keys being accumulated - size_t accumulator_log_circuit_size = keys_to_fold.get_max_log_circuit_size(); + const size_t accumulator_log_circuit_size = keys_to_fold.get_max_log_circuit_size(); next_accumulator->verification_key->log_circuit_size = accumulator_log_circuit_size; next_accumulator->verification_key->circuit_size = 1 << accumulator_log_circuit_size; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp index 2dd01739c42d..10739d2aa45f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp @@ -170,7 +170,7 @@ std::shared_ptr ProtogalaxyRecursiv accumulator->gate_challenges = update_gate_challenges(perturbator_challenge, accumulator->gate_challenges, deltas); // Set the accumulator circuit size data based on the max of the keys being accumulated - size_t accumulator_log_circuit_size = keys_to_fold.get_max_log_circuit_size(); + const size_t accumulator_log_circuit_size = keys_to_fold.get_max_log_circuit_size(); accumulator->verification_key->log_circuit_size = accumulator_log_circuit_size; accumulator->verification_key->circuit_size = 1 << accumulator_log_circuit_size; From 681c1e6c64ddf3b3d5b76810af3b33efa851d3ad Mon Sep 17 00:00:00 2001 From: maramihali Date: Tue, 26 Nov 2024 18:08:32 +0000 Subject: [PATCH 27/32] unused variable error when building everything --- .../barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp index fd54166a9a9b..0eaca9dfb54e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp @@ -60,7 +60,6 @@ template class stdlib_biggroup : public testing::Test { { Builder builder; affine_element input_a(element::random_element()); - affine_element input_b(element::random_element()); element_ct a = element_ct::from_witness(&builder, input_a); a.set_origin_tag(next_submitted_value_origin_tag); From 1f79b46dedc9a6619006115ed8477c72a18e4697 Mon Sep 17 00:00:00 2001 From: maramihali Date: Wed, 27 Nov 2024 11:44:28 +0000 Subject: [PATCH 28/32] now both builds work --- .../barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp index 0eaca9dfb54e..037a470649b3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp @@ -75,6 +75,7 @@ template class stdlib_biggroup : public testing::Test { EXPECT_EQ(a.get_origin_tag(), first_second_third_merged_tag); #ifndef NDEBUG + affine_element input_b(element::random_element()); // Working with instant death tagged element causes an exception element_ct b = element_ct::from_witness(&builder, input_b); b.set_origin_tag(instant_death_tag); From e7d8499bb2de51ecfa57d9af5113142fe878a89c Mon Sep 17 00:00:00 2001 From: maramihali Date: Wed, 27 Nov 2024 12:12:54 +0000 Subject: [PATCH 29/32] wopsie, I removed the commitment key from DeciderProvingKey constructor while cleaning up --- barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 8f889fc8b2c9..6d6c9d7afe5e 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -176,7 +176,8 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(circuit, trace_settings); trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); } else { - proving_key = std::make_shared(circuit, trace_settings); + proving_key = std::make_shared( + circuit, trace_settings, fold_output.accumulator->proving_key.commitment_key); } proving_key->proving_key.commitment_key = bn254_commitment_key; From 1f4df0fb85525be8f0d8ed0d446a077f751faa6d Mon Sep 17 00:00:00 2001 From: maramihali Date: Wed, 27 Nov 2024 12:50:32 +0000 Subject: [PATCH 30/32] fix commitment ket caveat --- .../barretenberg/client_ivc/client_ivc.cpp | 19 ++++++++++--------- .../barretenberg/client_ivc/client_ivc.hpp | 3 ++- .../commitment_schemes/commitment_key.hpp | 1 + 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 6d6c9d7afe5e..f5d0a7328171 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -172,14 +172,14 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr proving_key; - if (!initialized) { - proving_key = std::make_shared(circuit, trace_settings); - trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); - } else { - proving_key = std::make_shared( - circuit, trace_settings, fold_output.accumulator->proving_key.commitment_key); - } + proving_key = std::make_shared(circuit, trace_settings); + // The commitment key is initialised with the number of points determined by the trace_settings' dyadic size. If a + // circuit overflows past the dyadic size the commitment key will not have enough points so we need to increase it + if (proving_key->proving_key.circuit_size > trace_settings.dyadic_size()) { + bn254_commitment_key = std::make_shared>(proving_key->proving_key.circuit_size); + goblin.commitment_key = bn254_commitment_key; + } proving_key->proving_key.commitment_key = bn254_commitment_key; vinfo("getting honk vk... precomputed?: ", precomputed_vk); @@ -193,7 +193,8 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr oink_prover{ proving_key }; vinfo("computing oink proof..."); @@ -211,8 +212,8 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr>(trace_settings.dyadic_size()) diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp index 6440c016a627..a81da367352b 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp @@ -103,6 +103,7 @@ template class CommitmentKey { auto srs = srs::get_crs_factory()->get_prover_crs(consumed_srs); // We only need the if (consumed_srs > srs->get_monomial_size()) { + info("HERE"); throw_or_abort(format("Attempting to commit to a polynomial that needs ", consumed_srs, " points with an SRS of size ", From cd92b662c1385be15afb86dd1fec1a71e145ec86 Mon Sep 17 00:00:00 2001 From: maramihali Date: Wed, 27 Nov 2024 17:05:17 +0000 Subject: [PATCH 31/32] update PR based on review --- .../barretenberg/client_ivc/client_ivc.cpp | 3 +- .../client_ivc/client_ivc.test.cpp | 4 +- .../commitment_schemes/commitment_key.hpp | 1 - .../src/barretenberg/goblin/mock_circuits.hpp | 16 ++++++ .../execution_trace_usage_tracker.hpp | 54 +++++++++---------- .../plonk_honk_shared/relation_checker.hpp | 1 - .../protogalaxy/folding_test_utils.hpp | 1 + .../protogalaxy/protogalaxy.test.cpp | 4 +- .../ultra_honk/mega_honk.test.cpp | 4 +- 9 files changed, 50 insertions(+), 38 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index f5d0a7328171..22c0738a15c1 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -171,8 +171,7 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr(circuit)); // Construct the proving key for circuit - std::shared_ptr proving_key; - proving_key = std::make_shared(circuit, trace_settings); + std::shared_ptr proving_key = std::make_shared(circuit, trace_settings); // The commitment key is initialised with the number of points determined by the trace_settings' dyadic size. If a // circuit overflows past the dyadic size the commitment key will not have enough points so we need to increase it 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 215154b3dfbe..ec0d253ce93f 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -416,7 +416,7 @@ TEST_F(ClientIVCTests, StructuredTraceOverflow) TEST_F(ClientIVCTests, DynamicOverflow) { // Define trace settings with zero overflow capacity - ClientIVC ivc{ { SMALL_TEST_STRUCTURE, /*overflow_capacity=*/0 } }; + ClientIVC ivc{ { SMALL_TEST_STRUCTURE_FOR_OVERFLOWS, /*overflow_capacity=*/0 } }; MockCircuitProducer circuit_producer; @@ -445,7 +445,7 @@ TEST_F(ClientIVCTests, DynamicOverflowCircuitSizeChange) { uint32_t overflow_capacity = 0; // uint32_t overflow_capacity = 1 << 1; - ClientIVC ivc{ { SMALL_TEST_STRUCTURE, overflow_capacity } }; + ClientIVC ivc{ { SMALL_TEST_STRUCTURE_FOR_OVERFLOWS, overflow_capacity } }; MockCircuitProducer circuit_producer; diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp index a81da367352b..6440c016a627 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp @@ -103,7 +103,6 @@ template class CommitmentKey { auto srs = srs::get_crs_factory()->get_prover_crs(consumed_srs); // We only need the if (consumed_srs > srs->get_monomial_size()) { - info("HERE"); throw_or_abort(format("Attempting to commit to a polynomial that needs ", consumed_srs, " points with an SRS of size ", diff --git a/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp index e2d1c5987993..03c86a55b083 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp @@ -18,6 +18,22 @@ namespace bb { +/** + * @brief An arbitrary but small-ish structuring that can be used for testing with non-trivial circuits in cases when + * they overflow + */ +static constexpr TraceStructure SMALL_TEST_STRUCTURE_FOR_OVERFLOWS{ .ecc_op = 1 << 14, + .pub_inputs = 1 << 14, + .busread = 1 << 14, + .arithmetic = 1 << 15, + .delta_range = 1 << 14, + .elliptic = 1 << 14, + .aux = 1 << 14, + .poseidon2_external = 1 << 14, + .poseidon2_internal = 1 << 15, + .lookup = 1 << 14, + .overflow = 0 }; + class GoblinMockCircuits { public: using Curve = curve::BN254; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp index 55ce5512a69d..683a20a3d635 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp @@ -31,6 +31,21 @@ struct ExecutionTraceUsageTracker { size_t max_databus_size = 0; size_t max_tables_size = 0; + // For printing only. Must match the order of the members in the arithmetization + static constexpr std::array block_labels{ "ecc_op", + "pub_inputs", + "busread", + "arithmetic", + "delta_range", + "elliptic", + "aux", + "poseidon2_external", + "poseidon2_internal", + "lookup", + "overflow", + "databus_table_data", + "lookup_table_data" }; + TraceSettings trace_settings; ExecutionTraceUsageTracker(const TraceSettings& trace_settings = TraceSettings{}) @@ -76,6 +91,7 @@ struct ExecutionTraceUsageTracker { // need to determine the dyadic size for this. We call the size function on the current circuit which will have // the same fixed block sizes but might also have an overflow block potentially influencing the dyadic circuit // size. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1160) const size_t dyadic_circuit_size = circuit.blocks.get_structured_dyadic_size(); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1152): should be able to use simply Range{ 0, @@ -101,31 +117,13 @@ struct ExecutionTraceUsageTracker { }); } - // For printing only. Must match the order of the members in the arithmetization - std::vector block_labels{ "ecc_op", - "pub_inputs", - "busread", - "arithmetic", - "delta_range", - "elliptic", - "aux", - "poseidon2_external", - "poseidon2_internal", - "lookup", - "overflow" }; - - std::vector active_ranges_labels = [this] { - std::vector result = block_labels; - result.push_back("databus table data"); - result.push_back("lookup table data"); - return result; - }(); - void print() { info("Minimum required block sizes for structured trace: "); - for (auto [label, max_size] : zip_view(block_labels, max_sizes.get())) { - std::cout << std::left << std::setw(20) << (label + ":") << max_size << std::endl; + size_t idx = 0; + for (auto max_size : max_sizes.get()) { + std::cout << std::left << std::setw(20) << block_labels[idx] << ": " << max_size << std::endl; + idx++; } info(""); } @@ -133,9 +131,9 @@ struct ExecutionTraceUsageTracker { void print_active_ranges() { info("Active regions of accumulator: "); - for (auto [label, range] : zip_view(active_ranges_labels, active_ranges)) { - std::cout << std::left << std::setw(20) << (label + ":") << "(" << range.first << ", " << range.second - << ")" << std::endl; + for (auto [label, range] : zip_view(block_labels, active_ranges)) { + std::cout << std::left << std::setw(20) << label << ": (" << range.first << ", " << range.second << ")" + << std::endl; } info(""); } @@ -143,9 +141,9 @@ struct ExecutionTraceUsageTracker { void print_previous_active_ranges() { info("Active regions of previous accumulator: "); - for (auto [label, range] : zip_view(active_ranges_labels, previous_active_ranges)) { - std::cout << std::left << std::setw(20) << (label + ":") << "(" << range.first << ", " << range.second - << ")" << std::endl; + for (auto [label, range] : zip_view(block_labels, previous_active_ranges)) { + std::cout << std::left << std::setw(20) << label << ": (" << range.first << ", " << range.second << ")" + << std::endl; } info(""); } diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp index 37902dbd3447..07f2685ec403 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/relation_checker.hpp @@ -41,7 +41,6 @@ template class RelationChecker { element = 0; } - // for (size_t i = 0; i < polynomials.get_polynomial_size(); i++) { for (size_t i = 0; i < polynomials.w_l.virtual_size(); i++) { if (is_linearly_independent) { // Evaluate each constraint in the relation and check that each is satisfied diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp index c2581d53ba86..2c3523ebc9c8 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp @@ -6,6 +6,7 @@ #include "barretenberg/ultra_honk/decider_verifier.hpp" namespace bb { + /** * @brief Utility to manually compute the target sum of an accumulator and compare it to the one produced in Protogalxy * to attest correctness. diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index a3139c781dbb..bcbd70090d65 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -425,7 +425,7 @@ template class ProtogalaxyTests : public testing::Test { */ static void test_full_protogalaxy_structured_trace() { - TraceSettings trace_settings{ SMALL_TEST_STRUCTURE }; + TraceSettings trace_settings{ SMALL_TEST_STRUCTURE_FOR_OVERFLOWS }; TupleOfKeys keys_1 = construct_keys(2, trace_settings); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(keys_1), get<1>(keys_1)); @@ -450,7 +450,7 @@ template class ProtogalaxyTests : public testing::Test { static void test_fold_with_virtual_size_expansion() { uint32_t overflow_capacity = 0; // consider the case where the overflow is not known until runtime - TraceSettings trace_settings{ SMALL_TEST_STRUCTURE, overflow_capacity }; + TraceSettings trace_settings{ SMALL_TEST_STRUCTURE_FOR_OVERFLOWS, overflow_capacity }; ExecutionTraceUsageTracker trace_usage_tracker = ExecutionTraceUsageTracker(trace_settings); std::vector> decider_pks; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp index 2c478e41443b..0804bb3c97bf 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_honk.test.cpp @@ -146,7 +146,7 @@ TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease) auto builder_copy = builder; // Construct and verify Honk proof using a structured trace - TraceSettings trace_settings{ SMALL_TEST_STRUCTURE }; + TraceSettings trace_settings{ SMALL_TEST_STRUCTURE_FOR_OVERFLOWS }; auto proving_key = std::make_shared>(builder, trace_settings); auto proving_key_copy = std::make_shared>(builder_copy, trace_settings); auto circuit_size = proving_key->proving_key.circuit_size; @@ -378,7 +378,7 @@ TYPED_TEST(MegaHonkTests, PolySwap) using Flavor = TypeParam; using Builder = Flavor::CircuitBuilder; - TraceSettings trace_settings{ SMALL_TEST_STRUCTURE }; + TraceSettings trace_settings{ SMALL_TEST_STRUCTURE_FOR_OVERFLOWS }; // Construct a simple circuit and make a copy of it Builder builder; From 067cbb04bbc40a5cc92b8e20fea29b87a7e6c339 Mon Sep 17 00:00:00 2001 From: maramihali Date: Wed, 27 Nov 2024 19:06:12 +0000 Subject: [PATCH 32/32] remove extra boolean in compute_row_evaluations --- .../barretenberg/protogalaxy/folding_test_utils.hpp | 3 +++ .../protogalaxy/protogalaxy_prover_internal.hpp | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp index 2c3523ebc9c8..cd478da264f7 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/folding_test_utils.hpp @@ -10,6 +10,9 @@ namespace bb { /** * @brief Utility to manually compute the target sum of an accumulator and compare it to the one produced in Protogalxy * to attest correctness. + * + * @details As we create a ProtogalaxyProverInternal object with an empty execution trace tracker and no active_ranges + * set, compute_row_evaluations will operate on all rows. */ template static bool check_accumulator_target_sum_manual(const std::shared_ptr>& accumulator) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 76be5b175cd4..efad2d0e0726 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -113,8 +113,7 @@ template class ProtogalaxyProverInternal { */ std::vector compute_row_evaluations(const ProverPolynomials& polynomials, const RelationSeparator& alphas_, - const RelationParameters& relation_parameters, - const bool use_prev_accumulator_tracker = false) + const RelationParameters& relation_parameters) { @@ -145,7 +144,7 @@ template class ProtogalaxyProverInternal { for (size_t idx = start; idx < end; idx++) { // The contribution is only non-trivial at a given row if the accumulator is active at that row - if (trace_usage_tracker.check_is_active(idx, use_prev_accumulator_tracker)) { + if (trace_usage_tracker.check_is_active(idx, true)) { const AllValues row = polynomials.get_row(idx); // Evaluate all subrelations on given row. Separator is 1 since we are not summing across rows here. const RelationEvaluations evals = @@ -228,10 +227,8 @@ template class ProtogalaxyProverInternal { const std::vector& deltas) { PROFILE_THIS(); - auto full_honk_evaluations = compute_row_evaluations(accumulator->proving_key.polynomials, - accumulator->alphas, - accumulator->relation_parameters, - /*use_prev_accumulator_tracker=*/true); + auto full_honk_evaluations = compute_row_evaluations( + accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); const auto betas = accumulator->gate_challenges; ASSERT(betas.size() == deltas.size()); const size_t log_circuit_size = accumulator->proving_key.log_circuit_size;