Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ultra_verifier.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
17
19
25template <typename Builder> struct UltraRecursiveVerifierOutput {
27 using FF = typename Curve::ScalarField;
28 using G1 = typename Curve::Group;
29
34 std::array<G1, Builder::NUM_WIRES> ecc_op_tables; // Ecc op tables' commitments (HidingKernel/Chonk only)
35 FF transcript_hash; // The final state of the transcript of the AVM recursive verifier (GoblinAvm only)
36
38
39 template <class IO> UltraRecursiveVerifierOutput(IO& inputs)
40 {
41 if constexpr (std::is_same_v<IO, RollupIO>) {
42 ipa_claim = inputs.ipa_claim;
43 } else if constexpr (std::is_same_v<IO, HidingKernelIO<Builder>>) {
44 kernel_return_data = inputs.kernel_return_data;
45 ecc_op_tables = inputs.ecc_op_tables;
46 } else if constexpr (std::is_same_v<IO, GoblinAvmIO<Builder>>) {
47 transcript_hash = inputs.transcript_hash;
48 } else if constexpr (!std::is_same_v<IO, DefaultIO<Builder>>) {
49 throw_or_abort("Invalid public input type.");
50 }
51 }
52};
53
54} // namespace bb::stdlib::recursion::honk
55
56namespace bb {
57
58// Native verifier output
59template <typename Flavor> struct UltraVerifierOutput {
60 public:
62 bool result = false;
64 std::array<Commitment, Flavor::NUM_WIRES> ecc_op_tables;
65
67
68 template <class IO> UltraVerifierOutput(IO& inputs)
69 {
71 kernel_return_data = inputs.kernel_return_data;
72 ecc_op_tables = inputs.ecc_op_tables;
74 throw_or_abort("Invalid public input type.");
75 }
76 }
77};
78
79template <typename Flavor, class IO> class UltraVerifier_ {
80 public:
81 using FF = typename Flavor::FF;
83 using Curve = typename Flavor::Curve;
84 using PCS = typename Flavor::PCS;
89
90 static constexpr bool IsRecursive = IsRecursiveFlavor<Flavor>;
91
92 // Conditional types based on recursion
96
97 using PublicInputs = std::vector<FF>;
98 using Proof = typename Transcript::Proof;
99
100 // Conditional output type: UltraVerifierOutput for native, UltraRecursiveVerifierOutput for recursive
104
105 // IPA claim type: native uses curve::Grumpkin, recursive uses stdlib::grumpkin<Builder>
108
114 PairingPoints pairing_points; // KZG pairing points for deferred verification
115 bool reduction_succeeded = false; // Sumcheck and libra evaluation consistency checks
116 };
117
124 using VKAndHash = typename Flavor::VKAndHash;
125 explicit UltraVerifier_(const std::shared_ptr<VKAndHash>& vk_and_hash,
126 const std::shared_ptr<Transcript>& transcript = std::make_shared<Transcript>())
128 , verifier_instance(std::make_shared<Instance>(vk_and_hash))
130 {
131 if constexpr (!IsRecursive) {
132 // Native only: create IPA transcript
134 } else {
135 // Recursive only: extract builder from VKAndHash for later use
136 // Safe since VKAndHash contains field_t elements (hash) with builder context
137 builder = vk_and_hash->hash.get_context();
138 }
139 }
140
145 size_t compute_log_n() const;
146
151 std::vector<FF> compute_padding_indicator_array(size_t log_n) const;
152
153 [[nodiscard("Reduction result should be verified")]] ReductionResult reduce_to_pairing_check(const Proof& proof);
154
160 std::pair<Proof, Proof> split_rollup_proof(const Proof& combined_proof) const
161 requires(IO::HasIPA);
162
169 bool verify_ipa(const Proof& ipa_proof, const IPAClaim& ipa_claim)
170 requires(!IsRecursiveFlavor<Flavor> && IO::HasIPA);
171
184 Output verify_proof(const Proof& proof);
185
189 const std::shared_ptr<Transcript>& get_transcript() const { return transcript; }
190
195
199 const PublicInputs& get_public_inputs() const { return verifier_instance->public_inputs; }
200
204 const typename Flavor::WitnessCommitments& get_witness_commitments() const
205 {
206 return verifier_instance->witness_commitments;
207 }
208
213 requires IsMegaFlavor<Flavor>
214 {
215 return verifier_instance->witness_commitments.calldata;
216 }
217
221 auto get_ecc_op_wires() const
222 requires IsMegaFlavor<Flavor>
223 {
224 return verifier_instance->witness_commitments.get_ecc_op_wires().get_copy();
225 }
226
227 private:
228 std::shared_ptr<VKAndHash> vk_and_hash;
230 std::shared_ptr<Transcript> transcript;
231 std::shared_ptr<Transcript> ipa_transcript; // Native only
232
233 // Builder pointer (extracted from VKAndHash for recursive, nullptr for native)
234 Builder* builder = nullptr;
235};
236
237// Native verifier type aliases
243#ifdef STARKNET_GARAGA_FLAVORS
244using UltraStarknetVerifier = UltraVerifier_<UltraStarknetFlavor, DefaultIO>;
245using UltraStarknetZKVerifier = UltraVerifier_<UltraStarknetZKFlavor, DefaultIO>;
246#endif
251
252} // namespace bb
std::vector< DataType > Proof
typename Curve::ScalarField FF
VerifierCommitments_< Commitment, VerificationKey > VerifierCommitments
typename G1::affine_element Commitment
curve::Grumpkin Curve
FixedVKAndHash_< PrecomputedEntities< Commitment >, BF, ECCVMHardcodedVKAndHash > VerificationKey
The verification key stores commitments to the precomputed polynomials used by the verifier.
BaseTranscript< Codec, HashFunction > Transcript
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
Definition claim.hpp:55
An object storing two EC points that represent the inputs to a pairing check.
std::shared_ptr< VKAndHash > vk_and_hash
bool verify_ipa(const Proof &ipa_proof, const IPAClaim &ipa_claim)
Verify IPA proof for rollup circuits (native verifier only)
ReductionResult reduce_to_pairing_check(const Proof &proof)
Reduce ultra proof to verification claims (works for both native and recursive)
typename Transcript::Proof Proof
const Commitment & get_calldata_commitment() const
Get calldata commitment (MegaFlavor only)
std::conditional_t< IsRecursive, stdlib::recursion::PairingPoints< Curve >, bb::PairingPoints< Curve > > PairingPoints
std::conditional_t< IsRecursive, typename Flavor::CircuitBuilder, void > Builder
const std::shared_ptr< Instance > & get_verifier_instance() const
Get the verifier instance (for accessing VK and witness commitments in Chonk/Goblin)
size_t compute_log_n() const
Compute log_n based on flavor.
auto get_ecc_op_wires() const
Get ECC op wire commitments as an array (MegaFlavor only)
OpeningClaim< IPACurve > IPAClaim
std::vector< FF > PublicInputs
const Flavor::WitnessCommitments & get_witness_commitments() const
Get witness commitments from the verifier instance.
std::shared_ptr< Instance > verifier_instance
std::vector< FF > compute_padding_indicator_array(size_t log_n) const
Compute padding indicator array based on flavor configuration.
typename Flavor::VerificationKey VerificationKey
std::pair< Proof, Proof > split_rollup_proof(const Proof &combined_proof) const
Split a combined rollup proof into honk and IPA components.
const PublicInputs & get_public_inputs() const
Get public inputs from the verifier instance.
typename Flavor::VKAndHash VKAndHash
A constructor for native and recursive verifiers.
std::conditional_t< IsRecursive, stdlib::recursion::honk::UltraRecursiveVerifierOutput< Builder >, UltraVerifierOutput< Flavor > > Output
const std::shared_ptr< Transcript > & get_transcript() const
Get the transcript (for accessing manifest in tests)
typename Flavor::VerifierCommitments VerifierCommitments
static constexpr bool IsRecursive
std::shared_ptr< Transcript > ipa_transcript
typename Flavor::Transcript Transcript
typename Flavor::Curve Curve
std::shared_ptr< Transcript > transcript
typename Flavor::Commitment Commitment
std::conditional_t< IsRecursive, stdlib::grumpkin< Builder >, curve::Grumpkin > IPACurve
UltraVerifier_(const std::shared_ptr< VKAndHash > &vk_and_hash, const std::shared_ptr< Transcript > &transcript=std::make_shared< Transcript >())
Output verify_proof(const Proof &proof)
Perform ultra verification.
typename Flavor::PCS PCS
typename Flavor::FF FF
The VerifierInstance encapsulates all the necessary information for a Honk Verifier to verify a proof...
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
Manages the data that is propagated on the public inputs of a hiding kernel circuit.
AvmProvingInputs inputs
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Result of reducing ultra proof to pairing points check. Contains pairing points and the aggregate res...
Flavor::Commitment kernel_return_data
typename Flavor::Commitment Commitment
std::array< Commitment, Flavor::NUM_WIRES > ecc_op_tables
field_t< CircuitBuilder > ScalarField
Definition bn254.hpp:30
element< CircuitBuilder, bigfield< CircuitBuilder, bb::Bn254FqParams >, ScalarField, GroupNative > Group
Definition bn254.hpp:31
An object storing two EC points that represent the inputs to a pairing check.
Output type for recursive ultra verification.
void throw_or_abort(std::string const &err)