Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
two_layer_avm_recursive_verifier.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Federico], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6#pragma once
7
22
23namespace bb::avm2 {
24
54 public:
56
59
60 // The output of the goblinized AVM2 recursive verifier
63
64 // Output of prover for inner Mega-arithmetized AVM recursive verifier circuit; input to the outer verifier
68 std::shared_ptr<MegaAvmFlavor::VerificationKey> mega_vk; // VK_M
69 };
70
71 private:
73
74 public:
86 [[nodiscard("IPA claim and Pairing points should be accumulated")]] TwoLayerAvmRecursiveVerifierOutput verify_proof(
87 const stdlib::Proof<UltraCircuitBuilder>& stdlib_proof,
88 const std::vector<std::vector<UltraFF>>& public_inputs) const
89 {
90 // Construct and prove the inner Mega-arithmetized AVM recursive verifier circuit; proof is {\pi_M, \pi_G}
91 InnerProverOutput inner_output =
93
94 // Construct the outer Ultra-arithmetized Mega/Goblin recursive verifier circuit
96 construct_outer_recursive_verification_circuit(stdlib_proof, public_inputs, inner_output);
97
98 // Return ipa proof, ipa claim and output aggregation object produced from verifying the Mega + Goblin proofs
99 return result;
100 }
101
110 [[nodiscard("IPA claim and Pairing points should be accumulated")]] TwoLayerAvmRecursiveVerifierOutput
112 const std::vector<std::vector<UltraFF>>& public_inputs,
113 const InnerProverOutput& inner_output) const
114 {
115 // Types for MegaRecursiveVerifier specialized for the AVM
116 using MegaAvmRecursiveFlavor = MegaAvmRecursiveFlavor_<UltraCircuitBuilder>;
117 using MegaRecursiveVKAndHash = MegaAvmRecursiveFlavor::VKAndHash;
119 using MegaAvmRecursiveVerifier = UltraVerifier_<MegaAvmRecursiveFlavor, IO>;
120
121 // Step 1: Recursively verify the Mega proof \pi_M
122 auto transcript = std::make_shared<MegaAvmRecursiveFlavor::Transcript>(); // Single shared transcript
123 auto mega_vk_and_hash = std::make_shared<MegaRecursiveVKAndHash>(*outer_builder, inner_output.mega_vk);
124
125 // The vk of the inner Mega arithmetized AVM recursive verifier circuit must be fixed to ensure that the outer
126 // circuit verifies the validity of the intended inner circuit.
127 mega_vk_and_hash->vk->fix_witness();
128 mega_vk_and_hash->hash.fix_witness();
129
130 MegaAvmRecursiveVerifier mega_verifier(mega_vk_and_hash, transcript);
132 auto mega_verifier_output = mega_verifier.verify_proof(mega_proof);
133
134 // Step 2: Recursively verify the goblin proof \pi_G
135 GoblinAvmStdlibProof stdlib_goblin_proof(*outer_builder, inner_output.goblin_proof);
136 GoblinAvmRecursiveVerifier goblin_verifier{ transcript, stdlib_goblin_proof, mega_verifier.get_ecc_op_wires() };
137 auto goblin_verifier_output = goblin_verifier.reduce_to_pairing_check_and_ipa_opening();
138
139 // Step 3: Aggregate pairing points coming from Mega verification and Goblin verification
140 mega_verifier_output.points_accumulator.aggregate(goblin_verifier_output.translator_pairing_points);
141
142 // Step 4: Validate the consistency of the AVM2 verifier inputs {\pi, pub_inputs}_{AVM2} between the inner
143 // (Mega) circuit and the outer (Ultra) by asserting equality on the independently computed hashes
144 const UltraFF computed_transcript_hash =
146 mega_verifier_output.transcript_hash.assert_equal(computed_transcript_hash);
147
148 // Return ipa proof, ipa claim and output aggregation object produced from verifying the Mega + Goblin
149 // proofs
151 output.points_accumulator = std::move(mega_verifier_output.points_accumulator);
152 output.ipa_claim = goblin_verifier_output.ipa_claim;
153 output.ipa_proof = goblin_verifier_output.ipa_proof;
154 return output;
155 }
156
165 const stdlib::Proof<UltraCircuitBuilder>& stdlib_proof, const std::vector<std::vector<UltraFF>>& public_inputs)
166 {
167 using MegaAvmProverInstance = ProverInstance_<MegaAvmFlavor>;
168 using MegaAvmVerificationKey = MegaAvmFlavor::VerificationKey;
169 using MegaAvmProver = UltraProver_<MegaAvmFlavor>;
170
171 // Instantiate Mega builder for the inner circuit (AVM2 proof recursive verifier)
172 MegaCircuitBuilder inner_builder;
173 GoblinAvm goblin(inner_builder);
174
175 // Construct the inner recursive verification circuit
176 construct_inner_recursive_verification_circuit(inner_builder, stdlib_proof, public_inputs);
177
178 // Construct the Mega proof \pi_M of the AVM recursive verifier circuit
179 auto transcript = std::make_shared<NativeTranscript>(); // Single shared transcript
180 auto mega_proving_key = std::make_shared<MegaAvmProverInstance>(inner_builder);
181 // Detect when MEGA_AVM_LOG_N needs to be bumped.
183 mega_proving_key->log_dyadic_size(),
184 MEGA_AVM_LOG_N,
185 "AVMRecursiveVerifier: circuit size exceeded current upper bound. If expected, bump MEGA_AVM_LOG_N");
186 auto mega_vk = std::make_shared<MegaAvmVerificationKey>(mega_proving_key->get_precomputed());
187 MegaAvmProver mega_prover(mega_proving_key, mega_vk, transcript);
188 HonkProof mega_proof = mega_prover.construct_proof();
189
190 // Construct the GoblinAvm proof \pi_G (includes ECCVM, IPA, and Translator proofs)
191 goblin.transcript = transcript;
192 GoblinAvmProof goblin_proof = goblin.prove();
193
194 return {
195 .mega_proof = mega_proof,
196 .goblin_proof = goblin_proof,
197 .mega_vk = mega_vk,
198 };
199 }
200
206 const stdlib::Proof<UltraCircuitBuilder>& stdlib_proof,
207 const std::vector<std::vector<UltraFF>>& public_inputs)
208 {
210
211 // Create free witnesses representing the AVM proof and public inputs in the inner circuit.
212 // The honest prover sets these values to match the values of the proof and public inputs in the outer circuit.
213 // Consistency between these witnesses and the ones in the outer circuit is enforced via a hash check.
214 stdlib::Proof<MegaCircuitBuilder> inner_stdlib_proof(inner_builder, stdlib_proof.get_value());
215 std::vector<std::vector<MegaFF>> inner_public_inputs;
216 inner_public_inputs.reserve(AVM_NUM_PUBLIC_INPUT_COLUMNS);
217 for (const auto& public_input_column : public_inputs) {
218 std::vector<MegaFF> inner_public_input_column;
219 inner_public_input_column.reserve(AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH);
220 for (const auto& public_input : public_input_column) {
221 inner_public_input_column.push_back(MegaFF::from_witness(&inner_builder, public_input.get_value()));
222 }
223 inner_public_inputs.push_back(std::move(inner_public_input_column));
224 }
225
226 // Construct a Mega-arithmetized AVM2 recursive verifier circuit
227 // The constructor of AvmRecursiveVerifier hard-codes the VK and the VK hash of the AVM2 by copying the values
228 // into the selectors.
229 AvmRecursiveVerifier recursive_verifier{ inner_builder };
230 MegaPairingPoints points_accumulator = recursive_verifier.verify_proof(inner_stdlib_proof, inner_public_inputs);
231
232 // Append to the transcript the padding values of the proof (if any) and generate a challenge to record the
233 // final state of the transcript of the AVM recursive verifier
234 const MegaFF transcript_hash = recursive_verifier.hash_avm_transcript(inner_stdlib_proof);
235
236 // Public inputs
237 IO inputs;
238 inputs.transcript_hash = transcript_hash;
239 inputs.pairing_inputs = points_accumulator;
241 }
242};
243
244} // namespace bb::avm2
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:158
#define AVM_NUM_PUBLIC_INPUT_COLUMNS
#define AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH
Specialization of Goblin for the AVM.
GoblinAvmProof prove()
Constuct a full GoblinAvm proof (ECCVM, Translator)
std::shared_ptr< Transcript > transcript
Definition goblin.hpp:61
Recursive flavor for verifying proofs produced with MegaAvmFlavor.
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
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...
Recursive verifier of AVM2 proofs that utilizes the Goblin mechanism for efficient EC operations.
TwoLayerAvmRecursiveVerifierOutput verify_proof(const stdlib::Proof< UltraCircuitBuilder > &stdlib_proof, const std::vector< std::vector< UltraFF > > &public_inputs) const
Recursively verify an AVM proof using Goblin and two layers of recursive verification.
static void construct_inner_recursive_verification_circuit(MegaCircuitBuilder &inner_builder, const stdlib::Proof< UltraCircuitBuilder > &stdlib_proof, const std::vector< std::vector< UltraFF > > &public_inputs)
Construct the inner recursive verification circuit for the AVM2 recursive verifier.
static InnerProverOutput construct_and_prove_inner_recursive_verification_circuit(const stdlib::Proof< UltraCircuitBuilder > &stdlib_proof, const std::vector< std::vector< UltraFF > > &public_inputs)
Construct and prove the inner Mega-arithmetized AVM recursive verifier circuit.
stdlib::recursion::honk::UltraRecursiveVerifierOutput< UltraCircuitBuilder > TwoLayerAvmRecursiveVerifierOutput
TwoLayerAvmRecursiveVerifierOutput construct_outer_recursive_verification_circuit(const stdlib::Proof< UltraCircuitBuilder > &stdlib_proof, const std::vector< std::vector< UltraFF > > &public_inputs, const InnerProverOutput &inner_output) const
Construct the outer circuit which recursively verifies a Mega proof and a Goblin proof.
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
HonkProof get_value() const
Definition proof.hpp:38
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:455
The data that is propagated on the public inputs of the inner GoblinAvmRecursiveVerifier circuit.
AluTraceBuilder builder
Definition alu.test.cpp:124
AvmProvingInputs inputs
std::vector< fr > HonkProof
Definition proof.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
An object storing two EC points that represent the inputs to a pairing check.
uint32_t set_public()
Set the witness indices for the limbs of the pairing points to public.
Output type for recursive ultra verification.