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) {
172 case PolyType::Sparse:
174 for (
size_t i = 0; i < std::min<size_t>(100, poly_length / 2); ++i) {
190 template <
size_t log_poly_length>
191 void test_recursive_ipa(
Polynomial& poly,
Fr x, FailureMode failure_mode = FailureMode::None)
194 Builder builder(build_ipa_recursive_verifier_circuit<log_poly_length>(poly, x, failure_mode));
195 info(
"IPA Recursive Verifier num finalized gates = ",
builder.get_num_finalized_gates());
196 if (failure_mode == FailureMode::None) {
218 auto [transcript_1, claim_1] = create_ipa_claim<log_poly_length>(
builder, poly1, x1);
219 auto [transcript_2, claim_2] = create_ipa_claim<log_poly_length>(
builder, poly2, x2);
223 auto [output_claim, ipa_proof] =
224 RecursiveIPA::accumulate(this->
ck(), transcript_1, claim_1, transcript_2, claim_2);
225 output_claim.set_public();
227 builder.finalize_circuit(
false);
228 info(
"Circuit with 2 IPA Recursive Verifiers and IPA Accumulation num finalized gates = ",
229 builder.get_num_finalized_gates());
234 bb::fq(output_claim.opening_pair.evaluation.get_value()) };
235 Commitment native_comm = output_claim.commitment.get_value();
241 auto result = NativeIPA::reduce_verify(this->
vk(), opening_claim, verifier_transcript);
252TEST_F(IPARecursiveTests, RecursiveSmallSparse)
254 static constexpr size_t log_poly_length = 2;
255 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::ManyZeros);
256 test_recursive_ipa<log_poly_length>(poly, x);
262TEST_F(IPARecursiveTests, RecursiveMediumManyZeros)
264 static constexpr size_t log_poly_length = 10;
265 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Sparse);
266 test_recursive_ipa<log_poly_length>(poly, x);
269TEST_F(IPARecursiveTests, RecursiveMediumZeroPoly)
271 static constexpr size_t log_poly_length = 10;
272 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Zero);
273 test_recursive_ipa<log_poly_length>(poly, x);
276TEST_F(IPARecursiveTests, RecursiveMediumZeroChallenge)
278 static constexpr size_t log_poly_length = 10;
279 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
280 test_recursive_ipa<log_poly_length>(poly,
Fr::zero());
283TEST_F(IPARecursiveTests, RecursiveMediumZeroEvaluation)
285 static constexpr size_t log_poly_length = 10;
286 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
287 auto initial_evaluation = poly.
evaluate(x);
288 poly.
at(1) -= initial_evaluation / x;
289 test_recursive_ipa<log_poly_length>(poly, x);
295TEST_F(IPARecursiveTests, RecursiveLargeRandom)
297 static constexpr size_t log_poly_length = CONST_ECCVM_LOG_N;
298 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
299 test_recursive_ipa<log_poly_length>(poly, x);
306TEST_F(IPARecursiveTests, RecursiveMediumRandomFailure)
308 static constexpr size_t log_poly_length = 10;
309 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
310 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::A_Zero);
311 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::G_Zero);
312 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::ChangePoly);
318TEST_F(IPARecursiveTests, AccumulateSmallRandom)
320 static constexpr size_t log_poly_length = 2;
321 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
322 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
323 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
329TEST_F(IPARecursiveTests, AccumulateMediumRandom)
331 static constexpr size_t log_poly_length = 10;
332 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>();
333 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
334 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
336TEST_F(IPARecursiveTests, AccumulateMediumFirstZeroPoly)
338 static constexpr size_t log_poly_length = 10;
339 static constexpr size_t poly_length = 1UL << log_poly_length;
341 auto x1 = this->random_element();
342 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
343 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
345TEST_F(IPARecursiveTests, AccumulateMediumBothZeroPoly)
347 static constexpr size_t log_poly_length = 10;
348 static constexpr size_t poly_length = 1UL << log_poly_length;
351 auto x1 = this->random_element();
352 auto x2 = this->random_element();
353 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
355TEST_F(IPARecursiveTests, AccumulateMediumSparseManyZeros)
357 static constexpr size_t log_poly_length = 10;
358 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>(PolyType::Sparse);
359 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>(PolyType::ManyZeros);
360 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
363TEST_F(IPARecursiveTests, FullRecursiveVerifierMediumZeroPoly)
366 static constexpr size_t log_poly_length = 10;
367 static constexpr size_t poly_length = 1UL << log_poly_length;
372 auto x = this->random_element();
373 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x);
376 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, stdlib_claim, stdlib_transcript);
378 builder.finalize_circuit(
true);
379 info(
"Full IPA Recursive Verifier num finalized gates for length ",
380 1UL << log_poly_length,
382 builder.get_num_finalized_gates());
386TEST_F(IPARecursiveTests, FullRecursiveVerifierMediumRandom)
389 static constexpr size_t log_poly_length = 10;
390 static constexpr size_t poly_length = 1UL << log_poly_length;
394 auto [poly, x] = generate_poly_and_challenge<log_poly_length>();
395 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x);
398 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, stdlib_claim, stdlib_transcript);
400 builder.finalize_circuit(
true);
401 info(
"Full IPA Recursive Verifier num finalized gates for length ",
402 1UL << log_poly_length,
404 builder.get_num_finalized_gates());
408TEST_F(IPARecursiveTests, AccumulationAndFullRecursiveVerifierMediumRandom)
410 static constexpr size_t log_poly_length = 10;
419 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>();
420 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
422 auto [transcript_1, claim_1] = create_ipa_claim<log_poly_length>(
builder, poly1, x1);
423 auto [transcript_2, claim_2] = create_ipa_claim<log_poly_length>(
builder, poly2, x2);
427 auto [output_claim, ipa_proof] = RecursiveIPA::accumulate(this->
ck(), transcript_1, claim_1, transcript_2, claim_2);
428 output_claim.set_public();
430 builder.finalize_circuit(
false);
431 info(
"Circuit with 2 IPA Recursive Verifiers and IPA Accumulation num finalized gates = ",
432 builder.get_num_finalized_gates());
442 Curve::ScalarField::create_from_u512_as_witness(&root_rollup, output_claim.opening_pair.challenge.get_value());
444 Curve::ScalarField::create_from_u512_as_witness(&root_rollup, output_claim.opening_pair.evaluation.get_value());
445 ipa_claim.
commitment = Curve::AffineElement::from_witness(&root_rollup, output_claim.commitment.get_value());
446 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, ipa_claim, stdlib_verifier_transcript);
447 root_rollup.finalize_circuit(
true);
449 info(
"Full IPA Recursive Verifier num finalized gates for length ",
450 1UL << log_poly_length,
452 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) 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.