2#include "barretenberg/commitment_schemes/kzg/kzg.hpp"
3#include "barretenberg/ecc/curves/bn254/g1.hpp"
5#include "barretenberg/flavor/flavor_macros.hpp"
6#include "barretenberg/polynomials/barycentric.hpp"
7#include "barretenberg/polynomials/evaluation_domain.hpp"
8#include "barretenberg/polynomials/polynomial.hpp"
9#include "barretenberg/polynomials/univariate.hpp"
10#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
11#include "barretenberg/relations/auxiliary_relation.hpp"
12#include "barretenberg/relations/elliptic_relation.hpp"
13#include "barretenberg/relations/gen_perm_sort_relation.hpp"
14#include "barretenberg/relations/lookup_relation.hpp"
15#include "barretenberg/relations/permutation_relation.hpp"
16#include "barretenberg/relations/ultra_arithmetic_relation.hpp"
17#include "barretenberg/transcript/transcript.hpp"
19namespace proof_system::honk::flavor {
26 using GroupElement = Curve::Element;
27 using Commitment = Curve::AffineElement;
28 using CommitmentHandle = Curve::AffineElement;
31 using PolynomialHandle = std::span<FF>;
35 static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES;
39 static constexpr size_t NUM_ALL_ENTITIES = 43;
42 static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25;
44 static constexpr size_t NUM_WITNESS_ENTITIES = 7;
46 using GrandProductRelations =
49 using Relations = std::tuple<proof_system::UltraArithmeticRelation<FF>,
56 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
57 static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length<Relations>();
58 static_assert(MAX_PARTIAL_RELATION_LENGTH == 6);
59 static_assert(MAX_TOTAL_RELATION_LENGTH == 12);
60 static constexpr size_t NUMBER_OF_SUBRELATIONS = compute_number_of_subrelations<Relations>();
65 static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
66 static constexpr size_t BATCHED_RELATION_TOTAL_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1;
67 static constexpr size_t NUM_RELATIONS = std::tuple_size_v<Relations>;
69 template <
size_t NUM_INSTANCES>
70 using ProtogalaxyTupleOfTuplesOfUnivariates =
71 decltype(create_protogalaxy_tuple_of_tuples_of_univariates<Relations, NUM_INSTANCES>());
72 using SumcheckTupleOfTuplesOfUnivariates =
decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
73 using TupleOfArraysOfValues =
decltype(create_tuple_of_arrays_of_values<Relations>());
76 static constexpr bool has_zero_row =
true;
85 using DataType = DataType_;
86 DEFINE_FLAVOR_MEMBERS(DataType,
113 static constexpr CircuitType CIRCUIT_TYPE = CircuitBuilder::CIRCUIT_TYPE;
117 return { q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_sort, q_elliptic, q_aux, q_lookup };
119 RefVector<DataType> get_sigma_polynomials() {
return { sigma_1, sigma_2, sigma_3, sigma_4 }; };
122 RefVector<DataType> get_table_polynomials() {
return { table_1, table_2, table_3, table_4 }; };
129 template <
typename DataType>
class WitnessEntities {
131 DEFINE_FLAVOR_MEMBERS(DataType,
140 RefVector<DataType> get_wires() {
return { w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; };
146 template <
typename DataType>
class ShiftedEntities {
148 DEFINE_FLAVOR_MEMBERS(DataType,
163 return { table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, w_r_shift,
164 w_o_shift, w_4_shift, sorted_accum_shift, z_perm_shift, z_lookup_shift };
177 template <
typename DataType>
class AllEntities {
179 DEFINE_FLAVOR_MEMBERS(DataType,
228 return { q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_sort,
229 q_elliptic, q_aux, q_lookup, sigma_1, sigma_2, sigma_3, sigma_4, id_1,
230 id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first,
231 lagrange_last, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup
238 return { q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_sort,
239 q_elliptic, q_aux, q_lookup, sigma_1, sigma_2, sigma_3, sigma_4, id_1,
240 id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first,
246 RefVector<DataType> get_witness() {
return { w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; };
249 return { table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup };
253 return { table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, w_r_shift,
254 w_o_shift, w_4_shift, sorted_accum_shift, z_perm_shift, z_lookup_shift };
270 std::vector<uint32_t> memory_read_records;
271 std::vector<uint32_t> memory_write_records;
275 return { this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, this->w_r,
276 this->w_o, this->w_4, this->sorted_accum, this->z_perm, this->z_lookup };
279 std::array<PolynomialHandle, 3> get_table_column_wires() {
return { w_l, w_r, w_o }; };
298 using Base = AllEntities<FF>;
314 [[nodiscard]]
size_t get_polynomial_size()
const {
return q_c.size(); }
315 [[nodiscard]]
AllValues get_row(
const size_t row_idx)
const
335 for (
auto& poly : this->get_all()) {
345 template <
size_t LENGTH>
using ProverUnivariates = AllEntities<barretenberg::Univariate<FF, LENGTH>>;
372 z_lookup =
"Z_LOOKUP";
373 sorted_accum =
"SORTED_ACCUM";
383 q_elliptic =
"Q_ELLIPTIC";
385 q_lookup =
"Q_LOOKUP";
398 lagrange_first =
"LAGRANGE_FIRST";
399 lagrange_last =
"LAGRANGE_LAST";
407 q_m = verification_key->q_m;
408 q_c = verification_key->q_c;
409 q_l = verification_key->q_l;
410 q_r = verification_key->q_r;
411 q_o = verification_key->q_o;
412 q_4 = verification_key->q_4;
413 q_arith = verification_key->q_arith;
414 q_sort = verification_key->q_sort;
415 q_elliptic = verification_key->q_elliptic;
416 q_aux = verification_key->q_aux;
417 q_lookup = verification_key->q_lookup;
418 sigma_1 = verification_key->sigma_1;
419 sigma_2 = verification_key->sigma_2;
420 sigma_3 = verification_key->sigma_3;
421 sigma_4 = verification_key->sigma_4;
422 id_1 = verification_key->id_1;
423 id_2 = verification_key->id_2;
424 id_3 = verification_key->id_3;
425 id_4 = verification_key->id_4;
426 table_1 = verification_key->table_1;
427 table_2 = verification_key->table_2;
428 table_3 = verification_key->table_3;
429 table_4 = verification_key->table_4;
430 lagrange_first = verification_key->lagrange_first;
431 lagrange_last = verification_key->lagrange_last;
437 std::vector<FF> gate_challenges;
448 uint32_t circuit_size;
449 uint32_t public_input_size;
450 uint32_t pub_inputs_offset;
451 std::vector<FF> public_inputs;
455 Commitment sorted_accum_comm;
457 Commitment z_perm_comm;
458 Commitment z_lookup_comm;
459 std::vector<barretenberg::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>> sumcheck_univariates;
460 std::array<FF, NUM_ALL_ENTITIES> sumcheck_evaluations;
461 std::vector<Commitment> zm_cq_comms;
462 Commitment zm_cq_comm;
463 Commitment zm_pi_comm;
472 static std::shared_ptr<Transcript> prover_init_empty()
474 auto transcript = std::make_shared<Transcript>();
475 constexpr uint32_t init{ 42 };
476 transcript->send_to_verifier(
"Init", init);
480 static std::shared_ptr<Transcript> verifier_init_empty(
const std::shared_ptr<Transcript>& transcript)
482 auto verifier_transcript = std::make_shared<Transcript>(transcript->proof_data);
483 [[maybe_unused]]
auto _ = verifier_transcript->template receive_from_prover<uint32_t>(
"Init");
484 return verifier_transcript;
495 size_t num_bytes_read = 0;
496 circuit_size = deserialize_from_buffer<uint32_t>(proof_data, num_bytes_read);
497 size_t log_n = numeric::get_msb(circuit_size);
499 public_input_size = deserialize_from_buffer<uint32_t>(proof_data, num_bytes_read);
500 pub_inputs_offset = deserialize_from_buffer<uint32_t>(proof_data, num_bytes_read);
501 for (
size_t i = 0; i < public_input_size; ++i) {
502 public_inputs.push_back(deserialize_from_buffer<FF>(proof_data, num_bytes_read));
504 w_l_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
505 w_r_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
506 w_o_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
507 sorted_accum_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
508 w_4_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
509 z_perm_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
510 z_lookup_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
511 for (
size_t i = 0; i < log_n; ++i) {
512 sumcheck_univariates.push_back(
514 proof_data, num_bytes_read));
516 sumcheck_evaluations =
517 deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(proof_data, num_bytes_read);
518 for (
size_t i = 0; i < log_n; ++i) {
519 zm_cq_comms.push_back(deserialize_from_buffer<Commitment>(proof_data, num_bytes_read));
521 zm_cq_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
522 zm_pi_comm = deserialize_from_buffer<Commitment>(proof_data, num_bytes_read);
531 size_t old_proof_length = proof_data.size();
533 size_t log_n = numeric::get_msb(circuit_size);
537 for (
size_t i = 0; i < public_input_size; ++i) {
547 for (
size_t i = 0; i < log_n; ++i) {
551 for (
size_t i = 0; i < log_n; ++i) {
558 ASSERT(proof_data.size() == old_proof_length);
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
Definition: ref_vector.hpp:20
Definition: polynomial.hpp:12
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
Definition: univariate.hpp:23
The templates defined herein facilitate sharing the relation arithmetic between the prover and the ve...
Definition: relation_types.hpp:121
Definition: ultra_circuit_builder.hpp:31
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
Definition: transcript.hpp:62
T deserialize_from_buffer(const Proof &proof_data, size_t &offset) const
Deserializes the bytes starting at offset into the typed element and returns that element.
Definition: transcript.hpp:180
void serialize_to_buffer(const T &element, Proof &proof_data)
Serializes object and appends it to proof_data.
Definition: transcript.hpp:166
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: ultra.hpp:296
A container for commitment labels.
Definition: ultra.hpp:363
Definition: ultra.hpp:435
A container for storing the partially evaluated multivariates produced by sumcheck.
Definition: ultra.hpp:328
A container for polynomials handles.
Definition: ultra.hpp:305
The proving key is responsible for storing the polynomials used by the prover.
Definition: ultra.hpp:264
Derived class that defines proof structure for Ultra proofs, as well as supporting functions.
Definition: ultra.hpp:445
void deserialize_full_transcript()
Takes a FULL Ultra proof and deserializes it into the public member variables that compose the struct...
Definition: ultra.hpp:492
void serialize_full_transcript()
Serializes the structure variables into a FULL Ultra proof. Should be called only if deserialize_full...
Definition: ultra.hpp:529
Definition: ultra.hpp:403
WitnessEntities< Commitment > WitnessCommitments
A container for the witness commitments.
Definition: ultra.hpp:355
ProverUnivariates< MAX_PARTIAL_RELATION_LENGTH > ExtendedEdges
A container for univariates produced during the hot loop in sumcheck.
Definition: ultra.hpp:350
AllEntities< barretenberg::Univariate< FF, LENGTH > > ProverUnivariates
A container for univariates used during Protogalaxy folding and sumcheck.
Definition: ultra.hpp:345
CommitmentKey object over a pairing group 𝔾₁.
Definition: commitment_key.hpp:35
Definition: verification_key.hpp:25
Definition: zip_view.hpp:159
Base class templates for structures that contain data parameterized by the fundamental polynomials of...