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 =
56 auto app_vk = from_buffer<MegaFlavor::VerificationKey>(app_vk_response.bytes);
57 auto app_vk_fields = app_vk.to_field_elements();
64 .
circuit = { .
name =
"kernel_circuit", .bytecode = kernel_bytecode }
66 auto kernel_vk = kernel_vk_response.bytes;
70 raw_steps.push_back({ .bytecode = app_bytecode,
71 .witness = app_witness_data,
72 .vk = app_vk_response.bytes,
73 .function_name =
"app_function" });
74 raw_steps.push_back({ .bytecode = kernel_bytecode,
75 .witness = kernel_witness_data,
77 .function_name =
"kernel_function" });
89 const auto*
info = ::testing::UnitTest::GetInstance()->current_test_info();
95 if (std::filesystem::exists(
test_dir)) {
96 std::filesystem::remove_all(
test_dir);
104std::vector<uint8_t>
compress(
const std::vector<uint8_t>& input);
112 auto app_vk_response =
116 auto app_vk = from_buffer<MegaFlavor::VerificationKey>(app_vk_response.bytes);
117 size_t vk_field_count = app_vk.to_field_elements().size();
121 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
128 api.
write_vk(write_vk_flags, bytecode_path, test_dir);
131 return from_buffer<ClientIVC::MegaVerificationKey>(
buffer);
141 std::filesystem::path input_path = test_dir /
"input.msgpack";
142 create_test_private_execution_steps(input_path);
144 std::filesystem::path output_dir = test_dir /
"output";
145 std::filesystem::create_directories(output_dir);
148 auto create_proof_and_vk = [&]() {
152 api.
prove(flags, input_path, output_dir);
158 auto vk1 = from_buffer<ClientIVC::MegaVerificationKey>(vk1_data);
163 auto verify_proof = [&]() {
164 std::filesystem::path proof_path = output_dir /
"proof";
165 std::filesystem::path vk_path = output_dir /
"vk";
166 std::filesystem::path public_inputs_path;
170 return verify_api.
verify(flags, public_inputs_path, proof_path, vk_path);
174 create_proof_and_vk();
175 verify_vk_equivalence(output_dir /
"vk", ivc_vk);
177 EXPECT_TRUE(verify_proof());
187 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
195 api.
write_vk(flags, bytecode_path, test_dir);
198 EXPECT_TRUE(std::filesystem::exists(test_dir /
"vk"));
207 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
216 api.
write_vk(flags, bytecode_path, test_dir);
219 std::filesystem::path vk_path = test_dir /
"vk";
220 ASSERT_TRUE(std::filesystem::exists(vk_path));
222 ASSERT_FALSE(vk_data.empty());
232 std::filesystem::path bytecode_path = test_dir /
"circuit.acir";
239 std::ostringstream captured_output;
243 api.
gates(flags, bytecode_path);
247 std::string output = captured_output.str();
257 EXPECT_NE(output.find(
"\"functions\": ["), std::string::npos);
258 EXPECT_NE(output.find(
"\"acir_opcodes\": 1"), std::string::npos);
259 EXPECT_NE(output.find(
"\"circuit_size\": "), std::string::npos);
260 EXPECT_NE(output.find(
"\"gates_per_opcode\": ["), std::string::npos);
267 std::filesystem::path input_path = test_dir /
"input.msgpack";
268 create_test_private_execution_steps(input_path);
278 std::filesystem::path input_path = test_dir /
"input_with_vks.msgpack";
279 create_test_private_execution_steps(input_path);
296 size_t vk_size = from_buffer<MegaFlavor::VerificationKey>(vk_response.bytes).to_field_elements().size();
301 .
circuit = { .
name =
"different_circuit", .bytecode = different_bytecode }
303 auto vk = vk_response2.bytes;
315 std::filesystem::path input_path = test_dir /
"input_wrong_vks.msgpack";
321 EXPECT_FALSE(result);
325 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...
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)
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.