Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
standard_affine_point.test.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
2
5
6namespace bb::avm2 {
7namespace {
8
10using Fr = grumpkin::fr;
11using Fq = grumpkin::fq;
12
13TEST(StandardAffinePointTest, InfinityPreservesRawCoordinates)
14{
15 // When constructing an infinity point with non-zero coordinates,
16 // x() and y() should return the raw coordinates
17 Fq raw_x = 1;
18 Fq raw_y = 2;
19
20 EmbeddedCurvePoint point(raw_x, raw_y, /*is_infinity=*/true);
21
22 EXPECT_TRUE(point.is_infinity());
23 EXPECT_EQ(point.x(), raw_x);
24 EXPECT_EQ(point.y(), raw_y);
25}
26
27TEST(StandardAffinePointTest, NormalPointCoordinates)
28{
29 // Normal (non-infinity) points should return their coordinates
30 auto one = EmbeddedCurvePoint::one();
31 EXPECT_FALSE(one.is_infinity());
32 EXPECT_FALSE(one.x().is_zero());
33 EXPECT_FALSE(one.y().is_zero());
34}
35
36TEST(StandardAffinePointTest, AdditionResultingInInfinityNormalized)
37{
38 // When addition produces infinity, result should have (0,0) coordinates
39 auto p = EmbeddedCurvePoint::one();
40 auto neg_p = -p;
41
42 auto inf_result = p + neg_p;
43
44 EXPECT_TRUE(inf_result.is_infinity());
45 EXPECT_TRUE(inf_result.x().is_zero());
46 EXPECT_TRUE(inf_result.y().is_zero());
47}
48
49TEST(StandardAffinePointTest, SubtractingInfinityNormalized)
50{
51 // Subtracting a point from itself should yield infinity with (0,0) coordinates
52 auto p = EmbeddedCurvePoint::one();
54
55 auto result = p + (-inf);
56
57 EXPECT_EQ(result, p);
58}
59
60TEST(StandardAffinePointTest, ScalarMultiplicationResultingInInfinityNormalized)
61{
62 // When scalar multiplication produces infinity, result should have (0,0) coordinates
63 auto p = EmbeddedCurvePoint::one();
64 Fr zero_scalar = Fr::zero();
65
66 auto inf_result = p * zero_scalar;
67
68 EXPECT_TRUE(inf_result.is_infinity());
69 EXPECT_TRUE(inf_result.x().is_zero());
70 EXPECT_TRUE(inf_result.y().is_zero());
71}
72
73TEST(StandardAffinePointTest, StaticInfinityHasZeroCoordinates)
74{
75 // The static infinity() method should return (0,0,true)
76 auto& inf = EmbeddedCurvePoint::infinity();
77
78 EXPECT_TRUE(inf.is_infinity());
79 EXPECT_TRUE(inf.x().is_zero());
80 EXPECT_TRUE(inf.y().is_zero());
81}
82
83TEST(StandardAffinePointTest, NegatingInfinityPreservesRawCoordinates)
84{
85 // Negating an infinity point should preserve its raw coordinates
86 Fq raw_x = 1;
87 Fq raw_y = 2;
88 EmbeddedCurvePoint inf(raw_x, raw_y, /*is_infinity=*/true);
89
90 auto neg_inf = -inf;
91
92 EXPECT_TRUE(neg_inf.is_infinity());
93 EXPECT_EQ(neg_inf.x(), raw_x);
94 EXPECT_EQ(neg_inf.y(), raw_y);
95}
96
97} // namespace
98} // namespace bb::avm2
avm2::StandardAffinePoint< AffinePoint > StandardAffinePoint
StandardAffinePoint< AvmFlavorSettings::EmbeddedCurve::AffineElement > EmbeddedCurvePoint
Definition field.hpp:12
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
static constexpr field zero()