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_hash, 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
62template <size_t N> class KernelIO_ {
63 public:
64 using Builder = MegaCircuitBuilder; // kernel builder is always Mega
65 using Curve = stdlib::bn254<Builder>; // curve is always bn254
69 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
70 using AppReturnDataCommitments = std::array<G1, N>;
71
75
76 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
77 G1 kernel_return_data; // Commitment to the return data of a kernel circuit
78 AppReturnDataCommitments app_return_data; // Commitment to each verified app circuit's return data
79 FF ecc_op_hash; // Running Poseidon2 hash over ECC op column commitments
80 FF output_hn_accum_hash; // hash of the output HN verifier accumulator
81
82 // Total size of the kernel IO public inputs
83 static constexpr size_t PUBLIC_INPUTS_SIZE = kernel_public_inputs_size(N);
84 static constexpr bool HasIPA = false;
85
91 void reconstruct_from_public(const std::vector<FF>& public_inputs)
92 {
94 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for HidingKernelIO reconstruction");
95 // Assumes that the kernel-io public inputs are at the end of the public_inputs vector
96 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
97
101 index += G1::PUBLIC_INPUTS_SIZE;
102 for (auto& app_commitment : app_return_data) {
103 app_commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
104 index += G1::PUBLIC_INPUTS_SIZE;
105 }
110 }
111
117 {
119
121 kernel_return_data.set_public();
122 for (auto& app_commitment : app_return_data) {
123 app_commitment.set_public();
124 }
127
128 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
129 builder->finalize_public_inputs();
130 }
131
137 {
139
142 for (auto& app_commitment : inputs.app_return_data) {
144 }
145 inputs.ecc_op_hash = FF::from_witness(&builder, typename FF::native(0));
146 inputs.output_hn_accum_hash = FF::from_witness(&builder, typename FF::native(0));
147 inputs.set_public();
148 }
149};
150
152
157template <typename Builder_> class DefaultIO {
158 public:
159 using Builder = Builder_;
160 using Curve = stdlib::bn254<Builder>; // curve is always bn254
163
165
167
168 // Total size of the IO public inputs
169 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
170 static constexpr bool HasIPA = false;
171
177 void reconstruct_from_public(const std::vector<FF>& public_inputs)
178 {
180 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for AppCircuitIO reconstruction");
181 // Assumes that the app-io public inputs are at the end of the public_inputs vector
182 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
184 }
185
191 {
192 Builder* builder = validate_context<Builder>(pairing_inputs);
193 BB_ASSERT_NEQ(builder, nullptr, "Trying to set constant PairingPoints to public.");
194
196
197 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
198 builder->finalize_public_inputs();
199 }
200
206 {
208 builder.finalize_public_inputs();
209 };
210};
211
215using AppIO = DefaultIO<MegaCircuitBuilder>; // app IO is always Mega
216
220template <typename Builder_> class GoblinAvmIO {
221 public:
222 using Builder = Builder_;
223 using Curve = stdlib::bn254<Builder>; // curve is always bn254
226
229
230 FF transcript_hash; // The final state of the transcript of the AVM recursive verifier
232
233 // Total size of the IO public inputs
234 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
235 static constexpr bool HasIPA = false;
236
242 void reconstruct_from_public(const std::vector<FF>& public_inputs)
243 {
245 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for GoblinAvmIO reconstruction");
246 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
247 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
251 }
252
258 {
259 Builder* builder = validate_context<Builder>(pairing_inputs);
260
263
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 the full merged op queue tables, obtained from the
287 // batched merge verification performed inside the hiding kernel
288
289 // Total size of the IO public inputs
290 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
291 static constexpr bool HasIPA = false;
292
298 void reconstruct_from_public(const std::vector<FF>& public_inputs)
299 {
301 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for HidingKernelIO reconstruction");
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
323 kernel_return_data.set_public();
324 for (auto& commitment : ecc_op_tables) {
325 commitment.set_public();
326 }
327
328 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
329 builder->finalize_public_inputs();
330 }
331
337 {
340 inputs.kernel_return_data = G1(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
341 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
342 /*assert_on_curve=*/false);
343 inputs.kernel_return_data.convert_constant_to_fixed_witness(&builder);
344 for (auto& table_commitment : inputs.ecc_op_tables) {
345 table_commitment = G1(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
346 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
347 /*assert_on_curve=*/false);
348 table_commitment.convert_constant_to_fixed_witness(&builder);
349 }
350 inputs.set_public();
351 };
352};
353
357class RollupIO {
358 public:
359 using Builder = UltraCircuitBuilder; // rollup circuits are always Ultra
360 using Curve = stdlib::bn254<Builder>; // curve is always bn254
364
367
370
371 // Total size of the IO public inputs
372 static constexpr size_t PUBLIC_INPUTS_SIZE = ROLLUP_PUBLIC_INPUTS_SIZE;
373 static constexpr bool HasIPA = true;
374
380 void reconstruct_from_public(const std::vector<FF>& public_inputs)
381 {
382 BB_ASSERT_GTE(public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for RollupIO reconstruction");
383 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
387 }
388
394 {
395 Builder* builder = ipa_claim.commitment.get_context();
396
399
400 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
401 builder->finalize_public_inputs();
402 }
403
409 {
412 auto [stdlib_opening_claim, ipa_proof] =
413 IPA<grumpkin<Builder>>::create_random_valid_ipa_claim_and_proof(builder);
414 inputs.ipa_claim = stdlib_opening_claim;
415 inputs.set_public();
416
417 builder.ipa_proof = ipa_proof;
418 };
419};
420} // namespace bb::stdlib::recursion::honk
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_ASSERT_GTE(left, right,...)
Definition assert.hpp:128
#define BB_ASSERT_NEQ(actual, expected,...)
Definition assert.hpp:98
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:86
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:158
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:447
Builder * get_context() const
Definition field.hpp:432
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:467
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.
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.
std::array< G1, Builder::NUM_WIRES > TableCommitments
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 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.
constexpr std::size_t kernel_public_inputs_size(std::size_t num_apps)
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: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.
static constexpr size_t PUBLIC_INPUTS_SIZE
static uint32_t set_default_to_public(Builder *builder)
Set the witness indices for the default (infinity) pairing points to public.
static PairingPoints construct_default()
Construct default pairing points (both at infinity).
uint32_t set_public(Builder *ctx=nullptr)
Set the witness indices for the pairing points to public.