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