Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
recursive_verifier_instance.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
12
14
18template <IsRecursiveFlavor Flavor_> class RecursiveVerifierInstance_ {
19 public:
20 using Flavor = Flavor_;
21 using FF = typename Flavor::FF;
22 using NativeFF = typename Flavor::Curve::ScalarFieldNative;
25 using VKAndHash = typename Flavor::VKAndHash;
26 using WitnessCommitments = typename Flavor::WitnessCommitments;
28 using SubrelationSeparator = typename Flavor::SubrelationSeparator;
30 using NativeFlavor = typename Flavor::NativeFlavor;
33 using VerifierCommitmentKey = typename NativeFlavor::VerifierCommitmentKey;
35
37
38 std::shared_ptr<VKAndHash> vk_and_hash;
39
40 bool is_complete = false; // whether this instance has been completely populated
41 std::vector<FF> public_inputs; // to be extracted from the corresponding proof
42
43 // Single alpha challenge from which powers are computed for batching subrelations
46 std::vector<FF> gate_challenges;
47
50
51 // For ZK flavors: commitment to Gemini masking polynomial
53
56
57 // Constructor from native vk
63
64 // Constructor from stdlib vk and hash
68
73 std::shared_ptr<VerificationKey> get_vk() const { return vk_and_hash->vk; }
74
75 // Constructor from native verifier instance
77 : RecursiveVerifierInstance_(builder, verification_key->vk)
78 {
79 is_complete = verification_key->is_complete;
80 if (is_complete) {
81 alpha = FF::from_witness(builder, verification_key->alpha);
82
83 auto other_comms = verification_key->witness_commitments.get_all();
84 size_t comm_idx = 0;
85 for (auto& comm : witness_commitments.get_all()) {
86 comm = Commitment::from_witness(builder, other_comms[comm_idx]);
87 comm_idx++;
88 }
89 size_t challenge_idx = 0;
90 gate_challenges = std::vector<FF>(verification_key->gate_challenges.size());
91 for (auto& challenge : gate_challenges) {
92 challenge = FF::from_witness(builder, verification_key->gate_challenges[challenge_idx]);
93 challenge_idx++;
94 }
95 relation_parameters.eta = FF::from_witness(builder, verification_key->relation_parameters.eta);
96 relation_parameters.eta_two = FF::from_witness(builder, verification_key->relation_parameters.eta_two);
97 relation_parameters.eta_three = FF::from_witness(builder, verification_key->relation_parameters.eta_three);
98 relation_parameters.beta = FF::from_witness(builder, verification_key->relation_parameters.beta);
99 relation_parameters.gamma = FF::from_witness(builder, verification_key->relation_parameters.gamma);
101 FF::from_witness(builder, verification_key->relation_parameters.public_input_delta);
102
103 // For ZK flavors: convert gemini_masking_commitment
104 if constexpr (NativeFlavor::HasZK) {
106 Commitment::from_witness(builder, verification_key->gemini_masking_commitment);
107 }
108 }
109 }
110
119 {
121 auto native_honk_vk = std::make_shared<NativeVerificationKey>();
122 native_honk_vk->log_circuit_size = static_cast<uint64_t>(vk_and_hash->vk->log_circuit_size.get_value());
123 native_honk_vk->num_public_inputs = static_cast<uint64_t>(vk_and_hash->vk->num_public_inputs.get_value());
124 native_honk_vk->pub_inputs_offset = static_cast<uint64_t>(vk_and_hash->vk->pub_inputs_offset.get_value());
125
126 for (auto [vk, final_verifier_inst] : zip_view(vk_and_hash->vk->get_all(), native_honk_vk->get_all())) {
127 final_verifier_inst = vk.get_value();
128 }
129
130 NativeVerifierInstance verifier_inst(native_honk_vk);
131 verifier_inst.is_complete = is_complete;
132
133 verifier_inst.alpha = alpha.get_value();
134
135 for (auto [comm, inst_comm] :
136 zip_view(witness_commitments.get_all(), verifier_inst.witness_commitments.get_all())) {
137 inst_comm = comm.get_value();
138 }
139
141 for (auto [challenge, inst_challenge] : zip_view(gate_challenges, verifier_inst.gate_challenges)) {
142 inst_challenge = challenge.get_value();
143 }
144
145 verifier_inst.relation_parameters.eta = relation_parameters.eta.get_value();
146 verifier_inst.relation_parameters.eta_two = relation_parameters.eta_two.get_value();
148 verifier_inst.relation_parameters.beta = relation_parameters.beta.get_value();
149 verifier_inst.relation_parameters.gamma = relation_parameters.gamma.get_value();
151
152 // For ZK flavors: convert gemini_masking_commitment back to native
153 if constexpr (NativeFlavor::HasZK) {
154 verifier_inst.gemini_masking_commitment = gemini_masking_commitment.get_value();
155 }
156
157 return verifier_inst;
158 }
159};
160} // namespace bb::stdlib::recursion::honk
A container for commitment labels.
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
typename Curve::ScalarField FF
ECCVMCircuitBuilder CircuitBuilder
typename G1::affine_element Commitment
NativeTranscript Transcript
The VerifierInstance encapsulates all the necessary information for a Mega Honk Verifier to verify a ...
std::vector< FF > gate_challenges
WitnessCommitments witness_commitments
SubrelationSeparator alpha
RelationParameters< FF > relation_parameters
The stdlib counterpart of VerifierInstance, used in recursive folding verification.
RecursiveVerifierInstance_(Builder *builder, std::shared_ptr< VKAndHash > vk_and_hash)
RecursiveVerifierInstance_(Builder *builder, std::shared_ptr< NativeVerifierInstance > verification_key)
typename NativeFlavor::VerifierCommitmentKey VerifierCommitmentKey
typename Flavor::NativeFlavor::VerificationKey NativeVerificationKey
RecursiveVerifierInstance_(Builder *builder, std::shared_ptr< NativeVerificationKey > vk)
NativeVerifierInstance get_value()
Return the underlying native VerifierInstance.
std::shared_ptr< VerificationKey > get_vk() const
Get the verification key.
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
void hash(State &state) noexcept
VerifierCommitmentKey< Curve > vk
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Container for parameters used by the grand product (permutation, lookup) Honk relations.