23#include <gtest/gtest.h>
32std::filesystem::path get_test_dir(
const std::string_view& test_name)
34 std::filesystem::path temp_dir =
"tmp_api_client_ivc_test";
35 std::filesystem::create_directories(temp_dir);
36 std::filesystem::create_directories(temp_dir / test_name);
37 return temp_dir / test_name;
42void create_test_private_execution_steps(
const std::filesystem::path& output_path)
52 auto app_vk_response =
54 auto app_vk = app_vk_response.bytes;
55 auto app_vk_fields = from_buffer<MegaFlavor::VerificationKey>(app_vk).to_field_elements();
62 .
circuit = { .
name =
"kernel_circuit", .bytecode = kernel_bytecode }
64 auto kernel_vk = kernel_vk_response.bytes;
69 { .bytecode = app_bytecode, .witness = app_witness_data, .vk = app_vk, .function_name =
"app_function" });
70 raw_steps.push_back({ .bytecode = kernel_bytecode,
71 .witness = kernel_witness_data,
73 .function_name =
"kernel_function" });
85 const auto*
info = ::testing::UnitTest::GetInstance()->current_test_info();
91 if (std::filesystem::exists(
test_dir)) {
92 std::filesystem::remove_all(
test_dir);
100std::vector<uint8_t>
compress(
const std::vector<uint8_t>& input);
108 auto app_vk_response =
110 auto app_vk = app_vk_response.bytes;
111 auto app_vk_fields = from_buffer<MegaFlavor::VerificationKey>(app_vk).to_field_elements();
114 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
122 api.
write_vk(write_vk_flags, bytecode_path, test_dir);
124 return from_buffer<ClientIVC::MegaVerificationKey>(
read_file(test_dir /
"vk"));
134 std::filesystem::path input_path = test_dir /
"input.msgpack";
135 create_test_private_execution_steps(input_path);
137 std::filesystem::path output_dir = test_dir /
"output";
138 std::filesystem::create_directories(output_dir);
141 auto create_proof_and_vk = [&]() {
145 api.
prove(flags, input_path, output_dir);
151 auto vk1 = from_buffer<ClientIVC::MegaVerificationKey>(vk1_data);
156 auto verify_proof = [&]() {
157 std::filesystem::path proof_path = output_dir /
"proof";
158 std::filesystem::path vk_path = output_dir /
"vk";
159 std::filesystem::path public_inputs_path;
163 return verify_api.
verify(flags, public_inputs_path, proof_path, vk_path);
167 create_proof_and_vk();
168 verify_vk_equivalence(output_dir /
"vk", ivc_vk);
170 EXPECT_TRUE(verify_proof());
180 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
189 api.
write_vk(flags, bytecode_path, test_dir);
192 auto vk_data =
read_file(test_dir /
"vk_fields.json");
193 std::string vk_str(vk_data.begin(), vk_data.end());
195 EXPECT_NE(vk_str.find(
'['), std::string::npos);
196 EXPECT_NE(vk_str.find(
']'), std::string::npos);
205 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);
ClientIVC::MegaVerificationKey get_ivc_vk(const std::filesystem::path &test_dir)
TEST_F(ClientIVCAPITests, DISABLED_ProveAndVerifyFileBasedFlow)
std::filesystem::path test_dir
static void SetUpTestSuite()
void gates(const Flags &flags, const std::filesystem::path &bytecode_path) override
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
bool check_precomputed_vks(const Flags &flags, const std::filesystem::path &input_path)
bool prove_and_verify(const std::filesystem::path &input_path)
void prove(const Flags &flags, const std::filesystem::path &input_path, const std::filesystem::path &output_dir)
void write_vk(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &output_path) override
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
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::pair< std::vector< uint8_t >, std::vector< uint8_t > > create_simple_circuit_bytecode()
Helper function to create a minimal circuit bytecode and witness for 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)
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
bool msgpack_check_eq(const T &v1, const T &v2, const std::string_view &error_message)
Ensures that two msgpack objects are equal by applying the msgpack method to both and comparing the r...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
bool include_gates_per_opcode
std::string verifier_type
std::string output_format
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.