Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
get_grumpkin_crs.cpp
Go to the documentation of this file.
8
9namespace bb {
11 size_t num_points,
12 bool allow_download)
13{
14 std::filesystem::create_directories(path);
15
16 auto g1_path = path / "grumpkin_g1.flat.dat";
17 auto lock_path = path / "crs.lock";
18 // Acquire exclusive lock to prevent simultaneous generation/writes
19 FileLockGuard lock(lock_path.string());
20
21 size_t g1_downloaded_points = get_file_size(g1_path) / sizeof(curve::Grumpkin::AffineElement);
22
23 if (g1_downloaded_points >= num_points) {
24 vinfo("using cached grumpkin crs with num points ", g1_downloaded_points, " at: ", g1_path);
25 auto data = read_file(g1_path, num_points * sizeof(curve::Grumpkin::AffineElement));
27 for (uint32_t i = 0; i < num_points; ++i) {
28 points[i] = from_buffer<curve::Grumpkin::AffineElement>(data, i * sizeof(curve::Grumpkin::AffineElement));
29 }
30 if (points[0].on_curve()) {
31 return points;
32 }
33 }
34
35 if (!allow_download && g1_downloaded_points == 0) {
36 throw_or_abort("grumpkin g1 data not found and generation not allowed in this context");
37 } else if (!allow_download) {
38 throw_or_abort(format("grumpkin g1 data had ",
39 g1_downloaded_points,
40 " points and ",
41 num_points,
42 " were requested but generation not allowed in this context"));
43 }
44
45 vinfo("generating grumpkin crs...");
46 auto points = srs::generate_grumpkin_srs(num_points);
47 write_file(g1_path, to_buffer(points));
48 return points;
49}
50} // namespace bb
typename Group::affine_element AffineElement
Definition grumpkin.hpp:56
std::string format(Args... args)
Definition log.hpp:21
#define vinfo(...)
Definition log.hpp:79
const std::vector< FF > data
std::vector< grumpkin::g1::affine_element > generate_grumpkin_srs(size_t num_points)
Generates a monomial basis Grumpkin SRS on-the-fly.
Entry point for Barretenberg command-line interface.
std::vector< curve::Grumpkin::AffineElement > get_grumpkin_g1_data(const std::filesystem::path &path, size_t num_points, bool allow_download)
std::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)
Definition file_io.hpp:29
void write_file(const std::string &filename, std::vector< uint8_t > const &data)
Definition file_io.hpp:58
size_t get_file_size(std::string const &filename)
Definition file_io.hpp:17
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< uint8_t > to_buffer(T const &value)
void throw_or_abort(std::string const &err)