Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::field< Params_ > Struct Template Reference

General class for prime fields see Prime field documentation["field documentation"] for general implementation reference. More...

#include <field_declarations.hpp>

Classes

struct  wide_array
 
struct  wnaf_table
 

Public Types

using View = field
 
using CoefficientAccumulator = 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

 field ()=default
 
constexpr field (const numeric::uint256_t &input) noexcept
 
constexpr field (const uint128_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 bool () const
 
constexpr operator uint8_t () const
 
constexpr operator uint16_t () const
 
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
 
constexpr ~field () noexcept=default
 
BB_INLINE constexpr field operator* (const field &other) const noexcept
 
BB_INLINE constexpr field operator+ (const field &other) const noexcept
 
BB_INLINE constexpr field operator- (const field &other) const noexcept
 
BB_INLINE constexpr field operator- () const noexcept
 
constexpr field operator/ (const field &other) const noexcept
 
BB_INLINE constexpr field operator++ () noexcept
 
BB_INLINE constexpr field operator++ (int) noexcept
 
BB_INLINE constexpr fieldoperator*= (const field &other) &noexcept
 
BB_INLINE constexpr fieldoperator+= (const field &other) &noexcept
 
BB_INLINE constexpr fieldoperator-= (const field &other) &noexcept
 
constexpr fieldoperator/= (const field &other) &noexcept
 
BB_INLINE constexpr bool operator> (const field &other) const noexcept
 Greater-than operator.
 
BB_INLINE constexpr bool operator< (const field &other) const noexcept
 Less-than operator.
 
BB_INLINE constexpr bool operator== (const field &other) const noexcept
 
BB_INLINE constexpr bool operator!= (const field &other) const noexcept
 
BB_INLINE constexpr field to_montgomery_form () const noexcept
 
BB_INLINE constexpr field from_montgomery_form () const noexcept
 
BB_INLINE constexpr field sqr () const noexcept
 
BB_INLINE constexpr void self_sqr () &noexcept
 
BB_INLINE constexpr field pow (const uint256_t &exponent) const noexcept
 
BB_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.
 
constexpr std::pair< bool, fieldsqrt () const noexcept
 
BB_INLINE constexpr void self_neg () &noexcept
 
BB_INLINE constexpr void self_to_montgomery_form () &noexcept
 
BB_INLINE constexpr void self_from_montgomery_form () &noexcept
 
BB_INLINE constexpr void self_conditional_negate (uint64_t predicate) &noexcept
 
BB_INLINE constexpr field reduce_once () const noexcept
 
BB_INLINE constexpr void self_reduce_once () &noexcept
 
BB_INLINE constexpr void self_set_msb () &noexcept
 
BB_INLINE constexpr bool is_msb_set () const noexcept
 
BB_INLINE constexpr uint64_t is_msb_set_word () const noexcept
 
BB_INLINE constexpr bool is_zero () const noexcept
 
BB_INLINE std::vector< uint8_t > to_buffer () const
 
BB_INLINE constexpr wide_array mul_512 (const field &other) const noexcept
 
BB_INLINE constexpr wide_array sqr_512 () const noexcept
 
BB_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
 
BB_INLINE constexpr field reduce () const noexcept
 
BB_INLINE constexpr field add (const field &other) const noexcept
 
BB_INLINE constexpr field subtract (const field &other) const noexcept
 
BB_INLINE constexpr field subtract_coarse (const field &other) const noexcept
 
BB_INLINE constexpr field montgomery_mul (const field &other) const noexcept
 
BB_INLINE constexpr field montgomery_mul_big (const field &other) const noexcept
 Mongtomery multiplication for moduli > 2²⁵⁴
 
BB_INLINE constexpr field montgomery_square () const noexcept
 
constexpr field tonelli_shanks_sqrt () const noexcept
 Implements an optimized variant of Tonelli-Shanks via lookup tables. Algorithm taken from https://cr.yp.to/papers/sqroot-20011123-retypeset20220327.pdf "FASTER SQUARE ROOTS IN ANNOYING FINITE FIELDS" by D. Bernstein Page 5 "Accelerated Discrete Logarithm".
 

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 ()
 
template<size_t idx>
static constexpr field coset_generator ()
 
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)
 
template<class V >
static field reconstruct_from_public (const std::span< const field< V >, PUBLIC_INPUTS_SIZE > &limbs)
 
static void split_into_endomorphism_scalars (const field &k, field &k1, field &k2)
 
static std::pair< std::array< uint64_t, 2 >, std::array< uint64_t, 2 > > split_into_endomorphism_scalars (const field &k)
 
