14#include "gtest/gtest.h"
18static constexpr size_t SMALL_LOG_2_NUM_GATES = 5;
50 Commitment commitment = FrCodec::deserialize_from_fields<Commitment>(
51 std::span{ proof }.subspan(public_inputs_offset, FrCodec::template calc_num_fields<Commitment>()));
52 commitment = commitment + Commitment::one();
53 auto commitment_frs = FrCodec::serialize_to_fields<Commitment>(commitment);
54 for (
size_t idx = 0; idx < 4; ++idx) {
55 proof[public_inputs_offset + idx] = commitment_frs[idx];
63 const size_t num_circuits = circuit_producer.total_num_circuits;
65 ClientIVC ivc{ num_circuits, trace_settings };
67 for (
size_t j = 0; j < num_circuits; ++j) {
68 circuit_producer.construct_and_accumulate_next_circuit(ivc, settings);
70 return { ivc.
prove(), ivc.get_vk() };
80 const size_t NUM_APP_CIRCUITS = 1;
81 auto [proof,
vk] = accumulate_and_prove_ivc(NUM_APP_CIRCUITS);
97 const size_t NUM_APP_CIRCUITS = 2;
102 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
103 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
104 ClientIVC ivc{ NUM_CIRCUITS, trace_settings };
105 TestSettings settings{ .log2_num_gates = SMALL_LOG_2_NUM_GATES };
108 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
109 circuit_producer.construct_and_accumulate_next_circuit(ivc, settings);
111 auto proof = ivc.prove();
117 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
118 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
119 ClientIVC ivc{ NUM_CIRCUITS, trace_settings };
121 size_t num_public_inputs = 0;
124 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
126 circuit_producer.create_next_circuit_and_vk(ivc, { .log2_num_gates = SMALL_LOG_2_NUM_GATES });
130 num_public_inputs = circuit.num_public_inputs();
134 EXPECT_EQ(ivc.verification_queue.size(), 2);
139 auto proof = ivc.prove();
145 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
146 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
147 ClientIVC ivc{ NUM_CIRCUITS, trace_settings };
150 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
152 circuit_producer.create_next_circuit_and_vk(ivc, { .log2_num_gates = SMALL_LOG_2_NUM_GATES });
156 EXPECT_EQ(ivc.verification_queue.size(), 2);
158 circuit.num_public_inputs());
161 auto proof = ivc.prove();
176 auto [civc_proof_1, civc_vk_1] = accumulate_and_prove_ivc(1);
181 auto [civc_proof_2, civc_vk_2] = accumulate_and_prove_ivc(1);
199 tampered_proof.
mega_proof = civc_proof_2.mega_proof;
229 const TestSettings settings{ .log2_num_gates = SMALL_LOG_2_NUM_GATES };
231 auto [unused_1, civc_vk_1] = accumulate_and_prove_ivc(1, settings);
232 auto [unused_2, civc_vk_2] = accumulate_and_prove_ivc(3, settings);
235 EXPECT_EQ(*civc_vk_1.mega.get(), *civc_vk_2.mega.get());
238 EXPECT_EQ(*civc_vk_1.eccvm.get(), *civc_vk_2.eccvm.get());
241 EXPECT_EQ(*civc_vk_1.translator.get(), *civc_vk_2.translator.get());
256 const size_t NUM_APP_CIRCUITS = 1;
257 const size_t log2_num_gates_nominal = 5;
258 const size_t log2_num_gates_overflow = 18;
260 const TestSettings settings_1{ .log2_num_gates = log2_num_gates_nominal };
261 const TestSettings settings_2{ .log2_num_gates = log2_num_gates_overflow };
263 auto [unused_1, civc_vk_1] = accumulate_and_prove_ivc(NUM_APP_CIRCUITS, settings_1);
264 auto [unused_2, civc_vk_2] = accumulate_and_prove_ivc(NUM_APP_CIRCUITS, settings_2);
267 EXPECT_EQ(*civc_vk_1.mega.get(), *civc_vk_2.mega.get());
270 EXPECT_EQ(*civc_vk_1.eccvm.get(), *civc_vk_2.eccvm.get());
273 EXPECT_EQ(*civc_vk_1.translator.get(), *civc_vk_2.translator.get());
284 const size_t NUM_APP_CIRCUITS = 14;
288 EXPECT_TRUE(verified);
301 size_t NUM_APP_CIRCUITS = 1;
302 CircuitProducer circuit_producer(NUM_APP_CIRCUITS);
303 size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
304 ClientIVC ivc{ NUM_CIRCUITS, { SMALL_TEST_STRUCTURE, 1 << 17 } };
308 size_t log2_num_gates = 14;
309 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
310 settings.log2_num_gates = log2_num_gates;
311 circuit_producer.construct_and_accumulate_next_circuit(ivc, settings);
315 auto proof = ivc.
prove();
327 std::vector<size_t> log2_num_arith_gates;
334 {
"Case 1", { 14, 18, 14, 16, 14 } },
335 {
"Case 2", { 14, 16, 14, 18, 14 } },
338 for (
const auto& test : test_cases) {
339 SCOPED_TRACE(test.name);
341 CircuitProducer circuit_producer(1);
342 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
343 ClientIVC ivc{ NUM_CIRCUITS, { SMALL_TEST_STRUCTURE_FOR_OVERFLOWS } };
346 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
347 circuit_producer.construct_and_accumulate_next_circuit(
348 ivc, { .log2_num_gates = test.log2_num_arith_gates[idx] });
351 EXPECT_EQ(check_accumulator_target_sum_manual(ivc.prover_accumulator),
true);
352 auto proof = ivc.prove();
364 TestSettings settings{ .log2_num_gates = SMALL_LOG_2_NUM_GATES };
365 auto [proof,
vk] = accumulate_and_prove_ivc(1, settings);
368 const std::string filename =
"proof.msgpack";
369 proof.to_file_msgpack(filename);
376 uint8_t*
buffer = proof.to_msgpack_heap_buffer();
377 auto uint8_buffer = from_buffer<std::vector<uint8_t>>(
buffer);
378 uint8_t
const* uint8_ptr = uint8_buffer.data();
385 msgpack::sbuffer
buffer = proof.to_msgpack_buffer();
389 std::vector<uint8_t> random_bytes(
buffer.size());
390 std::generate(random_bytes.begin(), random_bytes.end(), []() { return static_cast<uint8_t>(rand() % 256); });
411 PrivateFunctionExecutionMockCircuitProducer circuit_producer{ 1 };
412 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
413 ClientIVC ivc{ NUM_CIRCUITS, { AZTEC_TRACE_STRUCTURE } };
416 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
417 auto [circuit,
vk] = circuit_producer.create_next_circuit_and_vk(ivc);
421 circuit_producer.tamper_with_databus();
427 auto proof = ivc.prove();
#define EXPECT_THROW_OR_ABORT(statement, matcher)
#define BB_DISABLE_ASSERTS()
static std::pair< ClientIVC::Proof, ClientIVC::VerificationKey > accumulate_and_prove_ivc(size_t num_app_circuits, TestSettings settings={})
static void SetUpTestSuite()
PrivateFunctionExecutionMockCircuitProducer CircuitProducer
static void tamper_with_proof(FoldProof &proof, size_t public_inputs_offset)
Tamper with a proof.
Flavor::Commitment Commitment
ClientIVC::FoldProof FoldProof
The IVC scheme used by the aztec client for private function execution.
Proof prove()
Construct a proof for the IVC, which, if verified, fully establishes its correctness.
DeciderVerifier_< Flavor > DeciderVerifier
void accumulate(ClientCircuit &circuit, const std::shared_ptr< MegaVerificationKey > &precomputed_vk) override
Perform prover work for accumulation (e.g. PG folding, merge proving)
VerifierInstance_< Flavor > VerifierInstance
DeciderProver_< Flavor > DeciderProver
std::vector< FF > FoldProof
MegaCircuitBuilder ClientCircuit
static bool verify(const Proof &proof, const VerificationKey &vk)
ProverInstance_< Flavor > ProverInstance
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 ...
TEST_F(ClientIVCTests, BasicStructured)
Using a structured trace allows for the accumulation of circuits of varying size.
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.
::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 circuit (wh...
static Proof from_msgpack_buffer(uint8_t const *&buffer)
static Proof from_file_msgpack(const std::string &filename)
HonkProof translator_proof