Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
mega_recursive_flavor.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
22
23namespace bb {
24
39template <typename BuilderType> class MegaRecursiveFlavor_ {
40 public:
41 using CircuitBuilder = BuilderType; // Determines arithmetization of circuit instantiated with this flavor
43 using PCS = KZG<Curve>;
44 using GroupElement = typename Curve::Element;
45 using FF = typename Curve::ScalarField;
46 using Commitment = typename Curve::Element;
48
50 static constexpr size_t VIRTUAL_LOG_N = MegaFlavor::VIRTUAL_LOG_N;
51 // indicates when evaluating sumcheck, edges can be left as degree-1 monomials
53 // Note(luke): Eventually this may not be needed at all
55 // Indicates that this flavor runs with non-ZK Sumcheck.
56 static constexpr bool HasZK = false;
57 // To achieve fixed proof size and that the recursive verifier circuit is constant, we are using padding in Sumcheck
58 // and Shplemini
59 static constexpr bool USE_PADDING = MegaFlavor::USE_PADDING;
60 static constexpr size_t NUM_WIRES = MegaFlavor::NUM_WIRES;
61 // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often
62 // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`.
63 // Note: this number does not include the individual sorted list polynomials.
65 // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying
66 // assignment of witnesses. We again choose a neutral name.
68 // The total number of witness entities not including shifts.
70 // Total number of folded polynomials, which is just all polynomials except the shifts
72
73 // define the tuple of Relations that comprise the Sumcheck relation
74 // Reuse the Relations from Mega
76
77 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
78 static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length<Relations>();
79
80 // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
81 // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
82 // length = 3
84
86
88
89 // For instances of this flavour, used in folding, we need a unique sumcheck batching challenge for each
90 // subrelation. This is because using powers of alpha would increase the degree of Protogalaxy polynomial $G$ (the
91 // combiner) to much.
93 using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;
94
100 public:
102 using Base::Base;
103 };
113 class VerificationKey : public StdlibVerificationKey_<BuilderType, MegaFlavor::PrecomputedEntities<Commitment>> {
114
115 public:
117
126 {
127 this->log_circuit_size = FF::from_witness(builder, native_key->log_circuit_size);
128 this->num_public_inputs = FF::from_witness(builder, native_key->num_public_inputs);
129 this->pub_inputs_offset = FF::from_witness(builder, native_key->pub_inputs_offset);
130
131 // Generate stdlib commitments (biggroup) from the native counterparts
132 for (auto [commitment, native_commitment] : zip_view(this->get_all(), native_key->get_all())) {
133 commitment = Commitment::from_witness(builder, native_commitment);
134 }
135 };
136
144 {
145 using namespace bb::stdlib::field_conversion;
146
147 size_t num_frs_read = 0;
148
149 this->log_circuit_size = deserialize_from_frs<FF>(builder, elements, num_frs_read);
150 this->num_public_inputs = deserialize_from_frs<FF>(builder, elements, num_frs_read);
151 this->pub_inputs_offset = deserialize_from_frs<FF>(builder, elements, num_frs_read);
152
153 for (Commitment& commitment : this->get_all()) {
154 commitment = deserialize_from_frs<Commitment>(builder, elements, num_frs_read);
155 }
156
157 if (num_frs_read != elements.size()) {
158 throw_or_abort("Invalid buffer length in VerificationKey constuctor from fields!");
159 }
160 }
161
170 const std::span<const uint32_t>& witness_indices)
171 {
172 std::vector<FF> vk_fields;
173 vk_fields.reserve(witness_indices.size());
174 for (const auto& idx : witness_indices) {
175 vk_fields.emplace_back(FF::from_witness_index(&builder, idx));
176 }
177 return VerificationKey(builder, vk_fields);
178 }
179
185 {
189 for (Commitment& commitment : this->get_all()) {
190 commitment.fix_witness();
191 }
192 }
193 };
194
199
201 // Reuse the VerifierCommitments from Mega
203
205};
206
207} // namespace bb
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
A base class labelling all entities (for instance, all of the polynomials used by the prover during s...
A container for commitment labels.
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
Container for all witness polynomials used/constructed by the prover.
static constexpr size_t NUM_PRECOMPUTED_ENTITIES
static constexpr RepeatedCommitmentsData REPEATED_COMMITMENTS
static constexpr size_t NUM_WIRES
static constexpr size_t NUM_SUBRELATIONS
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_WITNESS_ENTITIES
static constexpr size_t VIRTUAL_LOG_N
static constexpr bool USE_SHORT_MONOMIALS
static constexpr bool USE_PADDING
std::tuple< bb::UltraArithmeticRelation< FF >, bb::UltraPermutationRelation< FF >, bb::LogDerivLookupRelation< FF >, bb::DeltaRangeConstraintRelation< FF >, bb::EllipticRelation< FF >, bb::MemoryRelation< FF >, bb::NonNativeFieldRelation< FF >, bb::EccOpQueueRelation< FF >, bb::DatabusLookupRelation< FF >, bb::Poseidon2ExternalRelation< FF >, bb::Poseidon2InternalRelation< FF > > Relations_
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
static VerificationKey from_witness_indices(CircuitBuilder &builder, const std::span< const uint32_t > &witness_indices)
Construct a VerificationKey from a set of corresponding witness indices.
VerificationKey(CircuitBuilder &builder, std::span< FF > elements)
Deserialize a verification key from a vector of field elements.
VerificationKey(CircuitBuilder *builder, const std::shared_ptr< NativeVerificationKey > &native_key)
Construct a new Verification Key with stdlib types from a provided native verification key.
void fix_witness()
Fixes witnesses of VK to be constants.
The recursive counterpart to the "native" Mega flavor.
typename Curve::Element GroupElement
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr size_t NUM_WITNESS_ENTITIES
typename Curve::Element Commitment
static constexpr size_t NUM_WIRES
static constexpr size_t MAX_TOTAL_RELATION_LENGTH
static constexpr size_t NUM_PRECOMPUTED_ENTITIES
static constexpr bool USE_SHORT_MONOMIALS
std::array< FF, NUM_SUBRELATIONS - 1 > SubrelationSeparators
static constexpr size_t VIRTUAL_LOG_N
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
static constexpr RepeatedCommitmentsData REPEATED_COMMITMENTS
static constexpr bool USE_PADDING
static constexpr size_t NUM_ALL_ENTITIES
MegaFlavor::Relations_< FF > Relations
typename Curve::ScalarField FF
static constexpr size_t NUM_FOLDED_ENTITIES
static constexpr size_t NUM_SUBRELATIONS
static constexpr size_t NUM_RELATIONS
Base Stdlib verification key class.
Definition flavor.hpp:242
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
static field_t from_witness_index(Builder *ctx, uint32_t witness_index)
Definition field.cpp:59
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:424
AluTraceBuilder builder
Definition alu.test.cpp:123
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
field_t< CircuitBuilder > ScalarField
Definition bn254.hpp:33
void throw_or_abort(std::string const &err)