Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
flavor.cpp
Go to the documentation of this file.
1#include "flavor.hpp"
3
4namespace bb::avm2 {
5
6AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key)
7{
8 for (auto [prover_poly, key_poly] : zip_view(this->get_unshifted(), proving_key.get_all())) {
10 prover_poly = key_poly.share();
11 }
12 for (auto [prover_poly, key_poly] : zip_view(this->get_shifted(), proving_key.get_to_be_shifted())) {
13 BB_ASSERT_EQ(flavor_get_label(*this, prover_poly), (flavor_get_label(proving_key, key_poly) + "_shift"));
14 prover_poly = key_poly.shifted();
15 }
16}
17
18void AvmFlavor::Transcript::deserialize_full_transcript()
19{
20 size_t num_frs_read = 0;
21
22 for (auto& commitment : commitments) {
23 commitment = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
24 }
25
26 for (size_t i = 0; i < log_circuit_size; ++i) {
27 sumcheck_univariates.emplace_back(deserialize_from_buffer<bb::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>>(
28 Transcript::proof_data, num_frs_read));
29 }
30
31 sumcheck_evaluations =
32 deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(Transcript::proof_data, num_frs_read);
33
34 for (size_t i = 0; i < log_circuit_size - 1; ++i) {
35 gemini_fold_comms.push_back(deserialize_from_buffer<Commitment>(proof_data, num_frs_read));
36 }
37
38 for (size_t i = 0; i < log_circuit_size; ++i) {
39 gemini_fold_evals.push_back(deserialize_from_buffer<FF>(proof_data, num_frs_read));
40 }
41
42 shplonk_q_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
43
44 kzg_w_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
45}
46
47void AvmFlavor::Transcript::serialize_full_transcript()
48{
49 size_t old_proof_length = proof_data.size();
51
52 for (const auto& commitment : commitments) {
53 serialize_to_buffer(commitment, Transcript::proof_data);
54 }
55
56 for (size_t i = 0; i < log_circuit_size; ++i) {
57 serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data);
58 }
59
60 serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data);
61
62 for (size_t i = 0; i < log_circuit_size - 1; ++i) {
63 serialize_to_buffer(gemini_fold_comms[i], proof_data);
64 }
65
66 for (size_t i = 0; i < log_circuit_size; ++i) {
67 serialize_to_buffer(gemini_fold_evals[i], proof_data);
68 }
69
70 serialize_to_buffer(shplonk_q_comm, proof_data);
71 serialize_to_buffer(kzg_w_comm, proof_data);
72
73 // sanity check to make sure we generate the same length of proof as before.
74 BB_ASSERT_EQ(proof_data.size(), old_proof_length);
75}
76
77AvmFlavor::ProverPolynomials::ProverPolynomials(const ProverPolynomials& full_polynomials, size_t circuit_size)
78{
79 for (auto [poly, full_poly] : zip_view(get_all(), full_polynomials.get_all())) {
80 // After the initial sumcheck round, the new size is CEIL(size/2).
81 size_t desired_size = (full_poly.end_index() / 2) + (full_poly.end_index() % 2);
82 poly = Polynomial(desired_size, circuit_size / 2);
83 }
84}
85
87 : commitment_key(circuit_size + 1) {
88 // The proving key's polynomials are not allocated here because they are later overwritten
89 // AvmComposer::compute_witness(). We should probably refactor this flow.
90 };
91
93{
94 current_edge = edge_idx;
95 // If the current edge changed, we need to clear all the cached univariates.
96 dirty = true;
97}
98
101{
102 const auto& multivariate = multivariates.get(c);
103 if (multivariate.is_empty() || multivariate.end_index() < current_edge) {
104 static const auto zero_univariate = bb::Univariate<FF, MAX_PARTIAL_RELATION_LENGTH>::zero();
105 return zero_univariate;
106 } else {
107 auto& mutable_entities = const_cast<decltype(entities)&>(entities);
108 if (dirty) {
109 // If the current edge changed, we need to clear all the cached univariates.
110 for (auto& extended_ptr : mutable_entities) {
111 extended_ptr.reset();
112 }
113 dirty = false;
114 }
115 auto& extended_ptr = mutable_entities[static_cast<size_t>(c)];
116 if (extended_ptr.get() == nullptr) {
118 bb::Univariate<FF, 2>({ multivariate[current_edge], multivariate[current_edge + 1] })
119 .template extend_to<MAX_PARTIAL_RELATION_LENGTH>());
120 }
121 return *extended_ptr;
122 }
123}
124
125} // namespace bb::avm2
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:88
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
static Univariate zero()
std::span< DataType > get_all()
Definition flavor.hpp:137
DataType & get(ColumnAndShifts c)
Definition flavor.hpp:150
const bb::Univariate< FF, MAX_PARTIAL_RELATION_LENGTH > & get(ColumnAndShifts c) const
Definition flavor.cpp:100
A container for the prover polynomials handles.
Definition flavor.hpp:281
std::span< Polynomial > get_all()
Definition flavor.hpp:215
AvmFlavorSettings::Polynomial Polynomial
Definition flavor.hpp:37
ColumnAndShifts
Definition columns.hpp:34
std::string flavor_get_label(Container &&container, const Element &element)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13