7#include <gtest/gtest.h>
21 using Builder =
typename TypeParam::Builder;
22 static constexpr size_t NUM_GATES_ADDED = 8;
26 size_t num_gates =
builder.num_gates();
28 EXPECT_EQ(NUM_GATES_ADDED,
builder.num_gates() - num_gates)
29 <<
"There has been a change in the number of gates required to set default PairingPoints as public inputs.";
36 using Builder = TypeParam::Builder;
42 Group P0(DEFAULT_PAIRING_POINT_P0_X, DEFAULT_PAIRING_POINT_P0_Y,
false);
43 Group P1(DEFAULT_PAIRING_POINT_P1_X, DEFAULT_PAIRING_POINT_P1_Y,
false);
44 P0.convert_constant_to_fixed_witness(&
builder);
45 P1.convert_constant_to_fixed_witness(&
builder);
53 EXPECT_TRUE(native_pp.
check()) <<
"Default PairingPoints are not valid pairing points.";
58 using Curve = TypeParam;
59 using Builder =
typename Curve::Builder;
63 using NativeFr =
typename Curve::ScalarFieldNative;
67 Fr scalar_one = Fr::from_witness(&
builder, NativeFr::random_element());
68 Fr scalar_two = Fr::from_witness(&
builder, NativeFr::random_element());
69 Group P0 = Group::batch_mul({ Group::one(&
builder) }, { scalar_one });
70 Group P1 = Group::batch_mul({ Group::one(&
builder) }, { scalar_two });
73 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
83 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
90 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
101 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
113 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
119 using Curve = TypeParam;
120 using Builder =
typename Curve::Builder;
124 using NativeFr =
typename Curve::ScalarFieldNative;
130 Fr scalar_one = Fr::from_witness(&
builder, NativeFr::random_element());
131 Fr scalar_two = Fr::from_witness(&
builder, NativeFr::random_element());
132 Group P0 = Group::batch_mul({ Group::one(&
builder) }, { scalar_one });
133 Group P1 = Group::batch_mul({ Group::one(&
builder) }, { scalar_two });
145 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
148 pp_one.aggregate(pp_two);
151 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
156 "Pairing points must all be aggregated together. Either no pairing points should be created, or "
157 "all created pairing points must be aggregated into a single pairing point. Found 2 different "
161 pp_one.aggregate(pp_three);
166 "Pairing points must be set to public in the circuit before constructing the ProverInstance.");
178 using Curve = TypeParam;
179 using Builder =
typename Curve::Builder;
184 using NativeFr = Curve::ScalarFieldNative;
188 Fr scalar_one = Fr::from_witness(&
builder, NativeFr::random_element());
189 Fr scalar_two = Fr::from_witness(&
builder, NativeFr::random_element());
190 Group P0 = Group::batch_mul({ Group::one(&
builder) }, { scalar_one });
191 Group P1 = Group::batch_mul({ Group::one(&
builder) }, { scalar_two });
197 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
206 using Curve = TypeParam;
207 using Builder =
typename Curve::Builder;
214 Group P0(DEFAULT_PAIRING_POINT_P0_X, DEFAULT_PAIRING_POINT_P0_Y,
false);
215 Group P1(DEFAULT_PAIRING_POINT_P1_X, DEFAULT_PAIRING_POINT_P1_Y,
false);
216 P0.convert_constant_to_fixed_witness(&
builder);
217 P1.convert_constant_to_fixed_witness(&
builder);
235 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
241 for (
size_t idx = 0; idx < 3; ++idx) {
243 transcript.add_to_hash_buffer(
"second_component_" +
std::to_string(idx), pp_vector[idx].P1());
246 std::array<Fr, 2> challenges = transcript.template get_challenges<Fr, 2>(challenge_labels);
249 Fr total_scalar =
Fr(1);
250 for (
const auto& challenge : challenges) {
251 total_scalar += challenge;
253 Group expected_P0 = P0 * total_scalar;
254 Group expected_P1 = P1 * total_scalar;
257 EXPECT_EQ(aggregated.
P0().get_value(), expected_P0.get_value()) <<
"Aggregated P0 should equal (1 + r₁ + r₂)·P0";
258 EXPECT_EQ(aggregated.
P1().get_value(), expected_P1.get_value()) <<
"Aggregated P1 should equal (1 + r₁ + r₂)·P1";
262 aggregated.
P1().get_value());
263 EXPECT_TRUE(native_aggregated.
check())
264 <<
"Aggregated duplicate pairing points should still satisfy pairing equation";
#define BB_ASSERT_EQ(actual, expected,...)
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
void add_to_hash_buffer(const std::string &label, const T &element)
Adds an element to the transcript.
CommitmentKey object over a pairing group 𝔾₁.
An object storing two EC points that represent the inputs to a pairing check.
bool check() const
Perform the pairing check.
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
static void SetUpTestSuite()
Manages the data that is propagated on the public inputs of an application/function circuit.
PairingInputs pairing_inputs
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
TYPED_TEST(PairingPointsTests, ConstructDefault)
TYPED_TEST_SUITE(PairingPointsTests, Curves)
testing::Types< stdlib::bn254< UltraCircuitBuilder >, stdlib::bn254< MegaCircuitBuilder > > Curves
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
An object storing two EC points that represent the inputs to a pairing check.
static uint32_t set_default_to_public(Builder *builder)
Set the witness indices for the default limbs of the pairing points to public.
static PairingPoints aggregate_multiple(std::vector< PairingPoints > &pairing_points, bool handle_edge_cases=true)
Aggregate multiple PairingPoints using random linear combination.
void aggregate(PairingPoints const &other)
Compute a linear combination of the present pairing points with an input set of pairing points.
uint32_t set_public()
Set the witness indices for the pairing points to public.