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
117 kernel_return_data.set_public();
118 app_return_data.set_public();
119 for (auto& table_commitment : ecc_op_tables) {
120 table_commitment.set_public();
121 }
123
124 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
125 builder->finalize_public_inputs();
126 }
127
133 {
135
139 for (auto& table_commitment : inputs.ecc_op_tables) {
140 table_commitment = G1(typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.x)),
141 typename G1::BaseField(nullptr, uint256_t(DEFAULT_ECC_COMMITMENT.y)),
142 /*assert_on_curve=*/false);
143 table_commitment.convert_constant_to_fixed_witness(&builder);
144 }
145 inputs.output_hn_accum_hash = FF::from_witness(&builder, typename FF::native(0));
146 inputs.set_public();
147 }
148};
149
154template <typename Builder_> class DefaultIO {
155 public:
156 using Builder = Builder_;
157 using Curve = stdlib::bn254<Builder>; // curve is always bn254
160
162
164
165 // Total size of the IO public inputs
166 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
167 static constexpr bool HasIPA = false;
168
174 void reconstruct_from_public(const std::vector<FF>& public_inputs)
175 {
176 // Assumes that the app-io public inputs are at the end of the public_inputs vector
177 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
179 }
180
186 {
187 Builder* builder = validate_context<Builder>(pairing_inputs);
188 BB_ASSERT_NEQ(builder, nullptr, "Trying to set constant PairingPoints to public.");
189
191
192 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
193 builder->finalize_public_inputs();
194 }
195
201 {
203 builder.finalize_public_inputs();
204 };
205};
206
210using AppIO = DefaultIO<MegaCircuitBuilder>; // app IO is always Mega
211
215template <typename Builder_> class GoblinAvmIO {
216 public:
217 using Builder = Builder_;
218 using Curve = stdlib::bn254<Builder>; // curve is always bn254
221
224
225 FF transcript_hash; // The final state of the transcript of the AVM recursive verifier
227
228 // Total size of the IO public inputs
229 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
230 static constexpr bool HasIPA = false;
231
237 void reconstruct_from_public(const std::vector<FF>& public_inputs)
238 {
239 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
240 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
244 }
245
251 {
252 Builder* builder = validate_context<Builder>(pairing_inputs);
253
256
257 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
258 builder->finalize_public_inputs();
259 }
260};
261
265template <class Builder_> class HidingKernelIO {
266 public:
267 using Builder = Builder_;
268 using Curve = stdlib::bn254<Builder>; // curve is always bn254
272 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
273
276
277 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
278 G1 kernel_return_data; // Commitment to the return data of the tail kernel circuit
279 TableCommitments ecc_op_tables; // commitments to merged tables obtained from final Merge verification
280
281 // Total size of the IO public inputs
282 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
283 static constexpr bool HasIPA = false;
284
290 void reconstruct_from_public(const std::vector<FF>& public_inputs)
291 {
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 size_t index = public_inputs.size() - PUBLIC_INPUTS_SIZE;
376 }
377
383 {
384 Builder* builder = ipa_claim.commitment.get_context();
385
388
389 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
390 builder->finalize_public_inputs();
391 }
392
398 {
401 auto [stdlib_opening_claim, ipa_proof] =
402 IPA<grumpkin<Builder>>::create_random_valid_ipa_claim_and_proof(builder);
403 inputs.ipa_claim = stdlib_opening_claim;
404 inputs.set_public();
405
406 builder.ipa_proof = ipa_proof;
407 };
408};
409} // 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: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: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: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.