Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
special_public_inputs.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Sergei], commit: d1307bdee7f2ee0e737c19b77a26204a8dbafafc }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6//
7// Special public inputs designed propagate data between Chonk and Rollup circuits.
8//
9// These structures are binding several Chonk components:
10// - KernelIO: Standard kernel outputs (pairing points, databus, ecc_op_tables, accum hash)
11// - HidingKernelIO: Final kernel outputs (no accum hash since folding terminates)
12// - AppIO/DefaultIO: App circuit outputs (just pairing points)
13// - RollupIO: Rollup circuit outputs (pairing points + IPA claim)
14//
15#pragma once
16
25
26// Default coordinates of commitment to an ecc op table
27// These are the coordinates that come from committing to the ecc ops that are added to the op_queue by finalize_circuit
28static constexpr bb::fq DEFAULT_ECC_COMMITMENT_X("0x08434fa4480433735e7aeaccecb911eb7a06165ad70e5ced6ac6848296e59279");
29static constexpr bb::fq DEFAULT_ECC_COMMITMENT_Y("0x0a13a1839ab95ef15be8d0710b2c8aa47cea0b0e62a8596e68cc0fd54a6ae73d");
30static constexpr bb::curve::BN254::AffineElement DEFAULT_ECC_COMMITMENT(DEFAULT_ECC_COMMITMENT_X,
31 DEFAULT_ECC_COMMITMENT_Y);
32
43template <typename Builder>
45{
46 std::array<typename bn254<Builder>::Group, Builder::NUM_WIRES> empty_tables;
47 for (auto& table_commitment : empty_tables) {
49 // Sanity check: Verify the native value is actually at infinity
50 BB_ASSERT(table_commitment.get_value().is_point_at_infinity(),
51 "empty_ecc_op_tables: T_prev must be initialized to point at infinity");
52 }
53
54 return empty_tables;
55}
56
61class KernelIO {
62 public:
63 using Builder = MegaCircuitBuilder; // kernel builder is always Mega
64 using Curve = stdlib::bn254<Builder>; // curve is always bn254
68 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
69
73
74 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
75 G1 kernel_return_data; // Commitment to the return data of a kernel circuit
76 G1 app_return_data; // Commitment to the return data of an app circuit
77 TableCommitments ecc_op_tables; // commitments to merged tables obtained from recursive Merge verification
78 FF output_hn_accum_hash; // hash of the output HN verifier accumulator
79
80 // Total size of the kernel IO public inputs
81 static constexpr size_t PUBLIC_INPUTS_SIZE = KERNEL_PUBLIC_INPUTS_SIZE;
82 static constexpr bool HasIPA = false;
83
89 void reconstruct_from_public(const std::vector<FF>& public_inputs)
90 {
91 // Assumes that the kernel-io public inputs are at the end of the public_inputs vector
92 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
93
97 index += G1::PUBLIC_INPUTS_SIZE;
99 index += G1::PUBLIC_INPUTS_SIZE;
100 for (auto& table_commitment : ecc_op_tables) {
101 table_commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
102 index += G1::PUBLIC_INPUTS_SIZE;
103 }
106 }
107
113 {
115
116 Builder* pairing_ctx = validate_context<Builder>(pairing_inputs);
117 if (pairing_ctx == nullptr) {
118 // Both points are constant - add the default pairing points to public inputs
120 } else {
122 }
123 kernel_return_data.set_public();
124 app_return_data.set_public();
125 for (auto& table_commitment : ecc_op_tables) {
126 table_commitment.set_public();
127 }
129
130 // Record that pairing points have been set to public
131 builder->pairing_points_tagging.set_public_pairing_points();
132 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
133 builder->finalize_public_inputs();
134 }
135
141 {
143
147 for (auto& table_commitment : inputs.ecc_op_tables) {
148 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
149 table_commitment.convert_constant_to_fixed_witness(&builder);
150 }
151 inputs.output_hn_accum_hash = FF::from_witness(&builder, typename FF::native(0));
152 inputs.set_public();
153 }
154};
155
160template <typename Builder_> class DefaultIO {
161 public:
162 using Builder = Builder_;
163 using Curve = stdlib::bn254<Builder>; // curve is always bn254
166
168
170
171 // Total size of the IO public inputs
172 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
173 static constexpr bool HasIPA = false;
174
180 void reconstruct_from_public(const std::vector<FF>& public_inputs)
181 {
182 // Assumes that the app-io public inputs are at the end of the public_inputs vector
183 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
185 }
186
192 {
193 Builder* builder = validate_context<Builder>(pairing_inputs);
194 BB_ASSERT_NEQ(builder, nullptr, "Trying to set constant PairingPoints to public.");
195
197
198 // Record that pairing points have been set to public
199 builder->pairing_points_tagging.set_public_pairing_points();
200 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
201 builder->finalize_public_inputs();
202 }
203
209 {
211 builder.finalize_public_inputs();
212 };
213};
214
218using AppIO = DefaultIO<MegaCircuitBuilder>; // app IO is always Mega
219
223template <typename Builder_> class GoblinAvmIO {
224 public:
225 using Builder = Builder_;
226 using Curve = stdlib::bn254<Builder>; // curve is always bn254
229
232
233 FF transcript_hash; // The final state of the transcript of the AVM recursive verifier
235
236 // Total size of the IO public inputs
237 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
238 static constexpr bool HasIPA = false;
239
245 void reconstruct_from_public(const std::vector<FF>& public_inputs)
246 {
247 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
248 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
252 }
253
259 {
260 Builder* builder = validate_context<Builder>(pairing_inputs);
261
264
265 // Record that pairing points have been set to public
266 builder->pairing_points_tagging.set_public_pairing_points();
267 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
268 builder->finalize_public_inputs();
269 }
270};
271
275template <class Builder_> class HidingKernelIO {
276 public:
277 using Builder = Builder_;
278 using Curve = stdlib::bn254<Builder>; // curve is always bn254
282 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
283
286
287 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
288 G1 kernel_return_data; // Commitment to the return data of the tail kernel circuit
289 TableCommitments ecc_op_tables; // commitments to merged tables obtained from final Merge verification
290
291 // Total size of the IO public inputs
292 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
293 static constexpr bool HasIPA = false;
294
300 void reconstruct_from_public(const std::vector<FF>& public_inputs)
301 {
302 // Assumes that the hiding-kernel-io public inputs are at the end of the public_inputs vector
303 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
307 index += G1::PUBLIC_INPUTS_SIZE;
308 for (auto& commitment : ecc_op_tables) {
309 commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
310 index += G1::PUBLIC_INPUTS_SIZE;
311 }
312 }
313
319 {
320 Builder* builder = ecc_op_tables[0].get_context();
321
322 if (validate_context<Builder>(pairing_inputs) == nullptr) {
323 // Both points are constant - add the default pairing points to public inputs
325 } else {
327 }
328 kernel_return_data.set_public();
329 for (auto& commitment : ecc_op_tables) {
330 commitment.set_public();
331 }
332
333 // Record that pairing points have been set to public
334 builder->pairing_points_tagging.set_public_pairing_points();
335 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
336 builder->finalize_public_inputs();
337 }
338
344 {
347 inputs.kernel_return_data = G1(DEFAULT_ECC_COMMITMENT);
348 inputs.kernel_return_data.convert_constant_to_fixed_witness(&builder);
349 for (auto& table_commitment : inputs.ecc_op_tables) {
350 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
351 table_commitment.convert_constant_to_fixed_witness(&builder);
352 }
353 inputs.set_public();
354 };
355};
356
360class RollupIO {
361 public:
362 using Builder = UltraCircuitBuilder; // rollup circuits are always Ultra
363 using Curve = stdlib::bn254<Builder>; // curve is always bn254
367
370
373
374 // Total size of the IO public inputs
375 static constexpr size_t PUBLIC_INPUTS_SIZE = ROLLUP_PUBLIC_INPUTS_SIZE;
376 static constexpr bool HasIPA = true;
377
383 void reconstruct_from_public(const std::vector<FF>& public_inputs)
384 {
385 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
389 }
390
396 {
397 Builder* builder = ipa_claim.commitment.get_context();
398
399 if (validate_context<Builder>(pairing_inputs) == nullptr) {
400 // Both points are constant - add the default pairing points to public inputs
402 } else {
404 }
406
407 // Record that pairing points have been set to public
408 builder->pairing_points_tagging.set_public_pairing_points();
409 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
410 builder->finalize_public_inputs();
411 }
412
418 {
421 auto [stdlib_opening_claim, ipa_proof] =
422 IPA<grumpkin<Builder>>::create_random_valid_ipa_claim_and_proof(builder);
423 inputs.ipa_claim = stdlib_opening_claim;
424 inputs.set_public();
425
426 builder.ipa_proof = ipa_proof;
427 };
428};
429} // namespace bb::stdlib::recursion::honk
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_ASSERT_NEQ(actual, expected,...)
Definition assert.hpp:98
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:85
Commitment commitment
Definition claim.hpp:66
uint32_t set_public()
Set the witness indices for the opening claim to public.
Definition claim.hpp:78
typename Group::affine_element AffineElement
Definition bn254.hpp:22
static Commitment construct_default_commitment(Builder &builder)
Construct a default commitment for the databus return data.
Definition databus.hpp:117
A wrapper class for serializing objects to and from the public inputs of a circuit.
static ComponentType reconstruct(const std::vector< Fr > &public_inputs, const Key &key)
uint32_t set_public() const
Definition field.hpp:446
Builder * get_context() const
Definition field.hpp:431
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:466
static constexpr size_t PUBLIC_INPUTS_SIZE
Definition field.hpp:50
Manages the data that is propagated on the public inputs of an application/function circuit.
void reconstruct_from_public(const std::vector< FF > &public_inputs)
Reconstructs the IO components from a public inputs array.
void set_public()
Set each IO component to be a public input of the underlying circuit.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
The data that is propagated on the public inputs of the inner GoblinAvmRecursiveVerifier circuit.
void set_public()
Set each IO component to be a public input of the underlying circuit.
void reconstruct_from_public(const std::vector< FF > &public_inputs)
Reconstructs the IO components from a public inputs array.
Manages the data that is propagated on the public inputs of a hiding kernel circuit.
std::array< G1, Builder::NUM_WIRES > TableCommitments
void reconstruct_from_public(const std::vector< FF > &public_inputs)
Reconstructs the IO components from a public inputs array.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
void set_public()
Set each IO component to be a public input of the underlying circuit.
Manages the data that is propagated on the public inputs of a kernel circuit.
std::array< G1, Builder::NUM_WIRES > TableCommitments
static void add_default(Builder &builder)
Add default public inputs when they are not present.
void reconstruct_from_public(const std::vector< FF > &public_inputs)
Reconstructs the IO components from a public inputs array.
void set_public()
Set each IO component to be a public input of the underlying circuit.
The data that is propagated on the public inputs of a rollup circuit.
void reconstruct_from_public(const std::vector< FF > &public_inputs)
Reconstructs the IO components from a public inputs array.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
void set_public()
Set each IO component to be a public input of the underlying circuit.
AluTraceBuilder builder
Definition alu.test.cpp:124
AvmProvingInputs inputs
std::array< typename bn254< Builder >::Group, Builder::NUM_WIRES > empty_ecc_op_tables(Builder &builder)
Construct commitments to empty subtables.
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
field_t< CircuitBuilder > ScalarField
Definition bn254.hpp:33
element< CircuitBuilder, bigfield< CircuitBuilder, bb::Bn254FqParams >, ScalarField, GroupNative > Group
Definition bn254.hpp:34
An object storing two EC points that represent the inputs to a pairing check.
static constexpr size_t PUBLIC_INPUTS_SIZE
static uint32_t set_default_to_public(Builder *builder)
Set the witness indices for the default limbs of the pairing points to public.
uint32_t set_public()
Set the witness indices for the pairing points to public.
static PairingPoints construct_default()
Construct default pairing points.