barretenberg
Loading...
Searching...
No Matches
toy_avm.hpp
1#pragma once
2#include "barretenberg/commitment_schemes/commitment_key.hpp"
3#include "barretenberg/commitment_schemes/kzg/kzg.hpp"
4#include "barretenberg/ecc/curves/bn254/bn254.hpp"
6#include "barretenberg/flavor/flavor_macros.hpp"
7#include "barretenberg/polynomials/univariate.hpp"
8#include "barretenberg/relations/relation_parameters.hpp"
9#include "barretenberg/relations/relation_types.hpp"
12#include "relation_definitions_fwd.hpp"
13#include <array>
14#include <concepts>
15#include <span>
16#include <string>
17#include <type_traits>
18#include <vector>
19
20// NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
21
22namespace proof_system::honk {
23namespace flavor {
24
30class ToyAVM {
31 public:
32 using Curve = curve::BN254;
33 using FF = Curve::ScalarField;
34 using GroupElement = Curve::Element;
35 using Commitment = Curve::AffineElement;
36 using CommitmentHandle = Curve::AffineElement;
39 using PolynomialHandle = std::span<FF>;
42
43 // The number of wires is 5. The set of tuples (permutation_set_column_1,permutation_set_column_2) should be
44 // equivalent to (permutation_set_column_3, permutation_set_column_4) and the self_permutation_column contains 2
45 // subsets which are permutations of each other
46 static constexpr size_t NUM_WIRES = 5;
47
48 // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often
49 // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`.
50 // Note: this number does not include the individual sorted list polynomials.
51 static constexpr size_t NUM_ALL_ENTITIES = 12;
52 // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying
53 // assignment of witnesses. We again choose a neutral name.
54 static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 5;
55 // The total number of witness entities not including shifts.
56 static constexpr size_t NUM_WITNESS_ENTITIES = 7;
57
58 // define the tuple of Relations that comprise the Sumcheck relation
59 using Relations = std::tuple<sumcheck::GenericPermutationRelation<sumcheck::ExampleTuplePermutationSettings, FF>>;
60
61 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
62
63 // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
64 // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
65 // length = 3
66 static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
67 static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;
68
69 // Instantiate the BarycentricData needed to extend each Relation Univariate
70
71 // define the containers for storing the contributions from each relation in Sumcheck
72 using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
73 using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());
74
75 private:
80 template <typename DataType_> class PrecomputedEntities : public PrecomputedEntitiesBase {
81 public:
82 using DataType = DataType_;
83 DEFINE_FLAVOR_MEMBERS(DataType,
84 lagrange_first, // column 0
85 enable_tuple_set_permutation, // column 1
86 enable_single_column_permutation, // column 2
87 enable_first_set_permutation, // column 3
88 enable_second_set_permutation) // column 4
89
90 RefVector<DataType> get_selectors()
91 {
92 return { lagrange_first,
93 enable_tuple_set_permutation,
94 enable_single_column_permutation,
95 enable_first_set_permutation,
96 enable_second_set_permutation };
97 };
98 RefVector<DataType> get_sigma_polynomials() { return {}; };
99 RefVector<DataType> get_id_polynomials() { return {}; };
100 RefVector<DataType> get_table_polynomials() { return {}; };
101 };
102
108 template <typename DataType> class WitnessEntities {
109 public:
110 DEFINE_FLAVOR_MEMBERS(DataType,
111 permutation_set_column_1, // Column 0
112 permutation_set_column_2, // Column 1
113 permutation_set_column_3, // Column 2
114 permutation_set_column_4, // Column 3
115 self_permutation_column, // Column 4
116 tuple_permutation_inverses, // Column 5
117 single_permutation_inverses) // Column 6
118
119 RefVector<DataType> get_wires()
120 {
121 return { permutation_set_column_1,
122 permutation_set_column_2,
123 permutation_set_column_3,
124 permutation_set_column_4,
125 self_permutation_column };
126 };
127 };
128
139 template <typename DataType> class AllEntities {
140 public:
141 DEFINE_FLAVOR_MEMBERS(DataType,
142 lagrange_first, // Column 0
143 enable_tuple_set_permutation, // Column 1
144 enable_single_column_permutation, // Column 2
145 enable_first_set_permutation, // Column 3
146 enable_second_set_permutation, // Column 4
147 permutation_set_column_1, // Column 5
148 permutation_set_column_2, // Column 6
149 permutation_set_column_3, // Column 7
150 permutation_set_column_4, // Column 8
151 self_permutation_column, // Column 9
152 tuple_permutation_inverses, // Column 10
153 single_permutation_inverses) // Column 11
154
155 RefVector<DataType> get_wires()
156 {
157 return {
158 permutation_set_column_1, permutation_set_column_2, permutation_set_column_3, permutation_set_column_4
159 };
160 };
161 RefVector<DataType> get_unshifted()
162 {
163 return { lagrange_first,
164 enable_tuple_set_permutation,
165 enable_single_column_permutation,
166 enable_first_set_permutation,
167 enable_second_set_permutation,
168 permutation_set_column_1,
169 permutation_set_column_2,
170 permutation_set_column_3,
171 permutation_set_column_4,
172 self_permutation_column,
173 tuple_permutation_inverses,
174 single_permutation_inverses };
175 };
176 RefVector<DataType> get_to_be_shifted() { return {}; };
177 RefVector<DataType> get_shifted() { return {}; };
178 };
179
180 public:
186 class ProvingKey : public ProvingKey_<PrecomputedEntities<Polynomial>, WitnessEntities<Polynomial>> {
187 public:
188 // Expose constructors on the base class
189 using Base = ProvingKey_<PrecomputedEntities<Polynomial>, WitnessEntities<Polynomial>>;
190 using Base::Base;
191
192 // The plookup wires that store plookup read data.
193 std::array<PolynomialHandle, 3> get_table_column_wires() { return {}; };
194 };
195
205
210 class AllValues : public AllEntities<FF> {
211 public:
212 using Base = AllEntities<FF>;
213 using Base::Base;
214 };
215
219 class ProverPolynomials : public AllEntities<Polynomial> {
220 public:
221 // Define all operations as default, except move construction/assignment
222 ProverPolynomials() = default;
223 ProverPolynomials& operator=(const ProverPolynomials&) = delete;
224 ProverPolynomials(const ProverPolynomials& o) = delete;
225 ProverPolynomials(ProverPolynomials&& o) noexcept = default;
226 ProverPolynomials& operator=(ProverPolynomials&& o) noexcept = default;
227 ~ProverPolynomials() = default;
228 [[nodiscard]] size_t get_polynomial_size() const { return enable_tuple_set_permutation.size(); }
229 [[nodiscard]] AllValues get_row(const size_t row_idx) const
230 {
231 AllValues result;
232 for (auto [result_field, polynomial] : zip_view(result.get_all(), get_all())) {
233 result_field = polynomial[row_idx];
234 }
235 return result;
236 }
237 };
238
242 class PartiallyEvaluatedMultivariates : public AllEntities<Polynomial> {
243
244 public:
246 PartiallyEvaluatedMultivariates(const size_t circuit_size)
247 {
248 // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2)
249 for (auto& poly : this->get_all()) {
250 poly = Polynomial(circuit_size / 2);
251 }
252 }
253 };
258 template <size_t LENGTH> using ProverUnivariates = AllEntities<barretenberg::Univariate<FF, LENGTH>>;
259
264
269 using WitnessCommitments = WitnessEntities<Commitment>;
270
277 class CommitmentLabels : public AllEntities<std::string> {
278 private:
279 using Base = AllEntities<std::string>;
280
281 public:
283 : AllEntities<std::string>()
284 {
285 Base::permutation_set_column_1 = "PERMUTATION_SET_COLUMN_1";
286 Base::permutation_set_column_2 = "PERMUTATION_SET_COLUMN_2";
287 Base::permutation_set_column_3 = "PERMUTATION_SET_COLUMN_3";
288 Base::permutation_set_column_4 = "PERMUTATION_SET_COLUMN_4";
289 Base::self_permutation_column = "SELF_PERMUTATION_COLUMN";
290 Base::tuple_permutation_inverses = "TUPLE_PERMUTATION_INVERSES";
291 Base::single_permutation_inverses = "SINGLE_PERMUTATION_INVERSES";
292 // The ones beginning with "__" are only used for debugging
293 Base::lagrange_first = "__LAGRANGE_FIRST";
294 Base::enable_tuple_set_permutation = "__ENABLE_SET_PERMUTATION";
295 Base::enable_single_column_permutation = "__ENABLE_SINGLE_COLUMN_PERMUTATION";
296 Base::enable_first_set_permutation = "__ENABLE_FIRST_SET_PERMUTATION";
297 Base::enable_second_set_permutation = "__ENABLE_SECOND_SET_PERMUTATION";
298 };
299 };
300
301 class VerifierCommitments : public AllEntities<Commitment> {
302
303 public:
304 VerifierCommitments(const std::shared_ptr<VerificationKey>& verification_key)
305 {
306 lagrange_first = verification_key->lagrange_first;
307 enable_tuple_set_permutation = verification_key->enable_tuple_set_permutation;
308 enable_single_column_permutation = verification_key->enable_single_column_permutation;
309 enable_first_set_permutation = verification_key->enable_first_set_permutation;
310 enable_second_set_permutation = verification_key->enable_second_set_permutation;
311 }
312 };
313
318 class Transcript : public BaseTranscript {
319 public:
320 uint32_t circuit_size;
321 Commitment column_0_comm;
322 Commitment column_1_comm;
323 Commitment permutation_inverses_comm;
324 std::vector<barretenberg::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>> sumcheck_univariates;
325 std::array<FF, NUM_ALL_ENTITIES> sumcheck_evaluations;
326
327 std::vector<Commitment> zm_cq_comms;
328 Commitment zm_cq_comm;
329 Commitment zm_pi_comm;
330
331 Transcript() = default;
332
333 Transcript(const std::vector<uint8_t>& proof)
334 : BaseTranscript(proof)
335 {}
336
337 void deserialize_full_transcript()
338 {
339 // TODO. Codepath is dead for now, because there is no composer
340 abort();
341 // take current proof and put them into the struct
342 }
343
344 void serialize_full_transcript()
345 {
346 // TODO. Codepath is dead for now, because there is no composer
347 abort();
348 }
349 };
350};
351
352// NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members)
353
354} // namespace flavor
355namespace sumcheck {
356
357DECLARE_IMPLEMENTATIONS_FOR_ALL_SETTINGS(GenericPermutationRelationImpl, flavor::ToyAVM)
358
359} // namespace sumcheck
360} // namespace proof_system::honk
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
Definition: ref_vector.hpp:20
Definition: polynomial.hpp:12
Definition: bn254.hpp:10
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
Definition: transcript.hpp:62
Base class template containing circuit-specifying data.
Definition: flavor.hpp:85
Base proving key class.
Definition: flavor.hpp:101
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
Definition: toy_avm.hpp:210
A container for commitment labels.
Definition: toy_avm.hpp:277
A container for storing the partially evaluated multivariates produced by sumcheck.
Definition: toy_avm.hpp:242
A container for polynomials handles; only stores spans.
Definition: toy_avm.hpp:219
The proving key is responsible for storing the polynomials used by the prover.
Definition: toy_avm.hpp:186
Derived class that defines proof structure for ECCVM proofs, as well as supporting functions.
Definition: toy_avm.hpp:318
This class provides an example flavor for using GenericPermutationRelations with various settings to ...
Definition: toy_avm.hpp:30
AllEntities< barretenberg::Univariate< FF, LENGTH > > ProverUnivariates
A container for univariates used during Protogalaxy folding and sumcheck.
Definition: toy_avm.hpp:258
WitnessEntities< Commitment > WitnessCommitments
A container for the witness commitments.
Definition: toy_avm.hpp:269
ProverUnivariates< MAX_PARTIAL_RELATION_LENGTH > ExtendedEdges
A container for univariates produced during the hot loop in sumcheck.
Definition: toy_avm.hpp:263
CommitmentKey object over a pairing group 𝔾₁.
Definition: commitment_key.hpp:35
Definition: verification_key.hpp:25
Definition: kzg.hpp:14
Definition: zip_view.hpp:159
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
This file contains the template for the generic permutation that can be specialized to enforce variou...
Defines particular circuit builder types expected to be used for circuit construction in stdlib and c...
Definition: claim.hpp:6
This file contains settings for the General Permutation Relation implementations and (in the future) ...