From c71551749cb3750d2ea4de00f9303dd088b549e1 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Tue, 6 Jun 2023 17:04:38 +0000 Subject: [PATCH 1/3] Stupid check_circuit bug fix and memory leak in widget fix --- .../widgets/random_widgets/plookup_widget_impl.hpp | 3 +++ .../circuit_constructors/turbo_circuit_constructor.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp b/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp index 4dc1a6906e..53b968c3f9 100644 --- a/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp @@ -330,6 +330,9 @@ void ProverPlookupWidget::compute_gra // Compute and add monomial form of z_lookup to the polynomial store z_lookup.ifft(key->small_domain); key->polynomial_store.put("z_lookup", std::move(z_lookup)); + for (size_t k = 1; k < 4; ++k) { + free(accumulators[k]); + } } /** diff --git a/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.cpp b/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.cpp index 10a2ab7280..8399e7e2c8 100644 --- a/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.cpp +++ b/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.cpp @@ -1467,7 +1467,7 @@ bool TurboCircuitConstructor::check_circuit() std::vector alpha_powers; alpha_powers.push_back(alpha_base); for (size_t i = 1; i < 7; i++) { - alpha_powers.push_back(alpha_powers[i] * alpha); + alpha_powers.push_back(alpha_powers[i - 1] * alpha); } for (size_t i = 0; i < get_num_gates(); i++) { From d9be8d90a01c4641c0e123588a2916d072f7f95b Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Tue, 6 Jun 2023 18:17:21 +0000 Subject: [PATCH 2/3] More memory fixes --- .../srs/scalar_multiplication.test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp b/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp index 73f810aa39..1ee5d0600d 100644 --- a/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp +++ b/cpp/src/barretenberg/srs/scalar_multiplication.test.cpp @@ -720,7 +720,7 @@ TYPED_TEST(ScalarMultiplicationTests, UndersizedInputs) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr) * num_points); - AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * num_points * 2 + 1); + AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (num_points * 2 + 1)); for (size_t i = 0; i < num_points; ++i) { scalars[i] = Fr::random_element(); @@ -758,7 +758,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerSmall) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr) * num_points); - AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * num_points * 2 + 1); + AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (num_points * 2 + 1)); for (size_t i = 0; i < num_points; ++i) { scalars[i] = Fr::random_element(); @@ -795,7 +795,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerEdgeCaseDbl) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr) * num_points); - AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * num_points * 2 + 1); + AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (num_points * 2 + 1)); AffineElement point = AffineElement(Element::random_element()); for (size_t i = 0; i < num_points; ++i) { @@ -928,7 +928,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerUnsafeShortInputs) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr) * num_points); - AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * num_points * 2 + 1); + AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (num_points * 2 + 1)); for (size_t i = 0; i < num_points; ++i) { points[i] = AffineElement(Element::random_element()); @@ -986,7 +986,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerOne) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr) * 1); - AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * num_points * 2 + 1); + AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (num_points * 2 + 1)); for (size_t i = 0; i < num_points; ++i) { scalars[i] = Fr::random_element(); @@ -1021,7 +1021,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerZeroPoints) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr)); - AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * 2 + 1); + AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (2 + 1)); barretenberg::scalar_multiplication::pippenger_runtime_state state(0); Element result = barretenberg::scalar_multiplication::pippenger(scalars, points, 0, state); @@ -1042,7 +1042,7 @@ TYPED_TEST(ScalarMultiplicationTests, PippengerMulByZero) Fr* scalars = (Fr*)aligned_alloc(32, sizeof(Fr)); - AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * 2 + 1); + AffineElement* points = (AffineElement*)aligned_alloc(32, sizeof(AffineElement) * (2 + 1)); scalars[0] = Fr::zero(); points[0] = Group::affine_one; From e1057d134993d5937b1a846399e9f87edef6b6ea Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Tue, 20 Jun 2023 17:16:34 +0000 Subject: [PATCH 3/3] Remove free --- .../widgets/random_widgets/plookup_widget_impl.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp b/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp index 53b968c3f9..4dc1a6906e 100644 --- a/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp @@ -330,9 +330,6 @@ void ProverPlookupWidget::compute_gra // Compute and add monomial form of z_lookup to the polynomial store z_lookup.ifft(key->small_domain); key->polynomial_store.put("z_lookup", std::move(z_lookup)); - for (size_t k = 1; k < 4; ++k) { - free(accumulators[k]); - } } /**