Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
public_input_component.test.cpp
Go to the documentation of this file.
1
2#include <gtest/gtest.h>
3
10
11using namespace bb;
12
13namespace {
15}
16
21TEST(PublicInputComponentTest, GoblinBigGroup)
22{
25 using G1 = Curve::Element;
26 using Fr = Curve::ScalarField;
27 using AffineElementNative = Curve::GroupNative::affine_element;
28 using FrNative = Curve::ScalarFieldNative;
29 using PublicPoint = stdlib::PublicInputComponent<G1>;
30 using PublicPointNative = bb::PublicInputComponent<AffineElementNative>;
31
32 AffineElementNative point_value = AffineElementNative::random_element();
33
34 // The data needed by the second circuit to reconstruct the public point
35 std::vector<FrNative> public_inputs;
36 PublicPoint::Key public_point_key;
37
38 // The first circuit propagates a point via its public inputs
39 {
41
42 // Add some arbitrary public inputs for good measure
43 builder.add_public_variable(FrNative::random_element());
44 builder.add_public_variable(FrNative::random_element());
45
46 // Construct a stdlib point (e.g. representing a commitment received in the recursive verifier)
47 G1 point = G1::from_witness(&builder, point_value);
48
49 // Construct a public object from the point; store the key used to reconstruct it from the public inputs
50 public_point_key = PublicPoint::set(point);
51
52 // Add some more arbitrary public inputs
53 builder.add_public_variable(FrNative::random_element());
54
55 // Store the public inputs from the builder
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 public point from the public inputs and the public component key
62 {
64
65 // Construct the stdlib public inputs (e.g. as a recursive verifier would do upon receiving them in the proof)
66 std::vector<Fr> stdlib_public_inputs;
67 stdlib_public_inputs.reserve(public_inputs.size());
68 for (const auto& val : public_inputs) {
69 stdlib_public_inputs.push_back(Fr::from_witness(&builder, val));
70 }
71
72 // Reconstruct the stdlib point from the public inputs and the public component key
73 G1 reconstructed_point = PublicPoint::reconstruct(stdlib_public_inputs, public_point_key);
74
75 // Ensure the reconstructed point matches the original point
76 EXPECT_EQ(point_value, reconstructed_point.get_value());
77 }
78
79 // Reconstruct from native public inputs
80 {
81 // Reconstruct the point from the native public inputs and the public component key
82 AffineElementNative reconstructed_point = PublicPointNative::reconstruct(public_inputs, public_point_key);
83
84 // Ensure the reconstructed point matches the original point
85 EXPECT_EQ(point_value, reconstructed_point);
86 }
87}
A wrapper class for deserializing objects from the public inputs of a circuit.
typename Group::element Element
Definition grumpkin.hpp:55
A wrapper class for serializing objects to and from the public inputs of a circuit.
AluTraceBuilder builder
Definition alu.test.cpp:123
numeric::RNG & engine
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition engine.cpp:190
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
MegaCircuitBuilder_< field< Bn254FrParams > > MegaCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Curve::AffineElement G1