Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::srs Namespace Reference

Namespaces

namespace  factories
 

Functions

g1::affine_element get_bn254_g1_second_element ()
 Expected second G1 element from BN254 CRS.
 
g2::affine_element get_bn254_g2_crs_element ()
 Reference BN254 G2 element from the trusted setup CRS.
 
void verify_bn254_crs_integrity (const std::vector< uint8_t > &data)
 Verify downloaded CRS data against embedded SHA256 chunk hashes.
 
std::vector< grumpkin::g1::affine_elementgenerate_grumpkin_srs (size_t num_points)
 Generates a monomial basis Grumpkin SRS on-the-fly.
 
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.
 
std::filesystem::path bb_crs_path ()
 
void init_bn254_mem_crs_factory (std::vector< g1::affine_element > const &points, g2::affine_element const &g2_point)
 
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_grumpkin_net_crs_factory (const std::filesystem::path &path)
 
void init_grumpkin_file_crs_factory (const std::filesystem::path &path)
 
std::shared_ptr< factories::CrsFactory< curve::BN254 > > get_bn254_crs_factory ()
 
std::shared_ptr< factories::CrsFactory< curve::Grumpkin > > get_grumpkin_crs_factory ()
 
template<>
std::shared_ptr< factories::CrsFactory< curve::BN254 > > get_crs_factory ()
 
template<>
std::shared_ptr< factories::CrsFactory< curve::Grumpkin > > get_crs_factory ()
 
void init_file_crs_factory (const std::filesystem::path &path)
 
void init_net_crs_factory (const std::filesystem::path &path)
 
template<typename Curve >
std::shared_ptr< factories::CrsFactory< Curve > > get_crs_factory ()
 

Variables

constexpr g1::affine_element BN254_G1_FIRST_ELEMENT = g1::affine_one
 Expected first G1 element from BN254 CRS.
 
constexpr size_t CRS_HASH_CHUNK_SIZE = 8388608
 SHA256 hashes for integrity verification of downloaded BN254 CRS G1 data.
 
constexpr size_t CRS_NUM_CHUNK_HASHES = 257
 
constexpr size_t CRS_NUM_FULL_CHUNKS = 256
 
const std::array< crypto::Sha256Hash, 257 > BN254_CRS_CHUNK_HASHES
 

Function Documentation

◆ bb_crs_path()

std::filesystem::path bb::srs::bb_crs_path ( )

Definition at line 14 of file global_crs.cpp.

◆ generate_grumpkin_srs()

std::vector< grumpkin::g1::affine_element > bb::srs::generate_grumpkin_srs ( size_t  num_points)

Generates a monomial basis Grumpkin SRS on-the-fly.

The Grumpkin SRS does not require a trusted setup and has no underlying secret generator. Points are generated deterministically by hashing a protocol string with point indices. ! Note that the first element will not be equal to the generator point defined in grumpkin.hpp.

Parameters
num_pointsThe number of SRS points to generate
Returns
std::vector<grumpkin::g1::affine_element> The generated SRS points

Definition at line 12 of file grumpkin_srs_gen.cpp.

◆ get_bn254_crs_factory()

std::shared_ptr< factories::CrsFactory< curve::BN254 > > bb::srs::get_bn254_crs_factory ( )

Definition at line 72 of file global_crs.cpp.

◆ get_bn254_g1_second_element()

g1::affine_element bb::srs::get_bn254_g1_second_element ( )
inline

Expected second G1 element from BN254 CRS.

This is the second point in the BN254 CRS, corresponding to tau * G where tau is the secret from the trusted setup. Reference: https://crs.aztec-cdn.foundation/g1.dat (bytes 64-127)

Definition at line 20 of file bn254_crs_data.hpp.

◆ get_bn254_g2_crs_element()

g2::affine_element bb::srs::get_bn254_g2_crs_element ( )
inline

Reference BN254 G2 element from the trusted setup CRS.

This is the single G2 point used in the BN254 CRS for verification. Reference: https://crs.aztec-cdn.foundation/g2.dat

Definition at line 37 of file bn254_crs_data.hpp.

◆ get_crs_factory() [1/3]

template<>
std::shared_ptr< factories::CrsFactory< curve::BN254 > > bb::srs::get_crs_factory ( )

Definition at line 88 of file global_crs.cpp.

◆ get_crs_factory() [2/3]

template<>
std::shared_ptr< factories::CrsFactory< curve::Grumpkin > > bb::srs::get_crs_factory ( )

Definition at line 93 of file global_crs.cpp.

◆ get_crs_factory() [3/3]

template<typename Curve >
std::shared_ptr< factories::CrsFactory< Curve > > bb::srs::get_crs_factory ( )

◆ get_grumpkin_crs_factory()

std::shared_ptr< factories::CrsFactory< curve::Grumpkin > > bb::srs::get_grumpkin_crs_factory ( )

