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
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 FF ecc_op_hash; // Running Poseidon2 hash over ECC op column commitments
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 {
92 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for HidingKernelIO reconstruction");
93 // Assumes that the kernel-io public inputs are at the end of the public_inputs vector
94 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
95
99 index += G1::PUBLIC_INPUTS_SIZE;
101 index += G1::PUBLIC_INPUTS_SIZE;
106 }
107
113 {
115
117 kernel_return_data.set_public();
118 app_return_data.set_public();
121
122 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
123 builder->finalize_public_inputs();
124 }
125
131 {
133
137 inputs.ecc_op_hash = FF::from_witness(&builder, typename FF::native(0));
138 inputs.output_hn_accum_hash = FF::from_witness(&builder, typename FF::native(0));
139 inputs.set_public();
140 }
141};
142
147template <typename Builder_> class DefaultIO {
148 public:
149 using Builder = Builder_;
150 using Curve = stdlib::bn254<Builder>; // curve is always bn254
153
155
157
158 // Total size of the IO public inputs
159 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
160 static constexpr bool HasIPA = false;
161
167 void reconstruct_from_public(const std::vector<FF>& public_inputs)
168 {
170 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for AppCircuitIO reconstruction");
171 // Assumes that the app-io public inputs are at the end of the public_inputs vector
172 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
174 }
175
181 {
182 Builder* builder = validate_context<Builder>(pairing_inputs);
183 BB_ASSERT_NEQ(builder, nullptr, "Trying to set constant PairingPoints to public.");
184
186
187 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
188 builder->finalize_public_inputs();
189 }
190
196 {
198 builder.finalize_public_inputs();
199 };
200};
201
205using AppIO = DefaultIO<MegaCircuitBuilder>; // app IO is always Mega
206
210template <typename Builder_> class GoblinAvmIO {
211 public:
212 using Builder = Builder_;
213 using Curve = stdlib::bn254<Builder>; // curve is always bn254
216
219
220 FF transcript_hash; // The final state of the transcript of the AVM recursive verifier
222
223 // Total size of the IO public inputs
224 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
225 static constexpr bool HasIPA = false;
226
232 void reconstruct_from_public(const std::vector<FF>& public_inputs)
233 {
235 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for GoblinAvmIO reconstruction");
236 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
237 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
241 }
242
248 {
249 Builder* builder = validate_context<Builder>(pairing_inputs);
250
253
254 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
255 builder->finalize_public_inputs();
256 }
257};
258
262template <class Builder_> class HidingKernelIO {
263 public:
264 using Builder = Builder_;
265 using Curve = stdlib::bn254<Builder>; // curve is always bn254
269 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
270
273
274 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
275 G1 kernel_return_data; // Commitment to the return data of the tail kernel circuit
276 TableCommitments ecc_op_tables; // commitments to the full merged op queue tables, obtained from the
277 // batched merge verification performed inside the hiding kernel
278
279 // Total size of the IO public inputs
280 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
281 static constexpr bool HasIPA = false;
282
288 void reconstruct_from_public(const std::vector<FF>& public_inputs)
289 {
291 public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for HidingKernelIO reconstruction");
292 // Assumes that the hiding-kernel-io public inputs are at the end of the public_inputs vector
293 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
297 index += G1::PUBLIC_INPUTS_SIZE;
298 for (auto& commitment : ecc_op_tables) {
299 commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
300 index += G1::PUBLIC_INPUTS_SIZE;
301 }
302 }
303
309 {
310 Builder* builder = ecc_op_tables[0].get_context();
311
313 kernel_return_data.set_public();
314 for (auto& commitment : ecc_op_tables) {
315 commitment.set_public();
316 }
317
318 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
319 builder->finalize_public_inputs();
320 }
321
327 {
330 inputs.kernel_return_data = G1(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
331 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
332 /*assert_on_curve=*/false);
333 inputs.kernel_return_data.convert_constant_to_fixed_witness(&builder);
334 for (auto& table_commitment : inputs.ecc_op_tables) {
335 table_commitment = G1(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
336 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
337 /*assert_on_curve=*/false);
338 table_commitment.convert_constant_to_fixed_witness(&builder);
339 }
340 inputs.set_public();
341 };
342};
343
347class RollupIO {
348 public:
349 using Builder = UltraCircuitBuilder; // rollup circuits are always Ultra
350 using Curve = stdlib::bn254<Builder>; // curve is always bn254
354
357
360
361 // Total size of the IO public inputs
362 static constexpr size_t PUBLIC_INPUTS_SIZE = ROLLUP_PUBLIC_INPUTS_SIZE;
363 static constexpr bool HasIPA = true;
364
370 void reconstruct_from_public(const std::vector<FF>& public_inputs)
371 {
372 BB_ASSERT_GTE(public_inputs.size(), PUBLIC_INPUTS_SIZE, "Public inputs too small for RollupIO reconstruction");
373 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
377 }
378
384 {
385 Builder* builder = ipa_claim.commitment.get_context();
386
389
390 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
391 builder->finalize_public_inputs();
392 }
393
399 {
402 auto [stdlib_opening_claim, ipa_proof] =
403 IPA<grumpkin<Builder>>::create_random_valid_ipa_claim_and_proof(builder);
404 inputs.ipa_claim = stdlib_opening_claim;
405 inputs.set_public();
406
407 builder.ipa_proof = ipa_proof;
408 };
409};
410} // 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:118
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.
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: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.