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();
27 G1Native app_return_data_val = G1Native::random_element();
28 FFNative ecc_op_hash_val = FFNative::random_element();
29 FFNative output_hn_accum_hash_val = FFNative::random_element();
30
31 // Store the public inputs of the first circuit to be used by the second
32 std::vector<FFNative> public_inputs;
33
34 { // The first circuit propagates the kernel output via its public inputs
36
37 KernelIO kernel_output;
38
39 // Set the output values
40 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
41 kernel_output.pairing_inputs = pairing_inputs;
42 kernel_output.kernel_return_data = G1::from_witness(&builder, kernel_return_data_val);
43 kernel_output.app_return_data = G1::from_witness(&builder, app_return_data_val);
44 kernel_output.ecc_op_hash = FF::from_witness(&builder, ecc_op_hash_val);
45 kernel_output.output_hn_accum_hash = FF::from_witness(&builder, output_hn_accum_hash_val);
46
47 // Propagate the kernel output via the public inputs
48 kernel_output.set_public();
49
50 // Store the public inputs from this circuit for use in the second circuit
51 for (const auto& idx : builder.public_inputs()) {
52 public_inputs.push_back(builder.get_variable(idx));
53 }
54 }
55
56 { // The second circuit reconstructs the kernel inputs from the public inputs
58
59 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
60 std::vector<FF> stdlib_public_inputs;
61 stdlib_public_inputs.reserve(public_inputs.size());
62 for (const auto& val : public_inputs) {
63 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
64 }
65
66 KernelIO kernel_input;
67 kernel_input.reconstruct_from_public(stdlib_public_inputs);
68
69 // Ensure the reconstructed data matches the original values
70 EXPECT_EQ(kernel_input.pairing_inputs.P0().get_value(), P0_val);
71 EXPECT_EQ(kernel_input.pairing_inputs.P1().get_value(), P1_val);
72 EXPECT_EQ(kernel_input.kernel_return_data.get_value(), kernel_return_data_val);
73 EXPECT_EQ(kernel_input.app_return_data.get_value(), app_return_data_val);
74 EXPECT_EQ(kernel_input.ecc_op_hash.get_value(), ecc_op_hash_val);
75 EXPECT_EQ(kernel_input.output_hn_accum_hash.get_value(), output_hn_accum_hash_val);
76 }
77}
78
79// Demonstrates the basic functionality of the DefaultIO class
81{
83 using IO = DefaultIO<Builder>;
84 using IONative = bb::DefaultIO;
85
86 using Curve = IO::Curve;
87 using FF = IO::Curve::ScalarField;
88 using G1 = Curve::Group;
89 using PairingInputs = IO::PairingInputs;
90
91 using G1Native = Curve::GroupNative::affine_element;
92 using FFNative = IONative::FF;
93
94 G1Native P0_val = G1Native::random_element();
95 G1Native P1_val = G1Native::random_element();
96
97 // Store the public inputs of the circuit
98 std::vector<FFNative> public_inputs;
99
100 { // The circuit propagates the outputs via its public inputs
102
103 IO io_output;
104
105 // Set the output values
106 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
107 io_output.pairing_inputs = pairing_inputs;
108
109 // Propagate the output via the public inputs
110 io_output.set_public();
111
112 // Store the public inputs from this circuit for use in the second circuit
113 for (const auto& idx : builder.public_inputs()) {
114 public_inputs.push_back(builder.get_variable(idx));
115 }
116 }
117
118 {
119 // The second circuit reconstructs the inputs from the public inputs
121
122 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
123 std::vector<FF> stdlib_public_inputs;
124 stdlib_public_inputs.reserve(public_inputs.size());
125 for (const auto& val : public_inputs) {
126 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
127 }
128
129 IO io_input;
130 io_input.reconstruct_from_public(stdlib_public_inputs);
131
132 // Ensure the reconstructed data matches the original values
133 EXPECT_EQ(io_input.pairing_inputs.P0().get_value(), P0_val);
134 EXPECT_EQ(io_input.pairing_inputs.P1().get_value(), P1_val);
135 }
136
137 {
138 // Reconstruct the public inputs from native elements
139 IONative io_input_native;
140 io_input_native.reconstruct_from_public(public_inputs);
141
142 // Ensure the reconstructed data matches the original values
143 EXPECT_EQ(io_input_native.pairing_inputs.P0(), P0_val);
144 EXPECT_EQ(io_input_native.pairing_inputs.P1(), P1_val);
145 }
146}
147
148// Demonstrates the basic functionality of the RollUpIO class
150{
152 using RollUpIONative = bb::RollupIO;
153
154 using Curve = RollupIO::Curve;
155 using ScalarFieldBn254 = RollupIO::FF;
156 using ScalarFieldGrumpkin = Curve::BaseField;
157 using G1 = Curve::Group;
158 using G1Grumpkin = bb::stdlib::grumpkin<Builder>::Group;
159 using PairingInputs = RollupIO::PairingInputs;
160 using IpaClaim = RollupIO::IpaClaim;
161
162 using G1Native = Curve::GroupNative::affine_element;
163 using ScalarFieldBn254Native = RollUpIONative::FF;
164 using GrumpkinNative = bb::curve::Grumpkin;
165 using G1GrumpkinNative = GrumpkinNative::AffineElement;
166 using ScalarFieldGrumpkinNative = GrumpkinNative::ScalarField;
167
168 G1Native P0_val = G1Native::random_element();
169 G1Native P1_val = G1Native::random_element();
170 ScalarFieldGrumpkinNative challenge_val = ScalarFieldGrumpkinNative::random_element();
171 ScalarFieldGrumpkinNative evaluation_val = ScalarFieldGrumpkinNative::random_element();
172 G1GrumpkinNative commitment_val = G1GrumpkinNative::random_element();
173
174 // Store the public inputs of the circuit
176
177 { // The circuit propagates the outputs via its public inputs
179
180 RollupIO rollup_io_output;
181
182 // Set the output values
183 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
184 IpaClaim ipa_claim{ { ScalarFieldGrumpkin::from_witness(&builder, challenge_val),
185 ScalarFieldGrumpkin::from_witness(&builder, evaluation_val) },
186 G1Grumpkin::from_witness(&builder, commitment_val) };
187 rollup_io_output.pairing_inputs = pairing_inputs;
188 rollup_io_output.ipa_claim = ipa_claim;
189
190 // Propagate the kernel output via the public inputs
191 rollup_io_output.set_public();
192
193 // Store the public inputs from this circuit for use in the second circuit
194 for (const auto& idx : builder.public_inputs()) {
195 public_inputs.push_back(builder.get_variable(idx));
196 }
197 }
198
199 {
200 // The second circuit reconstructs the inputs from the public inputs
202
203 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
204 std::vector<ScalarFieldBn254> stdlib_public_inputs;
205 stdlib_public_inputs.reserve(public_inputs.size());
206 for (const auto& val : public_inputs) {
207 stdlib_public_inputs.push_back(ScalarFieldBn254::from_witness(&builder, val));
208 }
209
210 RollupIO rollup_io_input;
211 rollup_io_input.reconstruct_from_public(stdlib_public_inputs);
212
213 // Ensure the reconstructed data matches the original values
214 EXPECT_EQ(rollup_io_input.pairing_inputs.P0().get_value(), P0_val);
215 EXPECT_EQ(rollup_io_input.pairing_inputs.P1().get_value(), P1_val);
216 EXPECT_EQ(rollup_io_input.ipa_claim.opening_pair.challenge.get_value(), static_cast<uint512_t>(challenge_val));
217 EXPECT_EQ(rollup_io_input.ipa_claim.opening_pair.evaluation.get_value(),
218 static_cast<uint512_t>(evaluation_val));
219 EXPECT_EQ(rollup_io_input.ipa_claim.commitment.get_value(), commitment_val);
220 }
221
222 {
223 // Reconstruct the public inputs from native elements
224 RollUpIONative rollup_io_input_native;
225 rollup_io_input_native.reconstruct_from_public(public_inputs);
226
227 // Ensure the reconstructed data matches the original values
228 EXPECT_EQ(rollup_io_input_native.pairing_inputs.P0(), P0_val);
229 EXPECT_EQ(rollup_io_input_native.pairing_inputs.P1(), P1_val);
230 EXPECT_EQ(rollup_io_input_native.ipa_claim.opening_pair.challenge, challenge_val);
231 EXPECT_EQ(rollup_io_input_native.ipa_claim.opening_pair.evaluation, evaluation_val);
232 EXPECT_EQ(rollup_io_input_native.ipa_claim.commitment, commitment_val);
233 }
234}
235
236// Demonstrates the basic functionality of the HidingKernelIO class for propagating public inputs between circuits
238{
240
241 // IO classes
242 using HidingIO = HidingKernelIO<Builder>;
243 using HidingIONative = bb::HidingKernelIO;
244
245 // Recursive types
246 using Curve = HidingIO::Curve;
247 using G1 = HidingIO::G1;
248 using FF = HidingIO::FF;
249 using PairingInputs = HidingIO::PairingInputs;
250
251 // Native types
252 using G1Native = Curve::GroupNative::affine_element;
253 using FFNative = Curve::ScalarFieldNative;
254
255 static constexpr size_t NUM_WIRES = Builder::NUM_WIRES;
256
257 G1Native P0_val = G1Native::random_element();
258 G1Native P1_val = G1Native::random_element();
259 G1Native return_data_val = G1Native::random_element();
260 std::array<G1Native, NUM_WIRES> ecc_op_tables_val;
261 for (auto& commitment : ecc_op_tables_val) {
262 commitment = G1Native::random_element();
263 }
264
265 // Store the public inputs of the first circuit to be used by the second
266 std::vector<FFNative> public_inputs;
267
268 { // The first circuit propagates the kernel output via its public inputs
270
271 HidingIO hiding_output;
272
273 // Set the output values
274 PairingInputs pairing_inputs{ G1::from_witness(&builder, P0_val), G1::from_witness(&builder, P1_val) };
275 hiding_output.pairing_inputs = pairing_inputs;
276 hiding_output.kernel_return_data = G1::from_witness(&builder, return_data_val);
277
278 for (auto [table_commitment, table_val] : zip_view(hiding_output.ecc_op_tables, ecc_op_tables_val)) {
279 table_commitment = G1::from_witness(&builder, table_val);
280 }
281
282 // Propagate the kernel output via the public inputs
283 hiding_output.set_public();
284
285 // Store the public inputs from this circuit for use in the second circuit
286 for (const auto& idx : builder.public_inputs()) {
287 public_inputs.push_back(builder.get_variable(idx));
288 }
289 }
290
291 {
292 // The second circuit reconstructs the kernel inputs from the public inputs
294
295 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the
296 // proof)
297 std::vector<FF> stdlib_public_inputs;
298 stdlib_public_inputs.reserve(public_inputs.size());
299 for (const auto& val : public_inputs) {
300 stdlib_public_inputs.push_back(FF::from_witness(&builder, val));
301 }
302
303 HidingIO hiding_input;
304 hiding_input.reconstruct_from_public(stdlib_public_inputs);
305
306 // Ensure the reconstructed data matches the original values
307 EXPECT_EQ(hiding_input.pairing_inputs.P0().get_value(), P0_val);
308 EXPECT_EQ(hiding_input.pairing_inputs.P1().get_value(), P1_val);
309 EXPECT_EQ(hiding_input.kernel_return_data.get_value(), return_data_val);
310 for (auto [reconstructed_commitment, commitment] : zip_view(hiding_input.ecc_op_tables, ecc_op_tables_val)) {
311 EXPECT_EQ(reconstructed_commitment.get_value(), commitment);
312 }
313 }
314
315 {
316 // Reconstruct the public inputs from native elements
317 HidingIONative hiding_input_native;
318 hiding_input_native.reconstruct_from_public(public_inputs);
319
320 // Ensure the reconstructed data matches the original values
321 EXPECT_EQ(hiding_input_native.pairing_inputs.P0(), P0_val);
322 EXPECT_EQ(hiding_input_native.pairing_inputs.P1(), P1_val);
323 EXPECT_EQ(hiding_input_native.kernel_return_data, return_data_val);
324 for (auto [reconstructed_commitment, commitment] :
325 zip_view(hiding_input_native.ecc_op_tables, ecc_op_tables_val)) {
326 EXPECT_EQ(reconstructed_commitment, commitment);
327 }
328 }
329}
330
331} // 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 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::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