static void split_into_endomorphism_scalars_384 (const field &input, field &k1_out, field &k2_out)
 
static BB_INLINE void __copy (const field &a, field &r) noexcept
 
static BB_INLINE void __swap (field &src, field &dest) noexcept
 
static field random_element (numeric::RNG *engine=nullptr) noexcept
 
static constexpr field multiplicative_generator () noexcept
 
static BB_INLINE constexpr void wasm_madd (uint64_t &left_limb, const std::array< uint64_t, WASM_NUM_LIMBS > &right_limbs, uint64_t &result_0, uint64_t &result_1, uint64_t &result_2, uint64_t &result_3, uint64_t &result_4, uint64_t &result_5, uint64_t &result_6, uint64_t &result_7, uint64_t &result_8)
 Multiply left limb by a sequence of 9 limbs and put into result variables.
 
static BB_INLINE constexpr void wasm_reduce (uint64_t &result_0, uint64_t &result_1, uint64_t &result_2, uint64_t &result_3, uint64_t &result_4, uint64_t &result_5, uint64_t &result_6, uint64_t &result_7, uint64_t &result_8)
 Perform 29-bit montgomery reduction on 1 limb (result_0 should be zero modulo 2**29 after this)
 
static BB_INLINE constexpr void wasm_reduce_yuval (uint64_t &result_0, uint64_t &result_1, uint64_t &result_2, uint64_t &result_3, uint64_t &result_4, uint64_t &result_5, uint64_t &result_6, uint64_t &result_7, uint64_t &result_8, uint64_t &result_9)
 Perform 29-bit montgomery reduction on 1 limb using Yuval's method *.
 
static BB_INLINE constexpr std::array< uint64_t, WASM_NUM_LIMBSwasm_convert (const uint64_t *data)
 Convert 4 64-bit limbs into 9 29-bit limbs.
 
static BB_INLINE constexpr std::pair< uint64_t, uint64_t > mul_wide (uint64_t a, uint64_t b) noexcept
 
static BB_INLINE constexpr uint64_t mac (uint64_t a, uint64_t b, uint64_t c, uint64_t carry_in, uint64_t &carry_out) noexcept
 
static BB_INLINE constexpr void mac (uint64_t a, uint64_t b, uint64_t c, uint64_t carry_in, uint64_t &out, uint64_t &carry_out) noexcept
 
static BB_INLINE constexpr uint64_t mac_mini (uint64_t a, uint64_t b, uint64_t c, uint64_t &out) noexcept
 
static BB_INLINE constexpr void mac_mini (uint64_t a, uint64_t b, uint64_t c, uint64_t &out, uint64_t &carry_out) noexcept
 
static BB_INLINE constexpr uint64_t mac_discard_lo (uint64_t a, uint64_t b, uint64_t c) noexcept
 
static BB_INLINE constexpr uint64_t addc (uint64_t a, uint64_t b, uint64_t carry_in, uint64_t &carry_out) noexcept
 
static BB_INLINE constexpr uint64_t sbb (uint64_t a, uint64_t b, uint64_t borrow_in, uint64_t &borrow_out) noexcept
 
static BB_INLINE constexpr uint64_t square_accumulate (uint64_t a, uint64_t b, uint64_t c, uint64_t carry_in_lo, uint64_t carry_in_hi, uint64_t &carry_lo, uint64_t &carry_hi) noexcept
 
static constexpr size_t primitive_root_log_size () noexcept
 
static constexpr std::array< field, COSET_GENERATOR_SIZEcompute_coset_generators () noexcept
 

Public Attributes

uint64_t data [4]
 

Static Public Attributes

static constexpr size_t PUBLIC_INPUTS_SIZE = Params::PUBLIC_INPUTS_SIZE
 
static constexpr uint256_t modulus
 
static constexpr uint256_t r_squared_uint
 
static constexpr std::array< uint64_t, 9 > wasm_modulus
 
static constexpr std::array< uint64_t, 9 > wasm_r_inv
 
static constexpr uint256_t modulus_minus_two
 
static constexpr uint256_t twice_modulus = modulus + modulus
 
static constexpr uint256_t not_modulus = -modulus
 
static constexpr uint256_t twice_not_modulus = -twice_modulus
 
static constexpr size_t COSET_GENERATOR_SIZE = 15
 

Friends

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

Detailed Description

template<class Params_>
struct bb::field< Params_ >

General class for prime fields see Prime field documentation["field documentation"] for general implementation reference.

Template Parameters
Params_

Definition at line 36 of file field_declarations.hpp.

