22#include <gtest/gtest.h>
31std::filesystem::path get_test_dir(
const std::string_view& test_name)
33 std::filesystem::path temp_dir =
"tmp_api_chonk_test";
34 std::filesystem::create_directories(temp_dir);
35 std::filesystem::create_directories(temp_dir / test_name);
36 return temp_dir / test_name;
41void create_test_private_execution_steps(
const std::filesystem::path& output_path)
51 auto app_vk_response =
55 auto app_vk = from_buffer<MegaFlavor::VerificationKey>(app_vk_response.bytes);
56 auto app_vk_fields = app_vk.to_field_elements();
63 .
circuit = { .
name =
"kernel_circuit", .bytecode = kernel_bytecode }
65 auto kernel_vk = kernel_vk_response.bytes;
69 raw_steps.push_back({ .bytecode = app_bytecode,
70 .witness = app_witness_data,
71 .vk = app_vk_response.bytes,
72 .function_name =
"app_function" });
73 raw_steps.push_back({ .bytecode = kernel_bytecode,
74 .witness = kernel_witness_data,
76 .function_name =
"kernel_function" });
88 const auto*
info = ::testing::UnitTest::GetInstance()->current_test_info();
94 if (std::filesystem::exists(
test_dir)) {
95 std::filesystem::remove_all(
test_dir);
103std::vector<uint8_t>
compress(
const std::vector<uint8_t>& input);
111 auto app_vk_response =
115 auto app_vk = from_buffer<MegaFlavor::VerificationKey>(app_vk_response.bytes);
116 size_t vk_field_count = app_vk.to_field_elements().size();
120 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
127 api.
write_vk(write_vk_flags, bytecode_path, test_dir);
130 return from_buffer<Chonk::MegaVerificationKey>(
buffer);
140 std::filesystem::path input_path = test_dir /
"input.msgpack";
141 create_test_private_execution_steps(input_path);
143 std::filesystem::path output_dir = test_dir /
"output";
144 std::filesystem::create_directories(output_dir);
147 auto create_proof_and_vk = [&]() {
151 api.
prove(flags, input_path, output_dir);
157 auto vk1 = from_buffer<Chonk::MegaVerificationKey>(vk1_data);
162 auto verify_proof = [&]() {
163 std::filesystem::path proof_path = output_dir /
"proof";
164 std::filesystem::path vk_path = output_dir /
"vk";
165 std::filesystem::path public_inputs_path;
169 return verify_api.
verify(flags, public_inputs_path, proof_path, vk_path);
173 create_proof_and_vk();
174 verify_vk_equivalence(output_dir /
"vk", ivc_vk);
176 EXPECT_TRUE(verify_proof());
186 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
194 api.
write_vk(flags, bytecode_path, test_dir);
197 EXPECT_TRUE(std::filesystem::exists(test_dir /
"vk"));
206 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
215 api.
write_vk(flags, bytecode_path, test_dir);
218 std::filesystem::path vk_path = test_dir /
"vk";
219 ASSERT_TRUE(std::filesystem::exists(vk_path));
221 ASSERT_FALSE(vk_data.empty());
231 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
238 std::ostringstream captured_output;
242 api.
gates(flags, bytecode_path);
246 std::string output = captured_output.str();
256 EXPECT_NE(output.find(
"\"functions\": ["), std::string::npos);
257 EXPECT_NE(output.find(
"\"acir_opcodes\": 1"), std::string::npos);
258 EXPECT_NE(output.find(
"\"circuit_size\": "), std::string::npos);
259 EXPECT_NE(output.find(
"\"gates_per_opcode\": ["), std::string::npos);
266 std::filesystem::path input_path = test_dir /
"input.msgpack";
267 create_test_private_execution_steps(input_path);
277 std::filesystem::path input_path = test_dir /
"input_with_vks.msgpack";
278 create_test_private_execution_steps(input_path);
295 size_t vk_size = from_buffer<MegaFlavor::VerificationKey>(vk_response.bytes).to_field_elements().size();
300 .
circuit = { .
name =
"different_circuit", .bytecode = different_bytecode }
302 auto vk = vk_response2.bytes;
314 std::filesystem::path input_path = test_dir /
"input_wrong_vks.msgpack";
320 EXPECT_FALSE(result);
324 EXPECT_FALSE(result);
Chonk::MegaVerificationKey get_ivc_vk(const std::filesystem::path &test_dir)
TEST_F(ChonkAPITests, DISABLED_ProveAndVerifyFileBasedFlow)
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
static void SetUpTestSuite()
std::filesystem::path test_dir
CLI API for Chonk (Aztec's client-side proving).
bool prove_and_verify(const std::filesystem::path &input_path)
Test/debug function: prove and verify in one call (bypasses serialization).
bool verify(const Flags &flags, const std::filesystem::path &public_inputs_path, const std::filesystem::path &proof_path, const std::filesystem::path &vk_path) override
Verify a Chonk proof against a verification key.
void write_vk(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &output_path) override
Compute and write a verification key.
void prove(const Flags &flags, const std::filesystem::path &input_path, const std::filesystem::path &output_dir)
Main production entry point: generate a Chonk proof from private execution steps.
void gates(const Flags &flags, const std::filesystem::path &bytecode_path) override
Output gate count statistics for a circuit.
bool check_precomputed_vks(const Flags &flags, const std::filesystem::path &input_path)
Validate that precomputed VKs in ivc-inputs.msgpack match computed VKs.
Base Native verification key class.
uint8_t buffer[RANDOM_BUFFER_SIZE]
std::pair< std::vector< uint8_t >, std::vector< uint8_t > > create_simple_circuit_bytecode(size_t num_constraints=1)
Helper function to create a minimal circuit bytecode and witness for testing.
std::vector< uint8_t > create_simple_kernel(size_t vk_size, bool is_init_kernel)
Create a simple kernel circuit for IVC testing.
std::vector< uint8_t > create_kernel_witness(const std::vector< bb::fr > &app_vk_fields)
Create a kernel witness for IVC testing.
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< uint8_t > compress(const std::vector< uint8_t > &input)
Save modified ivc-inputs.msgpack when VKs are rewritten.
std::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)
void write_file(const std::string &filename, std::vector< uint8_t > const &data)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
bool include_gates_per_opcode
std::string verifier_type
This is the msgpack encoding of the objects returned by the following typescript: const stepToStruct ...
std::vector< uint8_t > vk
std::vector< uint8_t > bytecode
static void compress_and_save(std::vector< PrivateExecutionStepRaw > &&steps, const std::filesystem::path &output_path)
std::string function_name
std::vector< uint8_t > witness
Compute standalone verification key for a circuit.