Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
chonk.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
26#ifndef NDEBUG
28#endif
29#include <algorithm>
30
31namespace bb {
32
42class Chonk {
43 // CHONK: "Client Honk" - An UltraHonk variant with incremental folding and delayed non-native arithmetic.
44
45 public:
46 // Per-circuit accumulation uses these Mega flavors; folding is heterogeneous (different
47 // flavors per slot) because the Hypernova accumulator only depends on `MultilinearBatchingFlavor`.
54 // Common to all Mega flavors (all BN254).
55 using FF = bb::fr;
58 using ClientCircuit = MegaCircuitBuilder; // can only be Mega
62 // Recursive scalar / commitment / transcript shapes are common to App and Kernel recursive
63 // flavors (shared BN254 stdlib base), so these aliases are sourced from the kernel one.
82 // Folding: the Hypernova accumulator is flavor-agnostic, so all kinds share one accumulator type.
85 // The decider is flavor-independent, it uses the flavor only to get HasZK (= false) and whether we are in-circuit
86 // or not
91 // Ecc running hash passed to the hiding kernel
93
94 // Result types for decomposed verification steps
99
102
104 std::vector<FF> proof; // oink or HN
108
109 [[nodiscard]] bool is_kernel() const { return kind == CircuitKind::Kernel; }
110
111 [[nodiscard]] size_t num_public_inputs() const
112 {
113 return static_cast<size_t>(is_kernel() ? kernel_honk_vk->num_public_inputs
114 : app_honk_vk->num_public_inputs);
115 }
116 [[nodiscard]] std::vector<FF> vk_to_field_elements() const
117 {
118 return is_kernel() ? kernel_honk_vk->to_field_elements() : app_honk_vk->to_field_elements();
119 }
120 [[nodiscard]] FF vk_hash() const { return is_kernel() ? kernel_honk_vk->hash() : app_honk_vk->hash(); }
121 };
122 using VerificationQueue = std::deque<VerifierInputs>;
123
125 StdlibProof proof; // oink or HN
129
131 : proof(std::move(proof_))
132 , app_honk_vk_and_hash(std::move(app_vk_and_hash_))
134 {}
135
137 : proof(std::move(proof_))
138 , kernel_honk_vk_and_hash(std::move(kernel_vk_and_hash_))
140 {}
141
142 [[nodiscard]] bool is_kernel() const { return kind == CircuitKind::Kernel; }
143
144 [[nodiscard]] size_t vk_num_public_inputs() const
145 {
146 return static_cast<size_t>(uint64_t(is_kernel() ? kernel_honk_vk_and_hash->vk->num_public_inputs.get_value()
147 : app_honk_vk_and_hash->vk->num_public_inputs.get_value()));
148 }
149 };
150 using StdlibVerificationQueue = std::deque<StdlibVerifierInputs>;
151
152 private:
153 // Transcript for Chonk prover (shared between Hiding kernel, Merge, ECCVM, and Translator)
154 std::shared_ptr<Transcript> transcript = std::make_shared<Transcript>();
155
156 // Transcript to be shared across the folding of K_{i-1} (kernel), A_{i} (app)
158
159 std::vector<CircuitKind> circuit_kinds; // kind of every circuit in the IVC stack, in accumulation order
160 size_t num_circuits; // total number of circuits to be accumulated in the IVC
161
162 size_t num_circuits_accumulated = 0; // number of circuits accumulated so far
163 public:
164 ProverAccumulator prover_accumulator; // previous accumulator (output of the previous kernel's batch)
165 std::shared_ptr<FoldingProver> folding_prover; // folds the current group; (re)created at each group start
167 multilinear_batch_proof; // current kernel's multilinear batching proof (consumed in its recursive verifier)
168
169 HonkProof decider_proof; // decider proof to be verified in the Hiding kernel
170
171 VerifierAccumulator recursive_verifier_native_accum; // native value of the previous accumulator
172#ifndef NDEBUG
176#endif
177
178 // PARALLEL QUEUES: These two queues must stay synchronized.
179 // - verification_queue: Native proofs created by accumulate() (prover side)
180 // - stdlib_verification_queue: Circuit witnesses for complete_kernel_circuit_logic() (verifier side)
181 // The stdlib queue is populated from the native queue via instantiate_stdlib_verification_queue().
184
185 // Management of linking databus commitments between circuits in the IVC
187
189
190 // Hiding kernel prover state: built during accumulate_hiding_kernel(), consumed by prove().
192 std::shared_ptr<MegaZKVerificationKey> hiding_vk;
193
198 static constexpr size_t group_claim_count(bool has_previous_accumulator, size_t group_size)
199 {
200 return (has_previous_accumulator ? 1 : 0) + group_size;
201 }
202
203 size_t get_num_circuits() const { return num_circuits; }
204
205 Goblin& get_goblin() { return goblin; }
206 const Goblin& get_goblin() const { return goblin; }
207
208 Chonk(std::vector<CircuitKind> circuit_kinds);
209
211 const std::vector<StdlibCircuitVKAndHash>& input_keys = {});
212
213 [[nodiscard("Pairing points should be collected")]] std::pair<PairingPoints, EccOpRunningHash>
214 recursive_verification_and_consistency_checks(const StdlibVerifierInputs& verifier_inputs,
215 HypernovaFoldingRecursiveVerifier& folding_verifier,
216 const std::optional<StdlibFF>& prev_stdlib_acc_hash,
217 const std::optional<EccOpRunningHash>& running_ecc_op_hash);
218
219 // Complete the logic of a kernel circuit (e.g. HN/merge recursive verification, databus consistency checks)
221
241 void accumulate(ClientCircuit& circuit, const CircuitVerificationKey& vk);
242
246 [[nodiscard]] CircuitKind current_kind() const;
247
252 [[nodiscard]] CircuitKind next_kind() const;
253
261 [[nodiscard]] bool is_init_kernel() const;
262
268 [[nodiscard]] bool is_hiding_kernel() const { return current_kind() == CircuitKind::HidingKernel; }
269
275
284
286
288
294
295 private:
296#ifndef NDEBUG
303 void verify_native_instance_sumcheck(const VerifierInputs& queue_entry);
304
309 template <typename NativeFlavor>
311 const VerifierInputs& queue_entry);
312
321 void update_native_verifier_accumulator(bool is_init_group);
322
323 // Debug-only native verification of the decider proof against the final native verifier accumulator.
325
326 // Debug-only logging for an incoming circuit being folded: validity, and whether its precomputed
327 // VK matches the one derived during accumulation. Templated on the circuit's InstanceFlavor.
328 template <typename InstanceFlavor>
330 const std::shared_ptr<ProverInstance_<InstanceFlavor>>& prover_instance,
332
333#endif
334
335 PublicInputsResult process_kernel_public_inputs(std::vector<StdlibFF>& public_inputs,
336 KernelWitnessCommitments& witness_commitments,
337 const std::optional<StdlibFF>& prev_accum_hash);
338 PublicInputsResult process_app_public_inputs(std::vector<StdlibFF>& public_inputs,
339 AppWitnessCommitments& witness_commitments);
340
347
357
358 template <typename InstanceFlavor>
361
362 void accumulate_hiding_kernel(ClientCircuit& circuit, const std::shared_ptr<MegaZKVerificationKey>& precomputed_vk);
363};
364
365} // namespace bb
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
The IVC scheme used by the aztec client for private function execution.
Definition chonk.hpp:42
PublicInputsResult process_app_public_inputs(std::vector< StdlibFF > &public_inputs, AppWitnessCommitments &witness_commitments)
Definition chonk.cpp:271
ProverAccumulator prover_accumulator
Definition chonk.hpp:164
std::shared_ptr< FoldingProver > folding_prover
Definition chonk.hpp:165
void verify_decider_natively()
Definition chonk.cpp:107
void set_num_circuits_accumulated_for_mocking(const size_t num_circuits)
Set the num circuits accumulated for mocking an IVC state. Used when writing VKs.
Definition chonk.hpp:280
std::shared_ptr< MegaZKFlavor::VKAndHash > get_hiding_kernel_vk_and_hash() const
Get the hiding kernel verification key and hash for Chonk verification.
Definition chonk.cpp:772
void complete_kernel_circuit_logic(ClientCircuit &circuit)
Append logic to complete a kernel circuit.
Definition chonk.cpp:355
void run_native_instance_sumcheck(const std::shared_ptr< typename NativeFlavor::VerificationKey > &honk_vk, const VerifierInputs &queue_entry)
Templated native verification of the instance to accumulator sumcheck.
Definition chonk.cpp:28
CircuitKind current_kind() const
Kind of the circuit currently being accumulated (or, between accumulate calls, the next one expected)...
Definition chonk.cpp:610
VerifierAccumulator native_verifier_accum
Definition chonk.hpp:173
void prove_multilinear_batching()
Generate multilinear batching proof for the current group of accumulators.
Definition chonk.cpp:680
void accumulate(ClientCircuit &circuit, const CircuitVerificationKey &vk)
Accumulate a circuit into the running IVC.
Definition chonk.cpp:635
static void hide_op_queue_content_in_hiding(ClientCircuit &circuit)
Adds two random non-ops to the hiding kernel for zero-knowledge.
Definition chonk.cpp:713
void accumulate_hiding_kernel(ClientCircuit &circuit, const std::shared_ptr< MegaZKVerificationKey > &precomputed_vk)
Build the hiding kernel's ZK proving key and verification key (proving is deferred to prove()).
Definition chonk.cpp:487
Goblin & get_goblin()
Definition chonk.hpp:205
KernelRecursiveFlavor::FF StdlibFF
Definition chonk.hpp:66
DataBusDepot bus_depot
Definition chonk.hpp:186
std::shared_ptr< Transcript > transcript
Definition chonk.hpp:154
size_t num_circuits_accumulated
Definition chonk.hpp:162
std::pair< PairingPoints, EccOpRunningHash > recursive_verification_and_consistency_checks(const StdlibVerifierInputs &verifier_inputs, HypernovaFoldingRecursiveVerifier &folding_verifier, const std::optional< StdlibFF > &prev_stdlib_acc_hash, const std::optional< EccOpRunningHash > &running_ecc_op_hash)
Run sumcheck on a single proof in the group and perform its databus/accumulator-hash consistency chec...
Definition chonk.cpp:293
HonkProof decider_proof
Definition chonk.hpp:169
StdlibFF EccOpRunningHash
Definition chonk.hpp:92
std::vector< CircuitKind > circuit_kinds
Definition chonk.hpp:159
void update_native_verifier_accumulator(bool is_init_group)
Natively verify the multilinear batching proof and update the native verifier accumulator....
Definition chonk.cpp:83
bb::CircuitVerificationKey CircuitVerificationKey
Definition chonk.hpp:101
size_t get_num_circuits() const
Definition chonk.hpp:203
std::deque< StdlibVerifierInputs > StdlibVerificationQueue
Definition chonk.hpp:150
size_t get_num_circuits_accumulated() const
Get the number of circuits accumulated by the IVC.
Definition chonk.hpp:274
ChonkProof prove()
Construct Chonk proof using the batched MegaZK + Translator protocol.
Definition chonk.cpp:732
std::shared_ptr< HypernovaFoldingNativeVerifier > native_folding_verifier
Definition chonk.hpp:174
bb::CircuitKind CircuitKind
Definition chonk.hpp:100
void instantiate_stdlib_verification_queue(ClientCircuit &circuit, const std::vector< StdlibCircuitVKAndHash > &input_keys={})
Instantiate a stdlib verification queue for use in the kernel completion logic.
Definition chonk.cpp:160
VerifierAccumulator recursive_verifier_native_accum
Definition chonk.hpp:171
PublicInputsResult process_kernel_public_inputs(std::vector< StdlibFF > &public_inputs, KernelWitnessCommitments &witness_commitments, const std::optional< StdlibFF > &prev_accum_hash)
Process public inputs from a verified circuit and perform databus consistency checks.
Definition chonk.cpp:207
const Goblin & get_goblin() const
Definition chonk.hpp:206
curve::BN254::AffineElement Commitment
Definition chonk.hpp:56
KernelRecursiveFlavor::WitnessCommitments KernelWitnessCommitments
Definition chonk.hpp:80
std::shared_ptr< HidingKernelProverInstance > hiding_prover_inst
Definition chonk.hpp:191
CircuitKind next_kind() const
Kind of the circuit that follows the one currently being accumulated, or CircuitKind::None if the cur...
Definition chonk.cpp:616
MegaCircuitBuilder ClientCircuit
Definition chonk.hpp:58
std::shared_ptr< Transcript > native_verifier_accumulation_transcript
Definition chonk.hpp:175
bool is_hiding_kernel() const
Whether the circuit currently being accumulated/completed is the hiding kernel.
Definition chonk.hpp:268
void accumulate_and_fold(ClientCircuit &circuit, const CircuitVerificationKey &vk)
Turn the incoming instance into an accumulator. If a kernel follows, also produce a multilinear batch...
Definition chonk.cpp:545
KernelRecursiveFlavor::Commitment RecursiveCommitment
Definition chonk.hpp:68
AppRecursiveFlavor::WitnessCommitments AppWitnessCommitments
Definition chonk.hpp:79
size_t num_circuits
Definition chonk.hpp:160
std::deque< VerifierInputs > VerificationQueue
Definition chonk.hpp:122
void debug_incoming_circuit(ClientCircuit &circuit, const std::shared_ptr< ProverInstance_< InstanceFlavor > > &prover_instance, const std::shared_ptr< typename InstanceFlavor::VerificationKey > &precomputed_vk)
Definition chonk.cpp:48
VerificationQueue verification_queue
Definition chonk.hpp:182
static constexpr size_t group_claim_count(bool has_previous_accumulator, size_t group_size)
Number of claims a kernel batches: the previous accumulator (absent for the init kernel) plus one sum...
Definition chonk.hpp:198
Goblin goblin
Definition chonk.hpp:188
HonkProof multilinear_batch_proof
Definition chonk.hpp:167
std::shared_ptr< MegaZKVerificationKey > hiding_vk
Definition chonk.hpp:192
bool is_init_kernel() const
Whether the kernel currently being completed is the init kernel (the first kernel,...
Definition chonk.cpp:622
std::shared_ptr< Transcript > prover_accumulation_transcript
Definition chonk.hpp:157
HonkProof instance_to_accumulator(ClientCircuit &circuit, const std::shared_ptr< typename InstanceFlavor::VerificationKey > &vk)
Definition chonk.cpp:524
void verify_native_instance_sumcheck(const VerifierInputs &queue_entry)
Natively verify the instance-to-accumulator sumcheck of the circuit just accumulated....
Definition chonk.cpp:70
StdlibVerificationQueue stdlib_verification_queue
Definition chonk.hpp:183
FixedVKAndHash_< PrecomputedEntities< Commitment >, BF, ECCVMHardcodedVKAndHash > VerificationKey
The verification key stores commitments to the precomputed polynomials used by the verifier.
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
Definition flavor.hpp:104
HyperNova decider prover. Produces final opening proof for the accumulated claim.
HyperNova decider verifier (native + recursive). Verifies final opening proof.
HyperNova folding prover. Folds circuit instances into accumulators, deferring PCS verification.
MultilinearBatchingProverClaim Accumulator
Mega flavor specialized for Chonk app circuits.
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
Recursive counterpart to MegaAppFlavor.
MegaAppFlavor::WitnessEntities< Commitment > WitnessCommitments
VKAndHash_< FF, VerificationKey > VKAndHash
Mega flavor specialized for Chonk kernel circuits.
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
Recursive counterpart to MegaKernelFlavor.
MegaKernelFlavor::WitnessEntities< Commitment > WitnessCommitments
stdlib::bn254< CircuitBuilder > Curve
StdlibTranscript< CircuitBuilder > Transcript
VKAndHash_< FF, VerificationKey > VKAndHash
Hiding-kernel-only Mega variant: runs with ZK Sumcheck and a reduced relation set.
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
Base Native verification key class.
Definition flavor.hpp:138
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
FixedVKAndHash_< VKEntities< Commitment >, FF, TranslatorHardcodedVKAndHash > VerificationKey
The verification key stores commitments to the precomputed polynomials used by the verifier.
Wrapper holding a verification key and its precomputed hash.
Definition flavor.hpp:551
The VerifierInstance encapsulates all the necessary information for a Honk Verifier to verify a proof...
typename Group::affine_element AffineElement
Definition bn254.hpp:22
Manages the data that is propagated on the public inputs of an application/function circuit.
Manages the data that is propagated on the public inputs of a hiding kernel circuit.
Manages the data that is propagated on the public inputs of a kernel circuit.
KernelIO_< MAX_APPS_PER_KERNEL > KernelIO
DefaultIO< MegaCircuitBuilder > AppIO
The data that is propagated on the public inputs of an application/function circuit.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
std::variant< std::shared_ptr< MegaAppFlavor::VerificationKey >, std::shared_ptr< MegaKernelFlavor::VerificationKey >, std::shared_ptr< MegaZKFlavor::VerificationKey > > CircuitVerificationKey
field< Bn254FrParams > fr
Definition fr.hpp:155
HypernovaFoldingVerifier< true > HypernovaFoldingRecursiveVerifier
BaseTranscript< FrCodec, bb::crypto::Poseidon2< bb::crypto::Poseidon2Bn254ScalarFieldParams > > NativeTranscript
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
VerifierCommitmentKey< Curve > vk
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
PairingPoints pairing_points
Definition chonk.hpp:96
std::optional< StdlibFF > ecc_op_hash
Definition chonk.hpp:97
std::shared_ptr< AppRecursiveVKAndHash > app_honk_vk_and_hash
Definition chonk.hpp:126
std::shared_ptr< KernelRecursiveVKAndHash > kernel_honk_vk_and_hash
Definition chonk.hpp:127
StdlibVerifierInputs(StdlibProof proof_, std::shared_ptr< AppRecursiveVKAndHash > app_vk_and_hash_)
Definition chonk.hpp:130
size_t vk_num_public_inputs() const
Definition chonk.hpp:144
StdlibVerifierInputs(StdlibProof proof_, std::shared_ptr< KernelRecursiveVKAndHash > kernel_vk_and_hash_)
Definition chonk.hpp:136
std::shared_ptr< KernelVerificationKey > kernel_honk_vk
Definition chonk.hpp:106
bool is_kernel() const
Definition chonk.hpp:109
std::shared_ptr< AppVerificationKey > app_honk_vk
Definition chonk.hpp:105
std::vector< FF > vk_to_field_elements() const
Definition chonk.hpp:116
std::vector< FF > proof
Definition chonk.hpp:104
size_t num_public_inputs() const
Definition chonk.hpp:111
Prover's claim for multilinear batching - contains polynomials and their evaluation claims.