Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bbapi_chonk_pinned_inputs.test.cpp
Go to the documentation of this file.
7
8#include <gtest/gtest.h>
9
10#include <algorithm>
11#include <cstdint>
12#include <cstdlib>
13#include <filesystem>
14#include <string>
15#include <utility>
16#include <vector>
17
18namespace {
19
20class ChonkPinnedIvcInputsTest : public ::testing::Test {
21 protected:
22 static void SetUpTestSuite() { bb::srs::init_file_crs_factory(bb::srs::bb_crs_path()); }
23
24 static std::filesystem::path find_repo_root()
25 {
26 if (const char* env = std::getenv("AZTEC_REPO_ROOT"); env != nullptr && *env != '\0') {
27 return std::filesystem::path{ env };
28 }
29 return std::filesystem::weakly_canonical(std::filesystem::current_path() / "../../..");
30 }
31
32 static std::filesystem::path pinned_inputs_root()
33 {
34 if (const char* env = std::getenv("CHONK_PINNED_IVC_INPUTS_DIR"); env != nullptr && *env != '\0') {
35 return std::filesystem::path{ env };
36 }
37 return find_repo_root() / "yarn-project/end-to-end/example-app-ivc-inputs-out";
38 }
39
40 static std::vector<std::filesystem::path> find_flow_dirs(const std::filesystem::path& inputs_root)
41 {
43 if (!std::filesystem::is_directory(inputs_root)) {
44 return flows;
45 }
46 for (const auto& entry : std::filesystem::directory_iterator(inputs_root)) {
47 if (entry.is_directory() && std::filesystem::exists(entry.path() / "ivc-inputs.msgpack")) {
48 flows.push_back(entry.path());
49 }
50 }
51 std::sort(flows.begin(), flows.end());
52 return flows;
53 }
54
55 static void apply_flow_selection(std::vector<std::filesystem::path>& flows)
56 {
57 if (const char* filter = std::getenv("CHONK_PINNED_IVC_FLOW"); filter != nullptr && *filter != '\0') {
58 flows.erase(std::remove_if(flows.begin(),
59 flows.end(),
60 [filter](const auto& flow) {
61 return flow.filename().string().find(filter) == std::string::npos;
62 }),
63 flows.end());
64 }
65
66 const char* limit_env = std::getenv("CHONK_PINNED_IVC_FLOW_LIMIT");
67 if (limit_env == nullptr || *limit_env == '\0') {
68 return;
69 }
70 char* end = nullptr;
71 const long limit = std::strtol(limit_env, &end, 10);
72 if (end != limit_env && *end == '\0' && limit > 0 && static_cast<size_t>(limit) < flows.size()) {
73 flows.resize(static_cast<size_t>(limit));
74 }
75 }
76
77 static void run_flow(const std::filesystem::path& flow_dir)
78 {
79 const std::filesystem::path inputs_path = flow_dir / "ivc-inputs.msgpack";
80 info("ChonkPinnedIvcInputs: loading ", inputs_path.string());
81
82 auto raw_steps = bb::PrivateExecutionStepRaw::load_and_decompress(inputs_path);
83 ASSERT_FALSE(raw_steps.empty()) << "no execution steps in " << inputs_path;
84
85 const auto hiding_bytecode = raw_steps.back().bytecode;
86
89
90 bb::bbapi::ChonkStart{ .num_circuits = static_cast<uint32_t>(raw_steps.size()) }.execute(request);
91
92 for (auto& step : raw_steps) {
94 .circuit = { .name = std::move(step.function_name),
95 .bytecode = std::move(step.bytecode),
96 .verification_key = std::move(step.vk) }
97 }.execute(request);
98 bb::bbapi::ChonkAccumulate{ .witness = std::move(step.witness) }.execute(request);
99 }
100
101 auto prove_response = bb::bbapi::ChonkProve{}.execute(request);
102 auto vk_response =
103 bb::bbapi::ChonkComputeVk{ .circuit = { .bytecode = hiding_bytecode }, .use_zk_flavor = true }.execute();
104
105 auto verify_response =
106 bb::bbapi::ChonkVerify{ .proof = std::move(prove_response.proof), .vk = std::move(vk_response.bytes) }
107 .execute();
108 EXPECT_TRUE(verify_response.valid) << "ChonkVerify rejected " << flow_dir.filename();
109 }
110};
111
112TEST_F(ChonkPinnedIvcInputsTest, AllPinnedFlows)
113{
114 const auto inputs_root = pinned_inputs_root();
115 auto flows = find_flow_dirs(inputs_root);
116 ASSERT_FALSE(flows.empty()) << "no pinned Chonk flows under " << inputs_root
117 << ". Run `barretenberg/cpp/scripts/chonk_inputs.sh download` first.";
118
119 apply_flow_selection(flows);
120 const char* flow_filter = std::getenv("CHONK_PINNED_IVC_FLOW");
121 ASSERT_FALSE(flows.empty() && flow_filter != nullptr && *flow_filter != '\0')
122 << "CHONK_PINNED_IVC_FLOW='" << flow_filter << "' matched no pinned flows under " << inputs_root;
123 ASSERT_FALSE(flows.empty()) << "no pinned Chonk flows found under " << inputs_root;
124
125 for (const auto& flow : flows) {
126 SCOPED_TRACE("flow: " + flow.filename().string());
127 run_flow(flow);
128 }
129}
130
131} // namespace
Chonk-specific command definitions for the Barretenberg RPC API.
Shared type definitions for the Barretenberg RPC API.
#define info(...)
Definition log.hpp:93
TEST_F(BoomerangIPARecursiveTests, FullRecursiveVerifierMediumRandom)
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Cont filter(Cont const &in, F op)
Definition map.hpp:59
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static std::vector< PrivateExecutionStepRaw > load_and_decompress(const std::filesystem::path &input_path)
Accumulate the previously loaded circuit into the IVC proof.
std::vector< uint8_t > witness
Serialized witness data for the last loaded circuit.
Compute MegaHonk verification key for a circuit to be accumulated in Chonk.
Load a circuit into the Chonk instance for accumulation.
CircuitInput circuit
Circuit to be loaded with its bytecode and verification key.
Generate a proof for all accumulated circuits.
Response execute(BBApiRequest &request) &&
Initialize a new Chonk instance for incremental proof accumulation.
Verify a Chonk proof with its verification key.
ChonkProof proof
The Chonk proof to verify.
std::string name
Human-readable name for the circuit.
std::vector< uint8_t > bytecode
Serialized bytecode representation of the circuit.