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(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
149 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
150 /*assert_on_curve=*/false);
151 table_commitment.convert_constant_to_fixed_witness(&builder);
152 }
153 inputs.output_hn_accum_hash = FF::from_witness(&builder, typename FF::native(0));
154 inputs.set_public();
155 }
156};
157
162template <typename Builder_> class DefaultIO {
163 public:
164 using Builder = Builder_;
165 using Curve = stdlib::bn254<Builder>; // curve is always bn254
168
170
172
173 // Total size of the IO public inputs
174 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
175 static constexpr bool HasIPA = false;
176
182 void reconstruct_from_public(const std::vector<FF>& public_inputs)
183 {
184 // Assumes that the app-io public inputs are at the end of the public_inputs vector
185 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
187 }
188
194 {
195 Builder* builder = validate_context<Builder>(pairing_inputs);
196 BB_ASSERT_NEQ(builder, nullptr, "Trying to set constant PairingPoints to public.");
197
199
200 // Record that pairing points have been set to public
201 builder->pairing_points_tagging.set_public_pairing_points();
202 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
203 builder->finalize_public_inputs();
204 }
205
211 {
213 builder.finalize_public_inputs();
214 };
215};
216
220using AppIO = DefaultIO<MegaCircuitBuilder>; // app IO is always Mega
221
225template <typename Builder_> class GoblinAvmIO {
226 public:
227 using Builder = Builder_;
228 using Curve = stdlib::bn254<Builder>; // curve is always bn254
231
234
235 FF transcript_hash; // The final state of the transcript of the AVM recursive verifier
237
238 // Total size of the IO public inputs
239 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
240 static constexpr bool HasIPA = false;
241
247 void reconstruct_from_public(const std::vector<FF>& public_inputs)
248 {
249 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
250 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
254 }
255
261 {
262 Builder* builder = validate_context<Builder>(pairing_inputs);
263
266
267 // Record that pairing points have been set to public
268 builder->pairing_points_tagging.set_public_pairing_points();
269 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
270 builder->finalize_public_inputs();
271 }
272};
273
277template <class Builder_> class HidingKernelIO {
278 public:
279 using Builder = Builder_;
280 using Curve = stdlib::bn254<Builder>; // curve is always bn254
284 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
285
288
289 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
290 G1 kernel_return_data; // Commitment to the return data of the tail kernel circuit
291 TableCommitments ecc_op_tables; // commitments to merged tables obtained from final Merge verification
292
293 // Total size of the IO public inputs
294 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
295 static constexpr bool HasIPA = false;
296
302 void reconstruct_from_public(const std::vector<FF>& public_inputs)
303 {
304 // Assumes that the hiding-kernel-io public inputs are at the end of the public_inputs vector
305 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
309 index += G1::PUBLIC_INPUTS_SIZE;
310 for (auto& commitment : ecc_op_tables) {
311 commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
312 index += G1::PUBLIC_INPUTS_SIZE;
313 }
314 }
315
321 {
322 Builder* builder = ecc_op_tables[0].get_context();
323
324 if (validate_context<Builder>(pairing_inputs) == nullptr) {
325 // Both points are constant - add the default pairing points to public inputs
327 } else {
329 }
330 kernel_return_data.set_public();
331 for (auto& commitment : ecc_op_tables) {
332 commitment.set_public();
333 }
334
335 // Record that pairing points have been set to public
336 builder->pairing_points_tagging.set_public_pairing_points();
337 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
338 builder->finalize_public_inputs();
339 }
340
346 {
349 inputs.kernel_return_data = G1(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
350 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
351 /*assert_on_curve=*/false);
352 inputs.kernel_return_data.convert_constant_to_fixed_witness(&builder);
353 for (auto& table_commitment : inputs.ecc_op_tables) {
354 table_commitment = G1(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
355 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
356 /*assert_on_curve=*/false);
357 table_commitment.convert_constant_to_fixed_witness(&builder);
358 }
359 inputs.set_public();
360 };
361};
362
366class RollupIO {
367 public:
368 using Builder = UltraCircuitBuilder; // rollup circuits are always Ultra
369 using Curve = stdlib::bn254<Builder>; // curve is always bn254
373
376
379
380 // Total size of the IO public inputs
381 static constexpr size_t PUBLIC_INPUTS_SIZE = ROLLUP_PUBLIC_INPUTS_SIZE;
382 static constexpr bool HasIPA = true;
383
389 void reconstruct_from_public(const std::vector<FF>& public_inputs)
390 {
391 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
395 }
396
402 {
403 Builder* builder = ipa_claim.commitment.get_context();
404
405 if (validate_context<Builder>(pairing_inputs) == nullptr) {
406 // Both points are constant - add the default pairing points to public inputs
408 } else {
410 }
412
413 // Record that pairing points have been set to public
414 builder->pairing_points_tagging.set_public_pairing_points();
415 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
416 builder->finalize_public_inputs();
417 }
418
424 {
427 auto [stdlib_opening_claim, ipa_proof] =
428 IPA<grumpkin<Builder>>::create_random_valid_ipa_claim_and_proof(builder);
429 inputs.ipa_claim = stdlib_opening_claim;
430 inputs.set_public();
431
432 builder.ipa_proof = ipa_proof;
433 };
434};
435} // 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.