Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
special_public_inputs.test.cpp
Go to the documentation of this file.
3#include <gtest/gtest.h>
4
6
7class SpecialPublicInputsTests : public testing::Test {
8 public:
9 static void SetUpTestSuite() {}
10};
11
12// Demonstrates the basic functionality of the KernelIO class for propagating public inputs between circuits
14{
16 using Curve = KernelIO::Curve;
17 using G1 = KernelIO::G1;
18 using FF = KernelIO::FF;
19 using PairingInputs = KernelIO::PairingInputs;
20
21 using G1Native = Curve::GroupNative::affine_element;
22 using FFNative = Curve::ScalarFieldNative;
23
24 static constexpr size_t NUM_WIRES = Builder::NUM_WIRES;
25
26 G1Native P0_val = G1Native::random_element();
27 G1Native P1_val = G1Native::random_element();
28 G1Native kernel_return_data_val = G1Native::random_element();
29 G1Native app_return_data_val = G1Native::random_element();
30 std::array<G1Native, NUM_WIRES> ecc_op_tables_val;
31 for (auto& commitment : ecc_op_tables_val) {
32 commitment = G1Native::random_element();
33 }
34 FFNative output_pg_accum_hash_val = FFNative::random_element();
35
36 // Store the public inputs of the first circuit to be used by the second
37 std::vector<FFNative> public_inputs;
38
39 { // The first circuit propagates the kernel output via its public inputs
41
42 KernelIO kernel_output;
43
44 // Set the output values
45 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
46 kernel_output.pairing_inputs = pairing_inputs;
47 kernel_output.kernel_return_data = G1::from_witness(&builder, kernel_return_data_val);
48 kernel_output.app_return_data = G1::from_witness(&builder, app_return_data_val);
49 for (auto [table_commitment, table_val] : zip_view(kernel_output.ecc_op_tables, ecc_op_tables_val)) {
50 table_commitment = G1::from_witness(&builder, table_val);
51 }
52 kernel_output.output_pg_accum_hash = FF::from_witness(&builder, output_pg_accum_hash_val);
53
54 // Propagate the kernel output via the public inputs
55 kernel_output.set_public();
56
57 // Store the public inputs from this circuit for use in the second circuit
58 for (const auto& idx : builder.public_inputs()) {
59 public_inputs.push_back(builder.get_variable(idx));
60 }
61 }
62
63 { // The second circuit reconstructs the kernel inputs from the public inputs
65
66 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
67 std::vector<FF> stdlib_public_inputs;
68 stdlib_public_inputs.reserve(public_inputs.size());
69 for (const auto& val : public_inputs) {
70 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
71 }
72
73 KernelIO kernel_input;
74 kernel_input.reconstruct_from_public(stdlib_public_inputs);
75
76 // Ensure the reconstructed data matches the original values
77 EXPECT_EQ(kernel_input.pairing_inputs.P0.get_value(), P0_val);
78 EXPECT_EQ(kernel_input.pairing_inputs.P1.get_value(), P1_val);
79 EXPECT_EQ(kernel_input.kernel_return_data.get_value(), kernel_return_data_val);
80 EXPECT_EQ(kernel_input.app_return_data.get_value(), app_return_data_val);
81 for (auto [reconstructed_commitment, commitment] : zip_view(kernel_input.ecc_op_tables, ecc_op_tables_val)) {
82 EXPECT_EQ(reconstructed_commitment.get_value(), commitment);
83 }
84 EXPECT_EQ(kernel_input.output_pg_accum_hash.get_value(), output_pg_accum_hash_val);
85 }
86}
87
88// Demonstrates the basic functionality of the DefaultIO class
90{
92 using IO = DefaultIO<Builder>;
93 using IONative = bb::DefaultIO;
94
95 using Curve = IO::Curve;
96 using FF = IO::Curve::ScalarField;
97 using G1 = Curve::Group;
98 using PairingInputs = IO::PairingInputs;
99
100 using G1Native = Curve::GroupNative::affine_element;
101 using FFNative = IONative::FF;
102
103 G1Native P0_val = G1Native::random_element();
104 G1Native P1_val = G1Native::random_element();
105
106 // Store the public inputs of the circuit
107 std::vector<FFNative> public_inputs;
108
109 { // The circuit propagates the outputs via its public inputs
111
112 IO io_output;
113
114 // Set the output values
115 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
116 io_output.pairing_inputs = pairing_inputs;
117
118 // Propagate the output via the public inputs
119 io_output.set_public();
120
121 // Store the public inputs from this circuit for use in the second circuit
122 for (const auto& idx : builder.public_inputs()) {
123 public_inputs.push_back(builder.get_variable(idx));
124 }
125 }
126
127 {
128 // The second circuit reconstructs the inputs from the public inputs
130
131 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
132 std::vector<FF> stdlib_public_inputs;
133 stdlib_public_inputs.reserve(public_inputs.size());
134 for (const auto& val : public_inputs) {
135 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
136 }
137
138 IO io_input;
139 io_input.reconstruct_from_public(stdlib_public_inputs);
140
141 // Ensure the reconstructed data matches the original values
142 EXPECT_EQ(io_input.pairing_inputs.P0.get_value(), P0_val);
143 EXPECT_EQ(io_input.pairing_inputs.P1.get_value(), P1_val);
144 }
145
146 {
147 // Reconstruct the public inputs from native elements
148 IONative io_input_native;
149 io_input_native.reconstruct_from_public(public_inputs);
150
151 // Ensure the reconstructed data matches the original values
152 EXPECT_EQ(io_input_native.pairing_inputs.P0, P0_val);
153 EXPECT_EQ(io_input_native.pairing_inputs.P1, P1_val);
154 }
155}
156
157// Demonstrates the basic functionality of the RollUpIO class
159{
161 using RollUpIONative = bb::RollupIO;
162
163 using Curve = RollupIO::Curve;
164 using ScalarFieldBn254 = RollupIO::FF;
165 using ScalarFieldGrumpkin = Curve::BaseField;
166 using G1 = Curve::Group;
167 using G1Grumpkin = bb::stdlib::grumpkin<Builder>::Group;
168 using PairingInputs = RollupIO::PairingInputs;
169 using IpaClaim = RollupIO::IpaClaim;
170
171 using G1Native = Curve::GroupNative::affine_element;
172 using ScalarFieldBn254Native = RollUpIONative::FF;
173 using GrumpkinNative = bb::curve::Grumpkin;
174 using G1GrumpkinNative = GrumpkinNative::AffineElement;
175 using ScalarFieldGrumpkinNative = GrumpkinNative::ScalarField;
176
177 G1Native P0_val = G1Native::random_element();
178 G1Native P1_val = G1Native::random_element();
179 ScalarFieldGrumpkinNative challenge_val = ScalarFieldGrumpkinNative::random_element();
180 ScalarFieldGrumpkinNative evaluation_val = ScalarFieldGrumpkinNative::random_element();
181 G1GrumpkinNative commitment_val = G1GrumpkinNative::random_element();
182
183 // Store the public inputs of the circuit
185
186 { // The circuit propagates the outputs via its public inputs
188
189 RollupIO rollup_io_output;
190
191 // Set the output values
192 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
193 IpaClaim ipa_claim{ { ScalarFieldGrumpkin::from_witness(&builder, challenge_val),
194 ScalarFieldGrumpkin::from_witness(&builder, evaluation_val) },
195 G1Grumpkin::from_witness(&builder, commitment_val) };
196 rollup_io_output.pairing_inputs = pairing_inputs;
197 rollup_io_output.ipa_claim = ipa_claim;
198
199 // Propagate the kernel output via the public inputs
200 rollup_io_output.set_public();
201
202 // Store the public inputs from this circuit for use in the second circuit
203 for (const auto& idx : builder.public_inputs()) {
204 public_inputs.push_back(builder.get_variable(idx));
205 }
206 }
207
208 {
209 // The second circuit reconstructs the inputs from the public inputs
211
212 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
213 std::vector<ScalarFieldBn254> stdlib_public_inputs;
214 stdlib_public_inputs.reserve(public_inputs.size());
215 for (const auto& val : public_inputs) {
216 stdlib_public_inputs.push_back(ScalarFieldBn254::from_witness(&builder, val));
217 }
218
219 RollupIO rollup_io_input;
220 rollup_io_input.reconstruct_from_public(stdlib_public_inputs);
221
222 // Ensure the reconstructed data matches the original values
223 EXPECT_EQ(rollup_io_input.pairing_inputs.P0.get_value(), P0_val);
224 EXPECT_EQ(rollup_io_input.pairing_inputs.P1.get_value(), P1_val);
225 EXPECT_EQ(rollup_io_input.ipa_claim.opening_pair.challenge.get_value(), static_cast<uint512_t>(challenge_val));
226 EXPECT_EQ(rollup_io_input.ipa_claim.opening_pair.evaluation.get_value(),
227 static_cast<uint512_t>(evaluation_val));
228 EXPECT_EQ(rollup_io_input.ipa_claim.commitment.get_value(), commitment_val);
229 }
230
231 {
232 // Reconstruct the public inputs from native elements
233 RollUpIONative rollup_io_input_native;
234 rollup_io_input_native.reconstruct_from_public(public_inputs);
235
236 // Ensure the reconstructed data matches the original values
237 EXPECT_EQ(rollup_io_input_native.pairing_inputs.P0, P0_val);
238 EXPECT_EQ(rollup_io_input_native.pairing_inputs.P1, P1_val);
239 EXPECT_EQ(rollup_io_input_native.ipa_claim.opening_pair.challenge, challenge_val);
240 EXPECT_EQ(rollup_io_input_native.ipa_claim.opening_pair.evaluation, evaluation_val);
241 EXPECT_EQ(rollup_io_input_native.ipa_claim.commitment, commitment_val);
242 }
243}
244
245// Demonstrates the basic functionality of the HidingKernelIO class for propagating public inputs between circuits
247{
249
250 // IO classes
251 using HidingIO = HidingKernelIO<Builder>;
252 using HidingIONative = bb::HidingKernelIO;
253
254 // Recursive types
255 using Curve = HidingIO::Curve;
256 using G1 = HidingIO::G1;
257 using FF = HidingIO::FF;
258 using PairingInputs = HidingIO::PairingInputs;
259
260 // Native types
261 using G1Native = Curve::GroupNative::affine_element;
262 using FFNative = Curve::ScalarFieldNative;
263
264 static constexpr size_t NUM_WIRES = Builder::NUM_WIRES;
265
266 G1Native P0_val = G1Native::random_element();
267 G1Native P1_val = G1Native::random_element();
268 std::array<G1Native, NUM_WIRES> ecc_op_tables_val;
269 for (auto& commitment : ecc_op_tables_val) {
270 commitment = G1Native::random_element();
271 }
272
273 // Store the public inputs of the first circuit to be used by the second
274 std::vector<FFNative> public_inputs;
275
276 { // The first circuit propagates the kernel output via its public inputs
278
279 HidingIO hiding_output;
280
281 // Set the output values
282 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
283 hiding_output.pairing_inputs = pairing_inputs;
284
285 for (auto [table_commitment, table_val] : zip_view(hiding_output.ecc_op_tables, ecc_op_tables_val)) {
286 table_commitment = G1::from_witness(&builder, table_val);
287 }
288
289 // Propagate the kernel output via the public inputs
290 hiding_output.set_public();
291
292 // Store the public inputs from this circuit for use in the second circuit
293 for (const auto& idx : builder.public_inputs()) {
294 public_inputs.push_back(builder.get_variable(idx));
295 }
296 }
297
298 {
299 // The second circuit reconstructs the kernel inputs from the public inputs
301
302 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the
303 // proof)
304 std::vector<FF> stdlib_public_inputs;
305 stdlib_public_inputs.reserve(public_inputs.size());
306 for (const auto& val : public_inputs) {
307 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
308 }
309
310 HidingIO hiding_input;
311 hiding_input.reconstruct_from_public(stdlib_public_inputs);
312
313 // Ensure the reconstructed data matches the original values
314 EXPECT_EQ(hiding_input.pairing_inputs.P0.get_value(), P0_val);
315 EXPECT_EQ(hiding_input.pairing_inputs.P1.get_value(), P1_val);
316 for (auto [reconstructed_commitment, commitment] : zip_view(hiding_input.ecc_op_tables, ecc_op_tables_val)) {
317 EXPECT_EQ(reconstructed_commitment.get_value(), commitment);
318 }
319 }
320
321 {
322 // Reconstruct the public inputs from native elements
323 HidingIONative hiding_input_native;
324 hiding_input_native.reconstruct_from_public(public_inputs);
325
326 // Ensure the reconstructed data matches the original values
327 EXPECT_EQ(hiding_input_native.pairing_inputs.P0, P0_val);
328 EXPECT_EQ(hiding_input_native.pairing_inputs.P1, P1_val);
329 for (auto [reconstructed_commitment, commitment] :
330 zip_view(hiding_input_native.ecc_op_tables, ecc_op_tables_val)) {
331 EXPECT_EQ(reconstructed_commitment, commitment);
332 }
333 }
334}
335
336} // namespace bb::stdlib::recursion::honk
Manages the data that is propagated on the public inputs of an application/function circuit.
Manages the data that is propagated on the public inputs of of a hiding kernel circuit.
OpeningPair< Curve > opening_pair
Definition claim.hpp:62
Commitment commitment
Definition claim.hpp:64
The data that is propagated on the public inputs of a rollup circuit.
static constexpr size_t NUM_WIRES
typename grumpkin::g1 Group
Definition grumpkin.hpp:54
cycle_group represents a group Element of the proving system's embedded curve i.e....
Manages the data that is propagated on the public inputs of an application/function circuit.
Manages the data that is propagated on the public inputs of a hiding kernel circuit.
Manages the data that is propagated on the public inputs of a kernel circuit.
stdlib::recursion::PairingPoints< Builder > PairingInputs
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.
stdlib::bn254< Builder >::ScalarField FF
void set_public()
Set each IO component to be a public input of the underlying circuit.
OpeningClaim< stdlib::grumpkin< Builder > > IpaClaim
stdlib::recursion::PairingPoints< Builder > PairingInputs
AluTraceBuilder builder
Definition alu.test.cpp:123
TEST_F(BoomerangGoblinRecursiveVerifierTests, graph_description_basic)
Construct and check a goblin recursive verification circuit.
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Curve::AffineElement G1