|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
#include <polynomial.hpp>
Classes | |
| struct | ContiguousVectorWriteProxyT |
| struct | ScalarWriteProxy |
| struct | VectorWriteProxyT |
Public Types | |
| enum class | DontZeroMemory { FLAG } |
| using | FF = Fr |
Public Member Functions | |
| Polynomial (size_t size, size_t virtual_size, size_t start_index=0) | |
| Initialize a Polynomial to size 'size', zeroing memory. | |
| Polynomial (size_t size) | |
| Polynomial (size_t size, size_t virtual_size, size_t start_index, DontZeroMemory flag) | |
| Initialize a Polynomial to size 'size'. Important: This does NOT zero memory. | |
| Polynomial (size_t size, size_t virtual_size, DontZeroMemory flag) | |
| Polynomial (size_t size, DontZeroMemory flag) | |
| Polynomial (const Polynomial &other) | |
| Polynomial (const Polynomial &other, size_t target_size) | |
| Polynomial (Polynomial &&other) noexcept | |
| Polynomial (std::span< const Fr > coefficients, size_t virtual_size) | |
| Polynomial (std::span< const Fr > coefficients) | |
| Polynomial ()=default | |
| Polynomial (std::span< const Fr > interpolation_points, std::span< const Fr > evaluations, size_t virtual_size) | |
| Create the degree-(m-1) polynomial T(X) that interpolates the given evaluations. We have T(xⱼ) = yⱼ for j=1,...,m. | |
| Polynomial & | operator= (Polynomial &&other) noexcept |
| Polynomial & | operator= (const Polynomial &other) |
| ~Polynomial ()=default | |
| Polynomial | share () const |
| bool | is_zero () const |
| Check whether or not a polynomial is identically zero. | |
| bool | operator== (Polynomial const &rhs) const |
| const Fr & | get (size_t i, size_t virtual_padding=0) const |
| Retrieves the value at the specified index. | |
| bool | is_empty () const |
| Polynomial | shifted () const |
| Returns a Polynomial the left-shift of self. | |
| Polynomial | reverse () const |
| Returns the polynomial equal to the reverse of self. | |
| Fr | evaluate_mle (std::span< const Fr > evaluation_points, bool shift=false) const |
| evaluate multi-linear extension p(X_0,…,X_{n-1}) = \sum_i a_i*L_i(X_0,…,X_{n-1}) at u = (u_0,…,u_{n-1}) If the polynomial is embedded into a lower dimension k<n, i.e, start_index + size <= 2^k, we evaluate it in a more efficient way. Note that a_j == 0 for any j >= 2^k. We fold over k dimensions and then multiply the result by (1 - u_k) * (1 - u_{k+1}) ... * (1 - u_{n-1}). In this case, for any i < 2^k, L_i is a multiple of (1 - X_k) * (1 - X_{k+1}) ... * (1 - X_{n-1}). Dividing p by this monomial leads to a multilinear extension over variables X_0, X_1, ..X_{k-1}. | |
| void | factor_roots (const Fr &root) |
| Divides p(X) by (X-r) in-place. Assumes that p(rⱼ)=0 for all j. | |
| Fr | evaluate (const Fr &z) const |
| void | add_scaled (PolynomialSpan< const Fr > other, const Fr &scaling_factor) |
| adds the polynomial q(X) 'other', multiplied by a scaling factor. | |
| void | add_scaled_chunk (const ThreadChunk &chunk, PolynomialSpan< const Fr > other, const Fr &scaling_factor) |
| Polynomial & | operator+= (PolynomialSpan< const Fr > other) |
| adds the polynomial q(X) 'other'. | |
| void | add_chunk (const ThreadChunk &chunk, PolynomialSpan< const Fr > other) |
| Polynomial & | operator-= (PolynomialSpan< const Fr > other) |
| subtracts the polynomial q(X) 'other'. | |
| void | subtract_chunk (const ThreadChunk &chunk, PolynomialSpan< const Fr > other) |
| Polynomial & | operator*= (const Fr &scaling_factor) |
| sets this = p(X) to s⋅p(X) | |
| void | multiply_chunk (const ThreadChunk &chunk, const Fr &scaling_factor) |
| std::size_t | size () const |
| std::size_t | virtual_size () const |
| void | increase_virtual_size (const size_t size_in) |
| Fr * | data () |
| const Fr * | data () const |
| Fr & | at (size_t index) |
| Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[] as mutable and immutable, respectively. This means at() can only index within start_index()..end_index() unlike operator[] which can index 0..virtual_size. | |
| const Fr & | at (size_t index) const |
| const Fr & | operator[] (size_t i) |
| const Fr & | operator[] (size_t i) const |
| Fr | operator[] (ScalarIndex ctx) const |
| template<size_t N, typename U = Fr> | |
| VectorField< typename U::Params > | operator[] (VectorIndex< N > ctx) const |
| template<size_t N, typename U = Fr> | |
| VectorField< typename U::Params > | operator[] (ContiguousVectorIndex< N > ctx) const |
| ScalarWriteProxy | operator[] (ScalarIndex ctx) |
| template<size_t N, typename U = Fr> | |
| VectorWriteProxyT< typename U::Params > | operator[] (VectorIndex< N > ctx) |
| template<size_t N, typename U = Fr> | |
| ContiguousVectorWriteProxyT< typename U::Params > | operator[] (ContiguousVectorIndex< N > ctx) |
| void | shrink_end_index (const size_t new_end_index) |
| The end_index of the polynomial is decreased without any memory de-allocation. This is a very fast way to zeroize the polynomial tail from new_end_index to the end. It also means that the new end_index might be smaller than the backed memory. | |
| Polynomial | full () const |
| Copys the polynomial, but with the whole address space usable. The value of the polynomial remains the same, but defined memory region differs. | |
| size_t | start_index () const |
| size_t | end_index () const |
| bool | is_shiftable () const |
| std::span< Fr > | coeffs (size_t offset=0) |
| Strictly iterates the defined region of the polynomial. We keep this explicit, instead of having an implicit conversion to span. This is safer as it is more likely that we need to consider our start_index() along with the span, as in PolynomialSpan below. | |
| std::span< const Fr > | coeffs (size_t offset=0) const |
| operator PolynomialSpan< Fr > () | |
| Convert to an std::span bundled with our start index. | |
| operator PolynomialSpan< const Fr > () const | |
| Convert to an std::span bundled with our start index. | |
| auto | indices () const |
| auto | indexed_values () |
| auto | indexed_values () const |
| bool | is_valid_set_index (size_t index) const |
| Is this index valid for a set? i.e. calling poly.at(index) = value. | |
| void | set_if_valid_index (size_t index, const Fr &value) |
| Like setting with at(), but allows zeroes to result in no set. | |
| template<typename T > | |
| void | copy_vector (const std::vector< T > &vec) |
| Copy over values from a vector that is of a convertible type. | |
| void | add_masking () |
| Write random ZK masking values at positions {1, 2, 3} (the disabled head region after the zero row). | |
Static Public Member Functions | |
| static Polynomial | shiftable (size_t virtual_size, bool masked=false) |
| Utility to create a shiftable polynomial of given virtual size. | |
| static Polynomial | shiftable (size_t size, size_t virtual_size, bool masked=false) |
| Utility to create a shiftable polynomial of given size and virtual size. | |
| static Polynomial | shiftable (size_t size, size_t virtual_size, DontZeroMemory flag) |
Overload of shiftable that leaves the backing memory uninitialized. | |
| static Polynomial | random (size_t size, size_t start_index=0) |
| static Polynomial | random (size_t size, size_t virtual_size, size_t start_index) |
| static Polynomial | create_non_parallel_zero_init (size_t size, size_t virtual_size) |
| A factory to construct a polynomial where parallel initialization is not possible (e.g. AVM code). | |
Private Member Functions | |
| void | allocate_backing_memory (size_t size, size_t virtual_size, size_t start_index) |
Private Attributes | |
| SharedShiftedVirtualZeroesArray< Fr > | coefficients_ |
Definition at line 181 of file polynomial.hpp.
Definition at line 183 of file polynomial.hpp.
| Enumerator | |
|---|---|
| FLAG | |
Definition at line 184 of file polynomial.hpp.
| bb::Polynomial< Fr >::Polynomial | ( | size_t | size, |
| size_t | virtual_size, | ||
| size_t | start_index = 0 |
||
| ) |
Initialize a Polynomial to size 'size', zeroing memory.
Constructors / Destructors
| size | The size of the polynomial. |
Definition at line 73 of file polynomial.cpp.
|
inline |
Definition at line 188 of file polynomial.hpp.
| bb::Polynomial< Fr >::Polynomial | ( | size_t | size, |
| size_t | virtual_size, | ||
| size_t | start_index, | ||
| DontZeroMemory | flag | ||
| ) |
Initialize a Polynomial to size 'size'. Important: This does NOT zero memory.
| size | The initial size of the polynomial. |
| flag | Signals that we do not zero memory. |
Definition at line 98 of file polynomial.cpp.
|
inline |
Definition at line 193 of file polynomial.hpp.
|
inline |
Definition at line 196 of file polynomial.hpp.
| bb::Polynomial< Fr >::Polynomial | ( | const Polynomial< Fr > & | other | ) |
| bb::Polynomial< Fr >::Polynomial | ( | const Polynomial< Fr > & | other, |
| size_t | target_size | ||
| ) |
|
inlinenoexcept |
Definition at line 207 of file polynomial.hpp.
| bb::Polynomial< Fr >::Polynomial | ( | std::span< const Fr > | coefficients, |
| size_t | virtual_size | ||
| ) |
Definition at line 130 of file polynomial.cpp.
|
inline |
Definition at line 217 of file polynomial.hpp.
|
default |
| bb::Polynomial< Fr >::Polynomial | ( | std::span< const Fr > | interpolation_points, |
| std::span< const Fr > | evaluations, | ||
| size_t | virtual_size | ||
| ) |
Create the degree-(m-1) polynomial T(X) that interpolates the given evaluations. We have T(xⱼ) = yⱼ for j=1,...,m.
| interpolation_points | (x₁,…,xₘ) |
| evaluations | (y₁,…,yₘ) |
Definition at line 117 of file polynomial.cpp.
|
default |
|
inline |
Definition at line 725 of file polynomial.hpp.
|
inline |
Write random ZK masking values at positions {1, 2, 3} (the disabled head region after the zero row).
Definition at line 651 of file polynomial.hpp.
|
inline |
adds the polynomial q(X) 'other', multiplied by a scaling factor.
| other | q(X) |
| scaling_factor | scaling factor by which all coefficients of q(X) are multiplied |
Definition at line 704 of file polynomial.hpp.
|
inline |
Definition at line 675 of file polynomial.hpp.
|
private |
Definition at line 52 of file polynomial.cpp.
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[] as mutable and immutable, respectively. This means at() can only index within start_index()..end_index() unlike operator[] which can index 0..virtual_size.
| index | the index, to be subtracted by start_index() and read into the array memory |
Definition at line 417 of file polynomial.hpp.
Definition at line 418 of file polynomial.hpp.
Strictly iterates the defined region of the polynomial. We keep this explicit, instead of having an implicit conversion to span. This is safer as it is more likely that we need to consider our start_index() along with the span, as in PolynomialSpan below.
Definition at line 597 of file polynomial.hpp.
|
inline |
Definition at line 598 of file polynomial.hpp.
|
inline |
Copy over values from a vector that is of a convertible type.
Assumes that the relevant start index in the vector corresponds to the start_index of the destination polynomial and also that the number of elements we want to copy corresponds to the size of the polynomial. It is not intended to be a general-purpose method for vector copy and should be used with caution.
| T | a convertible type |
| vec | the vector |
Definition at line 639 of file polynomial.hpp.
|
static |
A factory to construct a polynomial where parallel initialization is not possible (e.g. AVM code).
Definition at line 193 of file polynomial.cpp.
|
inline |
Definition at line 406 of file polynomial.hpp.
Definition at line 407 of file polynomial.hpp.
|
inline |
Definition at line 586 of file polynomial.hpp.
Definition at line 177 of file polynomial.cpp.
| Fr bb::Polynomial< Fr >::evaluate_mle | ( | std::span< const Fr > | evaluation_points, |
| bool | shift = false |
||
| ) | const |
evaluate multi-linear extension p(X_0,…,X_{n-1}) = \sum_i a_i*L_i(X_0,…,X_{n-1}) at u = (u_0,…,u_{n-1}) If the polynomial is embedded into a lower dimension k<n, i.e, start_index + size <= 2^k, we evaluate it in a more efficient way. Note that a_j == 0 for any j >= 2^k. We fold over k dimensions and then multiply the result by (1 - u_k) * (1 - u_{k+1}) ... * (1 - u_{n-1}). In this case, for any i < 2^k, L_i is a multiple of (1 - X_k) * (1 - X_{k+1}) ... * (1 - X_{n-1}). Dividing p by this monomial leads to a multilinear extension over variables X_0, X_1, ..X_{k-1}.
this function allocates a temporary buffer of size 2^(k-1)
| evaluation_points | evaluation vector of size n |
| shift | a boolean and when set to true, we evaluate the shifted counterpart polynomial: enforce a_0 == 0 and compute \sum_i a_{i+1}*L_i(X_0,…,X_{n-1}) |
Definition at line 188 of file polynomial.cpp.
Divides p(X) by (X-r) in-place. Assumes that p(rⱼ)=0 for all j.
we specialize the method when only a single root is given. if one of the roots is 0, then we first factor all other roots. dividing by X requires only a left shift of all coefficient.
| root | a single root r |
Definition at line 359 of file polynomial.hpp.
| Polynomial< Fr > bb::Polynomial< Fr >::full | ( | ) | const |
Copys the polynomial, but with the whole address space usable. The value of the polynomial remains the same, but defined memory region differs.
Definition at line 208 of file polynomial.cpp.
|
inline |
Retrieves the value at the specified index.
| index | The index from which to retrieve the value. |
| virtual_padding | For the rare case where we explicitly want the 0-returning behavior beyond our usual virtual_size. |
Definition at line 312 of file polynomial.hpp.
|
inline |
Definition at line 404 of file polynomial.hpp.
|
inline |
Definition at line 612 of file polynomial.hpp.
|
inline |
Definition at line 613 of file polynomial.hpp.
|
inline |
Definition at line 611 of file polynomial.hpp.
|
inline |
Definition at line 314 of file polynomial.hpp.
|
inline |
Definition at line 587 of file polynomial.hpp.
Is this index valid for a set? i.e. calling poly.at(index) = value.
Definition at line 617 of file polynomial.hpp.
|
inline |
Check whether or not a polynomial is identically zero.
Definition at line 290 of file polynomial.hpp.
|
inline |
Definition at line 778 of file polynomial.hpp.
|
inline |
Convert to an std::span bundled with our start index.
Definition at line 609 of file polynomial.hpp.
|
inline |
Convert to an std::span bundled with our start index.
Definition at line 603 of file polynomial.hpp.
|
inline |
sets this = p(X) to s⋅p(X)
| scaling_factor | s |
Definition at line 791 of file polynomial.hpp.
|
inline |
adds the polynomial q(X) 'other'.
| other | q(X) |
Definition at line 737 of file polynomial.hpp.
|
inline |
subtracts the polynomial q(X) 'other'.
| other | q(X) |
Definition at line 763 of file polynomial.hpp.
| Polynomial & bb::Polynomial< Fr >::operator= | ( | const Polynomial< Fr > & | other | ) |
|
inlinenoexcept |
Definition at line 268 of file polynomial.hpp.
| bool bb::Polynomial< Fr >::operator== | ( | Polynomial< Fr > const & | rhs | ) | const |
Definition at line 156 of file polynomial.cpp.
|
inline |
Definition at line 538 of file polynomial.hpp.
|
inline |
Definition at line 524 of file polynomial.hpp.
|
inline |
Definition at line 531 of file polynomial.hpp.
|
inline |
Definition at line 509 of file polynomial.hpp.
|
inline |
Definition at line 420 of file polynomial.hpp.
|
inline |
Definition at line 421 of file polynomial.hpp.
|
inline |
Definition at line 532 of file polynomial.hpp.
|
inline |
Definition at line 515 of file polynomial.hpp.
|
inlinestatic |
Definition at line 544 of file polynomial.hpp.
|
inlinestatic |
Definition at line 551 of file polynomial.hpp.
| Polynomial< Fr > bb::Polynomial< Fr >::reverse | ( | ) | const |
Returns the polynomial equal to the reverse of self.
If the coefficients of self are \((a_0, \dots, a_n)\), we return the polynomial with coefficients \((a_n, \dots, a_0)\)
Definition at line 231 of file polynomial.cpp.
Like setting with at(), but allows zeroes to result in no set.
Definition at line 621 of file polynomial.hpp.
| Polynomial< Fr > bb::Polynomial< Fr >::share | ( | ) | const |
Return a shallow clone of the polynomial. i.e. underlying memory is shared.
Definition at line 149 of file polynomial.cpp.
|
inlinestatic |
Utility to create a shiftable polynomial of given size and virtual size.
| masked | If true, write random values at positions {1,2,3} for ZK masking. |
Definition at line 238 of file polynomial.hpp.
|
inlinestatic |
Overload of shiftable that leaves the backing memory uninitialized.
Use only when the caller writes every cell in [NUM_ZERO_ROWS, NUM_ZERO_ROWS + size) before any read.
Definition at line 251 of file polynomial.hpp.
|
inlinestatic |
Utility to create a shiftable polynomial of given virtual size.
| masked | If true, write random values at positions {1,2,3} for ZK masking. |
Definition at line 225 of file polynomial.hpp.
| Polynomial< Fr > bb::Polynomial< Fr >::shifted | ( | ) | const |
Returns a Polynomial the left-shift of self.
If the n coefficients of self are (0, a₁, …, aₙ₋₁), we returns the view of the n-1 coefficients (a₁, …, aₙ₋₁).
Definition at line 221 of file polynomial.cpp.
The end_index of the polynomial is decreased without any memory de-allocation. This is a very fast way to zeroize the polynomial tail from new_end_index to the end. It also means that the new end_index might be smaller than the backed memory.
Definition at line 200 of file polynomial.cpp.
|
inline |
Definition at line 402 of file polynomial.hpp.
|
inline |
Definition at line 585 of file polynomial.hpp.
|
inline |
Definition at line 750 of file polynomial.hpp.
|
inline |
Definition at line 403 of file polynomial.hpp.
|
private |
Definition at line 665 of file polynomial.hpp.