Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
global_crs.cpp
Go to the documentation of this file.
1#include "global_crs.hpp"
6
7namespace {
10} // namespace
11
12namespace bb::srs {
13
14std::filesystem::path bb_crs_path()
15{
16 char* crs_path = std::getenv("CRS_PATH");
17 if (crs_path != nullptr) {
18 return std::filesystem::path(crs_path);
19 }
20 // Detect home directory for default CRS path
21 char* home = std::getenv("HOME");
22 std::filesystem::path base = home != nullptr ? std::filesystem::path(home) : "./";
23 return base / ".bb-crs";
24}
25
27{
28 if (bn254_crs_factory != nullptr) {
29 return;
30 }
31 bn254_crs_factory = std::make_shared<factories::MemBn254CrsFactory>(points, g2_point);
32}
33
38
39// Initializes the crs using the memory buffers
40void init_bn254_net_crs_factory(const std::filesystem::path& path)
41{
42 if (bn254_crs_factory != nullptr) {
43 return;
44 }
46}
47
48// Initializes crs from a file path this we use in the entire codebase
49void init_bn254_file_crs_factory(const std::filesystem::path& path)
50{
51 if (bn254_crs_factory != nullptr) {
52 return;
53 }
54 bn254_crs_factory = std::make_shared<factories::NativeBn254CrsFactory>(path, /* allow download = false */ false);
55}
56
57// Initializes the crs using the memory buffers
58void init_grumpkin_net_crs_factory(const std::filesystem::path& path)
59{
60 if (grumpkin_crs_factory != nullptr) {
61 return;
62 }
64}
65
66void init_grumpkin_file_crs_factory(const std::filesystem::path& path)
67{
68 if (grumpkin_crs_factory != nullptr) {
69 return;
70 }
71 grumpkin_crs_factory =
72 std::make_shared<factories::NativeGrumpkinCrsFactory>(path, /* allow download = false */ false);
73}
74
76{
77 if (!bn254_crs_factory) {
78 throw_or_abort("You need to initialize the global CRS with a call to init_crs_factory(...)!");
79 }
80 return bn254_crs_factory;
81}
82
84{
85 if (!grumpkin_crs_factory) {
86 throw_or_abort("You need to initialize the global CRS with a call to init_grumpkin_crs_factory(...)!");
87 }
88 return grumpkin_crs_factory;
89}
90
95
100
101} // namespace bb::srs
void init_grumpkin_net_crs_factory(const std::filesystem::path &path)
std::shared_ptr< factories::CrsFactory< curve::BN254 > > get_bn254_crs_factory()
void init_grumpkin_file_crs_factory(const std::filesystem::path &path)
std::filesystem::path bb_crs_path()
std::shared_ptr< factories::CrsFactory< curve::BN254 > > get_crs_factory()
std::shared_ptr< factories::CrsFactory< curve::Grumpkin > > get_grumpkin_crs_factory()
void init_grumpkin_mem_crs_factory(std::vector< curve::Grumpkin::AffineElement > const &points)
void init_bn254_net_crs_factory(const std::filesystem::path &path)
void init_bn254_file_crs_factory(const std::filesystem::path &path)
void init_bn254_mem_crs_factory(std::vector< g1::affine_element > const &points, g2::affine_element const &g2_point)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
void throw_or_abort(std::string const &err)