|
3 | 3 | #include "barretenberg/ecc/curves/bn254/g1.hpp" |
4 | 4 | #include "barretenberg/ecc/curves/bn254/g2.hpp" |
5 | 5 | #include "barretenberg/numeric/uint256/uint256.hpp" |
| 6 | +#include <array> |
| 7 | +#include <cstdint> |
6 | 8 |
|
7 | 9 | namespace bb::srs { |
8 | 10 |
|
@@ -30,25 +32,42 @@ inline g1::affine_element get_bn254_g1_second_element() |
30 | 32 | return from_buffer<g1::affine_element>(g1_second_data); |
31 | 33 | } |
32 | 34 |
|
| 35 | +/** |
| 36 | + * @brief Raw 128-byte serialization of the BN254 G2 trusted-setup point [x]_2. |
| 37 | + * @details Identical to the contents of `bn254_g2.dat` distributed at |
| 38 | + * https://crs.aztec-cdn.foundation/g2.dat. Exposed as a public constant so callers can |
| 39 | + * SHA-256-pin the exact CDN bytes (see `BN254_G2_ELEMENT_SHA256` below). |
| 40 | + */ |
| 41 | +inline constexpr std::array<uint8_t, 128> BN254_G2_ELEMENT_BYTES = { |
| 42 | + 0x01, 0x18, 0xc4, 0xd5, 0xb8, 0x37, 0xbc, 0xc2, 0xbc, 0x89, 0xb5, 0xb3, 0x98, 0xb5, 0x97, 0x4e, 0x9f, 0x59, 0x44, |
| 43 | + 0x07, 0x3b, 0x32, 0x07, 0x8b, 0x7e, 0x23, 0x1f, 0xec, 0x93, 0x88, 0x83, 0xb0, 0x26, 0x0e, 0x01, 0xb2, 0x51, 0xf6, |
| 44 | + 0xf1, 0xc7, 0xe7, 0xff, 0x4e, 0x58, 0x07, 0x91, 0xde, 0xe8, 0xea, 0x51, 0xd8, 0x7a, 0x35, 0x8e, 0x03, 0x8b, 0x4e, |
| 45 | + 0xfe, 0x30, 0xfa, 0xc0, 0x93, 0x83, 0xc1, 0x22, 0xfe, 0xbd, 0xa3, 0xc0, 0xc0, 0x63, 0x2a, 0x56, 0x47, 0x5b, 0x42, |
| 46 | + 0x14, 0xe5, 0x61, 0x5e, 0x11, 0xe6, 0xdd, 0x3f, 0x96, 0xe6, 0xce, 0xa2, 0x85, 0x4a, 0x87, 0xd4, 0xda, 0xcc, 0x5e, |
| 47 | + 0x55, 0x04, 0xfc, 0x63, 0x69, 0xf7, 0x11, 0x0f, 0xe3, 0xd2, 0x51, 0x56, 0xc1, 0xbb, 0x9a, 0x72, 0x85, 0x9c, 0xf2, |
| 48 | + 0xa0, 0x46, 0x41, 0xf9, 0x9b, 0xa4, 0xee, 0x41, 0x3c, 0x80, 0xda, 0x6a, 0x5f, 0xe4 |
| 49 | +}; |
| 50 | + |
| 51 | +/** |
| 52 | + * @brief SHA-256 hash of `BN254_G2_ELEMENT_BYTES`. |
| 53 | + * @details Pinned so any G2 ingress (network download, on-disk cache, bbapi caller) can verify it |
| 54 | + * is delivering the canonical Aztec trusted-setup [x]_2. Mirrors the `BN254_G1_CHUNK_HASHES` |
| 55 | + * mechanism used for the (much larger) G1 CRS. Update this constant only in lockstep with |
| 56 | + * `BN254_G2_ELEMENT_BYTES`; the test `CrsFactory.Bn254G2HashMatchesPinnedBytes` enforces this. |
| 57 | + */ |
| 58 | +inline constexpr std::array<uint8_t, 32> BN254_G2_ELEMENT_SHA256 = { 0x01, 0x79, 0x7b, 0xfc, 0x4d, 0xe5, 0xa9, 0x6f, |
| 59 | + 0x0e, 0x51, 0x6a, 0x9e, 0xa4, 0x53, 0x7d, 0x18, |
| 60 | + 0x78, 0x6d, 0xc3, 0x0c, 0xb9, 0x91, 0xac, 0xa4, |
| 61 | + 0x27, 0x4c, 0x95, 0x82, 0x2b, 0x69, 0xc3, 0x2f }; |
| 62 | + |
33 | 63 | /** |
34 | 64 | * @brief Reference BN254 G2 element from the trusted setup CRS |
35 | 65 | * @details This is the single G2 point used in the BN254 CRS for verification. |
36 | 66 | * Reference: https://crs.aztec-cdn.foundation/g2.dat |
37 | 67 | */ |
38 | 68 | inline g2::affine_element get_bn254_g2_crs_element() |
39 | 69 | { |
40 | | - // Hardcoded G2 element (128 bytes) - see reference URL above |
41 | | - static constexpr uint8_t g2_data[128] = { |
42 | | - 0x01, 0x18, 0xc4, 0xd5, 0xb8, 0x37, 0xbc, 0xc2, 0xbc, 0x89, 0xb5, 0xb3, 0x98, 0xb5, 0x97, 0x4e, |
43 | | - 0x9f, 0x59, 0x44, 0x07, 0x3b, 0x32, 0x07, 0x8b, 0x7e, 0x23, 0x1f, 0xec, 0x93, 0x88, 0x83, 0xb0, |
44 | | - 0x26, 0x0e, 0x01, 0xb2, 0x51, 0xf6, 0xf1, 0xc7, 0xe7, 0xff, 0x4e, 0x58, 0x07, 0x91, 0xde, 0xe8, |
45 | | - 0xea, 0x51, 0xd8, 0x7a, 0x35, 0x8e, 0x03, 0x8b, 0x4e, 0xfe, 0x30, 0xfa, 0xc0, 0x93, 0x83, 0xc1, |
46 | | - 0x22, 0xfe, 0xbd, 0xa3, 0xc0, 0xc0, 0x63, 0x2a, 0x56, 0x47, 0x5b, 0x42, 0x14, 0xe5, 0x61, 0x5e, |
47 | | - 0x11, 0xe6, 0xdd, 0x3f, 0x96, 0xe6, 0xce, 0xa2, 0x85, 0x4a, 0x87, 0xd4, 0xda, 0xcc, 0x5e, 0x55, |
48 | | - 0x04, 0xfc, 0x63, 0x69, 0xf7, 0x11, 0x0f, 0xe3, 0xd2, 0x51, 0x56, 0xc1, 0xbb, 0x9a, 0x72, 0x85, |
49 | | - 0x9c, 0xf2, 0xa0, 0x46, 0x41, 0xf9, 0x9b, 0xa4, 0xee, 0x41, 0x3c, 0x80, 0xda, 0x6a, 0x5f, 0xe4 |
50 | | - }; |
51 | | - return from_buffer<g2::affine_element>(g2_data); |
| 70 | + return from_buffer<g2::affine_element>(BN254_G2_ELEMENT_BYTES.data()); |
52 | 71 | } |
53 | 72 |
|
54 | 73 | /** |
|
0 commit comments