Member Typedef Documentation

◆ CoefficientAccumulator

template<class Params_ >
using bb::field< Params_ >::CoefficientAccumulator = field

Definition at line 39 of file field_declarations.hpp.

◆ in_buf

template<class Params_ >
using bb::field< Params_ >::in_buf = const uint8_t*

Definition at line 41 of file field_declarations.hpp.

◆ out_buf

template<class Params_ >
using bb::field< Params_ >::out_buf = uint8_t*

Definition at line 43 of file field_declarations.hpp.

◆ Params

template<class Params_ >
using bb::field< Params_ >::Params = Params_

Definition at line 40 of file field_declarations.hpp.

◆ vec_in_buf

template<class Params_ >
using bb::field< Params_ >::vec_in_buf = const uint8_t*

Definition at line 42 of file field_declarations.hpp.

◆ vec_out_buf

template<class Params_ >
using bb::field< Params_ >::vec_out_buf = uint8_t**

Definition at line 44 of file field_declarations.hpp.

◆ View

template<class Params_ >
using bb::field< Params_ >::View = field

Definition at line 38 of file field_declarations.hpp.

Constructor & Destructor Documentation

◆ field() [1/12]

template<class Params_ >
bb::field< Params_ >::field ( )
default

◆ field() [2/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const numeric::uint256_t input)
inlineconstexprnoexcept

Definition at line 65 of file field_declarations.hpp.

◆ field() [3/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const uint128_t input)
inlineconstexprnoexcept

Definition at line 71 of file field_declarations.hpp.

◆ field() [4/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const unsigned long  input)
inlineconstexprnoexcept

Definition at line 76 of file field_declarations.hpp.

◆ field() [5/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const unsigned int  input)
inlineconstexprnoexcept

Definition at line 82 of file field_declarations.hpp.

◆ field() [6/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const unsigned long long  input)
inlineconstexprnoexcept

Definition at line 89 of file field_declarations.hpp.

◆ field() [7/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const int  input)
inlineconstexprnoexcept

Definition at line 95 of file field_declarations.hpp.

◆ field() [8/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const uint64_t  a,
const uint64_t  b,
const uint64_t  c,
const uint64_t  d 
)
inlineconstexprnoexcept

Definition at line 115 of file field_declarations.hpp.

◆ field() [9/12]

template<class Params_ >
constexpr bb::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

Definition at line 124 of file field_declarations.hpp.

