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.
6
7#include <gtest/gtest.h>
8
9#include <algorithm>
10#include <cstdint>
11#include <cstdlib>
12#include <filesystem>
13#include <string>
14#include <utility>
15#include <vector>
16
17namespace {
18
19class ChonkPinnedIvcInputsTest : public ::testing::Test {
20 protected:
21 static void SetUpTestSuite() { bb::srs::init_file_crs_factory(bb::srs::bb_crs_path()); }
22
23 static std::filesystem::path find_repo_root()
24 {
25 if (const char* env = std::getenv("AZTEC_REPO_ROOT"); env != nullptr && *env != '\0') {
26 return std::filesystem::path{ env };
27 }
28 return std::filesystem::weakly_canonical(std::filesystem::current_path() / "../../..");
29 }
30
31 static std::filesystem::path pinned_inputs_root()
32 {
33 if (const char* env = std::getenv("CHONK_PINNED_IVC_INPUTS_DIR"); env != nullptr && *env != '\0') {
34 return std::filesystem::path{ env };
35 }
36 return find_repo_root() / "barretenberg/cpp/chonk-pinned-flows";
37 }
38
39 static std::vector<std::filesystem::path> find_flow_dirs(const std::filesystem::path& inputs_root)
40 {
42 if (!std::filesystem::is_directory(inputs_root)) {
43 return flows;
44 }
45 for (const auto& entry : std::filesystem::directory_iterator(inputs_root)) {
46 if (entry.is_directory() && std::filesystem::exists(entry.path() / "ivc-inputs.msgpack")) {
47 flows.push_back(entry.path());
48 }
49 }
50 std::sort(flows.begin(), flows.end());
51 return flows;
52 }
53
54 static void apply_flow_selection(std::vector<std::filesystem::path>& flows)
55 {
56 if (const char* filter = std::getenv("CHONK_PINNED_IVC_FLOW"); filter != nullptr && *filter != '\0') {
57 flows.erase(std::remove_if(flows.begin(),
58 flows.end(),
59 [filter](const auto& flow) {
60 return flow.filename().string().find(filter) == std::string::npos;
61 }),
62 flows.end());
63 }
64
65 const char* limit_env = std::getenv("CHONK_PINNED_IVC_FLOW_LIMIT");
66 if (limit_env == nullptr || *limit_env == '\0') {
67 return;
68 }
69 char* end = nullptr;
70 const long limit = std::strtol(limit_env, &end, 10);
71 if (end != limit_env && *end == '\0' && limit > 0 && static_cast<size_t>(limit) < flows.size()) {
72 flows.resize(static_cast<size_t>(limit));
73 }
74 }
75
76 static void run_flow(const std::filesystem::path& flow_dir)
77 {
78 const std::filesystem::path inputs_path = flow_dir / "ivc-inputs.msgpack";
79 info("ChonkPinnedIvcInputs: loading ", inputs_path.string());
80
81 auto raw_steps = bb::PrivateExecutionStepRaw::load_and_decompress(inputs_path);
82 ASSERT_FALSE(raw_steps.empty()) << "no execution steps in " << inputs_path;
83
84 const auto hiding_vk = raw_steps.back().vk;
85
88
90 bb::bbapi::wire::ChonkStart{
91 .num_circuits = static_cast<uint32_t>(raw_steps.size()),
92 });
93
94 for (auto& step : raw_steps) {
96 bb::bbapi::wire::ChonkLoad{
97 .circuit = { .name = std::move(step.function_name),
98 .bytecode = std::move(step.bytecode),
99 .verification_key = std::move(step.vk) },
100 });
102 bb::bbapi::wire::ChonkAccumulate{
103 .witness = std::move(step.witness),
104 });
105 }
106
107 auto prove_response = bb::bbapi::handle_chonk_prove(request, bb::bbapi::wire::ChonkProve{});
108
109 auto verify_response = bb::bbapi::handle_chonk_verify(
110 request, bb::bbapi::wire::ChonkVerify{ .proof = std::move(prove_response.proof), .vk = hiding_vk });
111 EXPECT_TRUE(verify_response.valid) << "ChonkVerify rejected " << flow_dir.filename();
112 }
113};
114
115TEST_F(ChonkPinnedIvcInputsTest, AllPinnedFlows)
116{
117 const auto inputs_root = pinned_inputs_root();
118 auto flows = find_flow_dirs(inputs_root);
119 ASSERT_FALSE(flows.empty()) << "no pinned Chonk flows under " << inputs_root
120 << ". Run `barretenberg/cpp/scripts/chonk_inputs.sh download` first.";
121
122 apply_flow_selection(flows);
123 const char* flow_filter = std::getenv("CHONK_PINNED_IVC_FLOW");
124 ASSERT_FALSE(flows.empty() && flow_filter != nullptr && *flow_filter != '\0')
125 << "CHONK_PINNED_IVC_FLOW='" << flow_filter << "' matched no pinned flows under " << inputs_root;
126 ASSERT_FALSE(flows.empty()) << "no pinned Chonk flows found under " << inputs_root;
127
128 for (const auto& flow : flows) {
129 SCOPED_TRACE("flow: " + flow.filename().string());
130 run_flow(flow);
131 }
132}
133
134} // namespace
Non-template handler declarations for the bb service.
Shared type definitions for the Barretenberg RPC API.
#define info(...)
Definition log.hpp:93
TEST_F(BoomerangIPARecursiveTests, FullRecursiveVerifierMediumRandom)
wire::ChonkVerifyResponse handle_chonk_verify(BBApiRequest &, wire::ChonkVerify &&cmd)
wire::ChonkProveResponse handle_chonk_prove(BBApiRequest &request, wire::ChonkProve &&)
wire::ChonkAccumulateResponse handle_chonk_accumulate(BBApiRequest &request, wire::ChonkAccumulate &&cmd)
wire::ChonkLoadResponse handle_chonk_load(BBApiRequest &request, wire::ChonkLoad &&cmd)
wire::ChonkStartResponse handle_chonk_start(BBApiRequest &request, wire::ChonkStart &&cmd)
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)