21template <
typename Fq_,
typename Fr_,
typename Params_>
class alignas(64)
affine_element {
49 static constexpr
affine_element one() noexcept {
return { Params::one_x, Params::one_y }; };
60 template <
typename BaseField =
Fq,
73 template <
typename BaseField =
Fq,
85 template <
typename BaseField =
Fq,
95 [[nodiscard]] constexpr
bool on_curve() const noexcept;
108 constexpr
bool operator==(const
affine_element& other) const noexcept;
127 if (
value.is_point_at_infinity()) {
130 memset(
buffer, 255,
sizeof(
Fq) * 2);
175 [[nodiscard]]
inline std::vector<uint8_t>
to_buffer()
const
198 os <<
"{ " <<
a.x <<
", " <<
a.y <<
" }";
217 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL
219 raw_element = { all_ones, all_ones };
222 raw_element = {
x,
y };
224 packer.pack(raw_element);
232 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL, 0xffffffffffffffffUL
234 if (raw_element.
x == all_ones && raw_element.
y == all_ones) {
246 if (packer.set_emitted(
"affine_element")) {
247 packer.pack(
"affine_element");
251 packer.pack(
"__typename");
252 packer.pack(
"affine_element");
254 packer.pack_schema(
x);
256 packer.pack_schema(
y);
260template <
typename B,
typename Fq_,
typename Fr_,
typename Params>
270template <
typename B,
typename Fq_,
typename Fr_,
typename Params>
#define ASSERT(expression,...)
void msgpack_unpack(auto o)
friend std::ostream & operator<<(std::ostream &os, const affine_element &a)
static constexpr std::array< affine_element, 2 > from_compressed_unsafe(const uint256_t &compressed) noexcept
Reconstruct a point in affine coordinates from compressed form.
constexpr bool is_point_at_infinity() const noexcept
constexpr affine_element & operator=(const affine_element &other) noexcept=default
static constexpr affine_element hash_to_curve(const std::vector< uint8_t > &seed, uint8_t attempt_count=0) noexcept
Hash a seed buffer into a point.
static affine_element infinity()
static affine_element random_element(numeric::RNG *engine=nullptr) noexcept
Samples a random point on the curve.
std::vector< uint8_t > to_buffer() const
Serialize the point to a byte vector.
void msgpack_pack(auto &packer) const
const uint8_t * vec_in_buf
constexpr uint256_t compress() const noexcept
static affine_element serialize_from_buffer(const uint8_t *buffer, bool write_x_first=false)
Restore point from a buffer.
constexpr void self_set_infinity() noexcept
constexpr affine_element & operator=(affine_element &&other) noexcept=default
constexpr bool operator<(const affine_element &other) const noexcept
static affine_element reconstruct_from_public(const std::span< const bb::fr, PUBLIC_INPUTS_SIZE > &limbs)
constexpr affine_element operator+(const affine_element &other) const noexcept
static constexpr affine_element from_compressed(const uint256_t &compressed) noexcept
Reconstruct a point in affine coordinates from compressed form.
constexpr bool on_curve() const noexcept
affine_element() noexcept=default
static constexpr affine_element one() noexcept
static constexpr size_t PUBLIC_INPUTS_SIZE
static constexpr std::optional< affine_element > derive_from_x_coordinate(const Fq &x, bool sign_bit) noexcept
static void serialize_to_buffer(const affine_element &value, uint8_t *buffer, bool write_x_first=false)
Serialize the point to the given buffer.
constexpr bool operator>(const affine_element &other) const noexcept
constexpr affine_element operator*(const Fr &exponent) const noexcept
void msgpack_schema(auto &packer) const
constexpr affine_element set_infinity() const noexcept
element class. Implements ecc group arithmetic using Jacobian coordinates See https://hyperelliptic....
uint8_t buffer[RANDOM_BUFFER_SIZE]
void read(B &it, group_elements::affine_element< Fq_, Fr_, Params > &element)
void write(B &it, group_elements::affine_element< Fq_, Fr_, Params > const &element)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr size_t PUBLIC_INPUTS_SIZE
static field reconstruct_from_public(const std::span< const field< V >, PUBLIC_INPUTS_SIZE > &limbs)