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

Namespaces

namespace  detail
 

Classes

class  affine_element
 
struct  curve_for_element
 
struct  curve_for_element< fq, fr, Bn254G1Params >
 
struct  curve_for_element< fr, fq, grumpkin::G1Params >
 
class  element
 element class. Implements ecc group arithmetic using Jacobian coordinates See https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#doubling-dbl-2009-l More...
 
class  TestElementPrivate
 

Concepts

concept  SupportsHashToCurve
 

Functions

template<typename B , typename Fq_ , typename Fr_ , typename Params >
void read (B &it, group_elements::affine_element< Fq_, Fr_, Params > &element)
 
template<typename B , typename Fq_ , typename Fr_ , typename Params >
void write (B &it, group_elements::affine_element< Fq_, Fr_, Params > const &element)
 
template<class Fq , class Fr , class Params >
std::ostream & operator<< (std::ostream &os, element< Fq, Fr, Params > const &e)
 
template<typename AffineElement , typename Fq >
 __attribute__ ((always_inline)) inline void batch_affine_add_impl(const AffineElement *lhs
 Batch affine addition for parallel arrays: (lhs[i], rhs[i]) → rhs[i].
 
 for (size_t i=0;i< num_pairs;++i)
 
 if (batch_inversion_accumulator==Fq::zero())
 
 for (size_t i_plus_1=num_points;i_plus_1 > 0;--i_plus_1)
 

Variables

AffineElement * rhs
 
AffineElement const size_t num_pairs
 
AffineElement const size_t Fq *scratch_space noexcept
 
 batch_inversion_accumulator = batch_inversion_accumulator.invert()
 
const size_t num_points
 
Fq temp_x
 

Function Documentation

◆ __attribute__()

template<typename AffineElement , typename Fq >
bb::group_elements::__attribute__ ( (always_inline)  ) const

Batch affine addition for parallel arrays: (lhs[i], rhs[i]) → rhs[i].

Batch affine point doubling using Montgomery's trick.

Batch affine addition for interleaved arrays: pairs (points[2i], points[2i+1]) → points[num_points/2 + i].

Uses Montgomery's batch inversion trick. lhs and rhs are separate arrays so no aliasing issues.

Parameters
lhsInput array of first summands (read-only)
rhsInput array of second summands; results are written here (rhs[i] = lhs[i] + rhs[i])
num_pairsNumber of point pairs to add
scratch_spaceTemporary storage for batch inversion, size >= num_pairs
Warning
ASSUMES NO EDGE CASES:
  • All points must be valid (not point at infinity)
  • lhs[i] != rhs[i] for all i (no point doubling cases)
  • lhs[i] != -rhs[i] for all i (no point at infinity results)

Optimized for the pippenger interleaved memory layout where lhs and rhs live in the same contiguous array. Uses direct address arithmetic and hardcoded prefetch to avoid aliasing penalties that arise when the generic batch_affine_add_impl is called with lhs_base == rhs_base (the compiler cannot prove that writes to output don't alias reads from lhs, forcing unnecessary reloads).

Parameters
pointsInterleaved array: [lhs0, rhs0, lhs1, rhs1, ...]. Results written to top half.
num_pointsTotal number of points (must be even). Number of pairs = num_points / 2.
scratch_spaceTemporary storage for batch inversion, size >= num_points / 2.
Template Parameters
AffineElementAffine point type
FqBase field type
Warning
ASSUMES NO EDGE CASES:
  • All points must be valid (not point at infinity)
  • points[i].y != 0 for all i (no vertical tangents)
  • No points with order 2 (where 2P = point at infinity)
Note
This is the "unsafe" fast path. For general point doubling with edge case handling, use Jacobian arithmetic or check for edge cases before calling this function.

◆ for() [1/2]

bb::group_elements::for ( )

Definition at line 644 of file element_impl.hpp.

◆ for() [2/2]

bb::group_elements::for ( size_t  i_plus_1 = num_points; i_plus_1,
0;--  i_plus_1 
)

Definition at line 762 of file element_impl.hpp.

◆ if()

bb::group_elements::if ( batch_inversion_accumulator  = Fq::zero())

Definition at line 652 of file element_impl.hpp.

◆ operator<<()

template<class Fq , class Fr , class Params >
std::ostream & bb::group_elements::operator<< ( std::ostream &  os,
element< Fq, Fr, Params > const &  e 
)

Definition at line 138 of file element.hpp.

◆ read()

template<typename B , typename Fq_ , typename Fr_ , typename Params >
void bb::group_elements::read ( B &  it,
group_elements::affine_element< Fq_, Fr_, Params > &  element 
)
inline

Definition at line 304 of file affine_element.hpp.

◆ write()

template<typename B , typename Fq_ , typename Fr_ , typename Params >
void bb::group_elements::write ( B &  it,
group_elements::affine_element< Fq_, Fr_, Params > const &  element 
)
inline

Definition at line 314 of file affine_element.hpp.

Variable Documentation

◆ batch_inversion_accumulator

bb::group_elements::batch_inversion_accumulator = batch_inversion_accumulator.invert()

Definition at line 655 of file element_impl.hpp.

◆ noexcept

const size_t Fq *scratch_space bb::group_elements::noexcept

◆ num_pairs

AffineElement const size_t bb::group_elements::num_pairs

Definition at line 638 of file element_impl.hpp.

◆ num_points

const size_t bb::group_elements::num_points

Definition at line 685 of file element_impl.hpp.

◆ rhs

AffineElement* bb::group_elements::rhs

Definition at line 637 of file element_impl.hpp.

◆ temp_x

Fq bb::group_elements::temp_x

Definition at line 761 of file element_impl.hpp.