Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
mega_honk.test.cpp
Go to the documentation of this file.
1#include <cstddef>
2#include <cstdint>
3#include <gtest/gtest.h>
4
13
14using namespace bb;
15
17
18using FlavorTypes = ::testing::Types<MegaFlavor, MegaZKFlavor>;
19
20template <typename Flavor> class MegaHonkTests : public ::testing::Test {
21 public:
23
33
39 {
40 auto prover_instance = std::make_shared<ProverInstance>(builder);
41 auto verification_key = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
42 Prover prover(prover_instance, verification_key);
43 Verifier verifier(verification_key);
44 auto proof = prover.construct_proof();
45 bool verified = verifier.template verify_proof<DefaultIO>(proof).result;
46
47 return verified;
48 }
49};
50
52
62TYPED_TEST(MegaHonkTests, ProofLengthCheck)
63{
64 using Flavor = TypeParam;
67
68 auto builder = Builder{};
69 DefaultIO::add_default(builder);
70
71 // Construct a mega proof and ensure its size matches expectation; if not, the constant may need to be updated
73 auto verification_key = std::make_shared<typename Flavor::VerificationKey>(prover_instance->get_precomputed());
74 UltraProver_<Flavor> prover(prover_instance, verification_key);
75 HonkProof mega_proof = prover.construct_proof();
77}
78
85{
86 using Flavor = TypeParam;
88
90
91 // Construct and verify Honk proof
92 bool honk_verified = this->construct_and_verify_honk_proof(builder);
93 EXPECT_TRUE(honk_verified);
94}
95
101TYPED_TEST(MegaHonkTests, DynamicVirtualSizeIncrease)
102{
103 using Flavor = TypeParam;
104
105 // In MegaZKFlavor, we mask witness polynomials by placing random values at the indices `dyadic_circuit_size`-i for
106 // i=1,2,3. This mechanism does not work with structured polynomials yet.
108 GTEST_SKIP() << "Skipping 'DynamicVirtualSizeIncrease' test for MegaZKFlavor.";
109 }
111 using Prover = UltraProver_<Flavor>;
112 using Verifier = UltraVerifier_<Flavor>;
113
115
116 auto builder_copy = builder;
117
118 // Construct and verify Honk proof using a structured trace
119 auto prover_instance = std::make_shared<ProverInstance_<Flavor>>(builder);
120 auto prover_instance_copy = std::make_shared<ProverInstance_<Flavor>>(builder_copy);
121 auto circuit_size = prover_instance->dyadic_size();
122
123 auto doubled_circuit_size = 2 * circuit_size;
124 prover_instance_copy->polynomials.increase_polynomials_virtual_size(doubled_circuit_size);
125 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1158)
126 // prover_instance_copy->dyadic_circuit_size = doubled_circuit_size;
127
128 auto verification_key = std::make_shared<typename Flavor::VerificationKey>(prover_instance->get_precomputed());
129 Prover prover(prover_instance, verification_key);
130
131 auto verification_key_copy = std::make_shared<typename Flavor::VerificationKey>(prover_instance->get_precomputed());
132 Prover prover_copy(prover_instance_copy, verification_key_copy);
133
134 for (auto [entry, entry_copy] : zip_view(verification_key->get_all(), verification_key_copy->get_all())) {
135 EXPECT_EQ(entry, entry_copy);
136 }
137
138 Verifier verifier(verification_key);
139 auto proof = prover.construct_proof();
140
141 auto relation_failures =
142 RelationChecker<Flavor>::check_all(prover_instance->polynomials, prover_instance->relation_parameters);
143 EXPECT_TRUE(relation_failures.empty());
144 bool result = verifier.template verify_proof<DefaultIO>(proof).result;
145 EXPECT_TRUE(result);
146
147 Verifier verifier_copy(verification_key_copy);
148 auto proof_copy = prover_copy.construct_proof();
149
150 auto relation_failures_copy =
151 RelationChecker<Flavor>::check_all(prover_instance->polynomials, prover_instance->relation_parameters);
152 EXPECT_TRUE(relation_failures.empty());
153 bool result_copy = verifier_copy.template verify_proof<DefaultIO>(proof_copy).result;
154 EXPECT_TRUE(result_copy);
155}
156
165{
166 using Flavor = TypeParam;
167 // In MegaZKFlavor, we mask witness polynomials by placing random values at the indices `dyadic_circuit_size`-i, for
168 // i=1,2,3. This mechanism does not work with structured polynomials yet.
170 GTEST_SKIP() << "Skipping 'PolySwap' test for MegaZKFlavor.";
171 }
173
174 // Construct a simple circuit and make a copy of it
177 auto builder_copy = builder;
178
179 // Construct two identical proving keys
181 auto prover_instance_2 = std::make_shared<typename TestFixture::ProverInstance>(builder_copy);
182
183 // Tamper with the polys of pkey 1 in such a way that verification should fail
184 for (size_t i = 0; i < prover_instance_1->dyadic_size(); ++i) {
185 if (prover_instance_1->polynomials.q_arith[i] != 0) {
186 prover_instance_1->polynomials.w_l.at(i) += 1;
187 break;
188 }
189 }
190
191 // Swap the polys of the two proving keys; result should be pkey 1 is valid and pkey 2 should fail
192 std::swap(prover_instance_1->polynomials, prover_instance_2->polynomials);
193
194 { // Verification based on pkey 1 should succeed
195 auto verification_key =
196 std::make_shared<typename TestFixture::VerificationKey>(prover_instance_1->get_precomputed());
197 typename TestFixture::Prover prover(prover_instance_1, verification_key);
198 typename TestFixture::Verifier verifier(verification_key);
199 auto proof = prover.construct_proof();
200 bool result = verifier.template verify_proof<DefaultIO>(proof).result;
201 EXPECT_TRUE(result);
202 }
203
204 { // Verification based on pkey 2 should fail
205 auto verification_key =
206 std::make_shared<typename TestFixture::VerificationKey>(prover_instance_2->get_precomputed());
207 typename TestFixture::Prover prover(prover_instance_2, verification_key);
208 typename TestFixture::Verifier verifier(verification_key);
209 auto proof = prover.construct_proof();
210 bool result = verifier.template verify_proof<DefaultIO>(proof).result;
211 EXPECT_FALSE(result);
212 }
213}
Curve::AffineElement Point
typename Flavor::VerificationKey VerificationKey
static void SetUpTestSuite()
bool construct_and_verify_honk_proof(auto &builder)
Construct and a verify a Honk proof.
CommitmentKey object over a pairing group 𝔾₁.
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...
ECCVMCircuitBuilder CircuitBuilder
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
static void construct_simple_circuit(MegaBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
static AllSubrelationFailures check_all(const auto &polynomials, const auto &params)
Check that the provided polynomials satisfy all relations for a given Flavor.
The VerifierInstance encapsulates all the necessary information for a Mega Honk Verifier to verify a ...
typename Group::affine_element AffineElement
Definition bn254.hpp:22
bb::fr ScalarField
Definition bn254.hpp:18
Manages the data that is propagated on the public inputs of an application/function circuit.
AluTraceBuilder builder
Definition alu.test.cpp:124
auto & engine
testing::Types< MegaFlavor, UltraFlavor, UltraZKFlavor, UltraRollupFlavor > FlavorTypes
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition engine.cpp:190
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13