Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::stdlib::StdlibCodec< Field > Class Template Reference

#include <field_conversion.hpp>

Public Types

using DataType = Field
 
using Builder = typename Field::Builder
 
using fr = field_t< Builder >
 
using fq = bigfield< Builder, bb::Bn254FqParams >
 
using bn254_element = element< Builder, fq, fr, curve::BN254::Group >
 
using grumpkin_element = cycle_group< Builder >
 

Static Public Member Functions

template<typename T >
static bool_t< Buildercheck_point_at_infinity (std::span< const fr > fr_vec)
 Check whether a point corresponds to (0, 0), the conventional representation of the point infinity.
 
template<typename T >
static T convert_challenge (const fr &challenge)
 A stdlib Transcript method needed to convert an fr challenge to a bigfield one. Assumes that challenge is "short".
 
static std::vector< frconvert_goblin_fr_to_bn254_frs (const goblin_field< Builder > &input)
 
static std::vector< frconvert_grumpkin_fr_to_bn254_frs (const fq &input)
 
template<typename T >
static constexpr size_t calc_num_fields ()
 Calculates the size of a type (in its native form) in terms of frs.
 
template<typename T >
static T deserialize_from_fields (std::span< const fr > fr_vec)
 Core stdlib Transcript deserialization method.
 
template<typename T >
static std::vector< frserialize_to_fields (const T &val)
 Core stdlib Transcript serialization method.
 
static std::array< fr, 2 > split_challenge (const fr &challenge)
 Split a challenge field element into two half-width challenges.
 
template<typename TargetType >
static TargetType deserialize_from_frs (std::span< fr > elements, size_t &num_frs_read)
 A stdlib VerificationKey-specific method.
 

Detailed Description

template<typename Field>
class bb::stdlib::StdlibCodec< Field >

Definition at line 20 of file field_conversion.hpp.

Member Typedef Documentation

◆ bn254_element

template<typename Field >
using bb::stdlib::StdlibCodec< Field >::bn254_element = element<Builder, fq, fr, curve::BN254::Group>

Definition at line 26 of file field_conversion.hpp.

◆ Builder

template<typename Field >
using bb::stdlib::StdlibCodec< Field >::Builder = typename Field::Builder

Definition at line 23 of file field_conversion.hpp.

◆ DataType

template<typename Field >
using bb::stdlib::StdlibCodec< Field >::DataType = Field

Definition at line 22 of file field_conversion.hpp.

◆ fq

template<typename Field >
using bb::stdlib::StdlibCodec< Field >::fq = bigfield<Builder, bb::Bn254FqParams>

Definition at line 25 of file field_conversion.hpp.

◆ fr

template<typename Field >
using bb::stdlib::StdlibCodec< Field >::fr = field_t<Builder>

Definition at line 24 of file field_conversion.hpp.

◆ grumpkin_element

template<typename Field >
using bb::stdlib::StdlibCodec< Field >::grumpkin_element = cycle_group<Builder>

Definition at line 27 of file field_conversion.hpp.

Member Function Documentation

◆ calc_num_fields()

template<typename Field >
template<typename T >
static constexpr size_t bb::stdlib::StdlibCodec< Field >::calc_num_fields ( )
inlinestaticconstexpr

Calculates the size of a type (in its native form) in terms of frs.

Definition at line 97 of file field_conversion.hpp.

◆ check_point_at_infinity()

template<typename Field >
template<typename T >
static bool_t< Builder > bb::stdlib::StdlibCodec< Field >::check_point_at_infinity ( std::span< const fr fr_vec)
inlinestatic

Check whether a point corresponds to (0, 0), the conventional representation of the point infinity.

bn254: In the case of a bn254 point, the bigfield limbs (x_lo, x_hi, y_lo, y_hi) are range constrained, and their sum is a non-negative integer not exceeding 2^138, i.e. it does not overflow the fq modulus, hence all limbs must be 0.

Grumpkin: We are using the observation that (x^2 + 5 * y^2 = 0) has no non-trivial solutions in fr, since fr modulus p == 2 mod 5, i.e. 5 is not a square mod p.

Definition at line 39 of file field_conversion.hpp.

◆ convert_challenge()

template<typename Field >
template<typename T >
static T bb::stdlib::StdlibCodec< Field >::convert_challenge ( const fr challenge)
inlinestatic

A stdlib Transcript method needed to convert an fr challenge to a bigfield one. Assumes that challenge is "short".

Template Parameters
Tfr or fq
Parameters
challengea 128- or a 126- bit limb of a full challenge
Returns
T

Definition at line 61 of file field_conversion.hpp.

