15#include "gtest/gtest.h"
19#ifdef STARKNET_GARAGA_FLAVORS
23 UltraStarknetZKFlavor,
29 ::testing::Types<UltraFlavor, UltraKeccakFlavor, UltraRollupFlavor, UltraZKFlavor, UltraKeccakZKFlavor>;
65 size_t data_types_per_Frs = [] {
66 if constexpr (IsKeccakFlavor<Flavor>) {
67 return U256Codec::calc_num_fields<FF>();
69 return FrCodec::calc_num_fields<FF>();
72 size_t data_types_per_G = [] {
73 if constexpr (IsKeccakFlavor<Flavor>) {
74 return U256Codec::calc_num_fields<Commitment>();
76 return FrCodec::calc_num_fields<Commitment>();
79 size_t frs_per_uni = MAX_PARTIAL_RELATION_LENGTH * data_types_per_Frs;
83 manifest_expected.
add_entry(round,
"vk_hash", data_types_per_Frs);
85 manifest_expected.
add_entry(round,
"public_input_0", data_types_per_Frs);
86 constexpr size_t PUBLIC_INPUTS_SIZE =
88 for (
size_t i = 0; i < PUBLIC_INPUTS_SIZE; i++) {
94 manifest_expected.
add_entry(round,
"Gemini:masking_poly_comm", data_types_per_G);
96 manifest_expected.
add_entry(round,
"W_L", data_types_per_G);
97 manifest_expected.
add_entry(round,
"W_R", data_types_per_G);
98 manifest_expected.
add_entry(round,
"W_O", data_types_per_G);
99 manifest_expected.
add_challenge(round, std::array{
"eta",
"eta_two",
"eta_three" });
102 manifest_expected.
add_entry(round,
"LOOKUP_READ_COUNTS", data_types_per_G);
103 manifest_expected.
add_entry(round,
"LOOKUP_READ_TAGS", data_types_per_G);
104 manifest_expected.
add_entry(round,
"W_4", data_types_per_G);
105 manifest_expected.
add_challenge(round, std::array{
"beta",
"gamma" });
108 manifest_expected.
add_entry(round,
"LOOKUP_INVERSES", data_types_per_G);
109 manifest_expected.
add_entry(round,
"Z_PERM", data_types_per_G);
114 manifest_expected.
add_challenge(round,
"Sumcheck:gate_challenge");
118 manifest_expected.
add_entry(round,
"Libra:concatenation_commitment", data_types_per_G);
119 manifest_expected.
add_entry(round,
"Libra:Sum", data_types_per_Frs);
124 for (
size_t i = 0; i < virtual_log_n; ++i) {
126 manifest_expected.
add_entry(round,
"Sumcheck:univariate_" + idx, frs_per_uni);
127 std::string label =
"Sumcheck:u_" + idx;
132 manifest_expected.
add_entry(round,
"Sumcheck:evaluations", frs_per_evals);
135 manifest_expected.
add_entry(round,
"Libra:claimed_evaluation", data_types_per_Frs);
136 manifest_expected.
add_entry(round,
"Libra:grand_sum_commitment", data_types_per_G);
137 manifest_expected.
add_entry(round,
"Libra:quotient_commitment", data_types_per_G);
143 for (
size_t i = 1; i < virtual_log_n; ++i) {
145 manifest_expected.
add_entry(round,
"Gemini:FOLD_" + idx, data_types_per_G);
149 for (
size_t i = 1; i <= virtual_log_n; ++i) {
151 manifest_expected.
add_entry(round,
"Gemini:a_" + idx, data_types_per_Frs);
155 manifest_expected.
add_entry(round,
"Libra:concatenation_eval", data_types_per_Frs);
156 manifest_expected.
add_entry(round,
"Libra:shifted_grand_sum_eval", data_types_per_Frs);
157 manifest_expected.
add_entry(round,
"Libra:grand_sum_eval", data_types_per_Frs);
158 manifest_expected.
add_entry(round,
"Libra:quotient_eval", data_types_per_Frs);
163 manifest_expected.
add_entry(round,
"Shplonk:Q", data_types_per_G);
167 manifest_expected.
add_entry(round,
"KZG:W", data_types_per_G);
168 manifest_expected.
add_challenge(round,
"KZG:masking_challenge");
170 return manifest_expected;
178 if constexpr (HasIPAAccumulator<Flavor>) {
193 if constexpr (HasIPAAccumulator<Flavor>) {
194 auto [stdlib_opening_claim, ipa_proof] =
196 stdlib_opening_claim.set_public();
205 prover.
transcript->test_set_proof_parsing_state(0, proof_length);
219 auto builder =
typename TestFixture::Builder();
220 TestFixture::generate_test_circuit(
builder);
225 typename TestFixture::Prover prover(prover_instance, verification_key);
226 prover.transcript->enable_manifest();
227 auto proof = prover.construct_proof();
230 auto manifest_expected = TestFixture::construct_ultra_honk_manifest(prover.prover_instance->log_dyadic_size());
231 auto prover_manifest = prover.transcript->get_manifest();
233 manifest_expected.print();
234 prover_manifest.print();
235 ASSERT_GT(manifest_expected.size(), 0);
236 for (
size_t round = 0; round < manifest_expected.size(); ++round) {
237 if (prover_manifest[round] != manifest_expected[round]) {
238 info(
"Prover manifest discrepency in round ", round);
239 info(
"Prover manifest:");
240 prover_manifest[round].print();
241 info(
"Expected manifest:");
242 manifest_expected[round].print();
256 auto builder =
typename TestFixture::Builder();
257 TestFixture::generate_test_circuit(
builder);
262 typename TestFixture::Prover prover(prover_instance, verification_key);
263 prover.transcript->enable_manifest();
264 auto proof = prover.construct_proof();
267 typename TestFixture::Verifier verifier(verification_key);
268 verifier.transcript->enable_manifest();
269 typename TestFixture::Proof honk_proof;
270 typename TestFixture::Proof ipa_proof;
271 if constexpr (HasIPAAccumulator<TypeParam>) {
273 const size_t HONK_PROOF_LENGTH = TypeParam::PROOF_LENGTH_WITHOUT_PUB_INPUTS() - IPA_PROOF_LENGTH;
274 const size_t num_public_inputs =
static_cast<uint32_t
>(verification_key->num_public_inputs);
277 ASSERT_EQ(proof.size(), HONK_PROOF_LENGTH + IPA_PROOF_LENGTH + num_public_inputs);
280 static_cast<std::ptrdiff_t>(HONK_PROOF_LENGTH + num_public_inputs);
282 honk_proof =
typename TestFixture::Proof(proof.begin(), proof.begin() + honk_proof_with_pub_inputs_length);
283 ipa_proof =
typename TestFixture::Proof(proof.begin() + honk_proof_with_pub_inputs_length, proof.end());
287 [[maybe_unused]]
auto _ = verifier.template verify_proof<typename TestFixture::IO>(honk_proof, ipa_proof);
290 auto prover_manifest = prover.transcript->get_manifest();
291 auto verifier_manifest = verifier.transcript->get_manifest();
294 ASSERT_GT(prover_manifest.size(), 0);
295 for (
size_t round = 0; round < prover_manifest.size(); ++round) {
296 ASSERT_EQ(prover_manifest[round], verifier_manifest[round])
297 <<
"Prover/Verifier manifest discrepency in round " << round;
311 auto transcript = TypeParam::Transcript::prover_init_empty();
313 std::vector<std::string> challenge_labels{
"a",
"b",
"c",
"d",
"e",
"f" };
314 auto challenges = transcript->template get_challenges<FF>(challenge_labels);
316 for (
size_t i = 0; i < challenges.size(); ++i) {
317 ASSERT_NE(challenges[i], 0) <<
"Challenge " << i <<
" is 0";
319 constexpr uint32_t random_val{ 17 };
320 transcript->send_to_verifier(
"random val", random_val);
322 challenge_labels = {
"a",
"b",
"c" };
323 challenges = transcript->template get_challenges<FF>(challenge_labels);
324 ASSERT_NE(challenges[0], 0) <<
"Challenge a is 0";
325 ASSERT_NE(challenges[1], 0) <<
"Challenge b is 0";
326 ASSERT_NE(challenges[2], 0) <<
"Challenge c is 0";
335 auto builder =
typename TestFixture::Builder();
336 if constexpr (IsAnyOf<TypeParam, UltraRollupFlavor, UltraKeccakFlavor, UltraKeccakZKFlavor>) {
337 GTEST_SKIP() <<
"Not built for this parameter";
339 TestFixture::generate_test_circuit(
builder);
344 typename TestFixture::Prover prover(prover_instance, verification_key);
345 auto proof = prover.construct_proof();
346 typename TestFixture::Verifier verifier(verification_key);
348 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
352 const size_t virtual_log_n =
Flavor::USE_PADDING ? CONST_PROOF_SIZE_LOG_N : prover_instance->log_dyadic_size();
355 prover.transcript->deserialize_full_transcript(verification_key->num_public_inputs, virtual_log_n);
356 prover.transcript->serialize_full_transcript(virtual_log_n);
360 proof = TestFixture::export_serialized_proof(prover, prover_instance->num_public_inputs());
362 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
366 Commitment one_group_val = Commitment::one();
368 prover.transcript->z_perm_comm = one_group_val * rand_val;
370 proof = TestFixture::export_serialized_proof(prover, prover_instance->num_public_inputs());
372 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
376 prover.transcript->serialize_full_transcript();
378 proof = TestFixture::export_serialized_proof(prover, prover_instance->num_public_inputs());
380 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
381 EXPECT_FALSE(result);
384 prover.transcript->deserialize_full_transcript(verification_key->num_public_inputs, virtual_log_n);
385 EXPECT_EQ(
static_cast<Commitment
>(prover.transcript->z_perm_comm), one_group_val * rand_val);
void generate_random_test_circuit(Builder &builder)
Flavor::Commitment Commitment
Proof export_serialized_proof(Prover &prover, const size_t num_public_inputs)
typename Flavor::Transcript::Proof Proof
static void SetUpTestSuite()
TranscriptManifest construct_ultra_honk_manifest(const size_t &log_n)
Construct a manifest for a Ultra Honk proof.
void generate_test_circuit(Builder &builder)
std::conditional_t< HasIPAAccumulator< Flavor >, RollupIO, DefaultIO > IO
Manages the data that is propagated on the public inputs of an application/function circuit.
static constexpr size_t PUBLIC_INPUTS_SIZE
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 PROOF_LENGTH_WITHOUT_PUB_INPUTS
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr bool USE_PADDING
IPA (inner product argument) commitment scheme class.
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
The data that is propagated on the public inputs of a rollup circuit.
static constexpr size_t PUBLIC_INPUTS_SIZE
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
Child class of UltraFlavor that runs with ZK Sumcheck.
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
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)
static field random_element(numeric::RNG *engine=nullptr) noexcept