◆ field() [10/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( std::string  input)
inlineexplicitconstexprnoexcept

Definition at line 134 of file field_declarations.hpp.

◆ field() [11/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( const field< Params_ > &  other)
constexprdefaultnoexcept

◆ field() [12/12]

template<class Params_ >
constexpr bb::field< Params_ >::field ( field< Params_ > &&  other)
constexprdefaultnoexcept

◆ ~field()

template<class Params_ >
constexpr bb::field< Params_ >::~field ( )
constexprdefaultnoexcept

Member Function Documentation

◆ __copy()

template<class Params_ >
static BB_INLINE void bb::field< Params_ >::__copy ( const field< Params_ > &  a,
field< Params_ > &  r 
)
inlinestaticnoexcept

Definition at line 558 of file field_declarations.hpp.

◆ __swap()

template<class Params_ >
static BB_INLINE void bb::field< Params_ >::__swap ( field< Params_ > &  src,
field< Params_ > &  dest 
)
inlinestaticnoexcept

Definition at line 559 of file field_declarations.hpp.

◆ add()

template<class T >
constexpr field< T > bb::field< T >::add ( const field< Params_ > &  other) const
constexprnoexcept

Definition at line 210 of file field_impl_generic.hpp.

◆ addc()

template<class T >
constexpr uint64_t bb::field< T >::addc ( uint64_t  a,
uint64_t  b,
uint64_t  carry_in,
uint64_t &  carry_out 
)
staticconstexprnoexcept

Definition at line 109 of file field_impl_generic.hpp.

◆ batch_invert() [1/2]

template<class T >
void bb::field< T >::batch_invert ( field< Params_ > *  coeffs,
size_t  n 
)
staticnoexcept

Definition at line 386 of file field_impl.hpp.

◆ batch_invert() [2/2]

template<class T >
void bb::field< T >::batch_invert ( std::span< field< Params_ > >  coeffs)
staticnoexcept

Definition at line 392 of file field_impl.hpp.

◆ compute_coset_generators()

template<class T >
constexpr std::array< field< T >, field< T >::COSET_GENERATOR_SIZE > bb::field< T >::compute_coset_generators ( )
staticconstexprnoexcept

Definition at line 689 of file field_impl.hpp.

◆ conditionally_subtract_from_double_modulus()

template<class Params_ >
BB_INLINE constexpr field bb::field< Params_ >::conditionally_subtract_from_double_modulus ( const uint64_t  predicate) const
inlineconstexprnoexcept

Definition at line 389 of file field_declarations.hpp.

◆ coset_generator()

template<class Params_ >
template<size_t idx>
static constexpr field bb::field< Params_ >::coset_generator ( )
inlinestaticconstexpr

Definition at line 286 of file field_declarations.hpp.

◆ cube_root_of_unity()

template<class Params_ >
static constexpr field bb::field< Params_ >::cube_root_of_unity ( )
inlinestaticconstexpr

Definition at line 218 of file field_declarations.hpp.

◆ external_coset_generator()

template<class Params_ >
static constexpr field bb::field< Params_ >::external_coset_generator ( )
inlinestaticconstexpr

Definition at line 244 of file field_declarations.hpp.

◆ from_montgomery_form()

template<class T >
constexpr field< T > bb::field< T >::from_montgomery_form ( ) const
constexprnoexcept

Definition at line 301 of file field_impl.hpp.

◆ get_root_of_unity()

template<class T >
constexpr field< T > bb::field< T >::get_root_of_unity ( size_t  subgroup_size)
staticconstexprnoexcept

Definition at line 652 of file field_impl.hpp.

◆ invert()

template<class T >
constexpr field< T > bb::field< T >::invert ( ) const
constexprnoexcept

Definition at line 378 of file field_impl.hpp.

◆ is_msb_set()

template<class T >
constexpr bool bb::field< T >::is_msb_set ( ) const
constexprnoexcept

Definition at line 636 of file field_impl.hpp.

◆ is_msb_set_word()

template<class T >
constexpr uint64_t bb::field< T >::is_msb_set_word ( ) const
constexprnoexcept

Definition at line 641 of file field_impl.hpp.

◆ is_zero()

template<class T >
constexpr bool bb::field< T >::is_zero ( ) const
constexprnoexcept

Definition at line 646 of file field_impl.hpp.

◆ mac() [1/2]

template<class T >
constexpr uint64_t bb::field< T >::mac ( uint64_t  a,
uint64_t  b,
uint64_t  c,
uint64_t  carry_in,
uint64_t &  carry_out 
)
staticconstexprnoexcept

Definition at line 30 of file field_impl_generic.hpp.

◆ mac() [2/2]

template<class T >
constexpr void bb::field< T >::mac ( uint64_t  a,
uint64_t  b,
uint64_t  c,
uint64_t  carry_in,
uint64_t &  out,
uint64_t &  carry_out 
)
staticconstexprnoexcept

Definition at line 46 of file field_impl_generic.hpp.

◆ mac_discard_lo()

template<class T >
constexpr uint64_t bb::field< T >::mac_discard_lo ( uint64_t  a,
uint64_t  b,
uint64_t  c 
)
staticconstexprnoexcept

Definition at line 98 of file field_impl_generic.hpp.

◆ mac_mini() [1/2]

template<class T >
constexpr uint64_t bb::field< T >::mac_mini ( uint64_t  a,
uint64_t  b,
uint64_t  c,
uint64_t &  out 
)
staticconstexprnoexcept

Definition at line 66 of file field_impl_generic.hpp.

◆ mac_mini() [2/2]

template<class T >
constexpr void bb::field< T >::mac_mini ( uint64_t  a,
uint64_t  b,
uint64_t  c,
uint64_t &  out,
uint64_t &  carry_out 
)
staticconstexprnoexcept

Definition at line 83 of file field_impl_generic.hpp.

◆ montgomery_mul()

template<class T >
constexpr field< T > bb::field< T >::montgomery_mul ( const field< Params_ > &  other) const
constexprnoexcept

Definition at line 569 of file field_impl_generic.hpp.

◆ montgomery_mul_big()

template<class T >
constexpr field< T > bb::field< T >::montgomery_mul_big ( const field< Params_ > &  other) const
constexprnoexcept

Mongtomery multiplication for moduli > 2²⁵⁴

Explanation of Montgomery form can be found in Introduction to Montgomery form and the difference between WASM and generic versions is explained in Architecture details

Definition at line 317 of file field_impl_generic.hpp.

◆ montgomery_square()

template<class T >
constexpr field< T > bb::field< T >::montgomery_square ( ) const
constexprnoexcept

Definition at line 707 of file field_impl_generic.hpp.

◆ msgpack_pack()

template<class Params >
void bb::field< Params >::msgpack_pack ( auto &  packer) const

Definition at line 737 of file field_impl.hpp.

◆ msgpack_schema()

template<class Params_ >
void bb::field< Params_ >::msgpack_schema ( auto &  packer) const
inline

Definition at line 573 of file field_declarations.hpp.

◆ msgpack_unpack()

template<class Params >
void bb::field< Params >::msgpack_unpack ( auto  o)

Definition at line 757 of file field_impl.hpp.

◆ mul_512()

template<class T >
constexpr struct field< T >::wide_array bb::field< T >::mul_512 ( const field< Params_ > &  other) const
constexprnoexcept

Definition at line 911 of file field_impl_generic.hpp.

◆ mul_wide()

template<class T >
constexpr std::pair< uint64_t, uint64_t > bb::field< T >::mul_wide ( uint64_t  a,
uint64_t  b 
)
staticconstexprnoexcept

Definition at line 18 of file field_impl_generic.hpp.

◆ multiplicative_generator()

template<class T >
constexpr field< T > bb::field< T >::multiplicative_generator ( )
staticconstexprnoexcept

Definition at line 722 of file field_impl.hpp.

◆ neg_one()

template<class Params_ >
static constexpr field bb::field< Params_ >::neg_one ( )
inlinestaticconstexpr

Definition at line 241 of file field_declarations.hpp.

◆ one()

template<class Params_ >
static constexpr field bb::field< Params_ >::one ( )
inlinestaticconstexpr

Definition at line 242 of file field_declarations.hpp.

◆ operator bool()

template<class Params_ >
constexpr bb::field< Params_ >::operator bool ( ) const
inlineexplicitconstexpr

Definition at line 140 of file field_declarations.hpp.

◆ operator uint128_t()

template<class Params_ >
constexpr bb::field< Params_ >::operator uint128_t ( ) const
inlineexplicitconstexpr

Definition at line 171 of file field_declarations.hpp.

◆ operator uint16_t()

template<class Params_ >
constexpr bb::field< Params_ >::operator uint16_t ( ) const
inlineexplicitconstexpr

Definition at line 153 of file field_declarations.hpp.

◆ operator uint256_t()

template<class Params_ >
constexpr bb::field< Params_ >::operator uint256_t ( ) const
inlineconstexprnoexcept

Definition at line 179 of file field_declarations.hpp.

◆ operator uint32_t()

template<class Params_ >
constexpr bb::field< Params_ >::operator uint32_t ( ) const
inlineexplicitconstexpr

Definition at line 159 of file field_declarations.hpp.

◆ operator uint64_t()

template<class Params_ >
constexpr bb::field< Params_ >::operator uint64_t ( ) const
inlineexplicitconstexpr

Definition at line 165 of file field_declarations.hpp.

◆ operator uint8_t()

template<class Params_ >
constexpr bb::field< Params_ >::operator uint8_t ( ) const
inlineexplicitconstexpr

Definition at line 147 of file field_declarations.hpp.

◆ operator!=()

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

Definition at line 278 of file field_impl.hpp.

◆ operator*()

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

Mutiplication

Definition at line 35 of file field_impl.hpp.

◆ operator*=()

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

Definition at line 49 of file field_impl.hpp.

◆ operator+()

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

Addition

Definition at line 102 of file field_impl.hpp.

◆ operator++() [1/2]

template<class T >
constexpr field< T > bb::field< T >::operator++ ( )
constexprnoexcept

Definition at line 130 of file field_impl.hpp.

◆ operator++() [2/2]

template<class T >
constexpr field< T > bb::field< T >::operator++ ( int  )
constexprnoexcept

Definition at line 136 of file field_impl.hpp.

◆ operator+=()

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

Definition at line 115 of file field_impl.hpp.

◆ operator-() [1/2]

template<class T >
constexpr field< T > bb::field< T >::operator- ( ) const
constexprnoexcept

Definition at line 161 of file field_impl.hpp.

◆ operator-() [2/2]

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

Subtraction

Definition at line 148 of file field_impl.hpp.

◆ operator-=()

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

Definition at line 189 of file field_impl.hpp.

◆ operator/()

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

Definition at line 620 of file field_impl.hpp.

◆ operator/=()

template<class T >
constexpr field< T > & bb::field< T >::operator/= ( const field< Params_ > &  other) &
constexprnoexcept

Definition at line 625 of file field_impl.hpp.

◆ operator<()

template<class T >
constexpr bool bb::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

Definition at line 265 of file field_impl.hpp.

◆ operator=() [1/2]

template<class Params_ >
constexpr field & bb::field< Params_ >::operator= ( const field< Params_ > &  other) &
constexprdefaultnoexcept

◆ operator=() [2/2]

template<class Params_ >
constexpr field & bb::field< Params_ >::operator= ( field< Params_ > &&  other) &
constexprdefaultnoexcept

◆ operator==()

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

Definition at line 270 of file field_impl.hpp.

◆ operator>()

template<class T >
constexpr bool bb::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

Definition at line 241 of file field_impl.hpp.

◆ pow() [1/2]

template<class T >
constexpr field< T > bb::field< T >::pow ( const uint256_t exponent) const
constexprnoexcept

Definition at line 353 of file field_impl.hpp.

◆ pow() [2/2]

template<class T >
constexpr field< T > bb::field< T >::pow ( uint64_t  exponent) const
constexprnoexcept

Definition at line 373 of file field_impl.hpp.

◆ primitive_root_log_size()

template<class T >
constexpr size_t bb::field< T >::primitive_root_log_size ( )
staticconstexprnoexcept

Definition at line 678 of file field_impl.hpp.

◆ random_element()

template<class T >
field< T > bb::field< T >::random_element ( numeric::RNG engine = nullptr)
staticnoexcept

Definition at line 665 of file field_impl.hpp.

◆ reconstruct_from_public()

template<class Params_ >
template<class V >
static field bb::field< Params_ >::reconstruct_from_public ( const std::span< const field< V >, PUBLIC_INPUTS_SIZE > &  limbs)
static

◆ reduce()

template<class T >
constexpr field< T > bb::field< T >::reduce ( ) const
constexprnoexcept

Definition at line 185 of file field_impl_generic.hpp.

◆ reduce_once()

template<class T >
constexpr field< T > bb::field< T >::reduce_once ( ) const
constexprnoexcept

Definition at line 326 of file field_impl.hpp.

◆ sbb()

template<class T >
constexpr uint64_t bb::field< T >::sbb ( uint64_t  a,
uint64_t  b,
uint64_t  borrow_in,
uint64_t &  borrow_out 
)
staticconstexprnoexcept

Definition at line 128 of file field_impl_generic.hpp.

◆ self_conditional_negate()

template<class T >
constexpr void bb::field< T >::self_conditional_negate ( uint64_t  predicate) &
constexprnoexcept

Definition at line 216 of file field_impl.hpp.

◆ self_from_montgomery_form()

template<class T >
constexpr void bb::field< T >::self_from_montgomery_form ( ) &
constexprnoexcept

Definition at line 319 of file field_impl.hpp.

◆ self_neg()

template<class T >
constexpr void bb::field< T >::self_neg ( ) &
constexprnoexcept

Definition at line 204 of file field_impl.hpp.

◆ self_reduce_once()

template<class T >
constexpr void bb::field< T >::self_reduce_once ( ) &
constexprnoexcept

Definition at line 339 of file field_impl.hpp.

◆ self_set_msb()

template<class T >
constexpr void bb::field< T >::self_set_msb ( ) &
constexprnoexcept

Definition at line 631 of file field_impl.hpp.

◆ self_sqr()

template<class T >
constexpr void bb::field< T >::self_sqr ( ) &
constexprnoexcept

Definition at line 83 of file field_impl.hpp.

◆ self_to_montgomery_form()

template<class T >
constexpr void bb::field< T >::self_to_montgomery_form ( ) &
constexprnoexcept

Definition at line 307 of file field_impl.hpp.

◆ serialize_from_buffer()

template<class Params_ >
static field bb::field< Params_ >::serialize_from_buffer ( const uint8_t *  buffer)
inlinestatic

Definition at line 377 of file field_declarations.hpp.

◆ serialize_to_buffer()

template<class Params_ >
static void bb::field< Params_ >::serialize_to_buffer ( const field< Params_ > &  value,
uint8_t *  buffer 
)
inlinestatic

Definition at line 375 of file field_declarations.hpp.

◆ split_into_endomorphism_scalars() [1/2]

template<class Params_ >
static std::pair< std::array< uint64_t, 2 >, std::array< uint64_t, 2 > > bb::field< Params_ >::split_into_endomorphism_scalars ( const field< Params_ > &  k)
inlinestatic

Definition at line 451 of file field_declarations.hpp.

◆ split_into_endomorphism_scalars() [2/2]

template<class Params_ >
static void bb::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

Definition at line 424 of file field_declarations.hpp.

◆ split_into_endomorphism_scalars_384()

template<class Params_ >
static void bb::field< Params_ >::split_into_endomorphism_scalars_384 ( const field< Params_ > &  input,
field< Params_ > &  k1_out,
field< Params_ > &  k2_out 
)
inlinestatic

Definition at line 498 of file field_declarations.hpp.

◆ sqr()

template<class T >
constexpr field< T > bb::field< T >::sqr ( ) const
constexprnoexcept

Squaring

Definition at line 70 of file field_impl.hpp.

◆ sqr_512()

template<class Params_ >
BB_INLINE constexpr wide_array bb::field< Params_ >::sqr_512 ( ) const
constexprnoexcept

◆ sqrt() [1/2]

template<class T >
requires ((Params_::modulus_0 & 0x3UL) == 0x3UL)
constexpr std::pair< bool, field< T > > bb::field< T >::sqrt ( ) const
constexprnoexcept

Compute square root of the field element.

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

Definition at line 598 of file field_impl.hpp.

◆ sqrt() [2/2]

template<class Params_ >
constexpr std::pair< bool, field > bb::field< Params_ >::sqrt ( ) const
constexprnoexcept

◆ square_accumulate()

template<class T >
constexpr uint64_t bb::field< T >::square_accumulate ( uint64_t  a,
uint64_t  b,
uint64_t  c,
uint64_t  carry_in_lo,
uint64_t  carry_in_hi,
uint64_t &  carry_lo,
uint64_t &  carry_hi 
)
staticconstexprnoexcept

Definition at line 148 of file field_impl_generic.hpp.

◆ subtract()

template<class T >
constexpr field< T > bb::field< T >::subtract ( const field< Params_ > &  other) const
constexprnoexcept

Definition at line 259 of file field_impl_generic.hpp.

◆ subtract_coarse()

template<class T >
constexpr field< T > bb::field< T >::subtract_coarse ( const field< Params_ > &  other) const
constexprnoexcept
Template Parameters
T
Parameters
other
Returns
constexpr field<T>

Definition at line 291 of file field_impl_generic.hpp.

◆ tag_coset_generator()

template<class Params_ >
static constexpr field bb::field< Params_ >::tag_coset_generator ( )
inlinestaticconstexpr

Definition at line 265 of file field_declarations.hpp.

◆ to_buffer()

template<class Params_ >
BB_INLINE std::vector< uint8_t > bb::field< Params_ >::to_buffer ( ) const
inline

Definition at line 381 of file field_declarations.hpp.

◆ to_montgomery_form()

template<class T >
constexpr field< T > bb::field< T >::to_montgomery_form ( ) const
constexprnoexcept

Definition at line 283 of file field_impl.hpp.

◆ tonelli_shanks_sqrt()

template<class T >
constexpr field< T > bb::field< T >::tonelli_shanks_sqrt ( ) const
constexprnoexcept

Implements an optimized variant of Tonelli-Shanks via lookup tables. Algorithm taken from https://cr.yp.to/papers/sqroot-20011123-retypeset20220327.pdf "FASTER SQUARE ROOTS IN ANNOYING FINITE FIELDS" by D. Bernstein Page 5 "Accelerated Discrete Logarithm".

Template Parameters
T
Returns
constexpr field<T>

Definition at line 448 of file field_impl.hpp.

◆ uint256_t_no_montgomery_conversion()

template<class Params_ >
constexpr uint256_t bb::field< Params_ >::uint256_t_no_montgomery_conversion ( ) const
inlineconstexprnoexcept

Definition at line 185 of file field_declarations.hpp.

◆ wasm_convert()

template<class T >
constexpr std::array< uint64_t, WASM_NUM_LIMBS > bb::field< T >::wasm_convert ( const uint64_t *  data)
staticconstexpr

Convert 4 64-bit limbs into 9 29-bit limbs.

Definition at line 556 of file field_impl_generic.hpp.

◆ wasm_madd()

template<class T >
constexpr void bb::field< T >::wasm_madd ( uint64_t &  left_limb,
const std::array< uint64_t, WASM_NUM_LIMBS > &  right_limbs,
uint64_t &  result_0,
uint64_t &  result_1,
uint64_t &  result_2,
uint64_t &  result_3,
uint64_t &  result_4,
uint64_t &  result_5,
uint64_t &  result_6,
uint64_t &  result_7,
uint64_t &  result_8 
)
staticconstexpr

Multiply left limb by a sequence of 9 limbs and put into result variables.

Definition at line 471 of file field_impl_generic.hpp.

◆ wasm_reduce()

template<class T >
constexpr void bb::field< T >::wasm_reduce ( uint64_t &  result_0,
uint64_t &  result_1,
uint64_t &  result_2,
uint64_t &  result_3,
uint64_t &  result_4,
uint64_t &  result_5,
uint64_t &  result_6,
uint64_t &  result_7,
uint64_t &  result_8 
)
staticconstexpr

Perform 29-bit montgomery reduction on 1 limb (result_0 should be zero modulo 2**29 after this)

Definition at line 499 of file field_impl_generic.hpp.

◆ wasm_reduce_yuval()

template<class T >
constexpr void bb::field< T >::wasm_reduce_yuval ( uint64_t &  result_0,
uint64_t &  result_1,
uint64_t &  result_2,
uint64_t &  result_3,
uint64_t &  result_4,
uint64_t &  result_5,
uint64_t &  result_6,
uint64_t &  result_7,
uint64_t &  result_8,
uint64_t &  result_9 
)
staticconstexpr

Perform 29-bit montgomery reduction on 1 limb using Yuval's method *.

https://hackmd.io/@Ingonyama/Barret-Montgomery

Definition at line 529 of file field_impl_generic.hpp.

◆ zero()

template<class Params_ >
static constexpr field bb::field< Params_ >::zero ( )
inlinestaticconstexpr

Definition at line 240 of file field_declarations.hpp.

Friends And Related Symbol Documentation

◆ operator<<

template<class Params_ >
std::ostream & operator<< ( std::ostream &  os,
const field< Params_ > &  a 
)
friend

Definition at line 548 of file field_declarations.hpp.

Member Data Documentation

◆ COSET_GENERATOR_SIZE

template<class Params_ >
constexpr size_t bb::field< Params_ >::COSET_GENERATOR_SIZE = 15
staticconstexpr

Definition at line 711 of file field_declarations.hpp.

◆ data

template<class Params_ >
uint64_t bb::field< Params_ >::data[4]

Definition at line 195 of file field_declarations.hpp.

◆ modulus

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

Definition at line 197 of file field_declarations.hpp.

◆ modulus_minus_two

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

Definition at line 343 of file field_declarations.hpp.

◆ not_modulus

template<class Params_ >
constexpr uint256_t bb::field< Params_ >::not_modulus = -modulus
staticconstexpr

Definition at line 576 of file field_declarations.hpp.

◆ PUBLIC_INPUTS_SIZE

template<class Params_ >
constexpr size_t bb::field< Params_ >::PUBLIC_INPUTS_SIZE = Params::PUBLIC_INPUTS_SIZE
staticconstexpr

Definition at line 47 of file field_declarations.hpp.

◆ r_squared_uint

template<class Params_ >
constexpr uint256_t bb::field< Params_ >::r_squared_uint
staticconstexpr
Initial value:
{
Params_::r_squared_wasm_0, Params_::r_squared_wasm_1, Params_::r_squared_wasm_2, Params_::r_squared_wasm_3
}

Definition at line 204 of file field_declarations.hpp.

◆ twice_modulus

template<class Params_ >
constexpr uint256_t bb::field< Params_ >::twice_modulus = modulus + modulus
staticconstexpr

Definition at line 575 of file field_declarations.hpp.

◆ twice_not_modulus

template<class Params_ >
constexpr uint256_t bb::field< Params_ >::twice_not_modulus = -twice_modulus
staticconstexpr

Definition at line 577 of file field_declarations.hpp.

◆ wasm_modulus

template<class Params_ >
constexpr std::array<uint64_t, 9> bb::field< Params_ >::wasm_modulus
staticconstexpr
Initial value:
= { Params::modulus_wasm_0, Params::modulus_wasm_1,
Params::modulus_wasm_2, Params::modulus_wasm_3,
Params::modulus_wasm_4, Params::modulus_wasm_5,
Params::modulus_wasm_6, Params::modulus_wasm_7,
Params::modulus_wasm_8 }

Definition at line 207 of file field_declarations.hpp.

◆ wasm_r_inv

template<class Params_ >
constexpr std::array<uint64_t, 9> bb::field< Params_ >::wasm_r_inv
staticconstexpr
Initial value:
= {
Params::r_inv_wasm_0, Params::r_inv_wasm_1, Params::r_inv_wasm_2, Params::r_inv_wasm_3, Params::r_inv_wasm_4,
Params::r_inv_wasm_5, Params::r_inv_wasm_6, Params::r_inv_wasm_7, Params::r_inv_wasm_8
}

Definition at line 212 of file field_declarations.hpp.


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