Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ template <typename Composer> void cycle_group<Composer>::validate_is_on_curve()
auto xx = x * x;
auto xxx = xx * x;
auto res = y.madd(y, -xxx - Group::curve_b);
res *= is_point_at_infinity();
res *= !is_point_at_infinity(); // if the point is marked as the point at infinity, then res should be 0, but
Comment thread
lucasxia01 marked this conversation as resolved.
Outdated
// otherwise, we leave res unchanged
res.assert_is_zero();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,43 @@ template <class Builder> class CycleGroupTest : public ::testing::Test {
using CircuitTypes = ::testing::Types<bb::StandardCircuitBuilder, bb::UltraCircuitBuilder>;
TYPED_TEST_SUITE(CycleGroupTest, CircuitTypes);

TYPED_TEST(CycleGroupTest, TestValidateOnCurveSucceed)
Comment thread
lucasxia01 marked this conversation as resolved.
{
STDLIB_TYPE_ALIASES;
auto builder = Builder();
Comment thread
lucasxia01 marked this conversation as resolved.
Outdated

auto lhs = TestFixture::generators[0];
cycle_group_ct a = cycle_group_ct::from_witness(&builder, lhs);
a.validate_is_on_curve();
EXPECT_FALSE(builder.failed());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend doing the check_circuit, too. failed() doesn't check if constraints hold

}

TYPED_TEST(CycleGroupTest, TestValidateOnCurveInfinitySucceed)
{
STDLIB_TYPE_ALIASES;
auto builder = Builder();

auto x = stdlib::field_t<Builder>::from_witness(&builder, 1);
Comment thread
lucasxia01 marked this conversation as resolved.
auto y = stdlib::field_t<Builder>::from_witness(&builder, 1);

cycle_group_ct a(x, y, true);
Comment thread
lucasxia01 marked this conversation as resolved.
Outdated
a.validate_is_on_curve();
EXPECT_FALSE(builder.failed());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend doing the check_circuit, too. failed() doesn't check if constraints hold

}

TYPED_TEST(CycleGroupTest, TestValidateOnCurveFail)
{
STDLIB_TYPE_ALIASES;
auto builder = Builder();

auto x = stdlib::field_t<Builder>::from_witness(&builder, 1);
auto y = stdlib::field_t<Builder>::from_witness(&builder, 1);

cycle_group_ct a(x, y, false);
a.validate_is_on_curve();
EXPECT_TRUE(builder.failed());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend doing the check_circuit, too. failed() doesn't check if constraints hold

}

TYPED_TEST(CycleGroupTest, TestDbl)
{
STDLIB_TYPE_ALIASES;
Expand Down Expand Up @@ -436,8 +473,8 @@ TYPED_TEST(CycleGroupTest, TestBatchMul)
EXPECT_TRUE(result.is_point_at_infinity().get_value());
}

// case 5, fixed-base MSM with inputs that are combinations of constant and witnesses (group elements are in lookup
// table)
// case 5, fixed-base MSM with inputs that are combinations of constant and witnesses (group elements are in
// lookup table)
{
std::vector<cycle_group_ct> points;
std::vector<typename cycle_group_ct::cycle_scalar> scalars;
Expand Down Expand Up @@ -465,8 +502,8 @@ TYPED_TEST(CycleGroupTest, TestBatchMul)
EXPECT_EQ(result.get_value(), crypto::pedersen_commitment::commit_native(scalars_native));
}

// case 6, fixed-base MSM with inputs that are combinations of constant and witnesses (some group elements are in
// lookup table)
// case 6, fixed-base MSM with inputs that are combinations of constant and witnesses (some group elements are
// in lookup table)
{
std::vector<cycle_group_ct> points;
std::vector<typename cycle_group_ct::cycle_scalar> scalars;
Expand Down