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{
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_pg_accum_hash; // hash of the output PG 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 kernel_return_data.set_public();
105 app_return_data.set_public();
106 for (auto& table_commitment : ecc_op_tables) {
107 table_commitment.set_public();
108 }
110
111 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
112 Builder* builder = pairing_inputs.P0.get_context();
113 builder->finalize_public_inputs();
114 }
115
121 {
124 kernel_return_data.set_public();
126 app_return_data.set_public();
128 for (auto& table_commitment : ecc_op_tables) {
129 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
130 table_commitment.convert_constant_to_fixed_witness(&builder);
131 table_commitment.set_public();
132 }
135 }
136};
137
142template <typename Builder_> class DefaultIO {
143 public:
144 using Builder = Builder_;
145 using Curve = stdlib::bn254<Builder>; // curve is always bn254
148
150
152
153 // Total size of the IO public inputs
154 static constexpr size_t PUBLIC_INPUTS_SIZE = DEFAULT_PUBLIC_INPUTS_SIZE;
155
161 void reconstruct_from_public(const std::vector<FF>& public_inputs)
162 {
163 // Assumes that the app-io public inputs are at the end of the public_inputs vector
164 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
166 }
167
173 {
175
176 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
177 Builder* builder = pairing_inputs.P0.get_context();
178 builder->finalize_public_inputs();
179 }
180
186};
187
191using AppIO = DefaultIO<MegaCircuitBuilder>; // app IO is always Mega
192
196template <typename Builder_> class GoblinAvmIO {
197 public:
198 using Builder = Builder_;
199 using Curve = stdlib::bn254<Builder>; // curve is always bn254
202
205
208
209 // Total size of the IO public inputs
210 static constexpr size_t PUBLIC_INPUTS_SIZE = GOBLIN_AVM_PUBLIC_INPUTS_SIZE;
211
217 void reconstruct_from_public(const std::vector<FF>& public_inputs)
218 {
219 // Assumes that the GoblinAvm-io public inputs are at the end of the public_inputs vector
220 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
221 mega_hash = PublicFF::reconstruct(public_inputs, PublicComponentKey{ index });
222 index += FF::PUBLIC_INPUTS_SIZE;
224 }
225
231 {
234
235 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
236 Builder* builder = pairing_inputs.P0.get_context();
237 builder->finalize_public_inputs();
238 }
239};
240
244template <class Builder_> class HidingKernelIO {
245 public:
246 using Builder = Builder_;
247 using Curve = stdlib::bn254<Builder>; // curve is always bn254
251 using TableCommitments = std::array<G1, Builder::NUM_WIRES>;
252
255
256 PairingInputs pairing_inputs; // Inputs {P0, P1} to an EC pairing check
257 TableCommitments ecc_op_tables; // commitments to merged tables obtained from final Merge verification
258
259 // Total size of the IO public inputs
260 static constexpr size_t PUBLIC_INPUTS_SIZE = HIDING_KERNEL_PUBLIC_INPUTS_SIZE;
261
267 void reconstruct_from_public(const std::vector<FF>& public_inputs)
268 {
269 // Assumes that the app-io public inputs are at the end of the public_inputs vector
270 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
273 for (auto& commitment : ecc_op_tables) {
274 commitment = PublicPoint::reconstruct(public_inputs, PublicComponentKey{ index });
275 index += G1::PUBLIC_INPUTS_SIZE;
276 }
277 }
278
284 {
286 for (auto& commitment : ecc_op_tables) {
287 commitment.set_public();
288 }
289
290 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
291 Builder* builder = pairing_inputs.P0.get_context();
292 builder->finalize_public_inputs();
293 }
294
296 {
297 TableCommitments default_tables;
298 for (auto& table_commitment : default_tables) {
299 table_commitment = G1(DEFAULT_ECC_COMMITMENT);
300 table_commitment.convert_constant_to_fixed_witness(&builder);
301 }
302
303 return default_tables;
304 }
305
311 {
313 for (auto& table_commitment : default_ecc_op_tables(builder)) {
314 table_commitment.set_public();
315 }
316 };
317};
318
322class RollupIO {
323 public:
324 using Builder = UltraCircuitBuilder; // rollup circuits are always Ultra
325 using Curve = stdlib::bn254<Builder>; // curve is always bn254
329
332
335
336 // Total size of the IO public inputs
337 static constexpr size_t PUBLIC_INPUTS_SIZE = ROLLUP_PUBLIC_INPUTS_SIZE;
338
344 void reconstruct_from_public(const std::vector<FF>& public_inputs)
345 {
346 uint32_t index = static_cast<uint32_t>(public_inputs.size() - PUBLIC_INPUTS_SIZE);
350 }
351
357 {
360
361 // Finalize the public inputs to ensure no more public inputs can be added hereafter.
362 Builder* builder = pairing_inputs.P0.get_context();
363 builder->finalize_public_inputs();
364 }
365
371 {
373 auto [stdlib_opening_claim, ipa_proof] = IPA<grumpkin<Builder>>::create_fake_ipa_claim_and_proof(builder);
374 stdlib_opening_claim.set_public();
375 builder.ipa_proof = ipa_proof;
376 };
377};
378
379} // namespace bb::stdlib::recursion::honk
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:95
uint32_t set_public()
Set the witness indices for the opening claim to public.
Definition claim.hpp:76
static constexpr size_t NUM_WIRES
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:404
static field_t from_witness(Builder *ctx, const bb::fr &input)
Definition field.hpp:424
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.
static TableCommitments default_ecc_op_tables(Builder &builder)
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:123
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
static void add_default_to_public_inputs(Builder &builder)
Adds default public inputs to the builder.
uint32_t set_public()
Set the witness indices for the limbs of the pairing points to public.