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
9using EmbeddedCurvePoint = StandardAffinePoint<grumpkin::g1::affine_element>;
10using Fr = grumpkin::fr;
11using Fq = grumpkin::fq;
12
13TEST(StandardAffinePointTest, ConstructingInfinityNormalized)
14{
15 // Constructing a point with (0,0) coordinates should result in infinity
16 EmbeddedCurvePoint inf(0, 0);
17 EXPECT_TRUE(inf.is_infinity());
18 // Constructing a point with BB's inf should result in infinity with (0,0) coordinates
19 EmbeddedCurvePoint inf_bb(grumpkin::g1::affine_element::infinity());
20 EXPECT_TRUE(inf_bb.is_infinity());
21 EXPECT_TRUE(inf_bb.x().is_zero());
22 EXPECT_TRUE(inf_bb.y().is_zero());
23 EXPECT_EQ(inf, inf_bb);
24}
25
26TEST(StandardAffinePointTest, NormalPointCoordinates)
27{
28 // Normal (non-infinity) points should return their coordinates
29 auto one = EmbeddedCurvePoint::one();
30 EXPECT_FALSE(one.is_infinity());
31 EXPECT_FALSE(one.x().is_zero());
32 EXPECT_FALSE(one.y().is_zero());
33}
34
35TEST(StandardAffinePointTest, AdditionResultingInInfinityNormalized)
36{
37 // When addition produces infinity, result should have (0,0) coordinates
38 auto p = EmbeddedCurvePoint::one();
39 auto neg_p = -p;
40
41 auto inf_result = p + neg_p;
42
43 EXPECT_TRUE(inf_result.is_infinity());
44 EXPECT_TRUE(inf_result.x().is_zero());
45 EXPECT_TRUE(inf_result.y().is_zero());
46}
47
48TEST(StandardAffinePointTest, SubtractingInfinityNormalized)
49{
50 // Subtracting a point from itself should yield infinity with (0,0) coordinates
51 auto p = EmbeddedCurvePoint::one();
53
54 auto result = p + (-inf);
55
56 EXPECT_EQ(result, p);
57}
58
59TEST(StandardAffinePointTest, ScalarMultiplicationResultingInInfinityNormalized)
60{
61 // When scalar multiplication produces infinity, result should have (0,0) coordinates
62 auto p = EmbeddedCurvePoint::one();
63 Fr zero_scalar = Fr::zero();
64
65 auto inf_result = p * zero_scalar;
66
67 EXPECT_TRUE(inf_result.is_infinity());
68 EXPECT_TRUE(inf_result.x().is_zero());
69 EXPECT_TRUE(inf_result.y().is_zero());
70}
71
72TEST(StandardAffinePointTest, StaticInfinityHasZeroCoordinates)
73{
74 // The static infinity() method should return (0,0)
75 auto& inf = EmbeddedCurvePoint::infinity();
76
77 EXPECT_TRUE(inf.is_infinity());
78 EXPECT_TRUE(inf.x().is_zero());
79 EXPECT_TRUE(inf.y().is_zero());
80}
81
82TEST(StandardAffinePointTest, NegatingInfinity)
83{
84 // Negating an infinity point should return (0,0)
85 auto neg_inf = -EmbeddedCurvePoint::infinity();
86
87 EXPECT_TRUE(neg_inf.is_infinity());
88 EXPECT_TRUE(neg_inf.x().is_zero());
89 EXPECT_TRUE(neg_inf.y().is_zero());
90}
91
92} // namespace
93} // namespace bb::avm2
StandardAffinePoint< AvmFlavorSettings::EmbeddedCurve::AffineElement > EmbeddedCurvePoint
Definition field.hpp:12
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
static constexpr field zero()