13#include "gtest/gtest.h"
17static constexpr size_t SMALL_LOG_2_NUM_GATES = 5;
43 Commitment commitment = FrCodec::deserialize_from_fields<Commitment>(
44 std::span{ proof }.subspan(public_inputs_offset, FrCodec::template calc_num_fields<Commitment>()));
45 commitment = commitment + Commitment::one();
46 auto commitment_frs = FrCodec::serialize_to_fields<Commitment>(commitment);
47 for (
size_t idx = 0; idx < 4; ++idx) {
48 proof[public_inputs_offset + idx] = commitment_frs[idx];
54 bool check_circuit_sizes =
false)
57 const size_t num_circuits = circuit_producer.total_num_circuits;
58 Chonk ivc{ num_circuits };
60 for (
size_t j = 0; j < num_circuits; ++j) {
61 circuit_producer.construct_and_accumulate_next_circuit(ivc, settings, check_circuit_sizes);
63 return { ivc.
prove(), ivc.get_vk() };
76 const size_t NUM_APP_CIRCUITS = 2;
80 auto [proof,
vk] = accumulate_and_prove_ivc(NUM_APP_CIRCUITS, {},
true);
87 accumulate_and_prove_ivc(NUM_APP_CIRCUITS, { .log2_num_gates = SMALL_LOG_2_NUM_GATES },
true);
100 const size_t NUM_APP_CIRCUITS = 2;
101 auto [proof,
vk] = accumulate_and_prove_ivc(NUM_APP_CIRCUITS);
117 const size_t NUM_APP_CIRCUITS = 2;
121 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
122 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
123 Chonk ivc{ NUM_CIRCUITS };
124 TestSettings settings{ .log2_num_gates = SMALL_LOG_2_NUM_GATES };
127 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
128 circuit_producer.construct_and_accumulate_next_circuit(ivc, settings);
130 auto proof = ivc.prove();
136 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
137 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
138 Chonk ivc{ NUM_CIRCUITS };
140 size_t num_public_inputs = 0;
143 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
145 circuit_producer.create_next_circuit_and_vk(ivc, { .log2_num_gates = SMALL_LOG_2_NUM_GATES });
149 num_public_inputs = circuit.num_public_inputs();
153 EXPECT_EQ(ivc.verification_queue.size(), 2);
158 auto proof = ivc.prove();
164 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
165 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
166 Chonk ivc{ NUM_CIRCUITS };
169 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
171 circuit_producer.create_next_circuit_and_vk(ivc, { .log2_num_gates = SMALL_LOG_2_NUM_GATES });
175 EXPECT_EQ(ivc.verification_queue.size(), 2);
177 circuit.num_public_inputs());
180 auto proof = ivc.prove();
186 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
187 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
188 Chonk ivc{ NUM_CIRCUITS };
191 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
193 circuit_producer.create_next_circuit_and_vk(ivc, { .log2_num_gates = SMALL_LOG_2_NUM_GATES });
196 auto proof = ivc.prove();
214 auto [chonk_proof_1, chonk_vk_1] = accumulate_and_prove_ivc(1);
219 auto [chonk_proof_2, chonk_vk_2] = accumulate_and_prove_ivc(1);
237 tampered_proof.
mega_proof = chonk_proof_2.mega_proof;
267 const TestSettings settings{ .log2_num_gates = SMALL_LOG_2_NUM_GATES };
269 auto [unused_1, chonk_vk_1] = accumulate_and_prove_ivc(1, settings);
270 auto [unused_2, chonk_vk_2] = accumulate_and_prove_ivc(3, settings);
273 EXPECT_EQ(*chonk_vk_1.mega.get(), *chonk_vk_2.mega.get());
276 EXPECT_EQ(*chonk_vk_1.eccvm.get(), *chonk_vk_2.eccvm.get());
279 EXPECT_EQ(*chonk_vk_1.translator.get(), *chonk_vk_2.translator.get());
289 const size_t NUM_APP_CIRCUITS = 1;
290 const size_t log2_num_gates_small = 5;
291 const size_t log2_num_gates_big = 18;
293 const TestSettings settings_1{ .log2_num_gates = log2_num_gates_small };
294 const TestSettings settings_2{ .log2_num_gates = log2_num_gates_big };
296 auto [unused_1, chonk_vk_1] = accumulate_and_prove_ivc(NUM_APP_CIRCUITS, settings_1);
297 auto [unused_2, chonk_vk_2] = accumulate_and_prove_ivc(NUM_APP_CIRCUITS, settings_2);
300 EXPECT_EQ(*chonk_vk_1.mega.get(), *chonk_vk_2.mega.get());
303 EXPECT_EQ(*chonk_vk_1.eccvm.get(), *chonk_vk_2.eccvm.get());
306 EXPECT_EQ(*chonk_vk_1.translator.get(), *chonk_vk_2.translator.get());
317 const size_t NUM_APP_CIRCUITS = 17;
321 EXPECT_TRUE(verified);
331 TestSettings settings{ .log2_num_gates = SMALL_LOG_2_NUM_GATES };
332 auto [proof,
vk] = accumulate_and_prove_ivc(1, settings);
335 const std::string filename =
"proof.msgpack";
336 proof.to_file_msgpack(filename);
343 uint8_t*
buffer = proof.to_msgpack_heap_buffer();
344 auto uint8_buffer = from_buffer<std::vector<uint8_t>>(
buffer);
345 uint8_t
const* uint8_ptr = uint8_buffer.data();
352 msgpack::sbuffer
buffer = proof.to_msgpack_buffer();
356 std::vector<uint8_t> random_bytes(
buffer.size());
357 std::generate(random_bytes.begin(), random_bytes.end(), []() { return static_cast<uint8_t>(rand() % 256); });
378 PrivateFunctionExecutionMockCircuitProducer circuit_producer{ 1 };
379 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
380 Chonk ivc{ NUM_CIRCUITS };
383 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
384 auto [circuit,
vk] = circuit_producer.create_next_circuit_and_vk(ivc);
388 circuit_producer.tamper_with_databus();
394 auto proof = ivc.prove();
#define EXPECT_THROW_OR_ABORT(statement, matcher)
#define BB_DISABLE_ASSERTS()
TEST_F(ChonkTests, TestCircuitSizes)
Test sizes of the circuits generated by MockCircuitProducer.
PrivateFunctionExecutionMockCircuitProducer CircuitProducer
static void tamper_with_proof(HonkProof &proof, size_t public_inputs_offset)
Tamper with a proof.
Flavor::Commitment Commitment
static void SetUpTestSuite()
static std::pair< Chonk::Proof, Chonk::VerificationKey > accumulate_and_prove_ivc(size_t num_app_circuits, TestSettings settings={}, bool check_circuit_sizes=false)
The IVC scheme used by the aztec client for private function execution.
HypernovaDeciderProver DeciderProver
Proof prove()
Construct a proof for the IVC, which, if verified, fully establishes its correctness.
ProverInstance_< Flavor > ProverInstance
VerifierInstance_< Flavor > VerifierInstance
void accumulate(ClientCircuit &circuit, const std::shared_ptr< MegaVerificationKey > &precomputed_vk) override
Perform prover work for accumulation (e.g. HN folding, merge proving)
MegaCircuitBuilder ClientCircuit
static bool verify(const Proof &proof, const VerificationKey &vk)
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
Curve::AffineElement Commitment
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
The VerifierInstance encapsulates all the necessary information for a Mega Honk Verifier to verify a ...
uint8_t buffer[RANDOM_BUFFER_SIZE]
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
::testing::Types< BN254Settings, GrumpkinSettings > TestSettings
void tamper_with_proof(InnerProver &inner_prover, ProofType &inner_proof, TamperType type)
Test method that provides several ways to tamper with a proof. TODO(https://github....
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
A full proof for the IVC scheme containing a Mega proof showing correctness of the Hiding kernel (whi...
static Proof from_msgpack_buffer(uint8_t const *&buffer)
static Proof from_file_msgpack(const std::string &filename)
HonkProof translator_proof