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
21
22namespace bb {
23
38template <typename BuilderType> class MegaRecursiveFlavor_ {
39 public:
40 using CircuitBuilder = BuilderType; // Determines arithmetization of circuit instantiated with this flavor
42 using PCS = KZG<Curve>;
43 using GroupElement = typename Curve::Element;
44 using FF = typename Curve::ScalarField;
45 using Commitment = typename Curve::Element;
47
49 static constexpr size_t VIRTUAL_LOG_N = MegaFlavor::VIRTUAL_LOG_N;
50 // indicates when evaluating sumcheck, edges can be left as degree-1 monomials
52 // Note(luke): Eventually this may not be needed at all
54 // Indicates that this flavor runs with non-ZK Sumcheck.
55 static constexpr bool HasZK = false;
56 // To achieve fixed proof size and that the recursive verifier circuit is constant, we are using padding in Sumcheck
57 // and Shplemini
58 static constexpr bool USE_PADDING = MegaFlavor::USE_PADDING;
59 static constexpr size_t NUM_WIRES = MegaFlavor::NUM_WIRES;
60 // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often
61 // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`.
62 // Note: this number does not include the individual sorted list polynomials.
64 // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying
65 // assignment of witnesses. We again choose a neutral name.
67 // The total number of witness entities not including shifts.
69
70 // define the tuple of Relations that comprise the Sumcheck relation
71 // Reuse the Relations from Mega
73
74 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
75
76 // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
77 // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
78 // length = 3
80
82
84
85 // A challenge whose powers are used to batch subrelation contributions during Sumcheck
88
94 public:
96 using Base::Base;
97 };
98
108 class VerificationKey : public StdlibVerificationKey_<BuilderType, MegaFlavor::PrecomputedEntities<Commitment>> {
109
110 public:
112
121 {
122 this->log_circuit_size = FF::from_witness(builder, typename FF::native(native_key->log_circuit_size));
123 this->num_public_inputs = FF::from_witness(builder, typename FF::native(native_key->num_public_inputs));
124 this->pub_inputs_offset = FF::from_witness(builder, typename FF::native(native_key->pub_inputs_offset));
125
126 // Generate stdlib commitments (biggroup) from the native counterparts
127 for (auto [commitment, native_commitment] : zip_view(this->get_all(), native_key->get_all())) {
128 commitment = Commitment::from_witness(builder, native_commitment);
129 }
130 };
131
139 {
140 using Codec = stdlib::StdlibCodec<FF>;
141
142 size_t num_frs_read = 0;
143
144 this->log_circuit_size = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
145 this->num_public_inputs = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
146 this->pub_inputs_offset = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
147
148 for (Commitment& commitment : this->get_all()) {
149 commitment = Codec::template deserialize_from_frs<Commitment>(elements, num_frs_read);
150 }
151
152 if (num_frs_read != elements.size()) {
153 throw_or_abort("Invalid buffer length in VerificationKey constuctor from fields!");
154 }
155 }
156
165 const std::span<const uint32_t>& witness_indices)
166 {
167 std::vector<FF> vk_fields;
168 vk_fields.reserve(witness_indices.size());
169 for (const auto& idx : witness_indices) {
170 vk_fields.emplace_back(FF::from_witness_index(&builder, idx));
171 }
172 return VerificationKey(vk_fields);
173 }
174
180 {
184 for (Commitment& commitment : this->get_all()) {
185 commitment.fix_witness();
186 }
187 }
188
189#ifndef NDEBUG
196 {
197 NativeVerificationKey native_vk;
198 native_vk.log_circuit_size = static_cast<uint64_t>(this->log_circuit_size.get_value());
199 native_vk.num_public_inputs = static_cast<uint64_t>(this->num_public_inputs.get_value());
200 native_vk.pub_inputs_offset = static_cast<uint64_t>(this->pub_inputs_offset.get_value());
201 for (auto [commitment, native_commitment] : zip_view(this->get_all(), native_vk.get_all())) {
202 native_commitment = commitment.get_value();
203 }
204 return native_vk;
205 }
206#endif
207 };
208
213
215 // Reuse the VerifierCommitments from Mega
217
219};
220
221} // 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
std::tuple< bb::ArithmeticRelation< 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_
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
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, const std::shared_ptr< NativeVerificationKey > &native_key)
Construct a new Verification Key with stdlib types from a provided native verification key.
NativeVerificationKey get_value() const
Get the native verification key corresponding to this stdlib verification key.
void fix_witness()
Fixes witnesses of VK to be constants.
VerificationKey(std::span< FF > elements)
Deserialize a verification key from a vector of field elements.
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 NUM_PRECOMPUTED_ENTITIES
static constexpr bool USE_SHORT_MONOMIALS
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_SUBRELATIONS
static constexpr size_t NUM_RELATIONS
Base Stdlib verification key class.
Definition flavor.hpp:325
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:62
bb::fr get_value() const
Given a := *this, compute its value given by a.v * a.mul + a.add.
Definition field.cpp:828
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:454
AluTraceBuilder builder
Definition alu.test.cpp:124
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
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)