1
1
#include " get_bn254_crs.hpp"
2
-
3
- // Gets the transcript URL from the BARRETENBERG_TRANSCRIPT_URL environment variable, if set.
4
- // Otherwise returns the default URL.
5
- namespace {
6
- std::string get_bn254_transcript_url ()
7
- {
8
- const char * ENV_VAR_NAME = " BARRETENBERG_TRANSCRIPT_URL" ;
9
- const std::string DEFAULT_URL = " https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/monomial/transcript00.dat" ;
10
-
11
- const char * env_url = std::getenv (ENV_VAR_NAME);
12
-
13
- auto environment_variable_exists = ((env_url != nullptr ) && *env_url);
14
-
15
- return environment_variable_exists ? std::string (env_url) : DEFAULT_URL;
16
- }
17
- } // namespace
2
+ #include " barretenberg/bb/file_io.hpp"
18
3
19
4
std::vector<uint8_t > download_bn254_g1_data (size_t num_points)
20
5
{
21
- size_t g1_start = 28 ;
22
- size_t g1_end = g1_start + num_points * 64 - 1 ;
6
+ size_t g1_end = num_points * 64 - 1 ;
23
7
24
- std::string url = get_bn254_transcript_url () ;
8
+ std::string url = " https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/flat/g1.dat " ;
25
9
26
- std::string command =
27
- " curl -s -H \" Range: bytes=" + std::to_string (g1_start) + " -" + std::to_string (g1_end) + " \" '" + url + " '" ;
10
+ std::string command = " curl -s -H \" Range: bytes=0-" + std::to_string (g1_end) + " \" '" + url + " '" ;
28
11
29
12
auto data = exec_pipe (command);
30
13
// Header + num_points * sizeof point.
31
- if (data.size () < g1_end - g1_start ) {
14
+ if (data.size () < g1_end) {
32
15
throw std::runtime_error (" Failed to download g1 data." );
33
16
}
34
17
@@ -37,67 +20,52 @@ std::vector<uint8_t> download_bn254_g1_data(size_t num_points)
37
20
38
21
std::vector<uint8_t > download_bn254_g2_data ()
39
22
{
40
- size_t g2_start = 28 + 5040001 * 64 ;
41
- size_t g2_end = g2_start + 128 - 1 ;
42
-
43
- std::string url = get_bn254_transcript_url ();
44
-
45
- std::string command =
46
- " curl -s -H \" Range: bytes=" + std::to_string (g2_start) + " -" + std::to_string (g2_end) + " \" '" + url + " '" ;
47
-
23
+ std::string url = " https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/flat/g2.dat" ;
24
+ std::string command = " curl -s '" + url + " '" ;
48
25
return exec_pipe (command);
49
26
}
50
27
51
28
std::vector<barretenberg::g1::affine_element> get_bn254_g1_data (const std::filesystem::path& path, size_t num_points)
52
29
{
53
30
std::filesystem::create_directories (path);
54
- std::ifstream size_file (path / " size" );
55
- size_t size = 0 ;
56
- if (size_file) {
57
- size_file >> size;
58
- size_file.close ();
59
- }
60
- if (size >= num_points) {
61
- vinfo (" using cached crs at: " , path);
62
- auto data = read_file (path / " g1.dat" , 28 + num_points * 64 );
31
+
32
+ auto g1_path = path / " bn254_g1.dat" ;
33
+ size_t g1_file_size = get_file_size (g1_path);
34
+
35
+ if (g1_file_size >= num_points * 64 && g1_file_size % 64 == 0 ) {
36
+ vinfo (" using cached crs of size " , std::to_string (g1_file_size / 64 ), " at " , g1_path);
37
+ auto data = read_file (g1_path, g1_file_size);
63
38
auto points = std::vector<barretenberg::g1::affine_element>(num_points);
64
- auto size_of_points_in_bytes = num_points * 64 ;
65
- barretenberg::srs::IO<curve::BN254>:: read_affine_elements_from_buffer (
66
- points. data (), ( char *)data. data (), size_of_points_in_bytes);
39
+ for ( size_t i = 0 ; i < num_points; ++i) {
40
+ points[i] = from_buffer< barretenberg::g1::affine_element>(data, i * 64 );
41
+ }
67
42
return points;
68
43
}
69
44
70
45
vinfo (" downloading crs..." );
71
46
auto data = download_bn254_g1_data (num_points);
72
- write_file (path / " g1.dat" , data);
73
-
74
- std::ofstream new_size_file (path / " size" );
75
- if (!new_size_file) {
76
- throw std::runtime_error (" Failed to open size file for writing" );
77
- }
78
- new_size_file << num_points;
79
- new_size_file.close ();
47
+ write_file (g1_path, data);
80
48
81
49
auto points = std::vector<barretenberg::g1::affine_element>(num_points);
82
- barretenberg::srs::IO<curve::BN254>::read_affine_elements_from_buffer (
83
- points.data (), (char *)data.data (), data.size ());
50
+ for (size_t i = 0 ; i < num_points; ++i) {
51
+ points[i] = from_buffer<barretenberg::g1::affine_element>(data, i * 64 );
52
+ }
84
53
return points;
85
54
}
86
55
87
56
barretenberg::g2::affine_element get_bn254_g2_data (const std::filesystem::path& path)
88
57
{
89
58
std::filesystem::create_directories (path);
90
59
91
- try {
92
- auto data = read_file (path / " g2.dat" );
93
- barretenberg::g2::affine_element g2_point;
94
- barretenberg::srs::IO<curve::BN254>::read_affine_elements_from_buffer (&g2_point, (char *)data.data (), 128 );
95
- return g2_point;
96
- } catch (std::exception &) {
97
- auto data = download_bn254_g2_data ();
98
- write_file (path / " g2.dat" , data);
99
- barretenberg::g2::affine_element g2_point;
100
- barretenberg::srs::IO<curve::BN254>::read_affine_elements_from_buffer (&g2_point, (char *)data.data (), 128 );
101
- return g2_point;
60
+ auto g2_path = path / " bn254_g2.dat" ;
61
+ size_t g2_file_size = get_file_size (g2_path);
62
+
63
+ if (g2_file_size == 128 ) {
64
+ auto data = read_file (g2_path);
65
+ return from_buffer<barretenberg::g2::affine_element>(data.data ());
102
66
}
67
+
68
+ auto data = download_bn254_g2_data ();
69
+ write_file (g2_path, data);
70
+ return from_buffer<barretenberg::g2::affine_element>(data.data ());
103
71
}
0 commit comments