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:
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 G1Native P0_val = G1Native::random_element();
25 G1Native P1_val = G1Native::random_element();
26 G1Native kernel_return_data_val = G1Native::random_element();
28 for (auto& value : app_return_data_val) {
29 value = G1Native::random_element();
30 }
31 FFNative ecc_op_hash_val = FFNative::random_element();
32 FFNative output_hn_accum_hash_val = FFNative::random_element();
33
34 // Store the public inputs of the first circuit to be used by the second
35 std::vector<FFNative> public_inputs;
36
37 { // The first circuit propagates the kernel output via its public inputs
39
40 KernelIO kernel_output;
41
42 // Set the output values
43 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
44 kernel_output.pairing_inputs = pairing_inputs;
45 kernel_output.kernel_return_data = G1::from_witness(&builder, kernel_return_data_val);
46 for (size_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
47 kernel_output.app_return_data[idx] = G1::from_witness(&builder, app_return_data_val[idx]);
48 }
49 kernel_output.ecc_op_hash = FF::from_witness(&builder, ecc_op_hash_val);
50 kernel_output.output_hn_accum_hash = FF::from_witness(&builder, output_hn_accum_hash_val);
51
52 // Propagate the kernel output via the public inputs
53 kernel_output.set_public();
54
55 // Store the public inputs from this circuit for use in the second circuit
56 for (const auto& idx : builder.public_inputs()) {
57 public_inputs.push_back(builder.get_variable(idx));
58 }
59 }
60
61 { // The second circuit reconstructs the kernel inputs from the public inputs
63
64 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
65 std::vector<FF> stdlib_public_inputs;
66 stdlib_public_inputs.reserve(public_inputs.size());
67 for (const auto& val : public_inputs) {
68 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
69 }
70
71 KernelIO kernel_input;
72 kernel_input.reconstruct_from_public(stdlib_public_inputs);
73
74 // Ensure the reconstructed data matches the original values
75 EXPECT_EQ(kernel_input.pairing_inputs.P0().get_value(), P0_val);
76 EXPECT_EQ(kernel_input.pairing_inputs.P1().get_value(), P1_val);
77 EXPECT_EQ(kernel_input.kernel_return_data.get_value(), kernel_return_data_val);
78 for (size_t idx = 0; idx < MAX_APPS_PER_KERNEL; ++idx) {
79 EXPECT_EQ(kernel_input.app_return_data[idx].get_value(), app_return_data_val[idx]);
80 }
81 EXPECT_EQ(kernel_input.ecc_op_hash.get_value(), ecc_op_hash_val);
82 EXPECT_EQ(kernel_input.output_hn_accum_hash.get_value(), output_hn_accum_hash_val);
83 }
84}
85
86// Demonstrates the basic functionality of the DefaultIO class
88{
90 using IO = DefaultIO<Builder>;
91 using IONative = bb::DefaultIO;
92
93 using Curve = IO::Curve;
94 using FF = IO::Curve::ScalarField;
95 using G1 = Curve::Group;
96 using PairingInputs = IO::PairingInputs;
97
98 using G1Native = Curve::GroupNative::affine_element;
99 using FFNative = IONative::FF;
100
101 G1Native P0_val = G1Native::random_element();
102 G1Native P1_val = G1Native::random_element();
103
104 // Store the public inputs of the circuit
105 std::vector<FFNative> public_inputs;
106
107 { // The circuit propagates the outputs via its public inputs
109
110 IO io_output;
111
112 // Set the output values
113 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
114 io_output.pairing_inputs = pairing_inputs;
115
116 // Propagate the output via the public inputs
117 io_output.set_public();
118
119 // Store the public inputs from this circuit for use in the second circuit
120 for (const auto& idx : builder.public_inputs()) {
121 public_inputs.push_back(builder.get_variable(idx));
122 }
123 }
124
125 {
126 // The second circuit reconstructs the inputs from the public inputs
128
129 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
130 std::vector<FF> stdlib_public_inputs;
131 stdlib_public_inputs.reserve(public_inputs.size());
132 for (const auto& val : public_inputs) {
133 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
134 }
135
136 IO io_input;
137 io_input.reconstruct_from_public(stdlib_public_inputs);
138
139 // Ensure the reconstructed data matches the original values
140 EXPECT_EQ(io_input.pairing_inputs.P0().get_value(), P0_val);
141 EXPECT_EQ(io_input.pairing_inputs.P1().get_value(), P1_val);
142 }
143
144 {
145 // Reconstruct the public inputs from native elements
146 IONative io_input_native;
147 io_input_native.reconstruct_from_public(public_inputs);
148
149 // Ensure the reconstructed data matches the original values
150 EXPECT_EQ(io_input_native.pairing_inputs.P0(), P0_val);
151 EXPECT_EQ(io_input_native.pairing_inputs.P1(), P1_val);
152 }
153}
154
155// Demonstrates the basic functionality of the RollUpIO class
157{
159 using RollUpIONative = bb::RollupIO;
160
161 using Curve = RollupIO::Curve;
162 using ScalarFieldBn254 = RollupIO::FF;
163 using ScalarFieldGrumpkin = Curve::BaseField;
164 using G1 = Curve::Group;
165 using G1Grumpkin = bb::stdlib::grumpkin<Builder>::Group;
166 using PairingInputs = RollupIO::PairingInputs;
167 using IpaClaim = RollupIO::IpaClaim;
168
169 using G1Native = Curve::GroupNative::affine_element;
170 using ScalarFieldBn254Native = RollUpIONative::FF;
171 using GrumpkinNative = bb::curve::Grumpkin;
172 using G1GrumpkinNative = GrumpkinNative::AffineElement;
173 using ScalarFieldGrumpkinNative = GrumpkinNative::ScalarField;
174
175 G1Native P0_val = G1Native::random_element();
176 G1Native P1_val = G1Native::random_element();
177 ScalarFieldGrumpkinNative challenge_val = ScalarFieldGrumpkinNative::random_element();
178 ScalarFieldGrumpkinNative evaluation_val = ScalarFieldGrumpkinNative::random_element();
179 G1GrumpkinNative commitment_val = G1GrumpkinNative::random_element();
180
181 // Store the public inputs of the circuit
183
184 { // The circuit propagates the outputs via its public inputs
186
187 RollupIO rollup_io_output;
188
189 // Set the output values
190 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
191 IpaClaim ipa_claim{ { ScalarFieldGrumpkin::from_witness(&builder, challenge_val),
192 ScalarFieldGrumpkin::from_witness(&builder, evaluation_val) },
193 G1Grumpkin::from_witness(&builder, commitment_val) };
194 rollup_io_output.pairing_inputs = pairing_inputs;
195 rollup_io_output.ipa_claim = ipa_claim;
196
197 // Propagate the kernel output via the public inputs
198 rollup_io_output.set_public();
199
200 // Store the public inputs from this circuit for use in the second circuit
201 for (const auto& idx : builder.public_inputs()) {
202 public_inputs.push_back(builder.get_variable(idx));
203 }
204 }
205
206 {
207 // The second circuit reconstructs the inputs from the public inputs
209
210 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
211 std::vector<ScalarFieldBn254> stdlib_public_inputs;
212 stdlib_public_inputs.reserve(public_inputs.size());
213 for (const auto& val : public_inputs) {
214 stdlib_public_inputs.push_back(ScalarFieldBn254::from_witness(&builder, val));
215 }
216
217 RollupIO rollup_io_input;
218 rollup_io_input.reconstruct_from_public(stdlib_public_inputs);
219
220 // Ensure the reconstructed data matches the original values
221 EXPECT_EQ(rollup_io_input.pairing_inputs.P0().get_value(), P0_val);
222 EXPECT_EQ(rollup_io_input.pairing_inputs.P1().get_value(), P1_val);
223 EXPECT_EQ(rollup_io_input.ipa_claim.opening_pair.challenge.get_value(), static_cast<uint512_t>(challenge_val));
224 EXPECT_EQ(rollup_io_input.ipa_claim.opening_pair.evaluation.get_value(),
225 static_cast<uint512_t>(evaluation_val));
226 EXPECT_EQ(rollup_io_input.ipa_claim.commitment.get_value(), commitment_val);
227 }
228
229 {
230 // Reconstruct the public inputs from native elements
231 RollUpIONative rollup_io_input_native;
232 rollup_io_input_native.reconstruct_from_public(public_inputs);
233
234 // Ensure the reconstructed data matches the original values
235 EXPECT_EQ(rollup_io_input_native.pairing_inputs.P0(), P0_val);
236 EXPECT_EQ(rollup_io_input_native.pairing_inputs.P1(), P1_val);
237 EXPECT_EQ(rollup_io_input_native.ipa_claim.opening_pair.challenge, challenge_val);
238 EXPECT_EQ(rollup_io_input_native.ipa_claim.opening_pair.evaluation, evaluation_val);
239 EXPECT_EQ(rollup_io_input_native.ipa_claim.commitment, commitment_val);
240 }
241}
242
243// Demonstrates the basic functionality of the HidingKernelIO class for propagating public inputs between circuits
245{
247
248 // IO classes
249 using HidingIO = HidingKernelIO<Builder>;
250 using HidingIONative = bb::HidingKernelIO;
251
252 // Recursive types
253 using Curve = HidingIO::Curve;
254 using G1 = HidingIO::G1;
255 using FF = HidingIO::FF;
256 using PairingInputs = HidingIO::PairingInputs;
257
258 // Native types
259 using G1Native = Curve::GroupNative::affine_element;
260 using FFNative = Curve::ScalarFieldNative;
261
262 static constexpr size_t NUM_WIRES = Builder::NUM_WIRES;
263
264 G1Native P0_val = G1Native::random_element();
265 G1Native P1_val = G1Native::random_element();
266 G1Native return_data_val = G1Native::random_element();
267 std::array<G1Native, NUM_WIRES> ecc_op_tables_val;
268 for (auto& commitment : ecc_op_tables_val) {
269 commitment = G1Native::random_element();
270 }
271
272 // Store the public inputs of the first circuit to be used by the second
273 std::vector<FFNative> public_inputs;
274
275 { // The first circuit propagates the kernel output via its public inputs
277
278 HidingIO hiding_output;
279
280 // Set the output values
281 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
282 hiding_output.pairing_inputs = pairing_inputs;
283 hiding_output.kernel_return_data = G1::from_witness(&builder, return_data_val);
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 EXPECT_EQ(hiding_input.kernel_return_data.get_value(), return_data_val);
317 for (auto [reconstructed_commitment, commitment] : zip_view(hiding_input.ecc_op_tables, ecc_op_tables_val)) {
318 EXPECT_EQ(reconstructed_commitment.get_value(), commitment);
319 }
320 }
321
322 {
323 // Reconstruct the public inputs from native elements
324 HidingIONative hiding_input_native;
325 hiding_input_native.reconstruct_from_public(public_inputs);
326
327 // Ensure the reconstructed data matches the original values
328 EXPECT_EQ(hiding_input_native.pairing_inputs.P0(), P0_val);
329 EXPECT_EQ(hiding_input_native.pairing_inputs.P1(), P1_val);
330 EXPECT_EQ(hiding_input_native.kernel_return_data, return_data_val);
331 for (auto [reconstructed_commitment, commitment] :
332 zip_view(hiding_input_native.ecc_op_tables, ecc_op_tables_val)) {
333 EXPECT_EQ(reconstructed_commitment, commitment);
334 }
335 }
336}
337
338} // 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:64
Commitment commitment
Definition claim.hpp:66
The data that is propagated on the public inputs of a rollup circuit.
typename grumpkin::g1 Group
Definition grumpkin.hpp:62
cycle_group represents a group Element of the proving system's embedded curve, i.e....
bb::fr get_value() const
Given a := *this, compute its value given by a.v * a.mul + a.add.
Definition field.cpp:838
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< Curve > PairingInputs
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.
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::recursion::PairingPoints< Curve > PairingInputs
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
AluTraceBuilder builder
Definition alu.test.cpp:124
AvmFlavorSettings::FF FF
Definition field.hpp:10
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
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