Skip to content

Commit

Permalink
all targets building
Browse files Browse the repository at this point in the history
  • Loading branch information
ludamad committed Aug 13, 2024
1 parent a5e2b3a commit c2c7073
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "barretenberg/commitment_schemes/ipa/ipa.hpp"
#include "barretenberg/polynomials/sparse_polynomial.hpp"
#include <benchmark/benchmark.h>

using namespace benchmark;
Expand All @@ -7,6 +8,7 @@ using namespace bb;
namespace {
using Curve = curve::Grumpkin;
using Fr = Curve::ScalarField;
using Polynomial = SparsePolynomial<Fr>;

constexpr size_t MIN_POLYNOMIAL_DEGREE_LOG2 = 10;
constexpr size_t MAX_POLYNOMIAL_DEGREE_LOG2 = 16;
Expand All @@ -31,7 +33,7 @@ void ipa_open(State& state) noexcept
state.PauseTiming();
size_t n = 1 << static_cast<size_t>(state.range(0));
// Construct the polynomial
Polynomial<Fr> poly(n);
Polynomial poly(n);
for (size_t i = 0; i < n; ++i) {
poly[i] = Fr::random_element(&engine);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "gemini.hpp"

#include "../commitment_key.test.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/polynomials/sparse_polynomial.hpp"
#include "barretenberg/transcript/transcript.hpp"
#include <cstddef>
#include <gtest/gtest.h>
Expand All @@ -14,7 +14,7 @@ template <class Curve> class GeminiTest : public CommitmentTest<Curve> {
using GeminiVerifier = GeminiVerifier_<Curve>;
using Fr = typename Curve::ScalarField;
using GroupElement = typename Curve::Element;
using Polynomial = typename bb::Polynomial<Fr>;
using Polynomial = typename bb::SparsePolynomial<Fr>;

public:
void execute_gemini_and_verify_claims(size_t log_n,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TYPED_TEST(KZGTest, GeminiShplonkKzgWithShift)
using KZG = KZG<TypeParam>;
using Fr = typename TypeParam::ScalarField;
using GroupElement = typename TypeParam::Element;
using Polynomial = typename bb::Polynomial<Fr>;
using Polynomial = typename bb::SparsePolynomial<Fr>;

const size_t n = 16;
const size_t log_n = 4;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "barretenberg/commitment_schemes/commitment_key.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/polynomials/sparse_polynomial.hpp"
#include "barretenberg/srs/factories/file_crs_factory.hpp"

#include <gtest/gtest.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TEST(ZeroMorphRecursionTest, ProveAndVerifySingle)
using ZeroMorphProver = ZeroMorphProver_<NativeCurve>;
using Fr = typename Curve::ScalarField;
using NativeFr = typename Curve::NativeCurve::ScalarField;
using Polynomial = bb::Polynomial<NativeFr>;
using Polynomial = bb::SparsePolynomial<NativeFr>;
using ZeroMorphVerifier = ZeroMorphVerifier_<Curve>;
using Transcript = bb::BaseTranscript<bb::stdlib::recursion::honk::StdlibTranscriptParams<Builder>>;

Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST(Flavor, GetRow)
});
Flavor::ProverPolynomials prover_polynomials;
for (auto [poly, entry] : zip_view(prover_polynomials.get_all(), data)) {
poly = entry;
poly = Flavor::Polynomial(entry);
}
auto row0 = prover_polynomials.get_row(0);
auto row1 = prover_polynomials.get_row(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ template <typename Fr> class SparsePolynomial {
return coefficients_.data()[i];
}

static SparsePolynomial random(size_t size) { return random(size, size); }

static SparsePolynomial random(size_t size, size_t virtual_size)
{
SparsePolynomial p(size, virtual_size, DontZeroMemory::FLAG);
Expand Down
32 changes: 16 additions & 16 deletions barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
using Builder = typename Flavor::CircuitBuilder;
using Polynomial = typename Flavor::Polynomial;
using ProverPolynomials = typename Flavor::ProverPolynomials;
using RelationParameters = RelationParameters<FF>;
using RelationParameters = bb::RelationParameters<FF>;
using WitnessCommitments = typename Flavor::WitnessCommitments;
using CommitmentKey = typename Flavor::CommitmentKey;
using PowPolynomial = PowPolynomial<FF>;
using PowPolynomial = bb::PowPolynomial<FF>;
using DeciderProver = DeciderProver_<Flavor>;
using DeciderVerifier = DeciderVerifier_<Flavor>;
using FoldingProver = ProtoGalaxyProver_<ProverInstances>;
Expand All @@ -40,7 +40,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
using TupleOfInstances =
std::tuple<std::vector<std::shared_ptr<ProverInstance>>, std::vector<std::shared_ptr<VerifierInstance>>>;

static void SetUpTestSuite() { srs::init_crs_factory("../srs_db/ignition"); }
static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); }

static void construct_circuit(Builder& builder)
{
Expand Down Expand Up @@ -185,10 +185,10 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
// Construct fully random prover polynomials
ProverPolynomials full_polynomials;
for (auto& poly : full_polynomials.get_all()) {
poly = SparsePolynomial<FF>::random(instance_size);
poly = bb::SparsePolynomial<FF>::random(instance_size);
}

auto relation_parameters = RelationParameters<FF>::get_random();
auto relation_parameters = bb::RelationParameters<FF>::get_random();
RelationSeparator alphas;
for (auto& alpha : alphas) {
alpha = FF::random_element();
Expand All @@ -202,7 +202,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
}

// Construct pow(\vec{betas}) as in the paper
auto pow_beta = PowPolynomial(betas);
auto pow_beta = bb::PowPolynomial(betas);
pow_beta.compute_values();

// Compute the corresponding target sum and create a dummy accumulator
Expand Down Expand Up @@ -233,12 +233,12 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
static void test_combiner_quotient()
{
auto compressed_perturbator = FF(2); // F(\alpha) in the paper
auto combiner = Univariate<FF, 12>(std::array<FF, 12>{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 });
auto combiner = bb::Univariate<FF, 12>(std::array<FF, 12>{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 });
auto combiner_quotient = ProtoGalaxyProver::compute_combiner_quotient(compressed_perturbator, combiner);

// K(i) = (G(i) - ( L_0(i) * F(\alpha)) / Z(i), i = {2,.., 13} for ProverInstances::NUM = 2
// K(i) = (G(i) - (1 - i) * F(\alpha)) / i * (i - 1)
auto expected_evals = Univariate<FF, 12, 2>(std::array<FF, 10>{
auto expected_evals = bb::Univariate<FF, 12, 2>(std::array<FF, 10>{
(FF(22) - (FF(1) - FF(2)) * compressed_perturbator) / (FF(2) * FF(2 - 1)),
(FF(23) - (FF(1) - FF(3)) * compressed_perturbator) / (FF(3) * FF(3 - 1)),
(FF(24) - (FF(1) - FF(4)) * compressed_perturbator) / (FF(4) * FF(4 - 1)),
Expand Down Expand Up @@ -275,7 +275,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
ProverInstances instances{ { instance1, instance2 } };
ProtoGalaxyProver::combine_relation_parameters(instances);

Univariate<FF, 11> expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } };
bb::Univariate<FF, 11> expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } };
EXPECT_EQ(instances.relation_parameters.eta, expected_eta);
// Optimised relation parameters are the same, we just don't compute any values for non-used indices when
// deriving values from them
Expand All @@ -302,7 +302,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
ProverInstances instances{ { instance1, instance2 } };
ProtoGalaxyProver::combine_alpha(instances);

Univariate<FF, 12> expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 } };
bb::Univariate<FF, 12> expected_alpha{ { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 } };
for (const auto& alpha : instances.alphas) {
EXPECT_EQ(alpha, expected_alpha);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
construct_circuit(builder2);

// Add some arithmetic gates
MockCircuits::add_arithmetic_gates(builder1, /*num_gates=*/4);
bb::MockCircuits::add_arithmetic_gates(builder1, /*num_gates=*/4);

check_fold_and_decide(builder1, builder2);
}
Expand All @@ -352,7 +352,7 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
construct_circuit(builder2);

// Add some arithmetic gates with public inputs to the first circuit
MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4);
bb::MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4);

