Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
flavor_concepts.hpp
Go to the documentation of this file.
1#pragma once
2
3// Establish concepts for testing flavor attributes
6#include <cstddef>
7#include <string>
8#include <type_traits>
9namespace bb {
10class TranslatorShortMonomialFlavor;
11
12// clang-format off
13
14class ECCVMShortMonomialFlavor;
15
16// Recognise any instantiation of the multilinear batching flavors, independent of NumClaims.
17template <typename T> struct IsMultilinearBatchingFlavorImpl : std::false_type {};
18template <size_t NumClaims> struct IsMultilinearBatchingFlavorImpl<MultilinearBatchingFlavor_<NumClaims>> : std::true_type {};
19
20template <typename T> struct IsMultilinearBatchingRecursiveFlavorImpl : std::false_type {};
21template <size_t NumClaims> struct IsMultilinearBatchingRecursiveFlavorImpl<MultilinearBatchingRecursiveFlavor_<NumClaims>> : std::true_type {};
22
23#ifdef STARKNET_GARAGA_FLAVORS
24template <typename T>
26#else
27template <typename T>
29#endif
30template <typename T>
32
33// Whether the Flavor has randomness at the end of its trace to randomise commitments and evaluations of its polynomials
34// hence requiring an adjustment to the round univariates via the RowDisablingPolynomial.
35// This is not the case for Translator, where randomness resides in different parts of the trace and the locations will
36// be reflected via Translator relations.
37template <typename T>
39template <typename T> concept UseRowDisablingPolynomial = !IsTranslatorFlavor<T>;
40
41
42
43template <typename T>
45 UltraRecursiveFlavor_<MegaCircuitBuilder>,
46 UltraZKRecursiveFlavor_<UltraCircuitBuilder>,
47 UltraZKRecursiveFlavor_<MegaCircuitBuilder>,
48 MegaRecursiveFlavor_<UltraCircuitBuilder>,
49 MegaRecursiveFlavor_<MegaCircuitBuilder>,
50 MegaZKRecursiveFlavor_<MegaCircuitBuilder>,
51 MegaZKRecursiveFlavor_<UltraCircuitBuilder>,
52 MegaAvmRecursiveFlavor_<UltraCircuitBuilder>,
53 MegaAppRecursiveFlavor,
54 MegaKernelRecursiveFlavor,
55 TranslatorRecursiveFlavor,
56 ECCVMRecursiveFlavor,
57 avm2::AvmRecursiveFlavor> ||
58 IsMultilinearBatchingRecursiveFlavorImpl<T>::value;
59
60template <typename T>
62
63template <typename T>
64concept isMultilinearBatchingFlavor = IsMultilinearBatchingFlavorImpl<T>::value || IsMultilinearBatchingRecursiveFlavorImpl<T>::value;
65
66// Sumcheck-prover opt-in: a flavor declares PARALLELIZE_RELATION_BATCHING to batch each relation's subrelation
67// accumulators in parallel rather than serially. See the batching loop in sumcheck_round.hpp for when it pays off;
68// flavors that don't declare the flag default to the serial loop.
69template <typename T> concept ParallelizesRelationBatching = requires { requires T::PARALLELIZE_RELATION_BATCHING; };
70
71// Sumcheck-prover opt-in: a flavor declares USE_SIMD_SUMCHECK = true to route compute_univariate through the
72// row-parallel SimdLane, which packs several trace rows into each SIMD lane and evaluates the relation set with
73// VectorField as the element type. Flavors that don't declare the flag default to the scalar lane. Requires a
74// Relations_<T> template so the relation set can re-instantiate over the lane element. Whether the SIMD path is
75// actually taken is gated at dispatch on simd_available_v<FF::Params> (build target + field capability), so on
76// native or non-SIMD fields these flavors still run scalar; see SumcheckProverRound::compute_univariate.
77template <typename T>
79 requires { requires T::USE_SIMD_SUMCHECK; } && requires { typename T::template Relations_<typename T::FF>; };
80
81// Short-monomial flavors that expose the codegen'd array layout -- a `Generated` member (the generated
82// relation/entity definitions) together with an EntityId-keyed ProverUnivariates -- i.e. native Ultra/Mega.
83// The sumcheck prover materializes their edges lazily per column. ECCVM/Translator are short-monomial but lack the
84// nested EntityId, and AVM is dispatched separately, so all of those keep the eager edge-extension path.
85template <typename T>
86concept HasLazyShortEdges = T::USE_SHORT_MONOMIALS && requires {
87 typename T::Generated;
88 typename T::template ProverUnivariates<2>::EntityId;
89};
90
91// This concept is relevant for the Sumcheck Prover, where the logic differs between BN254 and Grumpkin
93
94// Flavors whose Sumcheck round univariates are committed (sent as commitment + evals at 0,1)
95// rather than sent in the clear. The committed data is later verified via Shplemini.
96template <typename T> concept UsesCommittedSumcheck = IsGrumpkinFlavor<T>;
97template <typename Container, typename Element>
98inline std::string flavor_get_label(Container&& container, const Element& element) {
99 for (auto [label, data] : zip_view(container.get_labels(), container.get_all())) {
100 if (&data == &element) {
101 return label;
102 }
103 }
104 return "(unknown label)";
105}
106
107// Whether a flavor includes a Gemini masking polynomial in its entities.
108// Defaults to Flavor::HasZK; flavors that define HasGeminiMasking = false (e.g., MegaZKFlavor)
109// opt out because a separate circuit provides the masking polynomial in the batched PCS.
110template <typename Flavor>
112{
113 if constexpr (requires { Flavor::HasGeminiMasking; }) {
114 return Flavor::HasGeminiMasking;
115 } else {
116 return Flavor::HasZK;
117 }
118}
119
120// Whether a flavor's entity layout actually carries a gemini_masking_poly column.
121template <typename Flavor>
123{
124 return requires(typename Flavor::AllValues values) { values.gemini_masking_poly(); };
125}
126
127// The masking invariant: the advertised flag must match the real entity layout. A flavor that
128// declares Gemini masking (via HasGeminiMasking / HasZK) must actually carry the gemini_masking_poly
129// column, and vice versa.
130template <typename Flavor>
132{
133 return flavor_has_gemini_masking<Flavor>() == flavor_entities_have_gemini_masking<Flavor>();
134}
135
136// clang-format on
137} // namespace bb
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
static constexpr bool HasZK
Native flavor for multilinear batching sumcheck with NumClaims polynomials.
std::string label
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr bool flavor_entities_have_gemini_masking()
constexpr bool gemini_masking_layout_consistent()
constexpr bool flavor_has_gemini_masking()
std::string flavor_get_label(Container &&container, const Element &element)
std::byte * data
Curve::Element Element