Barretenberg
The ZK-SNARK library at the core of Aztec
|
Functions | |
grumpkin::fr | convert_grumpkin_fr_from_bn254_frs (std::span< const bb::fr > fr_vec) |
Converts 2 bb::fr elements to grumpkin::fr. | |
std::vector< bb::fr > | convert_grumpkin_fr_to_bn254_frs (const grumpkin::fr &val) |
Converts grumpkin::fr to 2 bb::fr elements. | |
grumpkin::fr | convert_to_grumpkin_fr (const bb::fr &f) |
template<typename T > | |
constexpr size_t | calc_num_bn254_frs () |
Calculates the size of a types in terms of bb::frs. | |
template<typename T > | |
constexpr size_t | calc_num_uint256_ts () |
Calculates the size of a types in terms of uint256_t. | |
template<typename T > | |
T | convert_from_bn254_frs (std::span< const bb::fr > fr_vec) |
Conversions from vector of bb::fr elements to transcript types. | |
template<typename T > | |
T | convert_from_uint256_ts (std::span< const uint256_t > uint256_vec) |
template<typename T > | |
std::vector< bb::fr > | convert_to_bn254_frs (const T &val) |
Conversion from transcript values to bb::frs. | |
template<typename T > | |
std::vector< uint256_t > | convert_to_uint256 (const T &val) |
Conversion from transcript values to bb::frs. | |
template<typename T > | |
T | convert_challenge (const bb::fr &challenge) |
|
constexpr |
Calculates the size of a types in terms of bb::frs.
We want to support the following types: bool, size_t, uint32_t, uint64_t, bb::fr, grumpkin::fr, curve::BN254::AffineElement, curve::Grumpkin::AffineElement, bb::Univariate<FF, N>, std::array<FF, N>, for FF = bb::fr/grumpkinfr, and N is arbitrary
T |
Definition at line 26 of file field_conversion.hpp.
|
constexpr |
Calculates the size of a types in terms of uint256_t.
T |
Definition at line 45 of file field_conversion.hpp.
|
inline |
Definition at line 231 of file field_conversion.hpp.
T bb::field_conversion::convert_from_bn254_frs | ( | std::span< const bb::fr > | fr_vec | ) |
Conversions from vector of bb::fr elements to transcript types.
We want to support the following types: bool, size_t, uint32_t, uint64_t, bb::fr, grumpkin::fr, curve::BN254::AffineElement, curve::Grumpkin::AffineElement, bb::Univariate<FF, N>, std::array<FF, N>, for FF = bb::fr/grumpkinfr, and N is arbitrary. The only nontrivial implementation is the conversion for grumpkin::fr. More details are given in the function comment below.
T |
fr_vec |
Definition at line 70 of file field_conversion.hpp.
T bb::field_conversion::convert_from_uint256_ts | ( | std::span< const uint256_t > | uint256_vec | ) |
Definition at line 107 of file field_conversion.hpp.
grumpkin::fr bb::field_conversion::convert_grumpkin_fr_from_bn254_frs | ( | std::span< const bb::fr > | fr_vec | ) |
Converts 2 bb::fr elements to grumpkin::fr.
First, this function must take in 2 bb::fr elements because the grumpkin::fr field has a larger modulus than the bb::fr field, so we choose to send 1 grumpkin::fr element to 2 bb::fr elements to maintain injectivity. For the implementation, we want to minimize the number of constraints created by the circuit form, which happens to use 68 bit limbs to represent a grumpkin::fr (as a bigfield). Therefore, our mapping will split a grumpkin::fr into a 136 bit chunk for the lower two bigfield limbs and the upper chunk for the upper two limbs. The upper chunk ends up being 254 - 2*68 = 118 bits as a result. This is why we check that the bb::frs must be at most 136 and 118 bits respectively (to ensure no overflow). Then, we converts the two chunks to a grumpkin::fr using uint256_t conversions.
low_bits_in | |
high_bits_in |
Definition at line 28 of file field_conversion.cpp.
std::vector< bb::fr > bb::field_conversion::convert_grumpkin_fr_to_bn254_frs | ( | const grumpkin::fr & | val | ) |
Converts grumpkin::fr to 2 bb::fr elements.
First, this function must return 2 bb::fr elements because the grumpkin::fr field has a larger modulus than the bb::fr field, so we choose to send 1 grumpkin::fr element to 2 bb::fr elements to maintain injectivity. This function the reverse of convert_from_bn254_frs(std::span<const bb::fr> fr_vec, grumpkin::fr*) by merging the two pairs of limbs back into the 2 bb::fr elements. For the implementation, we want to minimize the number of constraints created by the circuit form, which happens to use 68 bit limbs to represent a grumpkin::fr (as a bigfield). Therefore, our mapping will split a grumpkin::fr into a 136 bit chunk for the lower two bigfield limbs and the upper chunk for the upper two limbs. The upper chunk ends up being 254 - 2*68 = 118 bits as a result. We manipulate the value using bitwise masks and shifts to obtain our two chunks.
input |
Definition at line 55 of file field_conversion.cpp.
std::vector< bb::fr > bb::field_conversion::convert_to_bn254_frs | ( | const T & | val | ) |
Conversion from transcript values to bb::frs.
We want to support the following types: bool, size_t, uint32_t, uint64_t, bb::fr, grumpkin::fr, curve::BN254::AffineElement, curve::Grumpkin::AffineElement, bb::Univariate<FF, N>, std::array<FF, N>, for FF = bb::fr/grumpkinfr, and N is arbitrary.
T |
val |
Definition at line 152 of file field_conversion.hpp.
grumpkin::fr bb::field_conversion::convert_to_grumpkin_fr | ( | const bb::fr & | f | ) |
Definition at line 70 of file field_conversion.cpp.
std::vector< uint256_t > bb::field_conversion::convert_to_uint256 | ( | const T & | val | ) |
Conversion from transcript values to bb::frs.
We want to support the following types: bool, size_t, uint32_t, uint64_t, bb::fr, grumpkin::fr, curve::BN254::AffineElement, curve::Grumpkin::AffineElement, bb::Univariate<FF, N>, std::array<FF, N>, for FF = bb::fr/grumpkinfr, and N is arbitrary.
T |
val |
Definition at line 196 of file field_conversion.hpp.