14#include <gtest/gtest.h>
25void check_bn254_consistency(
const fs::path& crs_download_path,
size_t num_points,
bool allow_download)
39 auto f_prover = file_crs.get_crs(num_points);
40 auto m_prover = mem_crs.get_crs(num_points);
41 EXPECT_EQ(m_prover->get_monomial_size(), f_prover->get_monomial_size());
47 auto f_ver = file_crs.get_verifier_crs();
48 auto m_ver = mem_crs.get_verifier_crs();
49 EXPECT_EQ(m_ver->get_g2x(), f_ver->get_g2x());
51 memcmp(m_ver->get_precomputed_g2_lines(),
52 f_ver->get_precomputed_g2_lines(),
57void check_grumpkin_consistency(
const fs::path& crs_download_path,
size_t num_points,
bool allow_download)
72 auto f_prover = file_crs.get_crs(num_points);
73 auto m_prover = mem_crs.get_crs(num_points);
74 EXPECT_EQ(m_prover->get_monomial_size(), f_prover->get_monomial_size());
85 const std::filesystem::path& temp_crs_path =
"barretenberg_srs_test_crs_bn254";
86 fs::remove_all(temp_crs_path);
87 fs::create_directories(temp_crs_path);
89 ASSERT_ANY_THROW(check_bn254_consistency(temp_crs_path, 1,
false));
90 check_bn254_consistency(temp_crs_path, 1,
true);
96 const std::filesystem::path& temp_crs_path =
"barretenberg_srs_test_crs_grumpkin";
97 fs::remove_all(temp_crs_path);
98 fs::create_directories(temp_crs_path);
100 ASSERT_ANY_THROW(check_grumpkin_consistency(temp_crs_path, 1,
false));
101 check_grumpkin_consistency(temp_crs_path, 1,
true);
108 const std::filesystem::path& temp_crs_path =
"barretenberg_srs_test_crs_bn254_fallback";
109 fs::remove_all(temp_crs_path);
110 fs::create_directories(temp_crs_path);
113 std::string bad_primary =
"http://nonexistent.invalid/g1_compressed.dat";
114 std::string good_fallback =
"http://crs.aztec-labs.com/g1_compressed.dat";
118 EXPECT_EQ(points.size(), 1);
122 fs::remove_all(temp_crs_path);
129 ASSERT_TRUE(g2_point.on_curve());
130 EXPECT_TRUE(g2_point.is_in_prime_subgroup());
154 const std::filesystem::path temp_path =
"barretenberg_srs_test_crs_g2_corruption";
155 fs::remove_all(temp_path);
156 fs::create_directories(temp_path);
160 corrupted[64] ^= 0xFF;
165 fs::remove_all(temp_path);
171 const std::filesystem::path temp_path =
"barretenberg_srs_test_crs_g2_infinity";
172 fs::remove_all(temp_path);
173 fs::create_directories(temp_path);
175 std::vector<uint8_t> infinity_bytes(128, 0xFF);
180 fs::remove_all(temp_path);
188 "http://crs.aztec-cdn.foundation/g1_compressed.dat", 0, bb::srs::SRS_CHUNK_SIZE_BYTES - 1);
191 EXPECT_EQ(hash, bb::srs::BN254_G1_CHUNK_HASHES[0]);
198 "http://crs.aztec-cdn.foundation/g1_compressed.dat", 0, bb::srs::SRS_CHUNK_SIZE_BYTES - 1);
200 data[bb::srs::SRS_CHUNK_SIZE_BYTES / 2] ^= 0xFF;
203 EXPECT_NE(hash, bb::srs::BN254_G1_CHUNK_HASHES[0]);
#define EXPECT_THROW_OR_ABORT(statement, matcher)
typename Group::affine_element AffineElement
const std::vector< MemoryValue > data
Sha256Hash sha256(const ByteContainer &input)
SHA-256 hash function (FIPS 180-4)
g2::affine_element get_bn254_g2_crs_element()
Reference BN254 G2 element from the trusted setup CRS.
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()
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 g1::affine_element BN254_G1_FIRST_ELEMENT
Expected first 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)
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
g2::affine_element get_bn254_g2_data(const std::filesystem::path &path)
void write_file(const std::string &filename, std::span< const uint8_t > data)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept