22 using Fr =
typename NativeCurve::ScalarField;
23 using GroupElement =
typename NativeCurve::Element;
27 using Commitment =
typename NativeCurve::AffineElement;
35 enum class FailureMode :
std::uint8_t { None, A_Zero, G_Zero, ChangePoly };
52 template <
size_t log_poly_length>
57 EXPECT_EQ(1UL << log_poly_length, poly.
size());
58 Commitment commitment = this->
commit(poly);
67 std::vector<DataType> proof;
69 switch (failure_mode) {
70 case FailureMode::None:
72 NativeIPA::compute_opening_proof(this->
ck(), prover_claim, prover_transcript);
73 proof = prover_transcript->export_proof();
75 case FailureMode::A_Zero:
76 NativeIPA::compute_opening_proof(this->
ck(), prover_claim, prover_transcript);
77 proof = prover_transcript->export_proof();
81 case FailureMode::G_Zero: {
82 NativeIPA::compute_opening_proof(this->
ck(), prover_claim, prover_transcript);
83 proof = prover_transcript->export_proof();
85 const size_t comm_frs = 2;
86 const size_t offset = log_poly_length * 2 * comm_frs;
87 auto element_frs = std::span{ proof }.subspan(
offset, comm_frs);
89 Commitment op_commitment = NativeTranscript::template deserialize<Commitment>(element_frs);
90 Commitment new_op_commitment = op_commitment + op_commitment;
92 std::copy(new_op_commitment_reserialized.begin(),
93 new_op_commitment_reserialized.end(),
97 case FailureMode::ChangePoly:
100 NativeIPA::add_claim_to_hash_buffer(this->
ck(), prover_claim, prover_transcript);
102 auto [new_poly, new_x] = generate_poly_and_challenge<log_poly_length>();
103 auto new_eval = new_poly.evaluate(new_x);
107 NativeIPA::compute_opening_proof_internal(this->
ck(), new_prover_claim, prover_transcript);
108 proof = prover_transcript->export_proof();
114 verifier_transcript->load_proof(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);
131 return { recursive_verifier_transcript, stdlib_opening_claim };
141 template <
size_t log_poly_length>
142 Builder build_ipa_recursive_verifier_circuit(
Polynomial& poly,
Fr x, FailureMode failure_mode = FailureMode::None)
147 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x, failure_mode);
149 RecursiveIPA::reduce_verify(stdlib_claim, stdlib_transcript);
151 builder.finalize_circuit(
true);
155 enum class PolyType :
std::uint8_t { Random, ManyZeros, Sparse, Zero };
157 template <
size_t log_poly_length>
161 static constexpr size_t poly_length = 1UL << log_poly_length;
164 case PolyType::Random:
167 case PolyType::ManyZeros:
169 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) {
175 size_t idx =
static_cast<size_t>(this->
engine->get_random_uint64() % poly_length);
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();
240 verifier_transcript->load_proof(ipa_proof);
242 auto result = NativeIPA::reduce_verify(this->
vk(), opening_claim, verifier_transcript);
253TEST_F(IPARecursiveTests, RecursiveSmallSparse)
255 static constexpr size_t log_poly_length = 2;
256 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::ManyZeros);
257 test_recursive_ipa<log_poly_length>(poly, x);
263TEST_F(IPARecursiveTests, RecursiveMediumManyZeros)
265 static constexpr size_t log_poly_length = 10;
266 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Sparse);
267 test_recursive_ipa<log_poly_length>(poly, x);
270TEST_F(IPARecursiveTests, RecursiveMediumZeroPoly)
272 static constexpr size_t log_poly_length = 10;
273 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Zero);
274 test_recursive_ipa<log_poly_length>(poly, x);
277TEST_F(IPARecursiveTests, RecursiveMediumZeroChallenge)
279 static constexpr size_t log_poly_length = 10;
280 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
281 test_recursive_ipa<log_poly_length>(poly,
Fr::zero());
284TEST_F(IPARecursiveTests, RecursiveMediumZeroEvaluation)
286 static constexpr size_t log_poly_length = 10;
287 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
288 auto initial_evaluation = poly.
evaluate(x);
289 poly.
at(1) -= initial_evaluation / x;
290 test_recursive_ipa<log_poly_length>(poly, x);
296TEST_F(IPARecursiveTests, RecursiveLargeRandom)
298 static constexpr size_t log_poly_length = CONST_ECCVM_LOG_N;
299 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
300 test_recursive_ipa<log_poly_length>(poly, x);
307TEST_F(IPARecursiveTests, RecursiveMediumRandomFailure)
309 static constexpr size_t log_poly_length = 10;
310 auto [poly, x] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
311 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::A_Zero);
312 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::G_Zero);
313 test_recursive_ipa<log_poly_length>(poly, x, FailureMode::ChangePoly);
319TEST_F(IPARecursiveTests, AccumulateSmallRandom)
321 static constexpr size_t log_poly_length = 2;
322 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
323 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>(PolyType::Random);
324 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
330TEST_F(IPARecursiveTests, AccumulateMediumRandom)
332 static constexpr size_t log_poly_length = 10;
333 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>();
334 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
335 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
337TEST_F(IPARecursiveTests, AccumulateMediumFirstZeroPoly)
339 static constexpr size_t log_poly_length = 10;
340 static constexpr size_t poly_length = 1UL << log_poly_length;
342 auto x1 = this->random_element();
343 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
344 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
346TEST_F(IPARecursiveTests, AccumulateMediumBothZeroPoly)
348 static constexpr size_t log_poly_length = 10;
349 static constexpr size_t poly_length = 1UL << log_poly_length;
352 auto x1 = this->random_element();
353 auto x2 = this->random_element();
354 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
356TEST_F(IPARecursiveTests, AccumulateMediumSparseManyZeros)
358 static constexpr size_t log_poly_length = 10;
359 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>(PolyType::Sparse);
360 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>(PolyType::ManyZeros);
361 test_accumulation<log_poly_length>(poly1, poly2, x1, x2);
364TEST_F(IPARecursiveTests, FullRecursiveVerifierMediumZeroPoly)
367 static constexpr size_t log_poly_length = 10;
368 static constexpr size_t poly_length = 1UL << log_poly_length;
373 auto x = this->random_element();
374 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x);
377 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, stdlib_claim, stdlib_transcript);
379 builder.finalize_circuit(
true);
380 info(
"Full IPA Recursive Verifier num finalized gates for length ",
381 1UL << log_poly_length,
383 builder.get_num_finalized_gates());
387TEST_F(IPARecursiveTests, FullRecursiveVerifierMediumRandom)
390 static constexpr size_t log_poly_length = 10;
391 static constexpr size_t poly_length = 1UL << log_poly_length;
395 auto [poly, x] = generate_poly_and_challenge<log_poly_length>();
396 auto [stdlib_transcript, stdlib_claim] = create_ipa_claim<log_poly_length>(
builder, poly, x);
399 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, stdlib_claim, stdlib_transcript);
401 builder.finalize_circuit(
true);
402 info(
"Full IPA Recursive Verifier num finalized gates for length ",
403 1UL << log_poly_length,
405 builder.get_num_finalized_gates());
409TEST_F(IPARecursiveTests, AccumulationAndFullRecursiveVerifierMediumRandom)
411 static constexpr size_t log_poly_length = 10;
420 auto [poly1, x1] = generate_poly_and_challenge<log_poly_length>();
421 auto [poly2, x2] = generate_poly_and_challenge<log_poly_length>();
423 auto [transcript_1, claim_1] = create_ipa_claim<log_poly_length>(
builder, poly1, x1);
424 auto [transcript_2, claim_2] = create_ipa_claim<log_poly_length>(
builder, poly2, x2);
428 auto [output_claim, ipa_proof] = RecursiveIPA::accumulate(this->
ck(), transcript_1, claim_1, transcript_2, claim_2);
429 output_claim.set_public();
431 builder.finalize_circuit(
false);
432 info(
"Circuit with 2 IPA Recursive Verifiers and IPA Accumulation num finalized gates = ",
433 builder.get_num_finalized_gates());
441 stdlib_verifier_transcript->load_proof(StdlibProof(root_rollup, ipa_proof));
444 Curve::ScalarField::create_from_u512_as_witness(&root_rollup, output_claim.opening_pair.challenge.get_value());
446 Curve::ScalarField::create_from_u512_as_witness(&root_rollup, output_claim.opening_pair.evaluation.get_value());
447 ipa_claim.
commitment = Curve::AffineElement::from_witness(&root_rollup, output_claim.commitment.get_value());
448 auto result = RecursiveIPA::full_verify_recursive(stdlib_pcs_vkey, ipa_claim, stdlib_verifier_transcript);
449 root_rollup.finalize_circuit(
true);
451 info(
"Full IPA Recursive Verifier num finalized gates for length ",
452 1UL << log_poly_length,
454 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)
Serialize a size_t to a vector of field elements.
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.
A simple wrapper around a vector of stdlib field elements representing a proof.
stdlib::Proof< Builder > StdlibProof
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.
static void add_default_to_public_inputs(Builder &builder)
Adds default public inputs to the builder.