7#include <gtest/gtest.h>
21 static constexpr size_t NUM_GATES_ADDED = 20;
23 typename TypeParam::Builder
builder;
25 size_t num_gates =
builder.num_gates();
27 EXPECT_EQ(NUM_GATES_ADDED,
builder.num_gates() - num_gates)
28 <<
"There has been a change in the number of gates required to set default PairingPoints as public inputs.";
35 using Builder = TypeParam::Builder;
41 Group P0(DEFAULT_PAIRING_POINTS_P0_X, DEFAULT_PAIRING_POINTS_P0_Y,
false);
42 Group P1(DEFAULT_PAIRING_POINTS_P1_X, DEFAULT_PAIRING_POINTS_P1_Y,
false);
43 P0.convert_constant_to_fixed_witness(&
builder);
44 P1.convert_constant_to_fixed_witness(&
builder);
52 EXPECT_TRUE(native_pp.
check()) <<
"Default PairingPoints are not valid pairing points.";
57 using Curve = TypeParam;
58 using Builder =
typename Curve::Builder;
62 using NativeFr =
typename Curve::ScalarFieldNative;
66 Fr scalar_one = Fr::from_witness(&
builder, NativeFr::random_element());
67 Fr scalar_two = Fr::from_witness(&
builder, NativeFr::random_element());
68 Group P0 = Group::batch_mul({ Group::one(&
builder) }, { scalar_one });
69 Group P1 = Group::batch_mul({ Group::one(&
builder) }, { scalar_two });
72 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
82 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
89 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
100 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
112 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
118 using Curve = TypeParam;
119 using Builder =
typename Curve::Builder;
123 using NativeFr =
typename Curve::ScalarFieldNative;
129 Fr scalar_one = Fr::from_witness(&
builder, NativeFr::random_element());
130 Fr scalar_two = Fr::from_witness(&
builder, NativeFr::random_element());
131 Group P0 = Group::batch_mul({ Group::one(&
builder) }, { scalar_one });
132 Group P1 = Group::batch_mul({ Group::one(&
builder) }, { scalar_two });
144 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
147 pp_one.aggregate(pp_two);
150 EXPECT_FALSE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
155 "Pairing points must all be aggregated together. Either no pairing points should be created, or "
156 "all created pairing points must be aggregated into a single pairing point. Found 2 different "
160 pp_one.aggregate(pp_three);
165 "Pairing points must be set to public in the circuit before constructing the ProverInstance.");
177 using Curve = TypeParam;
178 using Builder =
typename Curve::Builder;
183 using NativeFr = Curve::ScalarFieldNative;
187 Fr scalar_one = Fr::from_witness(&
builder, NativeFr::random_element());
188 Fr scalar_two = Fr::from_witness(&
builder, NativeFr::random_element());
189 Group P0 = Group::batch_mul({ Group::one(&
builder) }, { scalar_one });
190 Group P1 = Group::batch_mul({ Group::one(&
builder) }, { scalar_two });
196 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
205 using Curve = TypeParam;
206 using Builder =
typename Curve::Builder;
213 Group P0(DEFAULT_PAIRING_POINTS_P0_X, DEFAULT_PAIRING_POINTS_P0_Y,
false);
214 Group P1(DEFAULT_PAIRING_POINTS_P1_X, DEFAULT_PAIRING_POINTS_P1_Y,
false);
215 P0.convert_constant_to_fixed_witness(&
builder);
216 P1.convert_constant_to_fixed_witness(&
builder);
234 EXPECT_TRUE(
builder.pairing_points_tagging.has_single_pairing_point_tag());
240 for (
size_t idx = 0; idx < 3; ++idx) {
242 transcript.add_to_hash_buffer(
"second_component_" +
std::to_string(idx), pp_vector[idx].P1);
245 std::array<Fr, 2> challenges = transcript.template get_challenges<Fr, 2>(challenge_labels);
248 Fr total_scalar =
Fr(1);
249 for (
const auto& challenge : challenges) {
250 total_scalar += challenge;
252 Group expected_P0 = P0 * total_scalar;
253 Group expected_P1 = P1 * total_scalar;
256 EXPECT_EQ(aggregated.
P0.get_value(), expected_P0.get_value()) <<
"Aggregated P0 should equal (1 + r₁ + r₂)·P0";
257 EXPECT_EQ(aggregated.
P1.get_value(), expected_P1.get_value()) <<
"Aggregated P1 should equal (1 + r₁ + r₂)·P1";
261 aggregated.
P1.get_value());
262 EXPECT_TRUE(native_aggregated.
check())
263 <<
"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 limbs of the pairing points to public.