6#include <gtest/gtest.h>
23 auto srs =
ck.get_monomial_points();
26 result += srs[i] * poly[i];
28 return result.normalize();
33 constexpr size_t n = 16;
39 EXPECT_TRUE(commitment.is_point_at_infinity());
44 constexpr size_t n = 16;
53 EXPECT_EQ(expected, commitment);
58 constexpr size_t n = 16;
64 EXPECT_EQ(expected, commitment);
70 for (
size_t n : {
size_t{ 10 },
size_t{ 100 },
size_t{ 1000 },
size_t{ 1234 } }) {
73 EXPECT_EQ(
ck.srs_size, n);
75 EXPECT_GE(
ck.get_monomial_size(), n);
80 EXPECT_EQ(expected, commitment);
86 constexpr size_t n = 16;
91 for (
size_t i = 0; i < 5; ++i) {
96 auto batch_commitments =
ck.batch_commit(poly_refs);
98 EXPECT_EQ(batch_commitments.size(), polys.size());
101 for (
size_t i = 0; i < polys.size(); ++i) {
104 EXPECT_EQ(batch_commitments[i], individual);
105 EXPECT_EQ(batch_commitments[i], expected);
111 constexpr size_t n = 32;
117 constexpr size_t start_index = 8;
118 constexpr size_t poly_size = 16;
119 constexpr size_t virtual_size = start_index + poly_size;
120 Polynomial poly(poly_size, virtual_size, start_index);
121 for (
size_t i = 0; i < poly_size; ++i) {
127 EXPECT_EQ(expected, commitment);
168 constexpr size_t n = 5000000;
173 constexpr size_t num_fake_zeros = 100;
174 for (
size_t i = 0; i < num_fake_zeros; ++i) {
178 constexpr size_t num_targets = 10;
179 for (
size_t i = num_fake_zeros; i < num_fake_zeros + num_targets; ++i) {
180 poly.
at(i) =
Fr(65536);
183 for (
size_t i = num_fake_zeros + num_targets; i < n; ++i) {
194 constexpr size_t chunk_size = 1UL << 20;
195 auto srs_points =
ck.get_monomial_points();
197 correct_sum.self_set_infinity();
200 size_t this_chunk = std::min(chunk_size, n -
offset);
205 auto chunk_result = scalar_multiplication::pippenger_unsafe<Curve>(chunk_span, chunk_points);
206 correct_sum += chunk_result;
210 EXPECT_EQ(actual_commitment, correct_commitment);
214using Curves = ::testing::Types<curve::BN254, curve::Grumpkin>;
219 TestFixture::test_commit_to_zero_poly();
223 TestFixture::test_commit_sparse_poly();
227 TestFixture::test_commit_random_poly();
231 TestFixture::test_non_dyadic_srs_size();
235 TestFixture::test_batch_commit();
239 TestFixture::test_commit_with_start_index();
244 GTEST_SKIP() <<
"BN254 only: Grumpkin CRS has insufficient points for the 5M threshold";
247 GTEST_SKIP() <<
"Too slow in debug builds";
249 TestFixture::test_pippenger_zero_count_regression();
CommitmentKey object over a pairing group 𝔾₁.
void test_pippenger_zero_count_regression()
typename Curve::AffineElement Commitment
void test_commit_with_start_index()
void test_commit_to_zero_poly()
void test_commit_random_poly()
static Commitment commit_naive(const CK &ck, const Polynomial &poly)
void test_non_dyadic_srs_size()
typename Curve::Element GroupElement
typename Curve::ScalarField Fr
static void SetUpTestSuite()
void test_commit_sparse_poly()
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
size_t start_index() const
static Polynomial random(size_t size, size_t start_index=0)
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
typename Group::element Element
typename Group::affine_element AffineElement
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TYPED_TEST_SUITE(CommitmentKeyTest, Curves)
TYPED_TEST(CommitmentKeyTest, CommitToZeroPoly)
CommitmentKey< Curve > ck
void set_parallel_for_concurrency(size_t num_cores)
::testing::Types< curve::BN254, curve::Grumpkin > Curves
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static field random_element(numeric::RNG *engine=nullptr) noexcept