15#include <gtest/gtest.h>
21std::vector<uint8_t>
compress(
const std::vector<uint8_t>& input);
22std::vector<uint8_t>
decompress(
const void* bytes,
size_t size);
30std::filesystem::path get_test_dir(
const std::string_view& test_name)
32 std::filesystem::path temp_dir =
"tmp_api_ultra_honk_test";
33 std::filesystem::create_directories(temp_dir);
34 std::filesystem::create_directories(temp_dir / test_name);
35 return temp_dir / test_name;
43 auto bytecode_path = test_dir /
"circuit.gz";
44 auto witness_path = test_dir /
"witness.gz";
49 return { bytecode_path, witness_path };
60 const auto*
info = ::testing::UnitTest::GetInstance()->current_test_info();
66 if (std::filesystem::exists(
test_dir)) {
67 std::filesystem::remove_all(
test_dir);
76 auto [bytecode_path, witness_path] = create_test_circuit_files(test_dir);
85 auto vk_output_path = test_dir /
"vk";
86 std::filesystem::create_directories(vk_output_path);
87 api.
write_vk(flags, bytecode_path, vk_output_path);
88 EXPECT_TRUE(std::filesystem::exists(vk_output_path /
"vk"));
91 auto proof_output_dir = test_dir /
"proof";
92 std::filesystem::create_directories(proof_output_dir);
93 api.
prove(flags, bytecode_path, witness_path, vk_output_path /
"vk", proof_output_dir);
96 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"proof"));
97 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"public_inputs"));
101 api.
verify(flags, proof_output_dir /
"public_inputs", proof_output_dir /
"proof", vk_output_path /
"vk");
102 EXPECT_TRUE(verified);
107 auto [bytecode_path, witness_path] = create_test_circuit_files(test_dir);
117 auto proof_output_dir = test_dir /
"proof";
118 std::filesystem::create_directories(proof_output_dir);
119 api.
prove(flags, bytecode_path, witness_path,
"", proof_output_dir);
122 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"proof"));
123 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"public_inputs"));
124 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"vk"));
125 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"vk_hash"));
126 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"vk_fields.json"));
127 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"vk_hash_fields.json"));
131 api.
verify(flags, proof_output_dir /
"public_inputs", proof_output_dir /
"proof", proof_output_dir /
"vk");
132 EXPECT_TRUE(verified);
137 auto [bytecode_path, witness_path] = create_test_circuit_files(test_dir);
146 auto vk_output_path = test_dir /
"vk";
147 std::filesystem::create_directories(vk_output_path);
148 api.
write_vk(vk_flags, bytecode_path, vk_output_path);
149 EXPECT_TRUE(std::filesystem::exists(vk_output_path /
"vk"));
157 auto proof_output_dir = test_dir /
"proof";
158 std::filesystem::create_directories(proof_output_dir);
159 api.
prove(flags, bytecode_path, witness_path, vk_output_path /
"vk", proof_output_dir);
162 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"proof_fields.json"));
163 EXPECT_TRUE(std::filesystem::exists(proof_output_dir /
"public_inputs_fields.json"));
168 auto [bytecode_path, witness_path] = create_test_circuit_files(test_dir);
173 {
"poseidon2",
true },
175 {
"keccak",
true } };
177 for (
const auto& [oracle_hash_type, disable_zk] : test_cases) {
184 auto case_dir = test_dir / (oracle_hash_type +
"_" + (disable_zk ?
"no_zk" :
"zk"));
185 std::filesystem::create_directories(case_dir);
190 api.
prove(flags, bytecode_path, witness_path,
"", case_dir);
193 bool verified = api.
verify(flags, case_dir /
"public_inputs", case_dir /
"proof", case_dir /
"vk");
194 EXPECT_TRUE(verified) <<
"Failed with oracle_hash_type=" << oracle_hash_type <<
", disable_zk=" << disable_zk;
200 auto [bytecode_path, witness_path] = create_test_circuit_files(test_dir);
209 api.
write_vk(flags, bytecode_path, test_dir);
211 EXPECT_TRUE(std::filesystem::exists(test_dir /
"vk_fields.json"));
212 EXPECT_TRUE(std::filesystem::exists(test_dir /
"vk_hash_fields.json"));
214 EXPECT_FALSE(std::filesystem::exists(test_dir /
"vk"));
215 EXPECT_FALSE(std::filesystem::exists(test_dir /
"vk_hash"));
225 api.
write_vk(flags, bytecode_path, test_dir);
228 auto bytecode =
read_file(bytecode_path);
234 info(
"after write_vk, expected_vk size: {}", expected_vk.bytes.size());
235 EXPECT_EQ(expected_vk.bytes,
read_file(test_dir /
"vk"));
236 EXPECT_EQ(expected_vk.hash,
read_file(test_dir /
"vk_hash"));
243 auto [bytecode_path, witness_path] = create_test_circuit_files(test_dir);
246 testing::internal::CaptureStdout();
252 api.
gates(flags, bytecode_path);
254 std::string output = testing::internal::GetCapturedStdout();
257 EXPECT_TRUE(output.find(
"gates_per_opcode") != std::string::npos);
TEST_F(ApiUltraHonkTest, ProveAndVerify)
UltraHonk-specific command definitions for the Barretenberg RPC API.
static void SetUpTestSuite()
std::filesystem::path test_dir
void prove(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &witness_path, const std::filesystem::path &vk_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
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
void gates(const Flags &flags, const std::filesystem::path &bytecode_path) override
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 > decompress(const void *bytes, size_t size)
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)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
bool include_gates_per_opcode
std::string oracle_hash_type
std::string output_format