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
15template <typename AffinePoint> class StandardAffinePoint {
16 public:
19
20 constexpr StandardAffinePoint() noexcept = default;
21
22 constexpr StandardAffinePoint(AffinePoint val) noexcept
23 : point(val)
24 , x_coord(val.x)
25 , y_coord(val.y)
26 {}
27
33
34 constexpr StandardAffinePoint operator+(const StandardAffinePoint& other) const noexcept
35 {
36 AffinePoint result = point + other.point;
37 if (result.is_point_at_infinity()) {
38 // If the result is infinity, we need to normalise it to (0,0) to match noir outputs.
39 return StandardAffinePoint::infinity();
40 }
41 return StandardAffinePoint(result);
42 }
43
44 constexpr StandardAffinePoint operator*(const ScalarField& exponent) const noexcept
45 {
46 AffinePoint result = point * exponent;
47 if (result.is_point_at_infinity()) {
48 // If the result is infinity, we need to normalise it to (0,0) to match noir outputs.
49 return StandardAffinePoint::infinity();
50 }
51 return StandardAffinePoint(result);
52 }
53
54 constexpr bool operator==(const StandardAffinePoint& other) const noexcept
55 {
56 return (this == &other || point == other.point);
57 }
58
59 constexpr StandardAffinePoint operator-() const noexcept
60 {
61 // Negating infinity returns itself, preserving raw coordinates.
63 return *this;
64 }
66 }
67
68 [[nodiscard]] constexpr bool is_infinity() const noexcept { return point.is_point_at_infinity(); }
69
70 [[nodiscard]] constexpr bool on_curve() const noexcept { return point.on_curve(); }
71
72 // Always returns the raw coordinates, when an operation results in infinity these will be (0,0).
73 // If a point at infinity is constructed with non-zero coordinates, we likely want to preserve those.
74 constexpr const BaseField& x() const noexcept { return x_coord; }
75
76 constexpr const BaseField& y() const noexcept { return y_coord; }
77
79 {
80 static auto infinity = StandardAffinePoint(zero, zero, true);
81 return infinity;
82 }
83
84 static const StandardAffinePoint& one()
85 {
87 return one;
88 }
89
90 private:
91 // The affine point for operations, this will always match the raw coordinates unless the point is infinity.
92 // In that case, the point will be set to barretenberg's infinity representation - which is not (0,0).
94 // These are the raw x and y coordinates, that are set when constructing the point. When an operation results
95 // in infinity, these will be set to (0,0) to match noir's expected representation.
98 static constexpr const auto zero = BaseField::zero();
99};
100
101template <typename T> std::ostream& operator<<(std::ostream& os, const StandardAffinePoint<T>& point)
102{
103 os << "StandardAffinePoint(" << point.x() << ", " << point.y() << ", " << point.is_infinity() << ")";
104 return os;
105}
106
107} // 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(BaseField x, BaseField y, bool is_infinity) noexcept
constexpr StandardAffinePoint() noexcept=default
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:488