12constexpr const char* CRS_PRIMARY_URL =
"http://crs.aztec-cdn.foundation/g1.dat";
14constexpr const char* CRS_FALLBACK_URL =
"http://crs.aztec-labs.com/g1.dat";
16std::vector<uint8_t> download_bn254_g1_data(
size_t num_points,
17 const std::string& primary_url,
18 const std::string& fallback_url)
25 std::vector<uint8_t>
data;
29 }
catch (
const std::exception& e) {
30 vinfo(
"Primary CRS download failed: ", e.what(),
". Trying fallback...");
36 static_cast<void>(fallback_url);
44 auto first_element = from_buffer<bb::g1::affine_element>(
data, 0);
46 throw_or_abort(
"Downloaded BN254 G1 CRS first element does not match expected point.");
53 throw_or_abort(
"Downloaded BN254 G1 CRS second element does not match expected point.");
67 const std::string& primary_url,
68 const std::string& fallback_url)
70 std::filesystem::create_directories(path);
72 auto g1_path = path /
"bn254_g1.dat";
73 auto lock_path = path /
"crs.lock";
79 if (g1_downloaded_points >= num_points) {
80 vinfo(
"using cached bn254 crs with num points ",
std::to_string(g1_downloaded_points),
" at ", g1_path);
83 for (
size_t i = 0; i < num_points; ++i) {
89 if (!allow_download && g1_downloaded_points == 0) {
90 throw_or_abort(
"bn254 g1 data not found and download not allowed in this context");
91 }
else if (!allow_download) {
96 " were requested but download not allowed in this context"));
101 if (g1_downloaded_points >= num_points) {
102 vinfo(
"using cached bn254 crs with num points ",
std::to_string(g1_downloaded_points),
" at ", g1_path);
105 for (
size_t i = 0; i < num_points; ++i) {
111 vinfo(
"downloading bn254 crs...");
112 auto data = download_bn254_g1_data(num_points, primary_url, fallback_url);
116 for (
size_t i = 0; i < num_points; ++i) {
127 return get_bn254_g1_data(path, num_points, allow_download, CRS_PRIMARY_URL, CRS_FALLBACK_URL);
group_elements::affine_element< Fq, Fr, Params > affine_element
std::string format(Args... args)
const std::vector< MemoryValue > data
std::vector< uint8_t > http_download(const std::string &url, size_t start_byte=0, size_t end_byte=0)
Download data from a URL with optional Range header support.
constexpr g1::affine_element BN254_G1_FIRST_ELEMENT
Expected first G1 element from BN254 CRS.
g1::affine_element get_bn254_g1_second_element()
Expected second G1 element from BN254 CRS.
Entry point for Barretenberg command-line interface.
std::vector< g1::affine_element > get_bn254_g1_data(const std::filesystem::path &path, size_t num_points, bool allow_download, const std::string &primary_url, const std::string &fallback_url)
std::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)
void write_file(const std::string &filename, std::vector< uint8_t > const &data)
size_t get_file_size(std::string const &filename)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
void throw_or_abort(std::string const &err)