Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
recursive_flavor.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Federico], commit: 0e37cb8}
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
9#include <cstdint>
10
19
20namespace bb::avm2 {
21
23 public:
26 using PCS = KZG<Curve>;
31
34
35 // Native one is used!
37
39
43
45 using SubrelationSeparators = std::array<FF, NUM_SUBRELATIONS - 1>;
46
47 // This flavor would not be used with ZK Sumcheck
48 static constexpr bool HasZK = false;
49
50 // To achieve fixed proof size so that the recursive verifier circuit is constant, we are using padding in Sumcheck
51 // and Shplemini
52 static constexpr bool USE_PADDING = true;
53
59 public:
61 using Base::Base;
62 };
63
72
73 template <typename Builder> class TemplatedTranscript : public StdlibTranscript<Builder> {
78
79 private:
92 const stdlib::Proof<Builder>& stdlib_proof,
93 const std::vector<std::vector<stdlib::field_t<Builder>>>& public_inputs,
94 const bool enable_manifest = false)
95 {
96 // Container for challenges used in the PCS. Also used to get correct labels for transcript hashing.
97 using Challenges = AllValues;
98 Challenges challenges;
99
101 NativeFlavor::FF native_vk_hash = native_vk->get_hash();
102 FF vk_hash = FF::from_witness(&builder, native_vk_hash);
103 vk_hash.fix_witness();
104
106 if (enable_manifest) {
107 transcript->enable_manifest();
108 }
109
110 transcript->load_proof(stdlib_proof);
111
112 transcript->add_to_hash_buffer("avm_vk_hash", vk_hash);
113
114 for (size_t i = 0; i < AVM_NUM_PUBLIC_INPUT_COLUMNS; i++) {
115 for (size_t j = 0; j < public_inputs[i].size(); j++) {
116 transcript->add_to_hash_buffer("public_input_" + std::to_string(i) + "_" + std::to_string(j),
117 public_inputs[i][j]);
118 }
119 }
120
121 for (const auto& wire_label : challenges.get_wires_labels()) {
122 [[maybe_unused]] auto _ = transcript->template receive_from_prover<StdlibCommitment>(wire_label);
123 }
124
125 [[maybe_unused]] auto [_beta, _gamma] =
126 transcript->template get_challenges<FF>(std::array<std::string, 2>{ "beta", "gamma" });
127
128 for (const auto& derived_label : challenges.get_derived_labels()) {
129 [[maybe_unused]] auto _ = transcript->template receive_from_prover<StdlibCommitment>(derived_label);
130 }
131
132 [[maybe_unused]] const FF _alpha = transcript->template get_challenge<FF>("Sumcheck:alpha");
133
134 [[maybe_unused]] const FF _initial_gate_challenge =
135 transcript->template get_challenge<FF>("Sumcheck:gate_challenge");
136
137 using SumcheckUnivariate = std::array<FF, BATCHED_RELATION_PARTIAL_LENGTH>;
138 for (size_t i = 0; i < MAX_AVM_TRACE_LOG_SIZE; i++) {
139 std::string round_univariate_label = "Sumcheck:univariate_" + std::to_string(i);
140 [[maybe_unused]] auto _ =
141 transcript->template receive_from_prover<SumcheckUnivariate>(round_univariate_label);
142 [[maybe_unused]] FF _round_challenge =
143 transcript->template get_challenge<FF>("Sumcheck:u_" + std::to_string(i));
144 }
145
146 [[maybe_unused]] auto _evals =
147 transcript->template receive_from_prover<std::array<FF, NUM_ALL_ENTITIES>>("Sumcheck:evaluations");
148
149 [[maybe_unused]] auto _unshifted_challenges =
150 transcript->template get_challenges<FF>(challenges.get_unshifted_labels());
151
152 [[maybe_unused]] const FF _gemini_batching_challenge = transcript->template get_challenge<FF>("rho");
153
154 for (size_t i = 1; i < MAX_AVM_TRACE_LOG_SIZE; ++i) {
155 [[maybe_unused]] auto _ =
156 transcript->template receive_from_prover<StdlibCommitment>("Gemini:FOLD_" + std::to_string(i));
157 }
158
159 [[maybe_unused]] const FF _gemini_evaluation_challenge = transcript->template get_challenge<FF>("Gemini:r");
160
161 for (size_t i = 1; i <= MAX_AVM_TRACE_LOG_SIZE; ++i) {
162 [[maybe_unused]] auto _ = transcript->template receive_from_prover<FF>("Gemini:a_" + std::to_string(i));
163 }
164
165 [[maybe_unused]] const FF _shplonk_batching_challenge =
166 transcript->template get_challenge<FF>("Shplonk:nu");
167
168 [[maybe_unused]] auto _shplonk_q = transcript->template receive_from_prover<StdlibCommitment>("Shplonk:Q");
169
170 [[maybe_unused]] const FF _shplonk_evaluation_challenge =
171 transcript->template get_challenge<FF>("Shplonk:z");
172
173 [[maybe_unused]] auto _kzg_w = transcript->template receive_from_prover<StdlibCommitment>("KZG:W");
174
175 return transcript;
176 };
177
185 const std::shared_ptr<TemplatedTranscript<Builder>>& transcript, const stdlib::Proof<Builder>& stdlib_proof)
186 {
187 if (stdlib_proof.size() == AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED) {
188 // If the proof is padded, we need to add the padding values to the transcript because recursive
189 // verification doesn't do that
190 transcript->add_element_frs_to_hash_buffer(
191 "proof_padding",
192 std::span(stdlib_proof)
196 }
197 return transcript->template get_challenge<stdlib::field_t<Builder>>("final_transcript_state");
198 };
199
200 public:
208 const stdlib::Proof<Builder>& stdlib_proof,
209 const std::vector<std::vector<stdlib::field_t<Builder>>>& public_inputs)
210 {
211 auto transcript = perform_avm_transcript_operations(builder, stdlib_proof, public_inputs);
212 return pad_and_hash_avm_transcript(transcript, stdlib_proof);
213 }
214
221 const std::shared_ptr<TemplatedTranscript<Builder>>& transcript, const stdlib::Proof<Builder>& stdlib_proof)
222 {
223 return pad_and_hash_avm_transcript(transcript, stdlib_proof);
224 }
225
233 const stdlib::Proof<Builder>& stdlib_proof,
234 const std::vector<std::vector<stdlib::field_t<Builder>>>& public_inputs)
235 {
236 auto transcript = perform_avm_transcript_operations(builder, stdlib_proof, public_inputs, true);
237
238 return { pad_and_hash_avm_transcript(transcript, stdlib_proof), transcript };
239 }
240 };
241
246};
247
248} // namespace bb::avm2
#define AVM_V2_PROOF_LENGTH_IN_FIELDS_PADDED
#define AVM_NUM_PUBLIC_INPUT_COLUMNS
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
Simple stdlib verification key class for fixed-size circuits (ECCVM, Translator, AVM).
Definition flavor.hpp:330
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
Definition flavor.hpp:101
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
tuple_cat_t< MainRelations_< FF_ >, LookupRelations_< FF_ > > Relations_
Definition flavor.hpp:78
static constexpr size_t COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS
Definition flavor.hpp:99
static constexpr size_t NUM_SUBRELATIONS
Definition flavor.hpp:81
AvmFlavorSettings::FF FF
Definition flavor.hpp:43
FixedVKAndHash_< PrecomputedEntities< Commitment >, FF, typename constraining::AvmHardCodedVKAndHash > VerificationKey
Verification key of the AVM. It is fixed and reconstructed from precomputed values.
Definition flavor.hpp:226
AvmFlavorSettings::VerifierCommitmentKey VerifierCommitmentKey
Definition flavor.hpp:50
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Definition flavor.hpp:90
static constexpr size_t NUM_ALL_ENTITIES
Definition flavor.hpp:65
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
static std::pair< stdlib::field_t< Builder >, std::shared_ptr< TemplatedTranscript< Builder > > > hash_avm_transcript_for_testing(Builder &builder, const stdlib::Proof< Builder > &stdlib_proof, const std::vector< std::vector< stdlib::field_t< Builder > > > &public_inputs)
Testing method to hash the transcript after having replicated the operations performed on the AVM tra...
static stdlib::field_t< Builder > pad_and_hash_avm_transcript(const std::shared_ptr< TemplatedTranscript< Builder > > &transcript, const stdlib::Proof< Builder > &stdlib_proof)
Hash a transcript that has recorded the operations performed during AVM proof verification.
static stdlib::field_t< Builder > hash_avm_transcript(Builder &builder, const stdlib::Proof< Builder > &stdlib_proof, const std::vector< std::vector< stdlib::field_t< Builder > > > &public_inputs)
Construct a transcript replicating the operations performed on the AVM transcript during proof verifi...
static std::shared_ptr< TemplatedTranscript< Builder > > perform_avm_transcript_operations(Builder &builder, const stdlib::Proof< Builder > &stdlib_proof, const std::vector< std::vector< stdlib::field_t< Builder > > > &public_inputs, const bool enable_manifest=false)
Replicate the operations performed on the AVM transcript during proof verification.
static stdlib::field_t< Builder > hash_avm_transcript(const std::shared_ptr< TemplatedTranscript< Builder > > &transcript, const stdlib::Proof< Builder > &stdlib_proof)
Hash the AVM verifier transcript after having performed proof verification. Then, hash the transcript...
typename StdlibCurve::AffineElement StdlibCommitment
static constexpr size_t NUM_SUBRELATIONS
NativeFlavor::Relations_< FF > Relations
static constexpr size_t NUM_RELATIONS
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr size_t NUM_ALL_ENTITIES
static constexpr bool USE_PADDING
std::array< FF, NUM_SUBRELATIONS - 1 > SubrelationSeparators
Curve::AffineElement Commitment
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:466
AluTraceBuilder builder
Definition alu.test.cpp:124
Base class templates shared across Honk flavors.
constexpr std::size_t MAX_AVM_TRACE_LOG_SIZE
Definition constants.hpp:12
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string to_string(bb::avm2::ValueTag tag)
field_t< CircuitBuilder > ScalarField
Definition bn254.hpp:30
Group::BaseField BaseField
Definition bn254.hpp:32
Group AffineElement
Definition bn254.hpp:34