25 using ClaimBatch = ClaimBatcher::Batch;
30 static constexpr size_t log_n = 7;
34 static constexpr size_t n = 1UL << log_n;
38 ck = create_commitment_key<CK>(n);
39 vk = create_verifier_commitment_key<VK>();
42 struct ResultOfProveVerify {
48 static ResultOfProveVerify run_native_prove_verify(
const Polynomial& poly,
const Fr x)
50 Commitment commitment =
ck.commit(poly);
57 PCS::compute_opening_proof(ck, { poly, opening_pair }, prover_transcript);
62 bool result = PCS::reduce_verify(vk, opening_claim, verifier_transcript);
63 return { result, prover_transcript, verifier_transcript };
74TEST_F(IPATest, CommitOnManyZeroCoeffPolyWorks)
76 constexpr size_t n = 16;
78 for (
size_t i = 0; i < n - 1; i++) {
81 p.
at(3) = this->random_element();
82 GroupElement commitment =
ck.commit(p);
83 auto srs_elements =
ck.srs->get_monomial_points();
84 GroupElement expected = srs_elements[0] * p[0];
85 for (
size_t i = 1; i < n; i += 1) {
86 expected += srs_elements[i] * p[i];
88 EXPECT_EQ(expected.normalize(), commitment.normalize());
94 Commitment commitment =
ck.commit(poly);
95 EXPECT_TRUE(commitment.is_point_at_infinity());
97 auto x = this->random_element();
105 const GroupElement commitment =
ck.commit(poly);
106 auto srs_elements =
ck.srs->get_monomial_points();
107 GroupElement expected = srs_elements[0] * poly[0];
108 for (
size_t i = 1; i < n; ++i) {
109 expected += srs_elements[i] * poly[i];
111 EXPECT_EQ(expected.normalize(), commitment.normalize());
120 auto x = this->random_element();
121 bool result = run_native_prove_verify(poly, x).result;
131 for (
size_t i = 0; i < n / 2; ++i) {
132 poly_even.
at(2 * i) = this->random_element();
133 poly_odd.
at(2 * i + 1) = this->random_element();
135 auto x = this->random_element();
136 bool result_even = run_native_prove_verify(poly_even, x).result;
137 bool result_odd = run_native_prove_verify(poly_odd, x).result;
138 EXPECT_TRUE(result_even && result_odd);
147 bool result = run_native_prove_verify(poly, x).result;
156 auto x = this->random_element();
157 auto result_of_prove_verify = run_native_prove_verify(poly, x);
158 EXPECT_TRUE(result_of_prove_verify.result);
160 EXPECT_EQ(result_of_prove_verify.prover_transcript->get_manifest(),
161 result_of_prove_verify.verifier_transcript->get_manifest());
169 auto x = this->random_element();
170 auto initial_evaluation = poly.
evaluate(x);
171 auto change_in_linear_coefficient = initial_evaluation / x;
173 poly.
at(1) -= change_in_linear_coefficient;
176 bool result = run_native_prove_verify(poly, x).result;
183#if !defined(__wasm__)
189 auto [x, eval] = this->random_eval(poly);
190 auto commitment =
ck.commit(poly);
200 for (
size_t i = 0; i < num_challenges; i++) {
206 for (
size_t i = 0; i < num_challenges; i++) {
207 auto new_random_vector = random_vector;
209 transcript->initialize(new_random_vector);
210 EXPECT_ANY_THROW(PCS::compute_opening_proof<MockTranscript>(
ck, { poly, opening_pair }, transcript));
215 for (
size_t i = 0; i < num_challenges * 2; i++) {
216 lrs[i] = Curve::AffineElement::one();
220 for (
size_t i = 0; i < num_challenges; i++) {
221 auto new_random_vector = random_vector;
223 transcript->initialize(new_random_vector, lrs, {
uint256_t(n) });
224 EXPECT_ANY_THROW(PCS::reduce_verify(
vk, opening_claim, transcript));
233 for (
size_t i = 0; i < n / 2; i++) {
235 poly.
at(i + (n / 2)) = poly[i];
237 auto [x, eval] = this->random_eval(poly);
238 auto commitment =
ck.commit(poly);
244 const size_t num_challenges = log_n + 1;
248 for (
size_t i = 0; i < num_challenges; i++) {
255 transcript->initialize(random_vector);
258 PCS::compute_opening_proof<MockTranscript>(
ck, { poly, opening_pair }, transcript);
261 transcript->reset_indices();
264 EXPECT_TRUE(PCS::reduce_verify(
vk, opening_claim, transcript));
276 auto mle_opening_point = this->random_evaluation_point(log_n);
290 auto prover_opening_claims =
291 GeminiProver::prove(n, mock_claims.
polynomial_batcher, mle_opening_point,
ck, prover_transcript);
293 const auto opening_claim = ShplonkProver::prove(
ck, prover_opening_claims, prover_transcript);
294 PCS::compute_opening_proof(
ck, opening_claim, prover_transcript);
299 std::ranges::fill(padding_indicator_array,
Fr{ 1 });
301 const auto batch_opening_claim = ShpleminiVerifier::compute_batch_opening_claim(padding_indicator_array,
304 vk.get_g1_identity(),
306 .batch_opening_claim;
308 auto result = PCS::reduce_verify_batch_opening_claim(batch_opening_claim,
vk, verifier_transcript);
310 EXPECT_EQ(result,
true);
317 auto mle_opening_point = this->random_evaluation_point(log_n);
330 auto prover_opening_claims =
331 GeminiProver::prove(n, mock_claims.
polynomial_batcher, mle_opening_point,
ck, prover_transcript);
332 const auto opening_claim = ShplonkProver::prove(
ck, prover_opening_claims, prover_transcript);
333 PCS::compute_opening_proof(
ck, opening_claim, prover_transcript);
338 std::ranges::fill(padding_indicator_array,
Fr{ 1 });
340 const auto batch_opening_claim = ShpleminiVerifier::compute_batch_opening_claim(padding_indicator_array,
343 vk.get_g1_identity(),
345 .batch_opening_claim;
347 auto result = PCS::reduce_verify_batch_opening_claim(batch_opening_claim,
vk, verifier_transcript);
350 EXPECT_EQ(result,
true);
353TEST_F(IPATest, ShpleminiIPAShiftsRemoval)
357 auto mle_opening_point = this->random_evaluation_point(log_n);
371 auto prover_opening_claims =
372 GeminiProver::prove(n, mock_claims.
polynomial_batcher, mle_opening_point,
ck, prover_transcript);
374 const auto opening_claim = ShplonkProver::prove(
ck, prover_opening_claims, prover_transcript);
375 PCS::compute_opening_proof(
ck, opening_claim, prover_transcript);
379 const size_t to_be_shifted_commitments_start = 2;
382 const size_t shifted_commitments_start = 4;
384 const size_t num_shifted_commitments = 2;
393 std::ranges::fill(padding_indicator_array,
Fr{ 1 });
395 const auto batch_opening_claim = ShpleminiVerifier::compute_batch_opening_claim(padding_indicator_array,
398 vk.get_g1_identity(),
400 repeated_commitments)
401 .batch_opening_claim;
403 auto result = PCS::reduce_verify_batch_opening_claim(batch_opening_claim,
vk, verifier_transcript);
404 EXPECT_EQ(result,
true);
static std::shared_ptr< BaseTranscript > prover_init_empty()
For testing: initializes transcript with some arbitrary data so that a challenge can be generated aft...
static std::shared_ptr< BaseTranscript > verifier_init_empty(const std::shared_ptr< BaseTranscript > &transcript)
For testing: initializes transcript based on proof data then receives junk data produced by BaseTrans...
CommitmentKey object over a pairing group 𝔾₁.
static void SetUpTestSuite()
IPA (inner product argument) commitment scheme class.
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
Opening pair (r,v) for some witness polynomial p(X) such that p(r) = v.
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
static Polynomial random(size_t size, size_t start_index=0)
Fr evaluate(const Fr &z, size_t target_size) const
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
typename Group::element Element
typename Group::affine_element AffineElement
TEST_F(IPATest, CommitOnManyZeroCoeffPolyWorks)
constexpr T get_msb(const T in)
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
CommitmentKey< Curve > ck
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Logic to support batching opening claims for unshifted, shifted and interleaved polynomials in Shplem...
Constructs random polynomials, computes commitments and corresponding evaluations.
ClaimBatcher claim_batcher
PolynomialBatcher polynomial_batcher
static constexpr field one()
static field random_element(numeric::RNG *engine=nullptr) noexcept
static constexpr field zero()