Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::crypto::generator_data< Curve > Class Template Reference

class that stores precomputed generators used for Pedersen commitments and Pedersen hashes More...

#include <generator_data.hpp>

Public Types

using Group = typename Curve::Group
 
using AffineElement = typename Curve::AffineElement
 
using GeneratorList = std::vector< AffineElement >
 
using GeneratorView = std::span< AffineElement const >
 

Public Member Functions

constexpr generator_data ()=default
 
GeneratorView get (const size_t num_generators, const size_t generator_offset=0, const std::string_view domain_separator=DEFAULT_DOMAIN_SEPARATOR) const
 

Static Public Member Functions

static generator_dataget_default_generators ()
 

Static Public Attributes

static constexpr size_t DEFAULT_NUM_GENERATORS = 8
 
static constexpr std::string_view DEFAULT_DOMAIN_SEPARATOR = "DEFAULT_DOMAIN_SEPARATOR"
 
static constexpr std::span< const AffineElementprecomputed_generators
 We precompute and hard-code a small number of generators. For small pedersen commitments + pedersen hashes, this prevents us from having to derive generators at runtime.
 

Private Attributes

bool initialized_precomputed_generators = false
 
std::optional< std::map< std::string, GeneratorList > > generator_map = {}
 

Static Private Attributes

static constinit generator_data default_data = generator_data()
 

Detailed Description

template<typename Curve>
class bb::crypto::generator_data< Curve >

class that stores precomputed generators used for Pedersen commitments and Pedersen hashes

We create distinct sets of generators via the use of a domain separator. This enables the use of context-specific commitments and hashes. For example, a circuit that generates commitments foo = commit({ a, b }) and bar = commit({c, d}) where foo and bar should not collide.

The goal of generator_data is twofold:

  1. Prevent redundant computation of the same generators at runtime (i.e. store in a singleton object)
  2. Compute a small number of default generators at compile-time, so that short processes that require a small number of generators do not have to execute the expensive g1::derive_generators method

We store generators in a key:value map, where the key is the domain separator and the value is the vector of associated generators. Pedersen methods take in a pointer to a generator_data object.

generator_data contains a static instantiation of the class: default_data. The intention is for default_data to be used as a singleton class. All Pedersen methods that require a *generator_data parameter (from now on referred to as "generator context") should default to using default_data.

Q: Why make the generator context an input parameter when it defaults to default_data? A: This is not thread-safe. Each process that uses a generator_data object may extend generator_data if more generators are required. i.e. either each process must use an independent generator_data object or the author must KNOW that generator_data will not be extended by any process

Template Parameters
Curve

Definition at line 48 of file generator_data.hpp.

Member Typedef Documentation

◆ AffineElement

Definition at line 51 of file generator_data.hpp.

◆ GeneratorList

template<typename Curve >
using bb::crypto::generator_data< Curve >::GeneratorList = std::vector<AffineElement>

Definition at line 52 of file generator_data.hpp.

◆ GeneratorView

template<typename Curve >
using bb::crypto::generator_data< Curve >::GeneratorView = std::span<AffineElement const>

Definition at line 53 of file generator_data.hpp.

◆ Group

Definition at line 50 of file generator_data.hpp.

Constructor & Destructor Documentation

◆ generator_data()

template<typename Curve >
constexpr bb::crypto::generator_data< Curve >::generator_data ( )
inlineconstexprdefault

Member Function Documentation

◆ get()

template<typename Curve >
GeneratorView bb::crypto::generator_data< Curve >::get ( const size_t  num_generators,
const size_t  generator_offset = 0,
const std::string_view  domain_separator = DEFAULT_DOMAIN_SEPARATOR 
) const
inline

Definition at line 65 of file generator_data.hpp.

◆ get_default_generators()

template<typename Curve >
static generator_data * bb::crypto::generator_data< Curve >::get_default_generators ( )
inlinestatic

Definition at line 111 of file generator_data.hpp.

Member Data Documentation

◆ default_data

template<typename Curve >
constinit generator_data bb::crypto::generator_data< Curve >::default_data = generator_data()
inlinestaticprivate

Definition at line 115 of file generator_data.hpp.

◆ DEFAULT_DOMAIN_SEPARATOR

template<typename Curve >
constexpr std::string_view bb::crypto::generator_data< Curve >::DEFAULT_DOMAIN_SEPARATOR = "DEFAULT_DOMAIN_SEPARATOR"
inlinestaticconstexpr

Definition at line 55 of file generator_data.hpp.

◆ DEFAULT_NUM_GENERATORS

template<typename Curve >
constexpr size_t bb::crypto::generator_data< Curve >::DEFAULT_NUM_GENERATORS = 8
inlinestaticconstexpr

Definition at line 54 of file generator_data.hpp.

◆ generator_map

template<typename Curve >
std::optional<std::map<std::string, GeneratorList> > bb::crypto::generator_data< Curve >::generator_map = {}
mutableprivate

Definition at line 130 of file generator_data.hpp.

◆ initialized_precomputed_generators

template<typename Curve >
bool bb::crypto::generator_data< Curve >::initialized_precomputed_generators = false
mutableprivate

Definition at line 126 of file generator_data.hpp.

◆ precomputed_generators

template<typename Curve >
constexpr std::span<const AffineElement> bb::crypto::generator_data< Curve >::precomputed_generators
staticconstexpr
Initial value:
=
get_precomputed_generators<Group, "DEFAULT_DOMAIN_SEPARATOR", DEFAULT_NUM_GENERATORS, 0>()
typename Curve::Group Group
static constexpr size_t DEFAULT_NUM_GENERATORS
constexpr std::span< const typename Group::affine_element > get_precomputed_generators()

We precompute and hard-code a small number of generators. For small pedersen commitments + pedersen hashes, this prevents us from having to derive generators at runtime.

Definition at line 62 of file generator_data.hpp.


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