◆ convert_goblin_fr_to_bn254_frs()

template<typename Field >
static std::vector< fr > bb::stdlib::StdlibCodec< Field >::convert_goblin_fr_to_bn254_frs ( const goblin_field< Builder > &  input)
inlinestatic

Definition at line 78 of file field_conversion.hpp.

◆ convert_grumpkin_fr_to_bn254_frs()

template<typename Field >
static std::vector< fr > bb::stdlib::StdlibCodec< Field >::convert_grumpkin_fr_to_bn254_frs ( const fq input)
inlinestatic

Definition at line 83 of file field_conversion.hpp.

◆ deserialize_from_fields()

template<typename Field >
template<typename T >
static T bb::stdlib::StdlibCodec< Field >::deserialize_from_fields ( std::span< const fr fr_vec)
inlinestatic

Core stdlib Transcript deserialization method.

Deserializes a vector of in-circuit frs, i.e. field_t elements, into

  • field_t — no conversion needed
  • bigfield — 2 input field_ts are fed into bigfield constructor that ensures that they are properly constrained. Specific to UltraCircuitBuilder.
  • goblin field element — in contrast to bigfield, range constraints are performed in Translator (see Translator Range Constraint relation). Feed the limbs to the bigfield constructor and set the point_at_infinity flag derived by the check_point_at_infinity method. Specific to MegaCircuitBuilder.
  • bn254 goblin point — input vector of size 4 is transformed into a pair of goblin_field elements, which are fed into the relevant constructor with the point_at_infinity flag derived by the check_point_at_infinity method. Note that validate_on_curve is a vacuous method in this case, as these checks are performed in ECCVM (see ECCVM Transcript relation). Specific to MegaCircuitBuilder.
  • bn254 point — reconstruct a pair of bigfield elements (x, y), check whether the resulting point is a point at infinity and ensure it lies on the curve. Specific to UltraCircuitBuilder.
  • Grumpkin point — since the grumpkin base field is fr, the reconstruction is trivial. We check in-circuit whether the resulting point lies on the curve and whether it is a point at infinity. Specific to UltraCircuitBuilder.
  • Univariate or a std::array of elements of the above types.
Template Parameters
BuilderUltraCircuitBuilder or MegaCircuitBuilder
TTarget object type
Parameters
fr_vecInput field_t elements

Definition at line 145 of file field_conversion.hpp.

◆ deserialize_from_frs()

template<typename Field >
template<typename TargetType >
static TargetType bb::stdlib::StdlibCodec< Field >::deserialize_from_frs ( std::span< fr elements,
size_t &  num_frs_read 
)
inlinestatic

A stdlib VerificationKey-specific method.

Deserialize an object of specified type from a buffer of field elements; update provided read count in place

Template Parameters
TargetTypeType to reconstruct from buffer of field elements
Parameters
elementsBuffer of field_t elements
num_frs_readIndex at which to read into buffer

Definition at line 295 of file field_conversion.hpp.

◆ serialize_to_fields()

template<typename Field >
template<typename T >
static std::vector< fr > bb::stdlib::StdlibCodec< Field >::serialize_to_fields ( const T &  val)
inlinestatic

Core stdlib Transcript serialization method.

Serializes an object into a flat vector of in-circuit fr, i.e. field_t elements. This is the inverse of deserialize_from_fields (up to the conventional point-at-infinity representation; see TODO below).

Serializes the following types:

Round-trip note:

  • For supported types, serialize_to_fields(val) followed by deserialize_from_fields<T>(...) reconstructs an equivalent in-circuit object, assuming the same arithmetization and that range/ECC checks are enforced where applicable during reconstruction (see ECCVM Transcript relation).

TODO(https://github.com/AztecProtocol/barretenberg/issues/1527): make the point-at-infinity representation fully uniform across (de)serialization paths.

Template Parameters
BuilderUltraCircuitBuilder or MegaCircuitBuilder
TTarget object type
Parameters
valValue to serialize
Returns
Flat vector of fr<Builder> elements

Definition at line 240 of file field_conversion.hpp.

◆ split_challenge()

template<typename Field >
static std::array< fr, 2 > bb::stdlib::StdlibCodec< Field >::split_challenge ( const fr challenge)
inlinestatic

Split a challenge field element into two half-width challenges.

lo is 128 bits and hi is 126 bits which should provide significantly more than our security parameter bound: 100 bits. The decomposition is constrained to be unique.

Parameters
challenge
Returns
std::array<DataType, 2>

Definition at line 277 of file field_conversion.hpp.


The documentation for this class was generated from the following file: