12#include <gtest/gtest.h>
48 static void add_random_ops(std::shared_ptr<bb::ECCOpQueue>& op_queue,
size_t count)
50 for (
size_t i = 0; i < count; i++) {
51 op_queue->random_op_ultra_only();
56 static void add_mixed_ops(std::shared_ptr<bb::ECCOpQueue>& op_queue,
size_t count = 100)
58 auto P1 = InnerG1::random_element();
59 auto P2 = InnerG1::random_element();
61 for (
size_t i = 0; i < count; i++) {
62 op_queue->add_accumulate(P1);
63 op_queue->mul_accumulate(P2, z);
65 op_queue->eq_and_reset();
70 const InnerBF& evaluation_challenge_x,
71 const size_t circuit_size_parameter = 500)
76 op_queue->no_op_ultra_only();
84 return InnerBuilder{ batching_challenge_v, evaluation_challenge_x, op_queue };
91 std::array<InnerFlavor::Commitment, InnerFlavor::NUM_OP_QUEUE_WIRES> op_queue_commitments;
92 op_queue_commitments[0] =
93 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.op);
94 op_queue_commitments[1] =
95 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.x_lo_y_hi);
96 op_queue_commitments[2] =
97 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.x_hi_z_1);
98 op_queue_commitments[3] =
99 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.y_lo_z_2);
100 return op_queue_commitments;
105 OuterBuilder*
builder,
const std::array<InnerFlavor::Commitment, InnerFlavor::NUM_OP_QUEUE_WIRES>& native_comms)
107 std::array<RecursiveFlavor::Commitment, InnerFlavor::NUM_OP_QUEUE_WIRES> stdlib_comms;
109 stdlib_comms[i] = RecursiveFlavor::Commitment::from_witness(
builder, native_comms[i]);
130 const InnerBF& evaluation_challenge_x,
131 const InnerBF& batching_challenge_v)
135 auto accumulated_result = TranslatorBF::from_witness(
builder, accumulated_result_native);
139 auto stdlib_evaluation_challenge_x = TranslatorBF::from_witness(
builder, evaluation_challenge_x);
140 auto stdlib_batching_challenge_v = TranslatorBF::from_witness(
builder, batching_challenge_v);
148 return { accumulated_result, stdlib_evaluation_challenge_x, stdlib_batching_challenge_v,
149 op_queue_commitments, accumulated_result_native, native_op_queue_commitments };
155 size_t circuit_size_parameter = 500)
169 InnerProver prover{ proving_key, prover_transcript };
178 auto recursive_inputs =
184 stdlib_proof_for_verifier,
185 recursive_inputs.evaluation_challenge_x,
186 recursive_inputs.batching_challenge_v,
187 recursive_inputs.accumulated_result,
188 recursive_inputs.op_queue_commitments };
189 auto recursive_result = verifier.reduce_to_pairing_check();
199 evaluation_challenge_x,
200 batching_challenge_v,
201 recursive_inputs.accumulated_result_native,
202 recursive_inputs.native_op_queue_commitments);
204 bool native_verified = native_result.
pairing_points.check() && native_result.reduction_succeeded;
206 auto recursive_verified = recursive_result.pairing_points.check();
207 EXPECT_EQ(recursive_verified, native_verified);
210 auto recursive_vk = verifier.get_verification_key();
212 for (
auto [vk_poly, native_vk_poly] :
zip_view(recursive_vk->get_all(), native_vk->get_all())) {
213 EXPECT_EQ(vk_poly.get_value(), native_vk_poly);
217 auto outer_verification_key =
220 return {
std::move(outer_circuit), outer_verification_key };
228 info(
"Recursive Verifier: num gates = ", outer_circuit.get_num_finalized_gates_inefficient());
229 EXPECT_EQ(outer_circuit.failed(),
false) << outer_circuit.err();
234 OuterProver prover(prover_instance, outer_verification_key);
239 ASSERT_TRUE(verified);
255 InnerProver prover{ proving_key, prover_transcript };
261 auto proof_data = prover.transcript->test_get_proof_data();
265 auto original_data = prover.transcript->test_get_proof_data();
266 ASSERT_EQ(proof_data.size(), original_data.size());
267 EXPECT_EQ(proof_data, original_data);
279 typename InnerFlavor::Transcript::Proof& proof,
286 structured_proof.deserialize(prover.
transcript->test_get_proof_data(), 0, LOG_N);
288 switch (tamper_type) {
291 structured_proof.sumcheck_univariates[0].value_at(0) += delta;
292 structured_proof.sumcheck_univariates[0].value_at(1) -= delta;
308 structured_proof.serialize(prover.
transcript->test_get_proof_data(), LOG_N);
315 for (
size_t idx = 0; idx < static_cast<size_t>(
TamperType::END); idx++) {
326 InnerProver prover{ proving_key, prover_transcript };
336 auto recursive_inputs =
344 stdlib_proof_for_verifier,
345 recursive_inputs.evaluation_challenge_x,
346 recursive_inputs.batching_challenge_v,
347 recursive_inputs.accumulated_result,
348 recursive_inputs.op_queue_commitments };
349 auto recursive_result = verifier.reduce_to_pairing_check();
354 EXPECT_FALSE(recursive_result.pairing_points.check());
367 compare_ultra_blocks_and_verification_keys<OuterFlavor>({ outer_circuit_256.blocks, outer_circuit_512.blocks },
368 { verification_key_256, verification_key_512 });
385 InnerProver prover{ proving_key, prover_transcript };
394 auto recursive_inputs =
400 stdlib_proof_for_verifier,
401 recursive_inputs.evaluation_challenge_x,
402 recursive_inputs.batching_challenge_v,
403 recursive_inputs.accumulated_result,
404 recursive_inputs.op_queue_commitments };
405 auto recursive_result = verifier.reduce_to_pairing_check();
407 recursive_result.pairing_points.fix_witness();
413 EXPECT_EQ(outer_circuit.
failed(),
false) << outer_circuit.
err();
418 auto [cc, variables_in_one_gate] = graph.analyze_circuit(
true);
420 EXPECT_EQ(variables_in_one_gate.size(), 0);
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
const std::string & err() const
static const size_t OP_QUEUE_SIZE
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
static constexpr size_t NUM_RANDOM_OPS_END
static constexpr size_t NUM_RANDOM_OPS_START
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
BaseTranscript< Codec, HashFunction > Transcript
static constexpr size_t CONST_TRANSLATOR_LOG_N
static constexpr size_t NUM_OP_QUEUE_WIRES
static constexpr size_t PROOF_LENGTH
TranslatorCircuitBuilder CircuitBuilder
Curve::AffineElement Commitment
uint256_t get_accumulated_result() const
Extract the accumulated result from the circuit.
std::shared_ptr< TranslatorProvingKey > key
std::shared_ptr< Transcript > transcript
HonkProof construct_proof()
The recursive counterpart of the native Translator flavor.
TranslatorFlavor NativeFlavor
UltraCircuitBuilder CircuitBuilder
Test suite for standalone recursive verification of translation proofs.
@ MODIFY_SUMCHECK_UNIVARIATE
TranslatorRecursiveFlavor::BF TranslatorBF
static void add_mixed_ops(std::shared_ptr< bb::ECCOpQueue > &op_queue, size_t count=100)
static void SetUpTestSuite()
static InnerBuilder generate_test_circuit(const InnerBF &batching_challenge_v, const InnerBF &evaluation_challenge_x, const size_t circuit_size_parameter=500)
static void test_recursive_verification_fails()
std::conditional_t< IsMegaBuilder< OuterBuilder >, MegaFlavor, UltraFlavor > OuterFlavor
static RecursiveVerifierInputs create_recursive_verifier_inputs(OuterBuilder *builder, const InnerProver &prover, const InnerBF &evaluation_challenge_x, const InnerBF &batching_challenge_v)
static void test_independent_vk_hash()
static void test_static_analysis()
Static analysis (boomerang detection) of the translator recursive verifier circuit.
static void test_recursive_verification()
static void add_random_ops(std::shared_ptr< bb::ECCOpQueue > &op_queue, size_t count)
InnerFlavor::Commitment InnerG1
static void test_structured_proof_round_trip()
Verify that StructuredProof<TranslatorFlavor> can round-trip serialize/deserialize a proof.
static std::array< RecursiveFlavor::Commitment, InnerFlavor::NUM_OP_QUEUE_WIRES > create_stdlib_op_queue_commitments(OuterBuilder *builder, const std::array< InnerFlavor::Commitment, InnerFlavor::NUM_OP_QUEUE_WIRES > &native_comms)
static std::tuple< OuterBuilder, std::shared_ptr< OuterFlavor::VerificationKey > > create_recursive_verifier_circuit(size_t circuit_size_parameter=500)
static std::array< InnerFlavor::Commitment, InnerFlavor::NUM_OP_QUEUE_WIRES > create_native_op_queue_commitments(const std::shared_ptr< TranslatorProvingKey > &proving_key)
static void tamper_translator_proof(InnerProver &prover, typename InnerFlavor::Transcript::Proof &proof, TamperType tamper_type)
Translator verifier class that verifies the proof of the Translator circuit.
ReductionResult reduce_to_pairing_check()
Reduce the translator proof to a pairing check.
std::shared_ptr< VerificationKey > get_verification_key() const
Get the verification key.
void finalize_circuit(const bool ensure_nonzero)
Output verify_proof(const Proof &proof)
Perform ultra verification.
A simple wrapper around a vector of stdlib field elements representing a proof.
Manages the data that is propagated on the public inputs of an application/function circuit.
PairingInputs pairing_inputs
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TranslatorVerifier_< TranslatorRecursiveFlavor > TranslatorRecursiveVerifier
TEST_F(IPATest, ChallengesAreZero)
TranslatorVerifier_< TranslatorFlavor > TranslatorVerifier
StaticAnalyzer_< bb::fr, bb::UltraCircuitBuilder > UltraStaticAnalyzer
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...
static OriginTag constant()
Test utility for deserializing/serializing proof data into typed structures.
PairingPoints pairing_points
static field random_element(numeric::RNG *engine=nullptr) noexcept
uint32_t set_public(Builder *ctx=nullptr)
Set the witness indices for the pairing points to public.