barretenberg
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
barretenberg::field< Params_ > Struct Template Reference

Classes

struct  wide_array
 

Public Types

using View = field
 
using Params = Params_
 
using in_buf = const uint8_t *
 
using vec_in_buf = const uint8_t *
 
using out_buf = uint8_t *
 
using vec_out_buf = uint8_t **
 

Public Member Functions

constexpr field (const numeric::uint256_t &input) noexcept
 
constexpr field (const unsigned long input) noexcept
 
constexpr field (const unsigned int input) noexcept
 
constexpr field (const unsigned long long input) noexcept
 
constexpr field (const int input) noexcept
 
constexpr field (const uint64_t a, const uint64_t b, const uint64_t c, const uint64_t d) noexcept
 
constexpr field (const uint512_t &input) noexcept
 Convert a 512-bit big integer into a field element.
 
constexpr field (std::string input) noexcept
 
constexpr operator uint32_t () const
 
constexpr operator uint64_t () const
 
constexpr operator uint128_t () const
 
constexpr operator uint256_t () const noexcept
 
constexpr uint256_t uint256_t_no_montgomery_conversion () const noexcept
 
constexpr field (const field &other) noexcept=default
 
constexpr field (field &&other) noexcept=default
 
constexpr fieldoperator= (const field &other) noexcept=default
 
constexpr fieldoperator= (field &&other) noexcept=default
 
BBERG_INLINE constexpr field operator* (const field &other) const noexcept
 
BBERG_INLINE constexpr field operator+ (const field &other) const noexcept
 
BBERG_INLINE constexpr field operator- (const field &other) const noexcept
 
BBERG_INLINE constexpr field operator- () const noexcept
 
constexpr field operator/ (const field &other) const noexcept
 
BBERG_INLINE constexpr field operator++ () noexcept
 
BBERG_INLINE constexpr field operator++ (int) noexcept
 
BBERG_INLINE constexpr fieldoperator*= (const field &other) noexcept
 
BBERG_INLINE constexpr fieldoperator+= (const field &other) noexcept
 
BBERG_INLINE constexpr fieldoperator-= (const field &other) noexcept
 
constexpr fieldoperator/= (const field &other) noexcept
 
BBERG_INLINE constexpr bool operator> (const field &other) const noexcept
 Greater-than operator.
 
BBERG_INLINE constexpr bool operator< (const field &other) const noexcept
 Less-than operator.
 
BBERG_INLINE constexpr bool operator== (const field &other) const noexcept
 
BBERG_INLINE constexpr bool operator!= (const field &other) const noexcept
 
BBERG_INLINE constexpr field to_montgomery_form () const noexcept
 
BBERG_INLINE constexpr field from_montgomery_form () const noexcept
 
BBERG_INLINE constexpr field sqr () const noexcept
 
BBERG_INLINE constexpr void self_sqr () noexcept
 
BBERG_INLINE constexpr field pow (const uint256_t &exponent) const noexcept
 
BBERG_INLINE constexpr field pow (uint64_t exponent) const noexcept
 
constexpr field invert () const noexcept
 
constexpr std::pair< bool, fieldsqrt () const noexcept
 Compute square root of the field element.
 
BBERG_INLINE constexpr void self_neg () noexcept
 
BBERG_INLINE constexpr void self_to_montgomery_form () noexcept
 
BBERG_INLINE constexpr void self_from_montgomery_form () noexcept
 
BBERG_INLINE constexpr void self_conditional_negate (uint64_t predicate) noexcept
 
BBERG_INLINE constexpr field reduce_once () const noexcept
 
BBERG_INLINE constexpr void self_reduce_once () noexcept
 
BBERG_INLINE constexpr void self_set_msb () noexcept
 
BBERG_INLINE constexpr bool is_msb_set () const noexcept
 
BBERG_INLINE constexpr uint64_t is_msb_set_word () const noexcept
 
BBERG_INLINE constexpr bool is_zero () const noexcept
 
BBERG_INLINE std::vector< uint8_t > to_buffer () const
 
BBERG_INLINE constexpr wide_array mul_512 (const field &other) const noexcept
 
BBERG_INLINE constexpr wide_array sqr_512 () const noexcept
 
BBERG_INLINE constexpr field conditionally_subtract_from_double_modulus (const uint64_t predicate) const noexcept
 
void msgpack_pack (auto &packer) const
 
void msgpack_unpack (auto o)
 
void msgpack_schema (auto &packer) const
 

Static Public Member Functions

static constexpr field cube_root_of_unity ()
 
static constexpr field zero ()
 
static constexpr field neg_one ()
 
static constexpr field one ()
 
static constexpr field external_coset_generator ()
 
static constexpr field tag_coset_generator ()
 
static constexpr field coset_generator (const size_t idx)
 
static void batch_invert (std::span< field > coeffs) noexcept
 
static void batch_invert (field *coeffs, size_t n) noexcept
 
static constexpr field get_root_of_unity (size_t subgroup_size) noexcept
 
static void serialize_to_buffer (const field &value, uint8_t *buffer)
 
static field serialize_from_buffer (const uint8_t *buffer)
 
