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)
71 op_queue->no_op_ultra_only();
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));
120 const size_t num_mega_zk_pub_inputs)
125 constexpr size_t G = FrCodec::calc_num_fields<MZK::Commitment>();
126 constexpr size_t Fr = 1;
127 constexpr size_t JOINT_LOG_N = Trans::CONST_TRANSLATOR_LOG_N;
128 constexpr size_t LOG_MINI = Trans::LOG_MINI_CIRCUIT_SIZE;
131 constexpr size_t UNI = Trans::BATCHED_RELATION_PARTIAL_LENGTH;
138 for (
size_t i = 0; i < num_mega_zk_pub_inputs; ++i) {
141 m.
add_entry(round,
"Gemini:masking_poly_comm",
G);
145 for (
size_t i = 1; i <= 4; ++i) {
151 for (
const auto& label : {
"CALLDATA",
152 "CALLDATA_READ_COUNTS",
153 "CALLDATA_READ_TAGS",
154 "SECONDARY_CALLDATA",
155 "SECONDARY_CALLDATA_READ_COUNTS",
156 "SECONDARY_CALLDATA_READ_TAGS",
158 "RETURN_DATA_READ_COUNTS",
159 "RETURN_DATA_READ_TAGS" }) {
175 m.
add_entry(round,
"SECONDARY_CALLDATA_INVERSES",
G);
176 m.
add_entry(round,
"RETURN_DATA_INVERSES",
G);
180 m.
add_entry(round,
"Gemini:masking_poly_comm",
G);
181 for (
size_t i = 0; i < 4; ++i) {
184 m.
add_entry(round,
"CONCATENATED_NON_RANGE",
G);
185 for (
size_t i = 0; i < 5; ++i) {
194 for (
size_t i = 0; i < JOINT_LOG_N; ++i) {
200 m.
add_entry(round,
"Libra:concatenation_commitment",
G);
208 for (
size_t i = 0; i <= JOINT_LOG_N; ++i) {
213 if (i == mega_zk_log_n) {
214 m.
add_entry(round,
"Sumcheck:evaluations", MZK::NUM_ALL_ENTITIES);
216 if (i == JOINT_LOG_N) {
222 m.
add_entry(round,
"Sumcheck:minicircuit_evaluations", Trans::NUM_MINICIRCUIT_EVALUATIONS);
230 m.
add_entry(round,
"Sumcheck:evaluations_translator", Trans::NUM_FULL_CIRCUIT_EVALUATIONS);
231 m.
add_entry(round,
"Libra:claimed_evaluation",
Fr);
232 m.
add_entry(round,
"Libra:grand_sum_commitment",
G);
233 m.
add_entry(round,
"Libra:quotient_commitment",
G);
238 for (
size_t i = 1; i < JOINT_LOG_N; ++i) {
245 for (
size_t i = 1; i <= JOINT_LOG_N; ++i) {
248 m.
add_entry(round,
"Libra:concatenation_eval",
Fr);
249 m.
add_entry(round,
"Libra:shifted_grand_sum_eval",
Fr);
273 auto&
ck =
key->proving_key->commitment_key;
274 auto& polys =
key->proving_key->polynomials;
276 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)
297 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
304 const Fq accumulated_result = get_accumulated_result(translator_key);
305 const auto op_queue_wire_commitments = commit_op_queue_wires(translator_key);
328 auto joint_proof = prover.
prove(translator_key);
336 auto result = verifier.
verify(
337 joint_proof, evaluation_input_x, batching_challenge_v, accumulated_result, op_queue_wire_commitments);
339 EXPECT_TRUE(result.reduction_succeeded);
340 EXPECT_TRUE(result.pairing_points.check());
358 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
363 const Fq accumulated_result = get_accumulated_result(translator_key);
364 const auto op_queue_wire_commitments = commit_op_queue_wires(translator_key);
375 prover_transcript->enable_manifest();
378 auto joint_proof = prover.
prove(translator_key);
382 verifier_transcript->enable_manifest();
385 [[maybe_unused]]
auto _ = verifier.
verify(
386 joint_proof, evaluation_input_x, batching_challenge_v, accumulated_result, op_queue_wire_commitments);
388 auto prover_manifest = prover_transcript->get_manifest();
389 auto verifier_manifest = verifier_transcript->get_manifest();
391 ASSERT_GT(prover_manifest.size(), 0);
392 for (
size_t round = 0; round < prover_manifest.size(); ++round) {
393 ASSERT_EQ(prover_manifest[round], verifier_manifest[round])
394 <<
"Prover/verifier manifest discrepancy in round " << round;
412 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
423 const size_t mega_zk_log_n = mega_zk_inst->log_dyadic_size();
424 const size_t num_mega_zk_pub_inputs = mega_zk_inst->num_public_inputs();
428 prover_transcript->enable_manifest();
431 [[maybe_unused]]
auto __ = prover.
prove(translator_key);
433 auto prover_manifest = prover_transcript->get_manifest();
434 auto expected_manifest = build_expected_batched_manifest(mega_zk_log_n, num_mega_zk_pub_inputs);
436 ASSERT_EQ(prover_manifest.size(), expected_manifest.size()) <<
"Manifest round count mismatch";
437 for (
size_t round = 0; round < expected_manifest.size(); ++round) {
438 ASSERT_EQ(prover_manifest[round], expected_manifest[round]) <<
"Manifest discrepancy in round " << round;
456 auto translator_key = build_translator_key(batching_challenge_v, evaluation_input_x);
461 const Fq accumulated_result = get_accumulated_result(translator_key);
462 const auto op_queue_wire_commitments = commit_op_queue_wires(translator_key);
476 auto joint_proof = prover.
prove(translator_key);
481 auto result = verifier.
verify(
482 joint_proof, evaluation_input_x, batching_challenge_v, accumulated_result, op_queue_wire_commitments);
484 EXPECT_TRUE(result.reduction_succeeded);
485 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 TranscriptManifest build_expected_batched_manifest(const size_t mega_zk_log_n, const size_t num_mega_zk_pub_inputs)
Build the expected transcript manifest for a BatchedHonkTranslator proof.
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)
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 const size_t OP_QUEUE_SIZE
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
static constexpr size_t NUM_RANDOM_OPS_START
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