26#include <gtest/gtest.h>
45 for (
size_t i = 0; i < count; i++) {
46 op_queue->random_op_ultra_only();
52 auto P1 = G1::random_element();
53 auto P2 = G1::random_element();
55 for (
size_t i = 0; i < count; i++) {
56 op_queue->add_accumulate(P1);
57 op_queue->mul_accumulate(P2, z);
59 op_queue->eq_and_reset();
67 const Fq& evaluation_input_x,
68 size_t circuit_size_param = 500)
72 op_queue->construct_zk_columns();
77 op_queue->merge_fixed_append(op_queue->get_append_offset());
90 auto& polys =
key->proving_key->polynomials;
91 return Fq(
uint256_t(polys.accumulators_binary_limbs_0[RESULT_ROW]) +
92 (
uint256_t(polys.accumulators_binary_limbs_1[RESULT_ROW]) << 68) +
93 (
uint256_t(polys.accumulators_binary_limbs_2[RESULT_ROW]) << 136) +
94 (
uint256_t(polys.accumulators_binary_limbs_3[RESULT_ROW]) << 204));
123 constexpr size_t G = FrCodec::calc_num_fields<MZK::Commitment>();
124 constexpr size_t Fr = 1;
125 constexpr size_t JOINT_LOG_N = Trans::CONST_TRANSLATOR_LOG_N;
126 constexpr size_t LOG_MINI = Trans::LOG_MINI_CIRCUIT_SIZE;
133 for (
size_t i = 0; i < num_mega_zk_pub_inputs; ++i) {
139 for (
size_t i = 1; i <= 4; ++i) {
143 for (
const auto& label : {
"KERNEL_CALLDATA",
144 "KERNEL_CALLDATA_READ_COUNTS",
145 "FIRST_APP_CALLDATA",
146 "FIRST_APP_CALLDATA_READ_COUNTS",
147 "SECOND_APP_CALLDATA",
148 "SECOND_APP_CALLDATA_READ_COUNTS",
149 "THIRD_APP_CALLDATA",
150 "THIRD_APP_CALLDATA_READ_COUNTS",
152 "RETURN_DATA_READ_COUNTS" }) {
167 m.
add_entry(round,
"KERNEL_CALLDATA_INVERSES",
G);
168 m.
add_entry(round,
"FIRST_APP_CALLDATA_INVERSES",
G);
169 m.
add_entry(round,
"SECOND_APP_CALLDATA_INVERSES",
G);
170 m.
add_entry(round,
"THIRD_APP_CALLDATA_INVERSES",
G);
171 m.
add_entry(round,
"RETURN_DATA_INVERSES",
G);
175 m.
add_entry(round,
"Gemini:masking_poly_comm",
G);
176 for (
size_t i = 0; i < 4; ++i) {
179 m.
add_entry(round,
"CONCATENATED_NON_RANGE",
G);
180 for (
size_t i = 0; i < 5; ++i) {
193 m.
add_entry(round,
"Libra:concatenation_commitment",
G);
199 for (
size_t i = 0; i < JOINT_LOG_N; ++i) {
203 m.
add_entry(round,
"Sumcheck:minicircuit_evaluations", Trans::NUM_MINICIRCUIT_EVALUATIONS);
214 m.
add_entry(round,
"Sumcheck:evaluations", MZK::NUM_ALL_ENTITIES);
215 m.
add_entry(round,
"Sumcheck:evaluations_translator", Trans::NUM_FULL_CIRCUIT_EVALUATIONS);
216 m.
add_entry(round,
"Libra:claimed_evaluation",
Fr);
217 m.
add_entry(round,
"Libra:grand_sum_commitment",
G);
218 m.
add_entry(round,
"Libra:quotient_commitment",
G);
223 for (
size_t i = 1; i < JOINT_LOG_N; ++i) {
230 for (
size_t i = 1; i <= JOINT_LOG_N; ++i) {
233 m.
add_entry(round,
"Libra:concatenation_eval",
Fr);
234 m.
add_entry(round,
"Libra:shifted_grand_sum_eval",
Fr);
258 auto&
ck =
key->proving_key->commitment_key;
259 auto& polys =
key->proving_key->polynomials;
261 ck.commit(polys.op),
ck.commit(polys.x_lo_y_hi),
ck.commit(polys.x_hi_z_1),
ck.commit(polys.y_lo_z_2)
282 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
289 const Fq accumulated_result = get_accumulated_result(translator_key);
290 const auto op_queue_wire_commitments = commit_op_queue_wires(translator_key);
313 auto joint_proof = prover.
prove(translator_key);
321 auto result = verifier.
verify(
322 joint_proof, evaluation_input_x, batching_challenge_v, accumulated_result, op_queue_wire_commitments);
324 EXPECT_TRUE(result.reduction_succeeded);
325 EXPECT_TRUE(result.pairing_points.check());
343 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
348 const Fq accumulated_result = get_accumulated_result(translator_key);
349 const auto op_queue_wire_commitments = commit_op_queue_wires(translator_key);
360 prover_transcript->enable_manifest();
363 auto joint_proof = prover.
prove(translator_key);
367 verifier_transcript->enable_manifest();
370 [[maybe_unused]]
auto _ = verifier.
verify(
371 joint_proof, evaluation_input_x, batching_challenge_v, accumulated_result, op_queue_wire_commitments);
373 auto prover_manifest = prover_transcript->get_manifest();
374 auto verifier_manifest = verifier_transcript->get_manifest();
376 ASSERT_GT(prover_manifest.size(), 0);
377 for (
size_t round = 0; round < prover_manifest.size(); ++round) {
378 ASSERT_EQ(prover_manifest[round], verifier_manifest[round])
379 <<
"Prover/verifier manifest discrepancy in round " << round;
397 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
408 const size_t num_mega_zk_pub_inputs = mega_zk_inst->num_public_inputs();
412 prover_transcript->enable_manifest();
415 [[maybe_unused]]
auto __ = prover.
prove(translator_key);
417 auto prover_manifest = prover_transcript->get_manifest();
418 auto expected_manifest = build_expected_batched_manifest(num_mega_zk_pub_inputs);
420 ASSERT_EQ(prover_manifest.size(), expected_manifest.size()) <<
"Manifest round count mismatch";
421 for (
size_t round = 0; round < expected_manifest.size(); ++round) {
422 ASSERT_EQ(prover_manifest[round], expected_manifest[round]) <<
"Manifest discrepancy in round " << round;
440 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
445 const Fq accumulated_result = get_accumulated_result(translator_key);
446 const auto op_queue_wire_commitments = commit_op_queue_wires(translator_key);
460 auto joint_proof = prover.
prove(translator_key);
465 auto result = verifier.
verify(
466 joint_proof, evaluation_input_x, batching_challenge_v, accumulated_result, op_queue_wire_commitments);
468 EXPECT_TRUE(result.reduction_succeeded);
469 EXPECT_TRUE(result.pairing_points.check());
TEST_F(BatchedHonkTranslatorTests, ProveAndVerify)
static std::array< TranslatorFlavor::Commitment, TranslatorFlavor::NUM_OP_QUEUE_WIRES > commit_op_queue_wires(const std::shared_ptr< TranslatorProvingKey > &key)
Commit to the four op-queue wire polynomials.
TranslatorFlavor::Commitment G1
static void add_mixed_ops(std::shared_ptr< ECCOpQueue > &op_queue, size_t count=100)
static void SetUpTestSuite()
static Fq get_accumulated_result(const std::shared_ptr< TranslatorProvingKey > &key)
Read accumulated_result from the translator witness polynomials.
static std::shared_ptr< TranslatorProvingKey > build_translator_key(const Fq &batching_challenge_v, const Fq &evaluation_input_x, size_t circuit_size_param=500)
Build a translator circuit on a fresh op queue with random challenges.
static void add_random_ops(std::shared_ptr< ECCOpQueue > &op_queue, size_t count)
static TranscriptManifest build_expected_batched_manifest(const size_t num_mega_zk_pub_inputs)
Build the expected transcript manifest for a BatchedHonkTranslator proof.
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
Prover for the batched MegaZK circuit + translator sumcheck and PCS.
static constexpr size_t JOINT_LOG_N
HonkProof prove(std::shared_ptr< TranslatorProvingKey > translator_proving_key)
HonkProof prove_mega_zk_oink()
Verifier for the batched MegaZK circuit + translator sumcheck and PCS.
ReductionResult verify(const Proof &joint_proof, const TransBF &evaluation_input_x, const TransBF &batching_challenge_v, const TransBF &accumulated_result, const std::array< Commitment, TranslatorFlavor::NUM_OP_QUEUE_WIRES > &op_queue_wire_commitments)
Phase 2: Verify translator Oink + joint sumcheck + joint PCS.
OinkResult verify_mega_zk_oink(const Proof &mega_zk_proof)
Phase 1: Verify the MegaZK Oink phase on the shared transcript.
static void construct_simple_circuit(MegaBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
Child class of MegaFlavor that runs with ZK Sumcheck.
MegaFlavor::VKAndHash VKAndHash
static void construct_arithmetic_circuit(Builder &builder, const size_t target_log2_dyadic_size=4, bool include_public_inputs=true)
Populate a builder with a specified number of arithmetic gates; includes a PI.
Base Native verification key class.
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
void add_entry(size_t round, const std::string &element_label, size_t element_size)
void add_challenge(size_t round, const std::string &label)
Add a single challenge label to the manifest for the given round.
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
static constexpr size_t NUM_RANDOM_OPS_END
Curve::AffineElement Commitment
static constexpr size_t RESULT_ROW
#define G(r, i, a, b, c, d)
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
BaseTranscript< FrCodec, bb::crypto::Poseidon2< bb::crypto::Poseidon2Bn254ScalarFieldParams > > NativeTranscript
CommitmentKey< Curve > ck
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
static field random_element(numeric::RNG *engine=nullptr) noexcept