Definition at line 80 of file global_crs.cpp.

◆ http_download()

std::vector< uint8_t > bb::srs::http_download ( const std::string &  url,
size_t  start_byte = 0,
size_t  end_byte = 0 
)
inline

Download data from a URL with optional Range header support.

Parameters
urlFull URL (e.g., "http://crs.aztec-cdn.foundation/g1.dat")
start_byteStarting byte for range request (0 for no range)
end_byteEnding byte for range request (0 for no range)
Returns
Downloaded data as bytes

Definition at line 38 of file http_download.hpp.

◆ init_bn254_file_crs_factory()

void bb::srs::init_bn254_file_crs_factory ( const std::filesystem::path &  path)

Definition at line 46 of file global_crs.cpp.

◆ init_bn254_mem_crs_factory()

void bb::srs::init_bn254_mem_crs_factory ( std::vector< g1::affine_element > const &  points,
g2::affine_element const &  g2_point 
)

Definition at line 26 of file global_crs.cpp.

◆ init_bn254_net_crs_factory()

void bb::srs::init_bn254_net_crs_factory ( const std::filesystem::path &  path)

Definition at line 37 of file global_crs.cpp.

◆ init_file_crs_factory()

void bb::srs::init_file_crs_factory ( const std::filesystem::path &  path)
inline

Definition at line 14 of file global_crs.hpp.

◆ init_grumpkin_file_crs_factory()

void bb::srs::init_grumpkin_file_crs_factory ( const std::filesystem::path &  path)

Definition at line 63 of file global_crs.cpp.

◆ init_grumpkin_mem_crs_factory()

void bb::srs::init_grumpkin_mem_crs_factory ( std::vector< curve::Grumpkin::AffineElement > const &  points)

Definition at line 31 of file global_crs.cpp.

◆ init_grumpkin_net_crs_factory()

void bb::srs::init_grumpkin_net_crs_factory ( const std::filesystem::path &  path)

Definition at line 55 of file global_crs.cpp.

◆ init_net_crs_factory()

void bb::srs::init_net_crs_factory ( const std::filesystem::path &  path)
inline

Definition at line 29 of file global_crs.hpp.

◆ verify_bn254_crs_integrity()

void bb::srs::verify_bn254_crs_integrity ( const std::vector< uint8_t > &  data)
inline

Verify downloaded CRS data against embedded SHA256 chunk hashes.

Verifies the integrity of downloaded CRS data by checking SHA256 hashes of each 8MB chunk in parallel across available cores. Any trailing bytes smaller than a chunk are skipped. This provides integrity verification for CRS data downloaded over HTTP without requiring SSL/TLS.

Parameters
dataThe downloaded CRS data bytes (must be a multiple of CRS_HASH_CHUNK_SIZE)
Exceptions
Ifthe data is not chunk-aligned or any chunk hash does not match

Definition at line 307 of file bn254_crs_hashes.hpp.

Variable Documentation

◆ BN254_CRS_CHUNK_HASHES

const std::array<crypto::Sha256Hash, 257> bb::srs::BN254_CRS_CHUNK_HASHES
inline

Definition at line 34 of file bn254_crs_hashes.hpp.

◆ BN254_G1_FIRST_ELEMENT

constexpr g1::affine_element bb::srs::BN254_G1_FIRST_ELEMENT = g1::affine_one
inlineconstexpr

Expected first G1 element from BN254 CRS.

The first element of the G1 CRS is the standard BN254 G1 generator point (1, 2). This is used to verify the integrity of downloaded CRS files.

Definition at line 13 of file bn254_crs_data.hpp.

◆ CRS_HASH_CHUNK_SIZE

constexpr size_t bb::srs::CRS_HASH_CHUNK_SIZE = 8388608
constexpr

SHA256 hashes for integrity verification of downloaded BN254 CRS G1 data.

The CRS file is divided into 8MB (8,388,608 byte) chunks. Each entry contains the SHA256 hash of the corresponding chunk. Downloads are rounded up to 8MB boundaries so that every downloaded chunk can be fully verified.

Source file: bn254_g1.dat (2147483712 bytes, 33554433 G1 points) Chunk size: 8388608 bytes (131072 points per chunk) Total chunks: 257 (256 full + 1 partial of 64 bytes)

Regenerate with: barretenberg/scripts/generate_crs_hashes.sh

Definition at line 28 of file bn254_crs_hashes.hpp.

◆ CRS_NUM_CHUNK_HASHES

constexpr size_t bb::srs::CRS_NUM_CHUNK_HASHES = 257
constexpr

Definition at line 29 of file bn254_crs_hashes.hpp.

◆ CRS_NUM_FULL_CHUNKS

constexpr size_t bb::srs::CRS_NUM_FULL_CHUNKS = 256
constexpr

Definition at line 31 of file bn254_crs_hashes.hpp.