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 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1490): Make PublicInputComponent work with arrays
69 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
70
74
75 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
76 G1 kernel_return_data; // Commitment to the return data of a kernel circuit
77 G1 app_return_data; // Commitment to the return data of an app circuit
78 TableCommitments ecc_op_tables; // commitments to merged tables obtained from recursive Merge verification
79 FF output_hn_accum_hash; // hash of the output HN verifier accumulator
80
81 // Total size of the kernel IO public inputs
82 static constexpr size_t PUBLIC_INPUTS_SIZE = KERNEL_PUBLIC_INPUTS_SIZE;
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 uint32_t index = static_cast<uint32_t>(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 if (pairing_inputs.P0.get_context() == nullptr) {
117 // Add the default pairing points to the public inputs
119 } else {
121 }
122 kernel_return_data.set_public();
123 app_return_data.set_public();
124 for (auto& table_commitment : ecc_op_tables) {
125 table_commitment.set_public();
126 }
128
129 // Record that pairing points have been set to public
130 builder->pairing_points_tagging.set_public_pairing_points();
131 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
132 builder->finalize_public_inputs();
133 }
134
140 {
142
146 for (auto& table_commitment : inputs.ecc_op_tables) {
147 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
148 table_commitment.convert_constant_to_fixed_witness(&builder);
149 }
150 inputs.output_hn_accum_hash = FF::from_witness(&builder, typename FF::native(0));
151 inputs.set_public();
152 }
153};
154
159template <typename Builder_> class DefaultIO {
160 public:
161 using Builder = Builder_;
162 using Curve = stdlib::bn254<Builder>; // curve is always bn254
165
167
169
170 // Total size of the IO public inputs
171 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
172
178 void reconstruct_from_public(const std::vector<FF>& public_inputs)
179 {
180 // Assumes that the app-io public inputs are at the end of the public_inputs vector
181 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
183 }
184
190 {
191 Builder* builder = pairing_inputs.P0.get_context();
192 BB_ASSERT_NEQ(builder, nullptr, "Trying to set constant PairingPoints to public.");
193
195
196 // Record that pairing points have been set to public
197 builder->pairing_points_tagging.set_public_pairing_points();
198 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
199 builder->finalize_public_inputs();
200 }
201
207 {
209 builder.finalize_public_inputs();
210 };
211};
212
216using AppIO = DefaultIO<MegaCircuitBuilder>; // app IO is always Mega
217
221template <typename Builder_> class GoblinAvmIO {
222 public:
223 using Builder = Builder_;
224 using Curve = stdlib::bn254<Builder>; // curve is always bn254
227
230
233
234 // Total size of the IO public inputs
235 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
236
242 void reconstruct_from_public(const std::vector<FF>& public_inputs)
243 {
244 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
245 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
249 }
250
256 {
257 Builder* builder = pairing_inputs.P0.get_context();
258
261
262 // Record that pairing points have been set to public
263 builder->pairing_points_tagging.set_public_pairing_points();
264 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
265 builder->finalize_public_inputs();
266 }
267};
268
272template <class Builder_> class HidingKernelIO {
273 public:
274 using Builder = Builder_;
275 using Curve = stdlib::bn254<Builder>; // curve is always bn254
279 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
280
283
284 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
285 G1 kernel_return_data; // Commitment to the return data of the tail kernel circuit
286 TableCommitments ecc_op_tables; // commitments to merged tables obtained from final Merge verification
287
288 // Total size of the IO public inputs
289 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
290
296 void reconstruct_from_public(const std::vector<FF>& public_inputs)
297 {
298 // Assumes that the app-io public inputs are at the end of the public_inputs vector
299 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
303 index += G1::PUBLIC_INPUTS_SIZE;
304 for (auto& commitment : ecc_op_tables) {
305 commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
306 index += G1::PUBLIC_INPUTS_SIZE;
307 }
308 }
309
315 {
316 Builder* builder = ecc_op_tables[0].get_context();
317
318 if (pairing_inputs.P0.get_context() == nullptr) {
319 // Add the default pairing points to the public inputs
321 } else {
323 }
324 kernel_return_data.set_public();
325 for (auto& commitment : ecc_op_tables) {
326 commitment.set_public();
327 }
328
329 // Record that pairing points have been set to public
330 builder->pairing_points_tagging.set_public_pairing_points();
331 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
332 builder->finalize_public_inputs();
333 }
334
340 {
343 inputs.kernel_return_data = G1(DEFAULT_ECC_COMMITMENT);
344 inputs.kernel_return_data.convert_constant_to_fixed_witness(&builder);
345 for (auto& table_commitment : inputs.ecc_op_tables) {
346 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
347 table_commitment.convert_constant_to_fixed_witness(&builder);
348 }
349 inputs.set_public();
350 };
351};
352
356class RollupIO {
357 public:
358 using Builder = UltraCircuitBuilder; // rollup circuits are always Ultra
359 using Curve = stdlib::bn254<Builder>; // curve is always bn254
363
366
369
370 // Total size of the IO public inputs
371 static constexpr size_t PUBLIC_INPUTS_SIZE = ROLLUP_PUBLIC_INPUTS_SIZE;
372
378 void reconstruct_from_public(const std::vector<FF>& public_inputs)
379 {
380 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
384 }
385
391 {
392 Builder* builder = ipa_claim.commitment.get_context();
393
394 if (pairing_inputs.P0.get_context() == nullptr) {
395 // Add the default pairing points to the public inputs
397 } else {
398 BB_ASSERT_EQ(builder, pairing_inputs.P0.get_context());
400 }
402
403 // Record that pairing points have been set to public
404 builder->pairing_points_tagging.set_public_pairing_points();
405 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
406 builder->finalize_public_inputs();
407 }
408
414 {
417 auto [stdlib_opening_claim, ipa_proof] =
418 IPA<grumpkin<Builder>>::create_random_valid_ipa_claim_and_proof(builder);
419 inputs.ipa_claim = stdlib_opening_claim;
420 inputs.set_public();
421
422 builder.ipa_proof = ipa_proof;
423 };
424};
425
426// Default IO type for recursive verifiers: RollupIO for IPA flavors, DefaultIO<Builder> otherwise
427template <typename Flavor>
430
431} // namespace bb::stdlib::recursion::honk
#define BB_ASSERT(expression,...)
Definition assert.hpp:80
#define BB_ASSERT_NEQ(actual, expected,...)
Definition assert.hpp:108
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:93
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:93
Commitment commitment
Definition claim.hpp:64
uint32_t set_public()
Set the witness indices for the opening claim to public.
Definition claim.hpp:76
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:434
Builder * get_context() const
Definition field.hpp:419
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:454
static constexpr size_t PUBLIC_INPUTS_SIZE
Definition field.hpp:49
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::conditional_t< HasIPAAccumulator< Flavor >, RollupIO, DefaultIO< typename Flavor::CircuitBuilder > > DefaultRecursiveIO
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 limbs of the pairing points to public.
static PairingPoints construct_default()
Construct default pairing points.