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

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::frconvert_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 >
convert_from_bn254_frs (std::span< const bb::fr > fr_vec)
 Conversions from vector of bb::fr elements to transcript types.
 
template<typename T >
convert_from_uint256_ts (std::span< const uint256_t > uint256_vec)
 
template<typename T >
std::vector< bb::frconvert_to_bn254_frs (const T &val)
 Conversion from transcript values to bb::frs.
 
template<typename T >
std::vector< uint256_tconvert_to_uint256 (const T &val)
 Conversion from transcript values to bb::frs.
 
template<typename T >
convert_challenge (const bb::fr &challenge)
 

Function Documentation

◆ calc_num_bn254_frs()

template<typename T >
constexpr size_t bb::field_conversion::calc_num_bn254_frs ( )
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

Template Parameters
T
Returns
constexpr size_t

Definition at line 26 of file field_conversion.hpp.

◆ calc_num_uint256_ts()

template<typename T >
constexpr size_t bb::field_conversion::calc_num_uint256_ts ( )
constexpr

Calculates the size of a types in terms of uint256_t.

Template Parameters
T
Returns
constexpr size_t

Definition at line 45 of file field_conversion.hpp.

◆ convert_challenge()

template<typename T >
T bb::field_conversion::convert_challenge ( const bb::fr challenge)
inline

Definition at line 231 of file field_conversion.hpp.

◆ convert_from_bn254_frs()

template<typename T >
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.

Template Parameters
T
Parameters
fr_vec
Returns
T

Definition at line 70 of file field_conversion.hpp.

◆ convert_from_uint256_ts()

template<typename T >
T bb::field_conversion::convert_from_uint256_ts ( std::span< const uint256_t uint256_vec)

Definition at line 107 of file field_conversion.hpp.

◆ convert_grumpkin_fr_from_bn254_frs()

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.

Parameters
low_bits_in
high_bits_in
Returns
grumpkin::fr

Definition at line 28 of file field_conversion.cpp.

◆ convert_grumpkin_fr_to_bn254_frs()

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.

Parameters
input
Returns
std::array<bb::fr, 2>

Definition at line 55 of file field_conversion.cpp.

◆ convert_to_bn254_frs()

template<typename T >
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.

Template Parameters
T
Parameters
val
Returns
std::vector<bb::fr>

Definition at line 152 of file field_conversion.hpp.

◆ convert_to_grumpkin_fr()

grumpkin::fr bb::field_conversion::convert_to_grumpkin_fr ( const bb::fr f)

Definition at line 70 of file field_conversion.cpp.

◆ convert_to_uint256()

template<typename T >
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.

Template Parameters
T
Parameters
val
Returns
std::vector<bb::fr>

Definition at line 196 of file field_conversion.hpp.