Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
standard_affine_point.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <ostream>
5
6namespace bb::avm2 {
7
19template <typename AffinePoint> class StandardAffinePoint {
20 public:
23
24 constexpr StandardAffinePoint() noexcept = default;
25
26 constexpr StandardAffinePoint(AffinePoint val) noexcept
27 : point(val)
28 , x_coord(val.is_point_at_infinity() ? zero : val.x)
29 , y_coord(val.is_point_at_infinity() ? zero : val.y)
30 {}
31
33 : point((x.is_zero() && y.is_zero()) ? AffinePoint::infinity() : AffinePoint(x, y))
34 , x_coord(x)
35 , y_coord(y)
36 {}
37
38 constexpr StandardAffinePoint operator+(const StandardAffinePoint& other) const noexcept
39 {
40 AffinePoint result = point + other.point;
41 if (result.is_point_at_infinity()) {
42 // If the result is infinity, we need to normalise it to (0,0) to match noir outputs.
44 }
45 return StandardAffinePoint(result);
46 }
47
48 constexpr StandardAffinePoint operator*(const ScalarField& exponent) const noexcept
49 {
50 AffinePoint result = point * exponent;
51 if (result.is_point_at_infinity()) {
52 // If the result is infinity, we need to normalise it to (0,0) to match noir outputs.
54 }
55 return StandardAffinePoint(result);
56 }
57
58 constexpr bool operator==(const StandardAffinePoint& other) const noexcept
59 {
60 return (this == &other || point == other.point);
61 }
62
63 constexpr StandardAffinePoint operator-() const noexcept
64 {
65 // Negating infinity returns itself, preserving raw coordinates.
67 return *this;
68 }
70 }
71
72 [[nodiscard]] constexpr bool is_infinity() const noexcept { return point.is_point_at_infinity(); }
73
74 [[nodiscard]] constexpr bool on_curve() const noexcept { return point.on_curve(); }
75
76 // Always returns Noir standard coordinates. For the point at infinity this is always (0, 0). If that point was
77 // constructed via AffinePoint with a different representation, those non-zero coordinates are preserved in .point.
78 constexpr const BaseField& x() const noexcept { return x_coord; }
79
80 constexpr const BaseField& y() const noexcept { return y_coord; }
81
83 {
84 static auto infinity = StandardAffinePoint(zero, zero);
85 return infinity;
86 }
87
88 static const StandardAffinePoint& one()
89 {
91 return one;
92 }
93
94 private:
95 // The affine point for operations, this will always match the raw coordinates unless the point is infinity.
96 // In that case, the point will be set to AffinePoint's infinity representation - which may not be (0,0).
98 // These are the raw x and y coordinates, that are set when constructing the point. When an operation results
99 // in infinity, these will be set to (0,0) to match noir's expected representation.
102 static constexpr const auto zero = BaseField::zero();
103};
104
105template <typename T> std::ostream& operator<<(std::ostream& os, const StandardAffinePoint<T>& point)
106{
107 os << "StandardAffinePoint(" << point.x() << ", " << point.y() << ", " << point.is_infinity() << ")";
108 return os;
109}
110
111} // namespace bb::avm2
static const StandardAffinePoint & infinity()
constexpr StandardAffinePoint operator*(const ScalarField &exponent) const noexcept
constexpr StandardAffinePoint operator-() const noexcept
constexpr bool is_infinity() const noexcept
constexpr StandardAffinePoint operator+(const StandardAffinePoint &other) const noexcept
constexpr StandardAffinePoint() noexcept=default
constexpr StandardAffinePoint(BaseField x, BaseField y) noexcept
constexpr const BaseField & x() const noexcept
constexpr const BaseField & y() const noexcept
constexpr bool on_curve() const noexcept
constexpr bool operator==(const StandardAffinePoint &other) const noexcept
static const StandardAffinePoint & one()
static constexpr const auto zero
constexpr bool is_point_at_infinity() const noexcept
static constexpr affine_element infinity()
constexpr bool on_curve() const noexcept
static constexpr affine_element one() noexcept
std::ostream & operator<<(std::ostream &os, const CoarseTransactionPhase &phase)
Definition avm_io.hpp:490