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.
 
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 std::array< uint8_t, 128 > BN254_G2_ELEMENT_BYTES
 Raw 128-byte serialization of the BN254 G2 trusted-setup point [x]_2.
 
constexpr std::array< uint8_t, 32 > BN254_G2_ELEMENT_SHA256
 SHA-256 hash of BN254_G2_ELEMENT_BYTES.
 
constexpr uint256_t BN254_G1_FIRST_ELEMENT_COMPRESSED = uint256_t(1)
 Compressed form of the first G1 element (generator point).
 
constexpr uint256_t BN254_G1_SECOND_ELEMENT_COMPRESSED
 Compressed form of the second G1 element from the trusted setup.
 

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 75 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 21 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 66 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 91 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 96 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 83 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.

Retries on transient failures (connection errors, 5xx, 429) with exponential backoff so a momentary CDN/network blip doesn't propagate as a hard failure.

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 46 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 49 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 40 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 66 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 34 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 58 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.

Variable Documentation

◆ 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 14 of file bn254_crs_data.hpp.

◆ BN254_G1_FIRST_ELEMENT_COMPRESSED

constexpr uint256_t bb::srs::BN254_G1_FIRST_ELEMENT_COMPRESSED = uint256_t(1)
inlineconstexpr

Compressed form of the first G1 element (generator point).

For (1, 2): x=1, y=2 is even so sign bit = 0, compressed = uint256_t(1).

Definition at line 75 of file bn254_crs_data.hpp.

◆ BN254_G1_SECOND_ELEMENT_COMPRESSED

constexpr uint256_t bb::srs::BN254_G1_SECOND_ELEMENT_COMPRESSED
inlineconstexpr
Initial value:
=
uint256_t(0x266f22bdcf31e6f9ULL, 0xabe7fb61ba83effdULL, 0xff6bd1a87bbe4e62ULL, 0x2d360628289ff943ULL)

Compressed form of the second G1 element from the trusted setup.

x = 0x2d360628289ff943ff6bd1a87bbe4e62abe7fb61ba83effd266f22bdcf31e6f9 y = 0x26b92a79e563c3f48252cce7feeca2f0f8d33dcb4ef7b0643bf07bd405700aaa (even, sign bit = 0)

Definition at line 82 of file bn254_crs_data.hpp.

◆ BN254_G2_ELEMENT_BYTES

constexpr std::array<uint8_t, 128> bb::srs::BN254_G2_ELEMENT_BYTES
inlineconstexpr
Initial value:
= {
0x01, 0x18, 0xc4, 0xd5, 0xb8, 0x37, 0xbc, 0xc2, 0xbc, 0x89, 0xb5, 0xb3, 0x98, 0xb5, 0x97, 0x4e, 0x9f, 0x59, 0x44,
0x07, 0x3b, 0x32, 0x07, 0x8b, 0x7e, 0x23, 0x1f, 0xec, 0x93, 0x88, 0x83, 0xb0, 0x26, 0x0e, 0x01, 0xb2, 0x51, 0xf6,
0xf1, 0xc7, 0xe7, 0xff, 0x4e, 0x58, 0x07, 0x91, 0xde, 0xe8, 0xea, 0x51, 0xd8, 0x7a, 0x35, 0x8e, 0x03, 0x8b, 0x4e,
0xfe, 0x30, 0xfa, 0xc0, 0x93, 0x83, 0xc1, 0x22, 0xfe, 0xbd, 0xa3, 0xc0, 0xc0, 0x63, 0x2a, 0x56, 0x47, 0x5b, 0x42,
0x14, 0xe5, 0x61, 0x5e, 0x11, 0xe6, 0xdd, 0x3f, 0x96, 0xe6, 0xce, 0xa2, 0x85, 0x4a, 0x87, 0xd4, 0xda, 0xcc, 0x5e,
0x55, 0x04, 0xfc, 0x63, 0x69, 0xf7, 0x11, 0x0f, 0xe3, 0xd2, 0x51, 0x56, 0xc1, 0xbb, 0x9a, 0x72, 0x85, 0x9c, 0xf2,
0xa0, 0x46, 0x41, 0xf9, 0x9b, 0xa4, 0xee, 0x41, 0x3c, 0x80, 0xda, 0x6a, 0x5f, 0xe4
}

Raw 128-byte serialization of the BN254 G2 trusted-setup point [x]_2.

Identical to the contents of bn254_g2.dat distributed at https://crs.aztec-cdn.foundation/g2.dat. Exposed as a public constant so callers can SHA-256-pin the exact CDN bytes (see BN254_G2_ELEMENT_SHA256 below).

Definition at line 39 of file bn254_crs_data.hpp.

◆ BN254_G2_ELEMENT_SHA256

constexpr std::array<uint8_t, 32> bb::srs::BN254_G2_ELEMENT_SHA256
inlineconstexpr
Initial value:
= { 0x01, 0x79, 0x7b, 0xfc, 0x4d, 0xe5, 0xa9, 0x6f,
0x0e, 0x51, 0x6a, 0x9e, 0xa4, 0x53, 0x7d, 0x18,
0x78, 0x6d, 0xc3, 0x0c, 0xb9, 0x91, 0xac, 0xa4,
0x27, 0x4c, 0x95, 0x82, 0x2b, 0x69, 0xc3, 0x2f }

SHA-256 hash of BN254_G2_ELEMENT_BYTES.

Pinned so any G2 ingress (network download, on-disk cache, bbapi caller) can verify it is delivering the canonical Aztec trusted-setup [x]_2. Mirrors the BN254_G1_CHUNK_HASHES mechanism used for the (much larger) G1 CRS. Update this constant only in lockstep with BN254_G2_ELEMENT_BYTES; the test CrsFactory.Bn254G2HashMatchesPinnedBytes enforces this.

Definition at line 56 of file bn254_crs_data.hpp.