static void split_into_endomorphism_scalars (const field &k, field &k1, field &k2)
 
static void split_into_endomorphism_scalars_384 (const field &input, field &k1_out, field &k2_out)
 
static BBERG_INLINE void __copy (const field &a, field &r) noexcept
 
static BBERG_INLINE void __swap (field &src, field &dest) noexcept
 
static field random_element (numeric::random::Engine *engine=nullptr) noexcept
 
static constexpr field multiplicative_generator () noexcept
 

Public Attributes

uint64_t data [4]
 

Static Public Attributes

static constexpr uint256_t modulus
 
static constexpr uint256_t modulus_minus_two
 

Friends

std::ostream & operator<< (std::ostream &os, const field &a)
 

Constructor & Destructor Documentation

◆ field()

template<class Params_ >
constexpr barretenberg::field< Params_ >::field ( const uint512_t &  input)
inlineexplicitconstexprnoexcept

Convert a 512-bit big integer into a field element.

Used for deriving field elements from random values. 512-bits prevents biased output as 2^512>>modulus

Member Function Documentation

◆ operator*()

template<class T >
constexpr field< T > barretenberg::field< T >::operator* ( const field< Params_ > &  other) const
constexprnoexcept

Mutiplication

◆ operator+()

template<class T >
constexpr field< T > barretenberg::field< T >::operator+ ( const field< Params_ > &  other) const
constexprnoexcept

Addition

◆ operator-()

template<class T >
constexpr field< T > barretenberg::field< T >::operator- ( const field< Params_ > &  other) const
constexprnoexcept

Subtraction

◆ operator<()

template<class T >
constexpr bool barretenberg::field< T >::operator< ( const field< Params_ > &  other) const
constexprnoexcept

Less-than operator.

comparison operators exist so that field is comparible with stl methods that require them. (e.g. std::sort) Finite fields do not have an explicit ordering, these should NEVER be used in algebraic algorithms.

Template Parameters
T
Parameters
other
Returns
true
false

◆ operator>()

template<class T >
constexpr bool barretenberg::field< T >::operator> ( const field< Params_ > &  other) const
constexprnoexcept

Greater-than operator.

comparison operators exist so that field is comparible with stl methods that require them. (e.g. std::sort) Finite fields do not have an explicit ordering, these should NEVER be used in algebraic algorithms.

Template Parameters
T
Parameters
other
Returns
true
false

◆ split_into_endomorphism_scalars()

template<class Params_ >
static void barretenberg::field< Params_ >::split_into_endomorphism_scalars ( const field< Params_ > &  k,
field< Params_ > &  k1,
field< Params_ > &  k2 
)
inlinestatic

For short Weierstrass curves y^2 = x^3 + b mod r, if there exists a cube root of unity mod r, we can take advantage of an enodmorphism to decompose a 254 bit scalar into 2 128 bit scalars. \beta = cube root of 1, mod q (q = order of fq) \lambda = cube root of 1, mod r (r = order of fr)

For a point P1 = (X, Y), where Y^2 = X^3 + b, we know that the point P2 = (X * \beta, Y) is also a point on the curve We can represent P2 as a scalar multiplication of P1, where P2 = \lambda * P1

For a generic multiplication of P1 by a 254 bit scalar k, we can decompose k into 2 127 bit scalars (k1, k2), such that k = k1 - (k2 * \lambda)

We can now represent (k * P1) as (k1 * P1) - (k2 * P2), where P2 = (X * \beta, Y). As k1, k2 have half the bit length of k, we have reduced the number of loop iterations of our scalar multiplication algorithm in half

To find k1, k2, We use the extended euclidean algorithm to find 4 short scalars [a1, a2], [b1, b2] such that modulus = (a1 * b2) - (b1 * a2) We then compute scalars c1 = round(b2 * k / r), c2 = round(b1 * k / r), where k1 = (c1 * a1) + (c2 * a2), k2 = -((c1 * b1) + (c2 * b2)) We pre-compute scalars g1 = (2^256 * b1) / n, g2 = (2^256 * b2) / n, to avoid having to perform long division on 512-bit scalars

◆ sqr()

template<class T >
constexpr field< T > barretenberg::field< T >::sqr
constexprnoexcept

Squaring

◆ sqrt()

template<class T >
constexpr std::pair< bool, field< T > > barretenberg::field< T >::sqrt
constexprnoexcept

Compute square root of the field element.

Returns
<true, root> if the element is a quadratic remainder, <false, 0> if it's not

Member Data Documentation

◆ modulus

template<class Params_ >
constexpr uint256_t barretenberg::field< Params_ >::modulus
staticconstexpr
Initial value:
=
uint256_t{ Params::modulus_0, Params::modulus_1, Params::modulus_2, Params::modulus_3 }

◆ modulus_minus_two

template<class Params_ >
constexpr uint256_t barretenberg::field< Params_ >::modulus_minus_two
staticconstexpr
Initial value:
=
uint256_t(Params::modulus_0 - 2ULL, Params::modulus_1, Params::modulus_2, Params::modulus_3)

The documentation for this struct was generated from the following files: