53 template <
size_t log_poly_length>
58 EXPECT_EQ(1UL << log_poly_length, poly.
size());
59 Commitment commitment = this->
commit(poly);
68 std::vector<DataType> proof;
70 switch (failure_mode) {
71 case FailureMode::None:
73 NativeIPA::compute_opening_proof(this->
ck(), prover_claim, prover_transcript);
74 proof = prover_transcript->export_proof();
76 case FailureMode::A_Zero:
77 NativeIPA::compute_opening_proof(this->
ck(), prover_claim, prover_transcript);
78 proof = prover_transcript->export_proof();
82 case FailureMode::G_Zero: {
83 NativeIPA::compute_opening_proof(this->
ck(), prover_claim, prover_transcript);
84 proof = prover_transcript->export_proof();
86 const size_t comm_frs = 2;
87 const size_t offset = log_poly_length * 2 * comm_frs;
88 auto element_frs = std::span{ proof }.subspan(
offset, comm_frs);
90 Commitment op_commitment = NativeTranscript::template deserialize<Commitment>(element_frs);
91 Commitment new_op_commitment = op_commitment + op_commitment;
93 std::copy(new_op_commitment_reserialized.begin(),
94 new_op_commitment_reserialized.end(),
98 case FailureMode::ChangePoly:
101 NativeIPA::add_claim_to_hash_buffer(this->
ck(), prover_claim, prover_transcript);
103 auto [new_poly, new_x] = generate_poly_and_challenge<log_poly_length>();
104 auto new_eval = new_poly.evaluate(new_x);
108 NativeIPA::compute_opening_proof_internal(this->
ck(), new_prover_claim, prover_transcript);
109 proof = prover_transcript->export_proof();
116 auto result = NativeIPA::reduce_verify(this->
vk(), opening_claim, verifier_transcript);
118 if (failure_mode == FailureMode::None) {
123 auto stdlib_comm = Curve::Group::from_witness(&
builder, commitment);
124 auto stdlib_x = Curve::ScalarField::from_witness(&
builder, x);
125 auto stdlib_eval = Curve::ScalarField::from_witness(&
builder, eval);
130 return { recursive_verifier_transcript, stdlib_opening_claim };
140 template <
size_t log_poly_length>
141 Builder build_ipa_recursive_verifier_circuit(
Polynomial& poly,
Fr x, FailureMode failure_mode = FailureMode::None)
146 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x, failure_mode);
148 RecursiveIPA::reduce_verify(stdlib_claim, stdlib_transcript);
150 builder.finalize_circuit(
true);
156 template <
size_t log_poly_length>
160 static constexpr size_t poly_length = 1UL << log_poly_length;
163 case PolyType::Random:
166 case PolyType::ManyZeros:
168 for (
size_t i = 0; i < poly_length / 2; ++i) {
171 case PolyType::Sparse:
173 for (
size_t i = 0; i < std::min<size_t>(100, poly_length / 2); ++i) {
189 template <
size_t log_poly_length>
190 void test_recursive_ipa(
Polynomial& poly,
Fr x, FailureMode failure_mode = FailureMode::None)
193 Builder builder(build_ipa_recursive_verifier_circuit<log_poly_length>(poly, x, failure_mode));
194 info(
"IPA Recursive Verifier num finalized gates = ",
builder.get_num_finalized_gates());
195 if (failure_mode == FailureMode::None) {
217 auto [transcript_1, claim_1] = create_ipa_claim<log_poly_length>(
builder, poly1, x1);
218 auto [transcript_2, claim_2] = create_ipa_claim<log_poly_length>(
builder, poly2, x2);
222 auto [output_claim, ipa_proof] =
223 RecursiveIPA::accumulate(this->
ck(), transcript_1, claim_1, transcript_2, claim_2);
224 output_claim.set_public();
226 builder.finalize_circuit(
false);
227 info(
"Circuit with 2 IPA Recursive Verifiers and IPA Accumulation num finalized gates = ",
228 builder.get_num_finalized_gates());
233 bb::fq(output_claim.opening_pair.evaluation.get_value()) };
234 Commitment native_comm = output_claim.commitment.get_value();
240 auto result = NativeIPA::reduce_verify(this->
vk(), opening_claim, verifier_transcript);
251TEST_F(IPARecursiveTests, RecursiveSmallSparse)
253 static constexpr size_t log_poly_length = 2;
254 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::ManyZeros);
255 test_recursive_ipa<log_poly_length>(poly, x);
261TEST_F(IPARecursiveTests, RecursiveMediumManyZeros)
263 static constexpr size_t log_poly_length = 10;
264 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Sparse);
265 test_recursive_ipa<log_poly_length>(poly, x);
268TEST_F(IPARecursiveTests, RecursiveMediumZeroPoly)
270 static constexpr size_t log_poly_length = 10;
271 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Zero);
272 test_recursive_ipa<log_poly_length>(poly, x);
275TEST_F(IPARecursiveTests, RecursiveMediumZeroChallenge)
277 static constexpr size_t log_poly_length = 10;
278 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
279 test_recursive_ipa<log_poly_length>(poly,
Fr::zero());
282TEST_F(IPARecursiveTests, RecursiveMediumZeroEvaluation)
284 static constexpr size_t log_poly_length = 10;
285 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
286 auto initial_evaluation = poly.
evaluate(x);
287 poly.
at(1) -= initial_evaluation / x;
288 test_recursive_ipa<log_poly_length>(poly, x);
294TEST_F(IPARecursiveTests, RecursiveLargeRandom)
296 static constexpr size_t log_poly_length = CONST_ECCVM_LOG_N;
297 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
298 test_recursive_ipa<log_poly_length>(poly, x);
305TEST_F(IPARecursiveTests, RecursiveMediumRandomFailure)
307 static constexpr size_t log_poly_length = 10;
308 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
309 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::A_Zero);
310 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::G_Zero);
311 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::ChangePoly);
317TEST_F(IPARecursiveTests, AccumulateSmallRandom)
319 static constexpr size_t log_poly_length = 2;
320 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
321 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
322 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
328TEST_F(IPARecursiveTests, AccumulateMediumRandom)
330 static constexpr size_t log_poly_length = 10;
331 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>();
332 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
333 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
335TEST_F(IPARecursiveTests, AccumulateMediumFirstZeroPoly)
337 static constexpr size_t log_poly_length = 10;
338 static constexpr size_t poly_length = 1UL << log_poly_length;
340 auto x1 = this->random_element();
341 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
342 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
344TEST_F(IPARecursiveTests, AccumulateMediumBothZeroPoly)
346 static constexpr size_t log_poly_length = 10;
347 static constexpr size_t poly_length = 1UL << log_poly_length;
350 auto x1 = this->random_element();
351 auto x2 = this->random_element();
352 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
354TEST_F(IPARecursiveTests, AccumulateMediumSparseManyZeros)
356 static constexpr size_t log_poly_length = 10;
357 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>(PolyType::Sparse);
358 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>(PolyType::ManyZeros);
359 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
362TEST_F(IPARecursiveTests, FullRecursiveVerifierMediumZeroPoly)
365 static constexpr size_t log_poly_length = 10;
366 static constexpr size_t poly_length = 1UL << log_poly_length;
371 auto x = this->random_element();
372 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x);
375 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, stdlib_claim, stdlib_transcript);
377 builder.finalize_circuit(
true);
378 info(
"Full IPA Recursive Verifier num finalized gates for length ",
379 1UL << log_poly_length,
381 builder.get_num_finalized_gates());
385TEST_F(IPARecursiveTests, FullRecursiveVerifierMediumRandom)
388 static constexpr size_t log_poly_length = 10;
389 static constexpr size_t poly_length = 1UL << log_poly_length;
393 auto [poly, x] = generate_poly_and_challenge<log_poly_length>();
394 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x);
397 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, stdlib_claim, stdlib_transcript);
399 builder.finalize_circuit(
true);
400 info(
"Full IPA Recursive Verifier num finalized gates for length ",
401 1UL << log_poly_length,
403 builder.get_num_finalized_gates());
407TEST_F(IPARecursiveTests, AccumulationAndFullRecursiveVerifierMediumRandom)
409 static constexpr size_t log_poly_length = 10;
418 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>();
419 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
421 auto [transcript_1, claim_1] = create_ipa_claim<log_poly_length>(
builder, poly1, x1);
422 auto [transcript_2, claim_2] = create_ipa_claim<log_poly_length>(
builder, poly2, x2);
426 auto [output_claim, ipa_proof] = RecursiveIPA::accumulate(this->
ck(), transcript_1, claim_1, transcript_2, claim_2);
427 output_claim.set_public();
429 builder.finalize_circuit(
false);
430 info(
"Circuit with 2 IPA Recursive Verifiers and IPA Accumulation num finalized gates = ",
431 builder.get_num_finalized_gates());
441 Curve::ScalarField::create_from_u512_as_witness(&root_rollup, output_claim.opening_pair.challenge.get_value());
443 Curve::ScalarField::create_from_u512_as_witness(&root_rollup, output_claim.opening_pair.evaluation.get_value());
444 ipa_claim.
commitment = Curve::AffineElement::from_witness(&root_rollup, output_claim.commitment.get_value());
445 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, ipa_claim, stdlib_verifier_transcript);
446 root_rollup.finalize_circuit(
true);
448 info(
"Full IPA Recursive Verifier num finalized gates for length ",
449 1UL << log_poly_length,
451 root_rollup.get_num_finalized_gates());
#define BB_DISABLE_ASSERTS()
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
typename Codec::DataType DataType
static std::vector< DataType > serialize(const T &element)
CommitmentKey object over a pairing group 𝔾₁.
Commitment commit(const Polynomial &polynomial)
IPA (inner product argument) commitment scheme class.
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
OpeningPair< Curve > opening_pair
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[...
Polynomial p and an opening pair (r,v) such that p(r) = v.
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
typename Group::element Element
typename Group::affine_element AffineElement
virtual uint64_t get_random_uint64()=0
A simple wrapper around a vector of stdlib field elements representing a proof.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
Entry point for Barretenberg command-line interface.
field< Bn254FqParams > fq
TEST_F(IPATest, ChallengesAreZero)
BaseTranscript< stdlib::StdlibCodec< stdlib::field_t< UltraCircuitBuilder > >, stdlib::poseidon2< UltraCircuitBuilder > > UltraStdlibTranscript
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
CommitmentKey< Curve > ck
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr field zero()
Curve grumpkin in circuit setting.