14#include "gtest/gtest.h"
18#ifdef STARKNET_GARAGA_FLAVORS
22 UltraStarknetZKFlavor,
28 ::testing::Types<UltraFlavor, UltraKeccakFlavor, UltraRollupFlavor, UltraZKFlavor, UltraKeccakZKFlavor>;
41 using Proof =
typename Flavor::Transcript::Proof;
65 size_t data_types_per_Frs = [] {
66 if constexpr (IsKeccakFlavor<Flavor>) {
67 return bb::field_conversion::calc_num_uint256_ts<FF>();
69 return bb::field_conversion::calc_num_bn254_frs<FF>();
72 size_t data_types_per_G = [] {
73 if constexpr (IsKeccakFlavor<Flavor>) {
74 return bb::field_conversion::calc_num_uint256_ts<Commitment>();
76 return bb::field_conversion::calc_num_bn254_frs<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++) {
92 manifest_expected.
add_entry(round,
"W_L", data_types_per_G);
93 manifest_expected.
add_entry(round,
"W_R", data_types_per_G);
94 manifest_expected.
add_entry(round,
"W_O", data_types_per_G);
95 manifest_expected.
add_challenge(round,
"eta",
"eta_two",
"eta_three");
98 manifest_expected.
add_entry(round,
"LOOKUP_READ_COUNTS", data_types_per_G);
99 manifest_expected.
add_entry(round,
"LOOKUP_READ_TAGS", data_types_per_G);
100 manifest_expected.
add_entry(round,
"W_4", data_types_per_G);
104 manifest_expected.
add_entry(round,
"LOOKUP_INVERSES", data_types_per_G);
105 manifest_expected.
add_entry(round,
"Z_PERM", data_types_per_G);
108 for (
size_t i = 0; i < NUM_SUBRELATIONS - 1; i++) {
110 alpha_labels[i] = label;
116 manifest_expected.
add_challenge(round,
"Sumcheck:gate_challenge");
120 manifest_expected.
add_entry(round,
"Libra:concatenation_commitment", data_types_per_G);
121 manifest_expected.
add_entry(round,
"Libra:Sum", data_types_per_Frs);
126 for (
size_t i = 0; i < virtual_log_n; ++i) {
128 manifest_expected.
add_entry(round,
"Sumcheck:univariate_" + idx, frs_per_uni);
129 std::string label =
"Sumcheck:u_" + idx;
134 manifest_expected.
add_entry(round,
"Sumcheck:evaluations", frs_per_evals);
137 manifest_expected.
add_entry(round,
"Libra:claimed_evaluation", data_types_per_Frs);
138 manifest_expected.
add_entry(round,
"Libra:grand_sum_commitment", data_types_per_G);
139 manifest_expected.
add_entry(round,
"Libra:quotient_commitment", data_types_per_G);
140 manifest_expected.
add_entry(round,
"Gemini:masking_poly_comm", data_types_per_G);
141 manifest_expected.
add_entry(round,
"Gemini:masking_poly_eval", data_types_per_Frs);
147 for (
size_t i = 1; i < virtual_log_n; ++i) {
149 manifest_expected.
add_entry(round,
"Gemini:FOLD_" + idx, data_types_per_G);
153 for (
size_t i = 1; i <= virtual_log_n; ++i) {
155 manifest_expected.
add_entry(round,
"Gemini:a_" + idx, data_types_per_Frs);
159 manifest_expected.
add_entry(round,
"Libra:concatenation_eval", data_types_per_Frs);
160 manifest_expected.
add_entry(round,
"Libra:shifted_grand_sum_eval", data_types_per_Frs);
161 manifest_expected.
add_entry(round,
"Libra:grand_sum_eval", data_types_per_Frs);
162 manifest_expected.
add_entry(round,
"Libra:quotient_eval", data_types_per_Frs);
167 manifest_expected.
add_entry(round,
"Shplonk:Q", data_types_per_G);
171 manifest_expected.
add_entry(round,
"KZG:W", data_types_per_G);
174 return manifest_expected;
183 if constexpr (HasIPAAccumulator<Flavor>) {
184 auto [stdlib_opening_claim, ipa_proof] =
186 stdlib_opening_claim.set_public();
199 if constexpr (HasIPAAccumulator<Flavor>) {
200 auto [stdlib_opening_claim, ipa_proof] =
202 stdlib_opening_claim.set_public();
225 auto builder =
typename TestFixture::Builder();
226 TestFixture::generate_test_circuit(
builder);
231 typename TestFixture::Prover prover(proving_key, verification_key);
232 prover.transcript->enable_manifest();
233 auto proof = prover.construct_proof();
236 auto manifest_expected = TestFixture::construct_ultra_honk_manifest(prover.proving_key->log_dyadic_size());
237 auto prover_manifest = prover.transcript->get_manifest();
239 manifest_expected.print();
240 prover_manifest.print();
241 ASSERT_GT(manifest_expected.size(), 0);
242 for (
size_t round = 0; round < manifest_expected.size(); ++round) {
243 if (prover_manifest[round] != manifest_expected[round]) {
244 info(
"Prover manifest discrepency in round ", round);
245 info(
"Prover manifest:");
246 prover_manifest[round].print();
247 info(
"Expected manifest:");
248 manifest_expected[round].print();
262 auto builder =
typename TestFixture::Builder();
263 TestFixture::generate_test_circuit(
builder);
268 typename TestFixture::Prover prover(proving_key, verification_key);
269 prover.transcript->enable_manifest();
270 auto proof = prover.construct_proof();
273 typename TestFixture::Verifier verifier(verification_key);
274 verifier.transcript->enable_manifest();
275 typename TestFixture::Proof honk_proof;
276 typename TestFixture::Proof ipa_proof;
277 if constexpr (HasIPAAccumulator<TypeParam>) {
279 const size_t HONK_PROOF_LENGTH = TypeParam::PROOF_LENGTH_WITHOUT_PUB_INPUTS() - IPA_PROOF_LENGTH;
280 const size_t num_public_inputs =
static_cast<uint32_t
>(verification_key->num_public_inputs);
283 ASSERT_EQ(proof.size(), HONK_PROOF_LENGTH + IPA_PROOF_LENGTH + num_public_inputs);
286 static_cast<std::ptrdiff_t>(HONK_PROOF_LENGTH + num_public_inputs);
288 honk_proof =
typename TestFixture::Proof(proof.begin(), proof.begin() + honk_proof_with_pub_inputs_length);
289 ipa_proof =
typename TestFixture::Proof(proof.begin() + honk_proof_with_pub_inputs_length, proof.end());
293 [[maybe_unused]]
auto _ = verifier.template verify_proof<typename TestFixture::IO>(honk_proof, ipa_proof);
296 auto prover_manifest = prover.transcript->get_manifest();
297 auto verifier_manifest = verifier.transcript->get_manifest();
300 ASSERT_GT(prover_manifest.size(), 0);
301 for (
size_t round = 0; round < prover_manifest.size(); ++round) {
302 ASSERT_EQ(prover_manifest[round], verifier_manifest[round])
303 <<
"Prover/Verifier manifest discrepency in round " << round;
317 auto transcript = TypeParam::Transcript::prover_init_empty();
319 auto challenges = transcript->template get_challenges<FF>(
"a",
"b",
"c",
"d",
"e",
"f");
321 for (
size_t i = 0; i < challenges.size(); ++i) {
322 ASSERT_NE(challenges[i], 0) <<
"Challenge " << i <<
" is 0";
324 constexpr uint32_t random_val{ 17 };
325 transcript->send_to_verifier(
"random val", random_val);
327 auto [
a,
b, c] = transcript->template get_challenges<FF>(
"a",
"b",
"c");
328 ASSERT_NE(
a, 0) <<
"Challenge a is 0";
329 ASSERT_NE(
b, 0) <<
"Challenge b is 0";
330 ASSERT_NE(c, 0) <<
"Challenge c is 0";
339 auto builder =
typename TestFixture::Builder();
340 if constexpr (IsAnyOf<TypeParam, UltraRollupFlavor, UltraKeccakFlavor, UltraKeccakZKFlavor>) {
341 GTEST_SKIP() <<
"Not built for this parameter";
343 TestFixture::generate_test_circuit(
builder);
348 typename TestFixture::Prover prover(proving_key, verification_key);
349 auto proof = prover.construct_proof();
350 typename TestFixture::Verifier verifier(verification_key);
352 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
356 const size_t virtual_log_n =
Flavor::USE_PADDING ? CONST_PROOF_SIZE_LOG_N : proving_key->log_dyadic_size();
359 prover.transcript->deserialize_full_transcript(verification_key->num_public_inputs, virtual_log_n);
360 prover.transcript->serialize_full_transcript(virtual_log_n);
364 proof = TestFixture::export_serialized_proof(prover, proving_key->num_public_inputs());
366 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
370 Commitment one_group_val = Commitment::one();
371 FF rand_val = FF::random_element();
372 prover.transcript->z_perm_comm = one_group_val * rand_val;
374 proof = TestFixture::export_serialized_proof(prover, proving_key->num_public_inputs());
376 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
380 prover.transcript->serialize_full_transcript();
382 proof = TestFixture::export_serialized_proof(prover, proving_key->num_public_inputs());
384 bool result = verifier.template verify_proof<typename TestFixture::IO>(proof).result;
385 EXPECT_FALSE(result);
388 prover.transcript->deserialize_full_transcript(verification_key->num_public_inputs);
389 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
typename Flavor::Transcript::Proof Proof
static void SetUpTestSuite()
Proof export_serialized_proof(Prover prover, const size_t num_public_inputs)
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
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
Manages the data that is propagated on the public inputs of an application/function circuit.
static constexpr size_t PUBLIC_INPUTS_SIZE
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
IPA (inner product argument) commitment scheme class.
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
static constexpr size_t NUM_SUBRELATIONS
MegaCircuitBuilder CircuitBuilder
static constexpr size_t NUM_ALL_ENTITIES
static constexpr bool HasZK
Curve::AffineElement Commitment
static constexpr bool USE_PADDING
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
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, Strings &... labels)
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.
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
static void add_default_to_public_inputs(Builder &builder)
Adds default public inputs to the builder.