22 constexpr size_t COMPRESSED_POINT_SIZE = 32;
25 size_t bytes_per_point = num_points > 0 ? points_buf.size() / num_points : 0;
27 std::vector<uint8_t> uncompressed_out;
29 if (bytes_per_point == UNCOMPRESSED_POINT_SIZE) {
32 for (
auto i : chunk.
range(
static_cast<size_t>(num_points))) {
33 g1_points[i] = from_buffer<g1::affine_element>(points_buf.data(), i * UNCOMPRESSED_POINT_SIZE);
36 }
else if (bytes_per_point == COMPRESSED_POINT_SIZE) {
39 if (points_buf.size() == 0 || points_buf.size() % bb::srs::SRS_CHUNK_SIZE_BYTES != 0) {
41 " must be a positive multiple of " +
std::to_string(bb::srs::SRS_CHUNK_SIZE_BYTES));
43 size_t num_full_chunks = points_buf.size() / bb::srs::SRS_CHUNK_SIZE_BYTES;
44 size_t chunks_to_verify = std::min(num_full_chunks,
static_cast<size_t>(bb::srs::SRS_NUM_FULL_CHUNKS));
45 for (
size_t i = 0; i < chunks_to_verify; ++i) {
47 bb::srs::SRS_CHUNK_SIZE_BYTES);
49 if (hash != bb::srs::BN254_G1_CHUNK_HASHES[i]) {
56 for (
auto i : chunk.
range(
static_cast<size_t>(num_points))) {
57 uint256_t c = from_buffer<uint256_t>(points_buf.data(), i * COMPRESSED_POINT_SIZE);
58 g1_points[i] = g1::affine_element::from_compressed(c);
62 uncompressed_out.resize(
static_cast<size_t>(num_points) * UNCOMPRESSED_POINT_SIZE);
64 for (
auto i : chunk.
range(
static_cast<size_t>(num_points))) {
66 std::copy(buf.begin(), buf.end(), &uncompressed_out[i * UNCOMPRESSED_POINT_SIZE]);
70 throw_or_abort(
"SrsInitSrs: invalid points_buf size. Expected 32 or 64 bytes per point, got " +
77 throw_or_abort(
"SrsInitSrs: g1_points[0] is not the canonical BN254 generator");
80 throw_or_abort(
"SrsInitSrs: g1_points[1] does not match the canonical trusted-setup tau·G");
89 throw_or_abort(
"SrsInitSrs: g2_point bytes do not match the canonical Aztec [x]_2 SHA-256");
91 auto g2_point_elem = from_buffer<g2::affine_element>(g2_point.data());
92 if (!g2_point_elem.is_in_prime_subgroup()) {
93 throw_or_abort(
"SrsInitSrs: g2_point is not in the BN254 G2 prime-order subgroup");
99 return { .points_buf =
std::move(uncompressed_out) };