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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
17
18// Default coordinates of commitment to an ecc op table
19// These are the coordinates that come from committing to the ecc ops that are added to the op_queue by finalize_circuit
20static constexpr bb::fq DEFAULT_ECC_COMMITMENT_X("0x08434fa4480433735e7aeaccecb911eb7a06165ad70e5ced6ac6848296e59279");
21static constexpr bb::fq DEFAULT_ECC_COMMITMENT_Y("0x0a13a1839ab95ef15be8d0710b2c8aa47cea0b0e62a8596e68cc0fd54a6ae73d");
22static constexpr bb::curve::BN254::AffineElement DEFAULT_ECC_COMMITMENT(DEFAULT_ECC_COMMITMENT_X,
23 DEFAULT_ECC_COMMITMENT_Y);
24
35template <typename Builder>
37{
38 std::array<typename bn254<Builder>::Group, Builder::NUM_WIRES> empty_tables;
39 for (auto& table_commitment : empty_tables) {
41 }
42
43 return empty_tables;
44}
45
50class KernelIO {
51 public:
52 using Builder = MegaCircuitBuilder; // kernel builder is always Mega
53 using Curve = stdlib::bn254<Builder>; // curve is always bn254
57 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1490): Make PublicInputComponent work with arrays
58 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
59
63
64 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
65 G1 kernel_return_data; // Commitment to the return data of a kernel circuit
66 G1 app_return_data; // Commitment to the return data of an app circuit
67 TableCommitments ecc_op_tables; // commitments to merged tables obtained from recursive Merge verification
68 FF output_hn_accum_hash; // hash of the output HN verifier accumulator
69
70 // Total size of the kernel IO public inputs
71 static constexpr size_t PUBLIC_INPUTS_SIZE = KERNEL_PUBLIC_INPUTS_SIZE;
72
78 void reconstruct_from_public(const std::vector<FF>& public_inputs)
79 {
80 // Assumes that the kernel-io public inputs are at the end of the public_inputs vector
81 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
82
86 index += G1::PUBLIC_INPUTS_SIZE;
88 index += G1::PUBLIC_INPUTS_SIZE;
89 for (auto& table_commitment : ecc_op_tables) {
90 table_commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
91 index += G1::PUBLIC_INPUTS_SIZE;
92 }
95 }
96
102 {
104
105 if (pairing_inputs.P0.get_context() == nullptr) {
106 // Add the default pairing points to the public inputs
108 } else {
110 }
111 kernel_return_data.set_public();
112 app_return_data.set_public();
113 for (auto& table_commitment : ecc_op_tables) {
114 table_commitment.set_public();
115 }
117
118 // Record that pairing points have been set to public
119 builder->pairing_points_tagging.set_public_pairing_points();
120 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
121 builder->finalize_public_inputs();
122 }
123
129 {
131
135 for (auto& table_commitment : inputs.ecc_op_tables) {
136 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
137 table_commitment.convert_constant_to_fixed_witness(&builder);
138 }
139 inputs.output_hn_accum_hash = FF::from_witness(&builder, typename FF::native(0));
140 inputs.set_public();
141 }
142};
143
148template <typename Builder_> class DefaultIO {
149 public:
150 using Builder = Builder_;
151 using Curve = stdlib::bn254<Builder>; // curve is always bn254
154
156
158
159 // Total size of the IO public inputs
160 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
161
167 void reconstruct_from_public(const std::vector<FF>& public_inputs)
168 {
169 // Assumes that the app-io public inputs are at the end of the public_inputs vector
170 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
172 }
173
179 {
180 Builder* builder = pairing_inputs.P0.get_context();
181 BB_ASSERT_NEQ(builder, nullptr, "Trying to set constant PairingPoints to public.");
182
184
185 // Record that pairing points have been set to public
186 builder->pairing_points_tagging.set_public_pairing_points();
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
222
223 // Total size of the IO public inputs
224 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
225
231 void reconstruct_from_public(const std::vector<FF>& public_inputs)
232 {
233 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
234 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
238 }
239
245 {
246 Builder* builder = pairing_inputs.P0.get_context();
247
250
251 // Record that pairing points have been set to public
252 builder->pairing_points_tagging.set_public_pairing_points();
253 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
254 builder->finalize_public_inputs();
255 }
256};
257
261template <class Builder_> class HidingKernelIO {
262 public:
263 using Builder = Builder_;
264 using Curve = stdlib::bn254<Builder>; // curve is always bn254
268 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
269
272
273 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
274 G1 kernel_return_data; // Commitment to the return data of the tail kernel circuit
275 TableCommitments ecc_op_tables; // commitments to merged tables obtained from final Merge verification
276
277 // Total size of the IO public inputs
278 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
279
285 void reconstruct_from_public(const std::vector<FF>& public_inputs)
286 {
287 // Assumes that the app-io public inputs are at the end of the public_inputs vector
288 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
292 index += G1::PUBLIC_INPUTS_SIZE;
293 for (auto& commitment : ecc_op_tables) {
294 commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
295 index += G1::PUBLIC_INPUTS_SIZE;
296 }
297 }
298
304 {
305 Builder* builder = ecc_op_tables[0].get_context();
306
307 if (pairing_inputs.P0.get_context() == nullptr) {
308 // Add the default pairing points to the public inputs
310 } else {
312 }
313 kernel_return_data.set_public();
314 for (auto& commitment : ecc_op_tables) {
315 commitment.set_public();
316 }
317
318 // Record that pairing points have been set to public
319 builder->pairing_points_tagging.set_public_pairing_points();
320 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
321 builder->finalize_public_inputs();
322 }
323
329 {
332 inputs.kernel_return_data = G1(DEFAULT_ECC_COMMITMENT);
333 inputs.kernel_return_data.convert_constant_to_fixed_witness(&builder);
334 for (auto& table_commitment : inputs.ecc_op_tables) {
335 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
336 table_commitment.convert_constant_to_fixed_witness(&builder);
337 }
338 inputs.set_public();
339 };
340};
341
345class RollupIO {
346 public:
347 using Builder = UltraCircuitBuilder; // rollup circuits are always Ultra
348 using Curve = stdlib::bn254<Builder>; // curve is always bn254
352
355
358
359 // Total size of the IO public inputs
360 static constexpr size_t PUBLIC_INPUTS_SIZE = ROLLUP_PUBLIC_INPUTS_SIZE;
361
367 void reconstruct_from_public(const std::vector<FF>& public_inputs)
368 {
369 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
373 }
374
380 {
381 Builder* builder = ipa_claim.commitment.get_context();
382
383 if (pairing_inputs.P0.get_context() == nullptr) {
384 // Add the default pairing points to the public inputs
386 } else {
387 BB_ASSERT_EQ(builder, pairing_inputs.P0.get_context());
389 }
391
392 // Record that pairing points have been set to public
393 builder->pairing_points_tagging.set_public_pairing_points();
394 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
395 builder->finalize_public_inputs();
396 }
397
403 {
406 auto [stdlib_opening_claim, ipa_proof] =
407 IPA<grumpkin<Builder>>::create_random_valid_ipa_claim_and_proof(builder);
408 inputs.ipa_claim = stdlib_opening_claim;
409 inputs.set_public();
410
411 builder.ipa_proof = ipa_proof;
412 };
413};
414
415} // namespace bb::stdlib::recursion::honk
#define BB_ASSERT_NEQ(actual, expected,...)
Definition assert.hpp:92
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:77
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::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.