Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bbapi_ultra_honk.test.cpp
Go to the documentation of this file.
8#include <gtest/gtest.h>
9#include <vector>
10
11namespace bb::bbapi {
12
13class BBApiUltraHonkTest : public ::testing::Test {
14 protected:
16
17 void SetUp() override
18 {
19 // Store original concurrency for restoration
21 }
22
23 void TearDown() override
24 {
25 // Restore original concurrency
27 }
28
30};
32{
33 auto [bytecode, witness] = acir_bincode_mocks::create_simple_circuit_bytecode();
34
35 // Test different combinations of settings
36 const std::vector<bbapi::ProofSystemSettings> test_settings = {
37 // ipa_accumulation = true (other values don't matter)
38 { .ipa_accumulation = true, .oracle_hash_type = "poseidon2", .disable_zk = false },
39 // ipa_accumulation = false cases (test both disable_zk values)
40 { .ipa_accumulation = false, .oracle_hash_type = "poseidon2", .disable_zk = false },
41 { .ipa_accumulation = false, .oracle_hash_type = "poseidon2", .disable_zk = true },
42 { .ipa_accumulation = false, .oracle_hash_type = "keccak", .disable_zk = false },
43 { .ipa_accumulation = false, .oracle_hash_type = "keccak", .disable_zk = true }
44 };
45
46 for (const bbapi::ProofSystemSettings& settings : test_settings) {
47 // Compute VK
48 auto vk_response =
49 CircuitComputeVk{ .circuit = { .name = "test_circuit", .bytecode = bytecode }, .settings = settings }
50 .execute();
51
52 // First prove
53 auto prove_response = CircuitProve{ .circuit = { .name = "test_circuit",
54 .bytecode = bytecode,
55 .verification_key = vk_response.bytes },
56 .witness = witness,
57 .settings = settings }
58 .execute();
59
60 // Verify the proof
61 auto verify_response = CircuitVerify{ .verification_key = vk_response.bytes,
62 .public_inputs = prove_response.public_inputs,
63 .proof = prove_response.proof,
64 .settings = settings }
65 .execute();
66
67 EXPECT_TRUE(verify_response.verified)
68 << "Failed with ipa_accumulation=" << settings.ipa_accumulation
69 << ", oracle_hash_type=" << settings.oracle_hash_type << ", disable_zk=" << settings.disable_zk;
70 }
71}
72
73TEST_F(BBApiUltraHonkTest, ParallelComputeVk)
74{
75 // Set hardware concurrency to 8 to ensure we can run 8 VK computations in parallel
77
78 constexpr size_t num_vks = 8;
79
80 // Create different circuits by varying the number of constraints
81 std::vector<std::vector<uint8_t>> bytecodes(num_vks);
82 std::vector<std::vector<uint8_t>> witnesses(num_vks);
83 for (size_t i = 0; i < num_vks; ++i) {
84 // Create circuit with i+1 constraints (so each circuit is different)
85 auto [bytecode, witness] = acir_bincode_mocks::create_simple_circuit_bytecode(i + 1);
86 bytecodes[i] = bytecode;
87 witnesses[i] = witness;
88 }
89
90 std::vector<CircuitComputeVk::Response> parallel_vks(num_vks);
91 std::vector<CircuitComputeVk::Response> sequential_vks(num_vks);
92
93 // Use default settings
95 .oracle_hash_type = "poseidon2",
96 .disable_zk = false };
97
98 // Compute VKs in parallel
99 parallel_for(num_vks, [&](size_t i) {
100 parallel_vks[i] =
101 CircuitComputeVk{ .circuit = { .name = "test_circuit_" + std::to_string(i), .bytecode = bytecodes[i] },
102 .settings = settings }
103 .execute();
104 });
105
106 // Compute VKs sequentially
107 for (size_t i = 0; i < num_vks; ++i) {
108 sequential_vks[i] =
109 CircuitComputeVk{ .circuit = { .name = "test_circuit_" + std::to_string(i), .bytecode = bytecodes[i] },
110 .settings = settings }
111 .execute();
112 }
113
114 // Verify all VKs were computed successfully and match between parallel and sequential
115 for (size_t i = 0; i < num_vks; ++i) {
116 EXPECT_FALSE(parallel_vks[i].bytes.empty()) << "Parallel VK " << i << " is empty";
117 EXPECT_FALSE(sequential_vks[i].bytes.empty()) << "Sequential VK " << i << " is empty";
118
119 // Parallel and sequential should produce identical VKs for the same circuit
120 EXPECT_EQ(parallel_vks[i].bytes, sequential_vks[i].bytes)
121 << "Parallel VK " << i << " differs from sequential VK " << i;
122
123 // Each circuit should have a different VK (different number of constraints)
124 if (i > 0) {
125 EXPECT_NE(parallel_vks[i].bytes, parallel_vks[0].bytes)
126 << "VK " << i << " should differ from VK 0 (different circuits)";
127 }
128 }
129}
130
131} // namespace bb::bbapi
UltraHonk-specific command definitions for the Barretenberg RPC API.
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.
TEST_F(BBApiClientIvcTest, StandaloneVerificationKeySerialization)
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
size_t get_num_cpus()
Definition thread.cpp:33
void set_parallel_for_concurrency(size_t num_cores)
Definition thread.cpp:24
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:111
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
std::string name
Human-readable name for the circuit.
std::string name
Human-readable name for the circuit.
Represents a request to generate a proof. Currently, UltraHonk is the only proving system supported b...
Verify a proof against a verification key and public inputs.
std::vector< uint8_t > verification_key
bool ipa_accumulation
Optional flag to indicate if the proof should be generated with IPA accumulation (i....