12#include <gtest/gtest.h>
16using FlavorTypes = ::testing::Types<MegaFlavor, MegaZKFlavor>;
31 size_t proof_length = compute_proof_length_for_export<Flavor>(num_public_inputs);
32 prover.
transcript->test_set_proof_parsing_state(0, proof_length);
51 const size_t virtual_log_n = Flavor::VIRTUAL_LOG_N;
53 size_t NUM_PUBLIC_INPUTS =
57 size_t frs_per_Fr = FrCodec::calc_num_fields<FF>();
58 size_t frs_per_G = FrCodec::calc_num_fields<Commitment>();
59 size_t frs_per_uni = MAX_PARTIAL_RELATION_LENGTH * frs_per_Fr;
63 manifest_expected.
add_entry(round,
"vk_hash", frs_per_Fr);
64 manifest_expected.
add_entry(round,
"public_input_0", frs_per_Fr);
65 for (
size_t i = 0; i < NUM_PUBLIC_INPUTS; i++) {
69 manifest_expected.
add_entry(round,
"Gemini:masking_poly_comm", frs_per_G);
71 manifest_expected.
add_entry(round,
"W_L", frs_per_G);
72 manifest_expected.
add_entry(round,
"W_R", frs_per_G);
73 manifest_expected.
add_entry(round,
"W_O", frs_per_G);
74 manifest_expected.
add_entry(round,
"ECC_OP_WIRE_1", frs_per_G);
75 manifest_expected.
add_entry(round,
"ECC_OP_WIRE_2", frs_per_G);
76 manifest_expected.
add_entry(round,
"ECC_OP_WIRE_3", frs_per_G);
77 manifest_expected.
add_entry(round,
"ECC_OP_WIRE_4", frs_per_G);
78 manifest_expected.
add_entry(round,
"CALLDATA", frs_per_G);
79 manifest_expected.
add_entry(round,
"CALLDATA_READ_COUNTS", frs_per_G);
80 manifest_expected.
add_entry(round,
"CALLDATA_READ_TAGS", frs_per_G);
81 manifest_expected.
add_entry(round,
"SECONDARY_CALLDATA", frs_per_G);
82 manifest_expected.
add_entry(round,
"SECONDARY_CALLDATA_READ_COUNTS", frs_per_G);
83 manifest_expected.
add_entry(round,
"SECONDARY_CALLDATA_READ_TAGS", frs_per_G);
84 manifest_expected.
add_entry(round,
"RETURN_DATA", frs_per_G);
85 manifest_expected.
add_entry(round,
"RETURN_DATA_READ_COUNTS", frs_per_G);
86 manifest_expected.
add_entry(round,
"RETURN_DATA_READ_TAGS", frs_per_G);
87 manifest_expected.
add_challenge(round, std::array{
"eta",
"eta_two",
"eta_three" });
90 manifest_expected.
add_entry(round,
"LOOKUP_READ_COUNTS", frs_per_G);
91 manifest_expected.
add_entry(round,
"LOOKUP_READ_TAGS", frs_per_G);
92 manifest_expected.
add_entry(round,
"W_4", frs_per_G);
93 manifest_expected.
add_challenge(round, std::array{
"beta",
"gamma" });
96 manifest_expected.
add_entry(round,
"LOOKUP_INVERSES", frs_per_G);
97 manifest_expected.
add_entry(round,
"CALLDATA_INVERSES", frs_per_G);
98 manifest_expected.
add_entry(round,
"SECONDARY_CALLDATA_INVERSES", frs_per_G);
99 manifest_expected.
add_entry(round,
"RETURN_DATA_INVERSES", frs_per_G);
100 manifest_expected.
add_entry(round,
"Z_PERM", frs_per_G);
105 manifest_expected.
add_challenge(round,
"Sumcheck:gate_challenge");
109 manifest_expected.
add_entry(round,
"Libra:concatenation_commitment", frs_per_G);
110 manifest_expected.
add_entry(round,
"Libra:Sum", frs_per_Fr);
115 for (
size_t i = 0; i < virtual_log_n; ++i) {
117 manifest_expected.
add_entry(round,
"Sumcheck:univariate_" + idx, frs_per_uni);
118 std::string label =
"Sumcheck:u_" + idx;
123 manifest_expected.
add_entry(round,
"Sumcheck:evaluations", frs_per_evals);
126 manifest_expected.
add_entry(round,
"Libra:claimed_evaluation", frs_per_Fr);
127 manifest_expected.
add_entry(round,
"Libra:grand_sum_commitment", frs_per_G);
128 manifest_expected.
add_entry(round,
"Libra:quotient_commitment", frs_per_G);
134 for (
size_t i = 1; i < virtual_log_n; ++i) {
136 manifest_expected.
add_entry(round,
"Gemini:FOLD_" + idx, frs_per_G);
140 for (
size_t i = 1; i <= virtual_log_n; ++i) {
142 manifest_expected.
add_entry(round,
"Gemini:a_" + idx, frs_per_Fr);
145 manifest_expected.
add_entry(round,
"Libra:concatenation_eval", frs_per_Fr);
146 manifest_expected.
add_entry(round,
"Libra:shifted_grand_sum_eval", frs_per_Fr);
147 manifest_expected.
add_entry(round,
"Libra:grand_sum_eval", frs_per_Fr);
148 manifest_expected.
add_entry(round,
"Libra:quotient_eval", frs_per_Fr);
153 manifest_expected.
add_entry(round,
"Shplonk:Q", frs_per_G);
157 manifest_expected.
add_entry(round,
"KZG:W", frs_per_G);
158 manifest_expected.
add_challenge(round,
"KZG:masking_challenge");
160 return manifest_expected;
166 for (
size_t i = 0; i < 3; ++i) {
169 builder.queue_ecc_mul_accum(point, scalar);
178 uint32_t a_idx =
builder.add_public_variable(
a);
179 uint32_t b_idx =
builder.add_variable(
b);
180 uint32_t c_idx =
builder.add_variable(c);
181 uint32_t d_idx =
builder.add_variable(d);
183 builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx,
FF(1),
FF(1),
FF(1),
FF(-1),
FF(0) });
200 TestFixture::generate_test_circuit(
builder);
205 Prover prover(prover_instance, verification_key);
206 prover.transcript->enable_manifest();
207 auto proof = prover.construct_proof();
210 auto manifest_expected = TestFixture::construct_mega_honk_manifest();
211 auto prover_manifest = prover.transcript->get_manifest();
213 ASSERT_GT(manifest_expected.size(), 0);
214 for (
size_t round = 0; round < manifest_expected.size(); ++round) {
215 if (prover_manifest[round] != manifest_expected[round]) {
216 info(
"Prover manifest discrepency in round ", round);
217 info(
"Prover manifest:");
218 prover_manifest[round].print();
219 info(
"Expected manifest:");
220 manifest_expected[round].print();
241 TestFixture::generate_test_circuit(
builder);
247 Prover prover(prover_instance, verification_key);
248 prover.transcript->enable_manifest();
249 auto proof = prover.construct_proof();
253 verifier_transcript->enable_manifest();
254 Verifier verifier(vk_and_hash, verifier_transcript);
255 [[maybe_unused]]
auto verifier_output = verifier.verify_proof(proof);
258 auto prover_manifest = prover.transcript->get_manifest();
260 auto verifier_manifest = verifier.get_transcript()->get_manifest();
263 ASSERT_GT(prover_manifest.size(), 0);
264 for (
size_t round = 0; round < prover_manifest.size(); ++round) {
265 if (prover_manifest[round] != verifier_manifest[round]) {
266 info(
"Prover/Verifier manifest discrepency in round ", round);
267 prover_manifest[round].print();
268 verifier_manifest[round].print();
284 auto transcript = Flavor::Transcript::prover_init_empty();
286 std::vector<std::string> challenge_labels{
"a",
"b",
"c",
"d",
"e",
"f" };
287 auto challenges = transcript->template get_challenges<FF>(challenge_labels);
289 for (
size_t i = 0; i < challenges.size(); ++i) {
290 ASSERT_NE(challenges[i], 0) <<
"Challenge " << i <<
" is 0";
292 constexpr uint32_t random_val{ 17 };
293 transcript->send_to_verifier(
"random val", random_val);
295 challenge_labels = {
"a",
"b",
"c" };
296 challenges = transcript->template get_challenges<FF>(challenge_labels);
297 ASSERT_NE(challenges[0], 0) <<
"Challenge a is 0";
298 ASSERT_NE(challenges[1], 0) <<
"Challenge b is 0";
299 ASSERT_NE(challenges[2], 0) <<
"Challenge c is 0";
314 this->generate_test_circuit(
builder);
320 Prover prover(prover_instance, verification_key);
321 auto proof = prover.construct_proof();
322 Verifier verifier(vk_and_hash);
323 EXPECT_TRUE(verifier.verify_proof(proof).result);
325 const size_t virtual_log_n = Flavor::VIRTUAL_LOG_N;
331 proof_structure.deserialize(
332 prover.transcript->test_get_proof_data(), verification_key->num_public_inputs, virtual_log_n);
333 proof_structure.serialize(prover.transcript->test_get_proof_data(), virtual_log_n);
335 proof = TestFixture::export_serialized_proof(prover, prover_instance->num_public_inputs());
337 Verifier verifier2(vk_and_hash);
338 EXPECT_TRUE(verifier2.verify_proof(proof).result);
340 Commitment one_group_val = Commitment::one();
342 proof_structure.z_perm_comm = one_group_val * rand_val;
343 proof = TestFixture::export_serialized_proof(prover, prover_instance->num_public_inputs());
345 Verifier verifier3(vk_and_hash);
346 EXPECT_TRUE(verifier3.verify_proof(proof).result);
348 proof_structure.serialize(prover.transcript->test_get_proof_data(), virtual_log_n);
349 proof = TestFixture::export_serialized_proof(prover, prover_instance->num_public_inputs());
351 Verifier verifier4(vk_and_hash);
352 EXPECT_FALSE(verifier4.verify_proof(proof).result);
354 proof_structure.deserialize(
355 prover.transcript->test_get_proof_data(), verification_key->num_public_inputs, virtual_log_n);
356 EXPECT_EQ(
static_cast<Commitment
>(proof_structure.z_perm_comm), one_group_val * rand_val);
static void SetUpTestSuite()
typename Flavor::Transcript::Proof Proof
static Proof export_serialized_proof(Prover &prover, const size_t num_public_inputs)
void generate_test_circuit(auto &builder)
static TranscriptManifest construct_mega_honk_manifest()
Construct a manifest for a Mega Honk proof.
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
static constexpr bool HasZK
typename Curve::ScalarField FF
static constexpr size_t NUM_ALL_ENTITIES
ECCVMCircuitBuilder CircuitBuilder
typename G1::affine_element Commitment
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Base Native verification key class.
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
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.
std::shared_ptr< Transcript > transcript
Manages the data that is propagated on the public inputs of an application/function circuit.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
Test utility for deserializing/serializing proof data into typed structures.
static field random_element(numeric::RNG *engine=nullptr) noexcept