check_fold_and_decide(builder1, builder2);
}
Expand All @@ -366,8 +366,8 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
construct_circuit(builder2);

// Add a different number of lookup gates to each circuit
MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table
MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table
bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table
bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table

check_fold_and_decide(builder1, builder2);
}
Expand All @@ -386,8 +386,8 @@ template <typename Flavor> class ProtoGalaxyTests : public testing::Test {
construct_circuit(builder2);

// Add a different number of lookup gates to each circuit
MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table
MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table
bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table
bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table

// Erroneously set a non-zero wire value to zero in one of the lookup gates
for (auto& wire_3_witness_idx : builder1.blocks.lookup.w_o()) {
Expand Down
36 changes: 19 additions & 17 deletions barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sumcheck.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/polynomials/sparse_polynomial.hpp"
#include "barretenberg/relations/auxiliary_relation.hpp"
#include "barretenberg/relations/delta_range_constraint_relation.hpp"
#include "barretenberg/relations/elliptic_relation.hpp"
Expand All @@ -15,13 +16,14 @@ using namespace bb;
namespace {
using Flavor = UltraFlavor;
using FF = typename Flavor::FF;
using Polynomial = SparsePolynomial<FF>;
using ProverPolynomials = typename Flavor::ProverPolynomials;
using RelationSeparator = Flavor::RelationSeparator;
const size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES;

Polynomial<FF> random_poly(size_t size)
Polynomial random_poly(size_t size)
{
auto poly = bb::Polynomial<FF>(size);
auto poly = Polynomial(size);
for (auto& coeff : poly) {
coeff = FF::random_element();
}
Expand Down Expand Up @@ -51,7 +53,7 @@ TEST_F(SumcheckTests, PolynomialNormalization)

// Randomly construct the prover polynomials that are input to Sumcheck.
// Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory.
std::array<Polynomial<FF>, NUM_POLYNOMIALS> random_polynomials;
std::array<SparsePolynomial<FF>, NUM_POLYNOMIALS> random_polynomials;
for (auto& poly : random_polynomials) {
poly = random_poly(multivariate_n);
}
Expand Down Expand Up @@ -114,7 +116,7 @@ TEST_F(SumcheckTests, PolynomialNormalization)
// full polynomials at challenge u via the evaluate_mle() function
std::vector<FF> u_challenge = { u_0, u_1, u_2 };
for (auto [full_poly, claimed_eval] : zip_view(full_polynomials.get_all(), output.claimed_evaluations.get_all())) {
Polynomial<FF> poly(full_poly);
SparsePolynomial<FF> poly(full_poly);
auto v_expected = poly.evaluate_mle(u_challenge);
EXPECT_EQ(v_expected, claimed_eval);
}
Expand All @@ -127,7 +129,7 @@ TEST_F(SumcheckTests, Prover)

// Randomly construct the prover polynomials that are input to Sumcheck.
// Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory.
std::array<Polynomial<FF>, NUM_POLYNOMIALS> random_polynomials;
std::array<SparsePolynomial<FF>, NUM_POLYNOMIALS> random_polynomials;
for (auto& poly : random_polynomials) {
poly = random_poly(multivariate_n);
}
Expand Down Expand Up @@ -174,9 +176,9 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple)

// Construct prover polynomials where each is the zero polynomial.
// Note: ProverPolynomials are defined as spans so the polynomials they point to need to exist in memory.
std::array<Polynomial<FF>, NUM_POLYNOMIALS> zero_polynomials;
std::array<SparsePolynomial<FF>, NUM_POLYNOMIALS> zero_polynomials;
for (auto& poly : zero_polynomials) {
poly = Polynomial<FF>(multivariate_n);
poly = SparsePolynomial<FF>(multivariate_n);
}
auto full_polynomials = construct_ultra_full_polynomials(zero_polynomials);

Expand All @@ -199,16 +201,16 @@ TEST_F(SumcheckTests, ProverAndVerifierSimple)
std::array<FF, multivariate_n> q_arith = { 0, 1, 1, 0 };
// Setting all of these to 0 ensures the GrandProductRelation is satisfied

full_polynomials.w_l = w_l;
full_polynomials.w_r = w_r;
full_polynomials.w_o = w_o;
full_polynomials.w_4 = w_4;
full_polynomials.q_m = q_m;
full_polynomials.q_l = q_l;
full_polynomials.q_r = q_r;
full_polynomials.q_o = q_o;
full_polynomials.q_c = q_c;
full_polynomials.q_arith = q_arith;
full_polynomials.w_l = SparsePolynomial<FF>(w_l);
full_polynomials.w_r = SparsePolynomial<FF>(w_r);
full_polynomials.w_o = SparsePolynomial<FF>(w_o);
full_polynomials.w_4 = SparsePolynomial<FF>(w_4);
full_polynomials.q_m = SparsePolynomial<FF>(q_m);
full_polynomials.q_l = SparsePolynomial<FF>(q_l);
full_polynomials.q_r = SparsePolynomial<FF>(q_r);
full_polynomials.q_o = SparsePolynomial<FF>(q_o);
full_polynomials.q_c = SparsePolynomial<FF>(q_c);
full_polynomials.q_arith = SparsePolynomial<FF>(q_arith);

// Set aribitrary random relation parameters
RelationParameters<FF> relation_parameters{
Expand Down

0 comments on commit c2c7073

Please sign in to comment.